Fix failing ZkClient TTL test (#2120)
Some tests for the TTL feature rely on zookeeper.extendedTypesEnabled system property to be set. However, interleaving of test methods from different classes resulted in the property being cleaned by one completed test class while another class has tests that rely on this property still running. This commit sets the property at the beginning of every method that needs it, and cleans at the end of the method.
diff --git a/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/RealmAwareZkClientFactoryTestBase.java b/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/RealmAwareZkClientFactoryTestBase.java
index a374b1f..cb27e16 100644
--- a/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/RealmAwareZkClientFactoryTestBase.java
+++ b/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/RealmAwareZkClientFactoryTestBase.java
@@ -134,6 +134,7 @@
// Clean up
_realmAwareZkClient.deleteRecursively(TEST_VALID_PATH);
+ System.clearProperty("zookeeper.extendedTypesEnabled");
}
/**
@@ -141,6 +142,7 @@
*/
@Test(dependsOnMethods = "testRealmAwareZkClientCreateContainer")
public void testRealmAwareZkClientCreateSequentialWithTTL() {
+ System.setProperty("zookeeper.extendedTypesEnabled", "true");
// Test writing and reading data
_realmAwareZkClient.createPersistent(TEST_VALID_PATH, true);
long ttl = 1L;
@@ -152,6 +154,7 @@
// Clean up
_realmAwareZkClient.deleteRecursively(TEST_VALID_PATH);
+ System.clearProperty("zookeeper.extendedTypesEnabled");
}
/**
@@ -159,6 +162,7 @@
*/
@Test(dependsOnMethods = "testRealmAwareZkClientCreateSequentialWithTTL")
public void testRealmAwareZkClientCreateWithTTL() {
+ System.setProperty("zookeeper.extendedTypesEnabled", "true");
// Test with createParents = true
long ttl = 1L;
_realmAwareZkClient.createPersistentWithTTL(TEST_VALID_PATH, true, ttl);
diff --git a/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/TestFederatedZkClient.java b/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/TestFederatedZkClient.java
index f73624c..70581ca 100644
--- a/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/TestFederatedZkClient.java
+++ b/zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/client/TestFederatedZkClient.java
@@ -192,6 +192,7 @@
// Clean up
_realmAwareZkClient.deleteRecursively(TEST_VALID_PATH);
+ System.clearProperty("zookeeper.extendedTypesEnabled");
}
/**
@@ -199,6 +200,7 @@
*/
@Test(dependsOnMethods = "testRealmAwareZkClientCreateContainer")
public void testRealmAwareZkClientCreateSequentialWithTTL() {
+ System.setProperty("zookeeper.extendedTypesEnabled", "true");
// Create a dummy ZNRecord
ZNRecord znRecord = new ZNRecord("DummyRecord");
znRecord.setSimpleField("Dummy", "Value");
@@ -214,6 +216,7 @@
// Clean up
_realmAwareZkClient.deleteRecursively(TEST_VALID_PATH);
+ System.clearProperty("zookeeper.extendedTypesEnabled");
}
/**
@@ -221,6 +224,7 @@
*/
@Test(dependsOnMethods = "testRealmAwareZkClientCreateSequentialWithTTL")
public void testRealmAwareZkClientCreateWithTTL() {
+ System.setProperty("zookeeper.extendedTypesEnabled", "true");
// Create a dummy ZNRecord
ZNRecord znRecord = new ZNRecord("DummyRecord");
znRecord.setSimpleField("Dummy", "Value");