Skip to content

Commit 257731e

Browse files
authored
Added logic to manage versions of proxy, kvclient, and kvserver. (#14)
Added logic to manage versions of proxy, kvclient, and kvserver based on envrionment or properties settings. Used for testing, to skip tests that may not run properly against older versions. No changes to public APIs. Version checks in various tests are done with the minimum of client and server kv versions. The proxy version is not checked. All three values are available to tests if needed.
1 parent 55cdc99 commit 257731e

File tree

4 files changed

+170
-33
lines changed

4 files changed

+170
-33
lines changed

driver/src/test/java/oracle/nosql/driver/BasicTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,14 @@ public void recreateTest() throws Exception {
445445
PutResult pres = handle.put(pr);
446446
assertNotNull(pres.getVersion());
447447

448-
tres = tableOperation(handle,
449-
DROP_TABLE,
450-
null);
448+
try {
449+
tres = tableOperation(handle, DROP_TABLE, null);
450+
} catch (TableNotFoundException e) {
451+
/* versions before 20.3 had known issues with drop table */
452+
if (checkKVVersion(20, 3, 1)) {
453+
throw e;
454+
}
455+
}
451456

452457
tres = tableOperation(handle,
453458
CREATE_TABLE,
@@ -1339,6 +1344,7 @@ public void testLargeRow() {
13391344
*/
13401345
@Test
13411346
public void testFlexibleMapping() throws Exception {
1347+
assumeKVVersion("testFlexibleMapping", 20, 2, 1);
13421348
final String createTable =
13431349
"create table flex(id integer, primary key(id), " +
13441350
"str string, " +

driver/src/test/java/oracle/nosql/driver/OnPremiseTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ protected void dropAllUsers(NoSQLHandle nosqlHandle) {
146146
}
147147
*/
148148
protected void dropRegions(NoSQLHandle nosqlHandle) {
149+
if (checkKVVersion(20, 1, 1) == false) {
150+
return;
151+
}
149152
SystemResult res = doSysOp(nosqlHandle, "show as json regions");
150153
String regionString = res.getResultString();
151154
if (regionString != null) {
@@ -234,7 +237,7 @@ public void testTableLimits()
234237
@Test
235238
public void testChildTables()
236239
throws Exception {
237-
240+
assumeKVVersion("testChildTable", 20, 1, 1);
238241
String tableName = "parent";
239242
String createTableStatement =
240243
"CREATE TABLE IF NOT EXISTS " + tableName +
@@ -568,6 +571,7 @@ public void testUnsupportedOps() throws Exception {
568571

569572
@Test
570573
public void testLargeRow() {
574+
assumeKVVersion("testLargeRow", 20, 1, 1);
571575
doLargeRow(handle, true);
572576
}
573577

@@ -576,6 +580,7 @@ public void testLargeRow() {
576580
*/
577581
@Test
578582
public void testMultiRegion() {
583+
assumeKVVersion("testMultiRegion", 20, 1, 1);
579584
final String show = "show regions";
580585
final String createRegion = "create region remoteRegion";
581586
final String setRegion = "set local region localRegion";

driver/src/test/java/oracle/nosql/driver/ProxyTestBase.java

Lines changed: 138 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.junit.Assert.assertEquals;
2525
import static org.junit.Assert.assertNotNull;
2626
import static org.junit.Assert.assertTrue;
27+
import static org.junit.Assume.assumeTrue;
2728

2829
import java.net.URL;
2930
import java.util.ArrayList;
@@ -76,6 +77,18 @@ public class ProxyTestBase {
7677
protected static int DEFAULT_DML_TIMEOUT = 5000;
7778
protected static String TEST_TABLE_NAME = "drivertest";
7879

80+
protected static String PROXY_VERSION_PROP = "test.proxy.version";
81+
protected static String KVCLIENT_VERSION_PROP = "test.kv.client.version";
82+
protected static String KVSERVER_VERSION_PROP = "test.kv.server.version";
83+
protected static String PROXY_VERSION_ENV = "PROXY_VERSION";
84+
protected static String KVCLIENT_VERSION_ENV = "KV_CLIENT_VERSION";
85+
protected static String KVSERVER_VERSION_ENV = "KV_SERVER_VERSION";
86+
87+
/* (major * 1M) + (minor * 1K) + patch */
88+
protected static int proxyVersion;
89+
protected static int kvClientVersion;
90+
protected static int kvServerVersion;
91+
7992
protected static String serverType;
8093
protected static String endpoint;
8194
protected static boolean verbose;
@@ -130,6 +143,20 @@ public static void staticSetup() {
130143
verbose = Boolean.getBoolean(VERBOSE);
131144
local = Boolean.getBoolean(LOCAL);
132145
trace = Boolean.getBoolean(TRACE);
146+
147+
proxyVersion = intVersion(System.getProperty(PROXY_VERSION_PROP));
148+
if (proxyVersion <= 0) {
149+
proxyVersion = intVersion(System.getenv(PROXY_VERSION_ENV));
150+
}
151+
kvClientVersion = intVersion(System.getProperty(KVCLIENT_VERSION_PROP));
152+
if (kvClientVersion <= 0) {
153+
kvClientVersion = intVersion(System.getenv(KVCLIENT_VERSION_ENV));
154+
}
155+
kvServerVersion = intVersion(System.getProperty(KVSERVER_VERSION_PROP));
156+
if (kvServerVersion <= 0) {
157+
kvServerVersion = intVersion(System.getenv(KVSERVER_VERSION_ENV));
158+
}
159+
133160
/* these features are not yet available in the cloud */
134161
uuidSupported = onprem;
135162
arrayAsRecordSupported = onprem;
@@ -247,7 +274,7 @@ public void beforeTest() throws Exception {
247274
public void afterTest() throws Exception {
248275

249276
if (handle != null) {
250-
dropAllTables(handle, false);
277+
dropAllTables(handle, true);
251278
handle.close();
252279
}
253280
}
@@ -283,6 +310,12 @@ protected static void dropAllTables(NoSQLHandle nosqlHandle,
283310
}
284311
TableResult tres = dropTableWithoutWait(nosqlHandle, tableName);
285312
droppedTables.add(tres);
313+
} catch (TableNotFoundException tnfe) {
314+
/* this is expected in 20.X and older */
315+
if (checkKVVersion(21, 1, 1)) {
316+
System.err.println("DropAllTables: drop fail, table "
317+
+ tableName + ": " + tnfe);
318+
}
286319
} catch (Exception e) {
287320
System.err.println("DropAllTables: drop fail, table "
288321
+ tableName + ": " + e);
@@ -306,6 +339,12 @@ protected static void dropAllTables(NoSQLHandle nosqlHandle,
306339
/* ignore, but note exceptions */
307340
try {
308341
tres.waitForCompletion(nosqlHandle, 30000, 300);
342+
} catch (TableNotFoundException tnfe) {
343+
/* this is expected in 20.X and older */
344+
if (checkKVVersion(21, 1, 1)) {
345+
System.err.println("DropAllTables: drop wait fail, table "
346+
+ tres + ": " + tnfe);
347+
}
309348
} catch (Exception e) {
310349
System.err.println("DropAllTables: drop wait fail, table "
311350
+ tres + ": " + e);
@@ -318,13 +357,20 @@ protected void dropTable(String tableName) {
318357
}
319358

320359
static void dropTable(NoSQLHandle nosqlHandle, String tableName) {
321-
TableResult tres = dropTableWithoutWait(nosqlHandle, tableName);
360+
try {
361+
TableResult tres = dropTableWithoutWait(nosqlHandle, tableName);
322362

323-
if (tres.getTableState().equals(TableResult.State.DROPPED)) {
324-
return;
325-
}
363+
if (tres.getTableState().equals(TableResult.State.DROPPED)) {
364+
return;
365+
}
326366

327-
tres.waitForCompletion(nosqlHandle, 20000, 1000);
367+
tres.waitForCompletion(nosqlHandle, 20000, 1000);
368+
} catch (TableNotFoundException e) {
369+
/* 20.2 and below have a known issue with drop table */
370+
if (checkKVVersion(20, 3, 1) == true) {
371+
throw e;
372+
}
373+
}
328374
}
329375

330376
static private TableResult dropTableWithoutWait(NoSQLHandle nosqlHandle,
@@ -371,19 +417,22 @@ protected NoSQLHandle setupHandle(NoSQLHandleConfig config) {
371417
* sub classes can override this to affect the handle config
372418
*/
373419
protected void perTestHandleConfig(NoSQLHandleConfig config) {
374-
// no-op
420+
/* no-op */
375421
}
376422

377423
/**
378424
* get a handle based on the config
379425
*/
380426
protected NoSQLHandle getHandle(NoSQLHandleConfig config) {
381427
/*
382-
* Create a Logger, set to WARNING. TODO: use a property
383-
* for level.
428+
* Create a Logger, set to WARNING by default.
384429
*/
385430
Logger logger = Logger.getLogger(getClass().getName());
386-
logger.setLevel(Level.WARNING);
431+
String level = System.getProperty("test.loglevel");
432+
if (level == null) {
433+
level = "WARNING";
434+
}
435+
logger.setLevel(Level.parse(level));
387436
config.setLogger(logger);
388437

389438
/*
@@ -542,4 +591,83 @@ protected static void verbose(String msg) {
542591
System.out.println(msg);
543592
}
544593
}
594+
595+
/*
596+
* convert a version string in X.Y.Z format to an
597+
* integer value of (X * 1M) + (Y * 1K) + Z
598+
* return -1 if the string isn't in valid X.Y.Z format
599+
*/
600+
protected static int intVersion(String version) {
601+
if (version == null || version.length() < 5) {
602+
return -1;
603+
}
604+
String[] arr = version.split("\\.");
605+
if (arr == null || arr.length != 3) {
606+
return -1;
607+
}
608+
try {
609+
return (Integer.parseInt(arr[0]) * 1000000) +
610+
(Integer.parseInt(arr[1]) * 1000) +
611+
Integer.parseInt(arr[2]);
612+
} catch (Exception e) {}
613+
return -1;
614+
}
615+
616+
/*
617+
* Inverse of above, for messages
618+
*/
619+
protected static String stringVersion(int ver) {
620+
if (ver <= 0) {
621+
return "unknown";
622+
}
623+
return (ver / 1000000) + "." +
624+
((ver / 1000) % 1000) + "." +
625+
(ver % 1000);
626+
}
627+
628+
private static int getMinimumKVVersion() {
629+
/*
630+
* Use the minumum of the kv client and server versions to
631+
* determine what features should be valid to test.
632+
*/
633+
if (kvServerVersion <= 0) {
634+
return kvClientVersion;
635+
} else if (kvClientVersion <= 0) {
636+
return kvServerVersion;
637+
}
638+
if (kvServerVersion < kvClientVersion) {
639+
return kvServerVersion;
640+
}
641+
return kvClientVersion;
642+
}
643+
644+
/*
645+
* Used to skip test if run against KV prior to the specified version
646+
* <major>.<minor>.<patch>.
647+
*/
648+
protected static void assumeKVVersion(String test,
649+
int major,
650+
int minor,
651+
int patch) {
652+
if (checkKVVersion(major, minor, patch)) {
653+
return;
654+
}
655+
assumeTrue("Skipping " + test + " if run against KV prior to " +
656+
(major + "." + minor + "." + patch) + ": " +
657+
stringVersion(getMinimumKVVersion()), false);
658+
}
659+
660+
/*
661+
* Returns true if the current KV is >= version <major.minor.patch>
662+
*/
663+
public static boolean checkKVVersion(int major,
664+
int minor,
665+
int patch) {
666+
int minVersion = getMinimumKVVersion();
667+
if (minVersion <= 0) {
668+
return false; // we have no way of knowing for sure
669+
}
670+
int desiredVersion = (major * 1000000) + (minor * 1000) + patch;
671+
return (minVersion >= desiredVersion);
672+
}
545673
}

0 commit comments

Comments
 (0)