Skip to content

Commit 0a9f581

Browse files
committed
Setup CI targets for tarantool
- Add new CI targets for the following TNT versions: 1.9, 1.10, 2x, and 2.2 against JDKs versions 8, 11, and 12. - Add assume-style checks to skip Tarantool version incompatible tests. - Update testing tools versions in POM. - Update 'Building' section of README file how to run test w\o SQL part. Closes: #52, #143
1 parent 4c4f1ca commit 0a9f581

14 files changed

+206
-71
lines changed

Diff for: .travis.yml

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@ language: java
33
sudo: required
44
dist: trusty
55

6+
jdk:
7+
- openjdk8
8+
- openjdk11
9+
- openjdk12
10+
11+
env:
12+
- TNT_VERSION=1.9
13+
- TNT_VERSION=1.10
14+
- TNT_VERSION=2x
15+
- TNT_VERSION=2.2
16+
617
stages:
718
- checkstyle
819
- test
920

1021
jobs:
1122
include:
1223
- stage: checkstyle
24+
env: []
1325
jdk: openjdk11
1426
before_script: skip
1527
script: mvn checkstyle:check
1628
after_success: skip
17-
- stage: test
18-
jdk: openjdk8
19-
- stage: test
20-
jdk: openjdk11
21-
- stage: test
22-
jdk: openjdk12
2329

2430
before_script:
2531
- .travis/travis.pre.sh

Diff for: .travis/travis.build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -exu # Strict shell (w/o -o pipefail)
44

5-
if [ "${TRAVIS_JDK_VERSION}" = openjdk11 ]; then
5+
if [ "${TRAVIS_JDK_VERSION}" = "openjdk11" ] && [ "${TNT_VERSION}" = "2.2" ]; then
66
mvn verify jacoco:report
77
else
88
mvn verify

Diff for: .travis/travis.post.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -exu # Strict shell (w/o -o pipefail)
44

5-
if [ "${TRAVIS_JDK_VERSION}" = openjdk11 ]; then
5+
if [ "${TRAVIS_JDK_VERSION}" = "openjdk11" ] && [ "${TNT_VERSION}" = "2.2" ]; then
66
mvn coveralls:report -DrepoToken=${COVERALLS_TOKEN}
77
fi

Diff for: .travis/travis.pre.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
set -exuo pipefail # Strict shell
44

5-
# We need tarantool 2.* for jdbc/sql.
6-
curl http://download.tarantool.org/tarantool/2x/gpgkey | sudo apt-key add -
7-
release=`lsb_release -c -s`
5+
curl http://download.tarantool.org/tarantool/${TNT_VERSION}/gpgkey | sudo apt-key add -
6+
RELEASE=`lsb_release -c -s`
87

