2424import static org .junit .Assert .assertEquals ;
2525import static org .junit .Assert .assertNotNull ;
2626import static org .junit .Assert .assertTrue ;
27+ import static org .junit .Assume .assumeTrue ;
2728
2829import java .net .URL ;
2930import 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