9
9
import glide .api .GlideClient ;
10
10
import glide .api .GlideClusterClient ;
11
11
import glide .api .logging .Logger ;
12
+ import org .apache .commons .lang3 .tuple .Pair ;
12
13
13
14
public final class TestConfiguration {
14
- // All servers are hosted on localhost
15
15
public static final String [] STANDALONE_HOSTS =
16
16
System .getProperty ("test.server.standalone" , "" ).split ("," );
17
17
public static final String [] CLUSTER_HOSTS =
@@ -24,21 +24,64 @@ public final class TestConfiguration {
24
24
static {
25
25
Logger .init (Logger .Level .OFF );
26
26
Logger .setLoggerConfig (Logger .Level .OFF );
27
+
28
+ System .out .printf ("STANDALONE_HOSTS = %s\n " , System .getProperty ("test.server.standalone" , "" ));
29
+ System .out .printf ("CLUSTER_HOSTS = %s\n " , System .getProperty ("test.server.cluster" , "" ));
30
+ System .out .printf ("AZ_CLUSTER_HOSTS = %s\n " , System .getProperty ("test.server.azcluster" , "" ));
31
+
32
+ var result = getVersionFromStandalone ();
33
+ if (result .getKey () != null ) {
34
+ SERVER_VERSION = result .getKey ();
35
+ } else {
36
+ var errorStandalone = result .getValue ();
37
+ result = getVersionFromCluster ();
38
+ if (result .getKey () != null ) {
39
+ SERVER_VERSION = result .getKey ();
40
+ } else {
41
+ var errorCluster = result .getValue ();
42
+ errorStandalone .printStackTrace (System .err );
43
+ System .err .println ();
44
+ errorCluster .printStackTrace (System .err );
45
+ throw new RuntimeException ("Failed to get server version" );
46
+ }
47
+ }
48
+ System .out .printf ("SERVER_VERSION = %s\n " , SERVER_VERSION );
49
+ }
50
+
51
+ private static Pair <Semver , Exception > getVersionFromStandalone () {
52
+ if (STANDALONE_HOSTS [0 ].isEmpty ()) {
53
+ return Pair .of (null , new Exception ("No standalone nodes given" ));
54
+ }
27
55
try {
28
- BaseClient client =
29
- !STANDALONE_HOSTS [0 ].isEmpty ()
30
- ? GlideClient .createClient (commonClientConfig ().build ()).get ()
31
- : GlideClusterClient .createClient (commonClusterClientConfig ().build ()).get ();
56
+ BaseClient client = GlideClient .createClient (commonClientConfig ().build ()).get ();
32
57
33
58
String serverVersion = TestUtilities .getServerVersion (client );
34
59
if (serverVersion != null ) {
35
- SERVER_VERSION = new Semver (serverVersion );
60
+ return Pair . of ( new Semver (serverVersion ), null );
36
61
} else {
37
- throw new Exception ("Failed to get server version" );
62
+ return Pair . of ( null , new Exception ("Failed to parse version" ) );
38
63
}
64
+ } catch (Exception e ) {
65
+ return Pair .of (null , e );
66
+ }
67
+ }
68
+
69
+ private static Pair <Semver , Exception > getVersionFromCluster () {
70
+ if (CLUSTER_HOSTS [0 ].isEmpty ()) {
71
+ return Pair .of (null , new Exception ("No cluster nodes given" ));
72
+ }
73
+ try {
74
+ BaseClient client =
75
+ GlideClusterClient .createClient (commonClusterClientConfig ().build ()).get ();
39
76
77
+ String serverVersion = TestUtilities .getServerVersion (client );
78
+ if (serverVersion != null ) {
79
+ return Pair .of (new Semver (serverVersion ), null );
80
+ } else {
81
+ return Pair .of (null , new Exception ("Failed to parse version" ));
82
+ }
40
83
} catch (Exception e ) {
41
- throw new RuntimeException ( "Failed to get server version" , e );
84
+ return Pair . of ( null , e );
42
85
}
43
86
}
44
87
}
0 commit comments