98
sudo rm -f /etc/apt/sources.list.d/*tarantool*.list
10-
sudo tee /etc/apt/sources.list.d/tarantool_2x.list <<- EOF
11-
deb http://download.tarantool.org/tarantool/2x/ubuntu/ $release main
12-
deb-src http://download.tarantool.org/tarantool/2x/ubuntu/ $release main
9+
sudo tee /etc/apt/sources.list.d/tarantool_${TNT_VERSION/./_}.list <<- EOF
10+
deb http://download.tarantool.org/tarantool/${TNT_VERSION}/ubuntu/ ${RELEASE} main
11+
deb-src http://download.tarantool.org/tarantool/${TNT_VERSION}/ubuntu/ ${RELEASE} main
1312
EOF
1413

1514
sudo apt-get update

Diff for: README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,14 @@ base for possible answers and solutions.
281281
282282
## Building
283283
284-
To run tests
285-
```
284+
To run unit tests use:
285+
286+
```bash
286287
./mvnw clean test
288+
```
289+
290+
To run integration tests use:
291+
292+
```bash
293+
./mvnw clean verify
287294
```

Diff for: pom.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
<packaging>jar</packaging>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10-
<junit.jupiter.version>5.3.1</junit.jupiter.version>
10+
<junit.jupiter.version>5.4.2</junit.jupiter.version>
11+
<snakeyml.version>1.23</snakeyml.version>
12+
<mockito.version>1.10.19</mockito.version>
1113
</properties>
1214
<name>Tarantool Connector for Java</name>
1315
<url>https://github.com/tarantool/tarantool-java</url>
@@ -79,12 +81,12 @@
7981
</plugin>
8082
<plugin>
8183
<artifactId>maven-surefire-plugin</artifactId>
82-
<version>2.22.0</version>
84+
<version>3.0.0-M3</version>
8385
</plugin>
8486
<plugin>
8587
<groupId>org.apache.maven.plugins</groupId>
8688
<artifactId>maven-failsafe-plugin</artifactId>
87-
<version>2.22.0</version>
89+
<version>3.0.0-M3</version>
8890
<executions>
8991
<execution>
9092
<goals>
@@ -172,13 +174,13 @@
172174
<dependency>
173175
<groupId>org.mockito</groupId>
174176
<artifactId>mockito-all</artifactId>
175-
<version>1.9.5</version>
177+
<version>${mockito.version}</version>
176178
<scope>test</scope>
177179
</dependency>
178180
<dependency>
179181
<groupId>org.yaml</groupId>
180182
<artifactId>snakeyaml</artifactId>
181-
<version>1.23</version>
183+
<version>${snakeyml.version}</version>
182184
<scope>test</scope>
183185
</dependency>
184186
</dependencies>

Diff for: src/test/java/org/tarantool/AbstractTarantoolOpsIT.java

+30-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.tarantool.TestAssumptions.assumeMaximalServerVersion;
7+
import static org.tarantool.TestAssumptions.assumeMinimalServerVersion;
68

79
import org.junit.jupiter.api.Test;
810
import org.junit.jupiter.api.function.Executable;
@@ -371,23 +373,38 @@ public void execute() throws Throwable {
371373
}
372374

373375
@Test
374-
public void testInsertInvalidData() {
376+
void testInsertInvalidData() {
375377
// Invalid types.
376-
TarantoolException ex = assertThrows(TarantoolException.class, new Executable() {
377-
@Override
378-
public void execute() throws Throwable {
379-
getOps().insert(SPACE_ID, Arrays.asList("one", 1));
380-
}
381-
});
378+
TarantoolException ex = assertThrows(
379+
TarantoolException.class,
380+
() -> getOps().insert(SPACE_ID, Arrays.asList("one", 1))
381+
);
382382
assertEquals("Tuple field 1 type does not match one required by operation: expected integer", ex.getMessage());
383+
}
384+
385+
@Test
386+
public void testInsertInvalidTupleSize2xVersion() {
387+
assumeMinimalServerVersion(console, ServerVersion.V_2_1);
383388

384389
// Invalid tuple size.
385-
ex = assertThrows(TarantoolException.class, new Executable() {
386-
@Override
387-
public void execute() throws Throwable {
388-
getOps().insert(SPACE_ID, Collections.singletonList(101));
389-
}
390-
});
390+
TarantoolException ex = assertThrows(
391+
TarantoolException.class,
392+
() -> getOps().insert(SPACE_ID, Collections.singletonList(101))
393+
);
391394
assertEquals("Tuple field 2 required by space format is missing", ex.getMessage());
392395
}
396+
397+
@Test
398+
public void testInsertInvalidTupleSize1xVersion() {
399+
assumeMaximalServerVersion(console, ServerVersion.V_1_10);
400+
401+
// Invalid tuple size.
402+
TarantoolException ex = assertThrows(
403+
TarantoolException.class,
404+
() -> getOps().insert(SPACE_ID, Collections.singletonList(101))
405+
);
406+
assertEquals("Tuple field count 1 is less than required by space format or defined indexes " +
407+
"(expected at least 2)", ex.getMessage());
408+
}
409+
393410
}

Diff for: src/test/java/org/tarantool/AbstractTarantoolSQLConnectorIT.java

+1-24
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public abstract class AbstractTarantoolSQLConnectorIT {
2626
protected static final String LUA_FILE = "jdk-testing.lua";
2727
protected static final int LISTEN = 3301;
2828
protected static final int ADMIN = 3313;
29-
protected static final int TIMEOUT = 500;
3029
protected static final int RESTART_TIMEOUT = 2000;
3130

3231
protected static final SocketChannelProvider socketChannelProvider = new TestSocketChannelProvider(
@@ -36,46 +35,24 @@ public abstract class AbstractTarantoolSQLConnectorIT {
3635
protected static TarantoolControl control;
3736
protected static TarantoolConsole console;
3837

39-
protected static final String TABLE_NAME = "sql_test";
40-
41-
private static final String[] setupScript = new String[] {
42-
"\\set language sql",
43-
"\\set delimiter ;",
44-
45-
"CREATE TABLE sql_test (id INTEGER PRIMARY KEY, val VARCHAR(100));",
46-
"CREATE UNIQUE INDEX sql_test_val_index_unique ON sql_test (val);",
47-
48-
"INSERT INTO sql_test VALUES (1, 'A');",
49-
"INSERT INTO sql_test VALUES (2, 'B');",
50-
"INSERT INTO sql_test VALUES (3, 'C');",
51-
};
52-
53-
private static final String[] cleanScript = new String[] {
54-
"DROP TABLE sql_test;"
55-
};
56-
5738
@BeforeAll
5839
public static void setupEnv() {
5940
control = new TarantoolControl();
6041
control.createInstance("jdk-testing", LUA_FILE, makeInstanceEnv(LISTEN, ADMIN));
6142
startTarantool("jdk-testing");
62-
6343
console = openConsole();
64-
65-
executeLua(setupScript);
6644
}
6745

6846
@AfterAll
6947
public static void cleanupEnv() {
7048
try {
71-
executeLua(cleanScript);
7249
console.close();
7350
} finally {
7451
stopTarantool("jdk-testing");
7552
}
7653
}
7754

78-
private static void executeLua(String[] exprs) {
55+
protected static void executeLua(String[] exprs) {
7956
for (String expr : exprs) {
8057
console.exec(expr);
8158
}

Diff for: src/test/java/org/tarantool/AbstractTarantoolSQLOpsIT.java

+30
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
import static org.tarantool.TestAssumptions.assumeMinimalServerVersion;
56

7+
import org.junit.jupiter.api.AfterEach;
8+
import org.junit.jupiter.api.BeforeEach;
69
import org.junit.jupiter.api.Test;
710

811
import java.util.List;
@@ -13,8 +16,35 @@
1316
*/
1417
public abstract class AbstractTarantoolSQLOpsIT extends AbstractTarantoolSQLConnectorIT {
1518

19+
private static final String[] SETUP_SCRIPT = new String[] {
20+
"\\set language sql",
21+
22+
"CREATE TABLE sql_test (id INTEGER PRIMARY KEY, val VARCHAR(100));",
23+
"CREATE UNIQUE INDEX sql_test_val_index_unique ON sql_test (val);",
24+
25+
"INSERT INTO sql_test VALUES (1, 'A');",
26+
"INSERT INTO sql_test VALUES (2, 'B');",
27+
"INSERT INTO sql_test VALUES (3, 'C');"
28+
};
29+
30+
private static final String[] CLEAN_SCRIPT = new String[] {
31+
"DROP TABLE sql_test;",
32+
"\\set language lua"
33+
};
34+
1635
protected abstract TarantoolSQLOps<Object, Long, List<Map<String, Object>>> getSQLOps();
1736

37+
@BeforeEach
38+
void setUpTest() {
39+
assumeMinimalServerVersion(console, ServerVersion.V_2_1);
40+
executeLua(SETUP_SCRIPT);
41+
}
42+
43+
@AfterEach
44+
void tearDownTest() {
45+
executeLua(CLEAN_SCRIPT);
46+
}
47+
1848
@Test
1949
public void testSelectOne() {
2050
List<Map<String, Object>> result = getSQLOps().query("SELECT id, val FROM sql_test WHERE id = 1");

Diff for: src/test/java/org/tarantool/SQLOperationsIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public void setup() {
2222

2323
@AfterEach
2424
public void tearDown() {
25-
client.close();
25+
if (client != null) {
26+
client.close();
27+
}
2628
}
2729

2830
@Override

Diff for: src/test/java/org/tarantool/ServerVersion.java

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.tarantool;
2+
3+
import java.util.function.BiFunction;
4+
5+
public enum ServerVersion {
6+
7+
V_1_9("1", "9", "0"),
8+
V_1_10("1", "10", "0"),
9+
V_2_1("2", "1", "0"),
10+
V_2_2("2", "2", "0");
11+
12+
private final String majorVersion;
13+
private final String minorVersion;
14+
private final String patchVersion;
15+
16+
ServerVersion(String majorVersion,
17+
String minorVersion, String patchVersion) {
18+
this.majorVersion = majorVersion;
19+
this.minorVersion = minorVersion;
20+
this.patchVersion = patchVersion;
21+
}
22+
23+
public String getMajorVersion() {
24+
return majorVersion;
25+
}
26+
27+
public String getMinorVersion() {
28+
return minorVersion;
29+
}
30+
31+
public String getPatchVersion() {
32+
return patchVersion;
33+
}
34+
35+
public boolean haveMinimalVersion(String versionString) {
36+
return compareVersions(versionString, (server, minimal) -> server >= minimal);
37+
}
38+
39+
public boolean haveMaximalVersion(String versionString) {
40+
return compareVersions(versionString, (server, maximal) -> server <= maximal);
41+
}
42+
43+
private boolean compareVersions(String versionString, BiFunction<Integer, Integer, Boolean> comparator) {
44+
int parsedVersion = toNumber(splitVersionParts(versionString));
45+
int thisVersion = toNumber(new String[] { majorVersion, minorVersion, patchVersion });
46+
return comparator.apply(parsedVersion, thisVersion);
47+
}
48+
49+
/**
50+
* Translates version parts to format XXXYYYZZZ.
51+
* For example, {@code 1.2.1} translates to number {@code 1002001}
52+
*
53+
* @param parts version parts
54+
* @return version as number
55+
*/
56+
private int toNumber(String[] parts) {
57+
int version = 0;
58+
for (int i = 0; i < 3; i++) {
59+
version = (version + Integer.parseInt(parts[i])) * 1000;
60+
}
61+
return version / 1000;
62+
}
63+
64+
/**
65+
* Splits Tarantool version string into parts.
66+
* For example, {@code 2.1.1-423-g4007436aa} => {@code [2, 1, 1, 423, g4007436aa]}.
67+
*
68+
* @param version Tarantool version string
69+
* @return split parts
70+
*/
71+
private String[] splitVersionParts(String version) {
72+
return version.split("[.\\-]");
73+
}
74+
}

Diff for: src/test/java/org/tarantool/TestAssumptions.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.tarantool;
2+
3+
import org.junit.jupiter.api.Assumptions;
4+
5+
public class TestAssumptions {
6+
7+
public static void assumeMinimalServerVersion(TarantoolConsole console, ServerVersion version) {
8+
Assumptions.assumeTrue(version.haveMinimalVersion(TestUtils.getTarantoolVersion(console)));
9+
}
10+
11+
public static void assumeMaximalServerVersion(TarantoolConsole console, ServerVersion version) {
12+
Assumptions.assumeTrue(version.haveMaximalVersion(TestUtils.getTarantoolVersion(console)));
13+
}
14+
15+
}

0 commit comments

Comments
 (0)