Skip to content

Commit fcd8a15

Browse files
[Th2-5165] Cradle API uses page day cache (#3)
* Transformed Unit tests to integration * Updated github workflow --------- Co-authored-by: Oleg Smirnov <[email protected]>
1 parent 54781d6 commit fcd8a15

30 files changed

+1113
-1193
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
name: Build and release Docker image.
1+
name: Build and publish dev release Docker image to Github Container Registry ghcr.io
22

3-
on:
4-
push:
5-
tags:
6-
- \d+.\d+.\d+-dev
3+
on: workflow_dispatch
74

85
jobs:
96
build:
107
uses: th2-net/.github/.github/workflows/compound-java.yml@main
118
with:
129
build-target: 'Docker'
13-
runsOn: ubuntu-latest
14-
gradleVersion: '7'
15-
docker-username: ${{ github.actor }}
1610
devRelease: true
11+
createTag: true
12+
docker-username: ${{ github.actor }}
1713
secrets:
18-
docker-password: ${{ secrets.GITHUB_TOKEN }}
14+
docker-password: ${{ secrets.GITHUB_TOKEN }}

Diff for: .github/workflows/build-release.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Build and publish release Docker image to Github Container Registry ghcr.io
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
build:
7+
uses: th2-net/.github/.github/workflows/compound-java.yml@main
8+
with:
9+
build-target: 'Docker'
10+
devRelease: false
11+
createTag: true
12+
docker-username: ${{ github.actor }}
13+
secrets:
14+
docker-password: ${{ secrets.GITHUB_TOKEN }}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
name: Dev build and publish Docker image
1+
name: Build and publish Docker image to Github Container Registry ghcr.io
22

33
on:
44
push:
55
branches-ignore:
66
- master
77
- version-*
8-
- dependabot*
8+
- dependabot**
99
paths-ignore:
1010
- README.md
11-
# paths:
12-
# - gradle.properties
1311

1412
jobs:
1513
build-job:
1614
uses: th2-net/.github/.github/workflows/compound-java-dev.yml@main
1715
with:
1816
build-target: 'Docker'
19-
runsOn: ubuntu-latest
20-
gradleVersion: '7'
2117
docker-username: ${{ github.actor }}
2218
secrets:
23-
docker-password: ${{ secrets.GITHUB_TOKEN }}
24-
25-
26-
19+
docker-password: ${{ secrets.GITHUB_TOKEN }}

Diff for: .github/workflows/integration-tests.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Run integration tests for cradle admin tool"
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
8+
jobs:
9+
tests:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up JDK 'zulu' '11'
14+
uses: actions/setup-java@v3
15+
with:
16+
distribution: 'zulu'
17+
java-version: '11'
18+
- name: Setup Gradle
19+
uses: gradle/gradle-build-action@v2
20+
- name: Build with Gradle
21+
run: ./gradlew --info clean integrationTest
22+
- uses: actions/upload-artifact@v3
23+
if: failure()
24+
with:
25+
name: integration-test-results
26+
path: build/reports/tests/integrationTest/

Diff for: .github/workflows/java-publish-docker.yml

-20
This file was deleted.

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/.gradle/
22
/logs
33
/.settings
4-
/bin
54
**/build
65
/schema
76
/.idea
7+
bin/

Diff for: build.gradle

+23-11
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ apply plugin: 'application'
1212

1313

1414
ext {
15-
commonVersion = '5.4.2-dev'
16-
cradleVersion = '5.1.4-dev'
15+
commonVersion = '5.8.0-dev'
16+
cradleVersion = '5.2.0-dev'
1717
}
1818

1919
allprojects {
@@ -51,21 +51,33 @@ allprojects {
5151
}
5252
implementation "com.exactpro.th2:cradle-core:$cradleVersion"
5353
implementation "com.exactpro.th2:cradle-cassandra:$cradleVersion"
54-
implementation 'org.apache.commons:commons-lang3:3.12.0'
54+
implementation 'org.apache.commons:commons-lang3'
5555

5656
implementation "org.slf4j:slf4j-api"
5757

58-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
59-
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2'
60-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
58+
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
59+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
6160

62-
testImplementation 'org.mockito:mockito-inline:4.10.0'
63-
testImplementation 'org.mockito:mockito-junit-jupiter:4.10.0'
61+
testImplementation 'org.mockito:mockito-inline:5.2.0'
62+
testImplementation 'org.mockito:mockito-junit-jupiter:5.10.0'
63+
testImplementation 'com.exactpro.th2:junit-jupiter-integration:0.0.1-master-6956603819-5241ee5-SNAPSHOT'
64+
}
65+
66+
test {
67+
useJUnitPlatform {
68+
excludeTags('integration')
69+
}
6470
}
65-
}
6671

67-
test {
68-
useJUnitPlatform()
72+
tasks.register('integrationTest', Test) {
73+
group = 'verification'
74+
useJUnitPlatform {
75+
includeTags('integration')
76+
}
77+
testLogging {
78+
showStandardStreams = true
79+
}
80+
}
6981
}
7082

