-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTarantoolUtils.java
More file actions
88 lines (71 loc) · 2.71 KB
/
TarantoolUtils.java
File metadata and controls
88 lines (71 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package io.tarantool.driver;
import io.tarantool.driver.utils.Assert;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public final class TarantoolUtils {
private static final String TARANTOOL_VERSION = "TARANTOOL_VERSION";
private TarantoolUtils() {
}
public static boolean versionGreaterOrEqualThen(String tarantoolVersion) {
Assert.notNull(tarantoolVersion, "tarantoolVersion must not be null");
String tarantoolCiVersion = java.lang.System.getenv(TARANTOOL_VERSION);
if (tarantoolCiVersion == null || tarantoolCiVersion.isEmpty()) {
return true;
}
TarantoolVersion ciVersion = new TarantoolVersion(tarantoolCiVersion);
TarantoolVersion version = new TarantoolVersion(tarantoolVersion);
return ciVersion.getMajor() >= version.getMajor() &&
ciVersion.getMinor() >= version.getMinor();
}
public static boolean versionWithUUID() {
return versionGreaterOrEqualThen("2.4");
}
public static boolean versionWithInstant() {
return versionGreaterOrEqualThen("2.10");
}
public static boolean versionWithVarbinary() {
return versionGreaterOrEqualThen("2.2.1");
}
public static class TarantoolVersion {
private Integer major;
private Integer minor;
public TarantoolVersion(String stringVersion) {
List<String> majorMinor = stringVersion == null || stringVersion.isEmpty() ?
Collections.emptyList() :
Arrays.stream(stringVersion.split("\\."))
.collect(Collectors.toList());
if (majorMinor.size() >= 1) {
major = Integer.parseInt(majorMinor.get(0));
}
if (majorMinor.size() >= 2) {
String minorStr = majorMinor.get(1);
minor = minorStr.equals("x") ? 999 : Integer.parseInt(minorStr);
}
}
public Integer getMajor() {
return major;
}
public Integer getMinor() {
return minor;
}
}
public static Integer DEFAULT_RETRYING_ATTEMPTS = 5;
public static Integer DEFAULT_RETRYING_DELAY = 100;
public static void retry(Runnable fn) throws InterruptedException {
retry(DEFAULT_RETRYING_ATTEMPTS, DEFAULT_RETRYING_DELAY, fn);
}
public static void retry(Integer attempts, Integer delay, Runnable fn) throws InterruptedException {
while (attempts > 0) {
try {
fn.run();
return;
} catch (AssertionError ignored) {
}
--attempts;
Thread.sleep(delay);
}
fn.run();
}
}