Skip to content

Commit

Permalink
[Th2-5165] Cradle API uses page day cache (#3)
Browse files Browse the repository at this point in the history
* Transformed Unit tests to integration
* Updated github workflow

---------

Co-authored-by: Oleg Smirnov <[email protected]>
  • Loading branch information
Nikita-Smirnov-Exactpro and OptimumCode authored Mar 6, 2024
1 parent 54781d6 commit fcd8a15
Show file tree
Hide file tree
Showing 30 changed files with 1,113 additions and 1,193 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
name: Build and release Docker image.
name: Build and publish dev release Docker image to Github Container Registry ghcr.io

on:
push:
tags:
- \d+.\d+.\d+-dev
on: workflow_dispatch

jobs:
build:
uses: th2-net/.github/.github/workflows/compound-java.yml@main
with:
build-target: 'Docker'
runsOn: ubuntu-latest
gradleVersion: '7'
docker-username: ${{ github.actor }}
devRelease: true
createTag: true
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}
docker-password: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Build and publish release Docker image to Github Container Registry ghcr.io

on: workflow_dispatch

jobs:
build:
uses: th2-net/.github/.github/workflows/compound-java.yml@main
with:
build-target: 'Docker'
devRelease: false
createTag: true
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
name: Dev build and publish Docker image
name: Build and publish Docker image to Github Container Registry ghcr.io

on:
push:
branches-ignore:
- master
- version-*
- dependabot*
- dependabot**
paths-ignore:
- README.md
# paths:
# - gradle.properties

jobs:
build-job:
uses: th2-net/.github/.github/workflows/compound-java-dev.yml@main
with:
build-target: 'Docker'
runsOn: ubuntu-latest
gradleVersion: '7'
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}



docker-password: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Run integration tests for cradle admin tool"

on:
push:
branches:
- '*'

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 'zulu' '11'
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Build with Gradle
run: ./gradlew --info clean integrationTest
- uses: actions/upload-artifact@v3
if: failure()
with:
name: integration-test-results
path: build/reports/tests/integrationTest/
20 changes: 0 additions & 20 deletions .github/workflows/java-publish-docker.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/.gradle/
/logs
/.settings
/bin
**/build
/schema
/.idea
bin/
34 changes: 23 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ apply plugin: 'application'


ext {
commonVersion = '5.4.2-dev'
cradleVersion = '5.1.4-dev'
commonVersion = '5.8.0-dev'
cradleVersion = '5.2.0-dev'
}

allprojects {
Expand Down Expand Up @@ -51,21 +51,33 @@ allprojects {
}
implementation "com.exactpro.th2:cradle-core:$cradleVersion"
implementation "com.exactpro.th2:cradle-cassandra:$cradleVersion"
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.apache.commons:commons-lang3'

implementation "org.slf4j:slf4j-api"

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

testImplementation 'org.mockito:mockito-inline:4.10.0'
testImplementation 'org.mockito:mockito-junit-jupiter:4.10.0'
testImplementation 'org.mockito:mockito-inline:5.2.0'
testImplementation 'org.mockito:mockito-junit-jupiter:5.10.0'
testImplementation 'com.exactpro.th2:junit-jupiter-integration:0.0.1-master-6956603819-5241ee5-SNAPSHOT'
}

test {
useJUnitPlatform {
excludeTags('integration')
}
}
}

test {
useJUnitPlatform()
tasks.register('integrationTest', Test) {
group = 'verification'
useJUnitPlatform {
includeTags('integration')
}
testLogging {
showStandardStreams = true
}
}
}