7183
dependencyLocking {

Diff for: cradle-admin-tool-cli/build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ dependencies {
66
testImplementation project(':').sourceSets.test.output
77
}
88

9-
test {
10-
useJUnitPlatform()
11-
}
12-
139
jar {
1410
archivesBaseName = 'th2-cradle-admin-cli'
1511
manifest {

Diff for: cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/Application.java

+30-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 Exactpro (Exactpro Systems Limited)
2+
* Copyright 2021-2024 Exactpro (Exactpro Systems Limited)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@
4141
import java.util.Optional;
4242
import java.util.Spliterator;
4343
import java.util.Spliterators;
44+
import java.util.function.Function;
4445
import java.util.jar.Attributes;
4546
import java.util.jar.JarFile;
4647
import java.util.jar.Manifest;
@@ -56,34 +57,43 @@ public class Application {
5657
private static String BUILD_DATE;
5758

5859

59-
public static void main(String[] args) throws Exception {
60+
public static void main(String[] args) {
61+
run(args, CommonFactory::createFromArguments);
62+
}
6063

61-
initApplication(args);
62-
Options options = buildOptions();
63-
64-
CommandLine cmdLine = new DefaultParser().parse(options, args);
64+
static void run(String[] args, Function<String[], CommonFactory> createFactory) {
65+
try {
66+
initApplication(args);
67+
Options options = buildOptions();
68+
try {
6569

66-
try (CommonFactory commonFactory = CommonFactory.createFromArguments(buildSchemaParams(cmdLine))) {
67-
68-
AbstractMode<?, ?> mode = Mode.getMode(cmdLine);
69-
if (mode instanceof CliMode && !((CliMode<?>)mode).initParams(cmdLine)) {
70-
return;
71-
}
7270

73-
try (CradleManager mngr = commonFactory.getCradleManager()) {
71+
CommandLine cmdLine = new DefaultParser().parse(options, args);
72+
73+
try (CommonFactory commonFactory = createFactory.apply(buildSchemaParams(cmdLine))) {
7474

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

80+
try (CradleManager manager = commonFactory.getCradleManager()) {
81+
82+
CradleStorage storage = manager.getStorage();
83+
mode.init(storage);
84+
SimpleResult result = mode.execute();
85+
ResultPrinter.printToCmd(result);
86+
87+
}
88+
}
89+
} catch (Exception e) {
90+
logger.error("Cannot start application, cause {}", e.getMessage(), e);
91+
printHelp(options);
8092
}
8193
} catch (Exception e) {
82-
logger.error("Cannot start application, cause {}", e.getMessage(), e);
83-
printHelp(options);
94+
logger.error("Cannot init application, cause {}", e.getMessage(), e);
8495
}
8596
}
86-
8797
private static Options buildOptions() {
8898
Options options = new Options();
8999
options.addOption(new Option(CmdParams.COMMON_CFG_SHORT, CmdParams.COMMON_CFG_LONG, true, null));

Diff for: cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/ResultPrinter.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/*******************************************************************************
2-
* Copyright 2021-2021 Exactpro (Exactpro Systems Limited)
1+
/*
2+
* Copyright 2021-2024 Exactpro (Exactpro Systems Limited)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,11 @@
1616

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

19-
import com.exactpro.cradle.BookListEntry;
20-
import com.exactpro.th2.cradle.adm.results.*;
19+
import com.exactpro.th2.cradle.adm.results.BooksListInfo;
20+
import com.exactpro.th2.cradle.adm.results.ResultBookDetailedInfo;
21+
import com.exactpro.th2.cradle.adm.results.ResultBookInfo;
22+
import com.exactpro.th2.cradle.adm.results.ResultPageInfo;
23+
import com.exactpro.th2.cradle.adm.results.SimpleResult;
2124

2225
import java.util.List;
2326

Diff for: cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/AbstractCliTest.java

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/*******************************************************************************
2-
* Copyright 2022 Exactpro (Exactpro Systems Limited)
1+
/*
2+
* Copyright 2022-2024 Exactpro (Exactpro Systems Limited)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -12,33 +12,54 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
******************************************************************************/
15+
*/
1616

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

19+
import com.exactpro.cradle.CradleManager;
20+
import com.exactpro.th2.cradle.adm.TestBookPageBuilder;
21+
import com.exactpro.th2.test.annotations.Th2IntegrationTest;
22+
import com.exactpro.th2.test.spec.CradleSpec;
1923
import org.junit.jupiter.api.AfterEach;
2024
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.BeforeAll;
2126
import org.junit.jupiter.api.BeforeEach;
2227

2328
import java.io.ByteArrayOutputStream;
2429
import java.io.PrintStream;
2530
import java.util.Arrays;
2631
import java.util.regex.Pattern;
2732

33+
@Th2IntegrationTest
2834
public class AbstractCliTest {
29-
3035
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}$");
36+
protected ByteArrayOutputStream outContent;
37+
protected ByteArrayOutputStream errContent;
38+
39+
protected TestBookPageBuilder testBookPageBuilder;
40+
private PrintStream originalOut;
41+
private PrintStream originalErr;
3142

32-
protected final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
33-
protected final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
34-
private final PrintStream originalOut = System.out;
35-
private final PrintStream originalErr = System.err;
43+
@SuppressWarnings("unused")
44+
public final CradleSpec cradleSpec = CradleSpec.Companion.create()
45+
.disableAutoPages()
46+
.reuseKeyspace();
3647

37-
public static final String INITIAL_BOOK = "init_book";
38-
public static final String INITIAL_PAGE = "init_page";
48+
@BeforeAll
49+
public static void initStorage(CradleManager manager) {
50+
// init database schema
51+
manager.getStorage();
52+
}
3953

4054
@BeforeEach
4155
public void before() {
56+
testBookPageBuilder = TestBookPageBuilder.builder();
57+
58+
outContent = new ByteArrayOutputStream();
59+
errContent = new ByteArrayOutputStream();
60+
originalOut = System.out;
61+
originalErr = System.err;
62+
4263
System.setOut(new PrintStream(outContent));
4364
System.setErr(new PrintStream(errContent));
4465
}

0 commit comments

Comments
 (0)