dependencyLocking {
Expand Down
4 changes: 0 additions & 4 deletions cradle-admin-tool-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ dependencies {
testImplementation project(':').sourceSets.test.output
}

test {
useJUnitPlatform()
}

jar {
archivesBaseName = 'th2-cradle-admin-cli'
manifest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 Exactpro (Exactpro Systems Limited)
* Copyright 2021-2024 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,7 @@
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Function;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
Expand All @@ -56,34 +57,43 @@ public class Application {
private static String BUILD_DATE;


public static void main(String[] args) throws Exception {
public static void main(String[] args) {
run(args, CommonFactory::createFromArguments);
}

initApplication(args);
Options options = buildOptions();

CommandLine cmdLine = new DefaultParser().parse(options, args);
static void run(String[] args, Function<String[], CommonFactory> createFactory) {
try {
initApplication(args);
Options options = buildOptions();
try {

try (CommonFactory commonFactory = CommonFactory.createFromArguments(buildSchemaParams(cmdLine))) {

AbstractMode<?, ?> mode = Mode.getMode(cmdLine);
if (mode instanceof CliMode && !((CliMode<?>)mode).initParams(cmdLine)) {
return;
}

try (CradleManager mngr = commonFactory.getCradleManager()) {
CommandLine cmdLine = new DefaultParser().parse(options, args);

try (CommonFactory commonFactory = createFactory.apply(buildSchemaParams(cmdLine))) {

CradleStorage storage = mngr.getStorage();
mode.init(storage);
SimpleResult result = mode.execute();
ResultPrinter.printToCmd(result);
AbstractMode<?, ?> mode = Mode.getMode(cmdLine);
if (mode instanceof CliMode && !((CliMode<?>) mode).initParams(cmdLine)) {
return;
}

try (CradleManager manager = commonFactory.getCradleManager()) {

CradleStorage storage = manager.getStorage();
mode.init(storage);
SimpleResult result = mode.execute();
ResultPrinter.printToCmd(result);

}
}
} catch (Exception e) {
logger.error("Cannot start application, cause {}", e.getMessage(), e);
printHelp(options);
}
} catch (Exception e) {
logger.error("Cannot start application, cause {}", e.getMessage(), e);
printHelp(options);
logger.error("Cannot init application, cause {}", e.getMessage(), e);
}
}

private static Options buildOptions() {
Options options = new Options();
options.addOption(new Option(CmdParams.COMMON_CFG_SHORT, CmdParams.COMMON_CFG_LONG, true, null));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2021-2021 Exactpro (Exactpro Systems Limited)
/*
* Copyright 2021-2024 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,11 @@

package com.exactpro.th2.cradle.adm.cli;

import com.exactpro.cradle.BookListEntry;
import com.exactpro.th2.cradle.adm.results.*;
import com.exactpro.th2.cradle.adm.results.BooksListInfo;
import com.exactpro.th2.cradle.adm.results.ResultBookDetailedInfo;
import com.exactpro.th2.cradle.adm.results.ResultBookInfo;
import com.exactpro.th2.cradle.adm.results.ResultPageInfo;
import com.exactpro.th2.cradle.adm.results.SimpleResult;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2022 Exactpro (Exactpro Systems Limited)
/*
* Copyright 2022-2024 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,33 +12,54 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
*/

package com.exactpro.th2.cradle.adm.cli;

import com.exactpro.cradle.CradleManager;
import com.exactpro.th2.cradle.adm.TestBookPageBuilder;
import com.exactpro.th2.test.annotations.Th2IntegrationTest;
import com.exactpro.th2.test.spec.CradleSpec;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.regex.Pattern;

@Th2IntegrationTest
public class AbstractCliTest {

public static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$");
protected ByteArrayOutputStream outContent;
protected ByteArrayOutputStream errContent;

protected TestBookPageBuilder testBookPageBuilder;
private PrintStream originalOut;
private PrintStream originalErr;

protected final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
protected final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
private final PrintStream originalErr = System.err;
@SuppressWarnings("unused")
public final CradleSpec cradleSpec = CradleSpec.Companion.create()
.disableAutoPages()
.reuseKeyspace();

public static final String INITIAL_BOOK = "init_book";
public static final String INITIAL_PAGE = "init_page";
@BeforeAll
public static void initStorage(CradleManager manager) {
// init database schema
manager.getStorage();
}

@BeforeEach
public void before() {
testBookPageBuilder = TestBookPageBuilder.builder();

outContent = new ByteArrayOutputStream();
errContent = new ByteArrayOutputStream();
originalOut = System.out;
originalErr = System.err;

System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
}
Expand Down
Loading

0 comments on commit fcd8a15

Please sign in to comment.