accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [2/6] accumulo git commit: ACCUMULO-4035 Retry assertions when data is not propagated to ZK.
Date Wed, 21 Oct 2015 18:28:59 GMT
ACCUMULO-4035 Retry assertions when data is not propagated to ZK.

Simply waiting an arbitrary amount of time is insufficient
to have reliably-passing tests. Convert sleep+check into a
loop of check+sleep-on-failure.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/ddace504
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/ddace504
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/ddace504

Branch: refs/heads/1.7
Commit: ddace50491f205a1b501de088c90aa956c11796f
Parents: deef535
Author: Josh Elser <elserj@apache.org>
Authored: Wed Oct 21 13:44:49 2015 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Wed Oct 21 13:44:49 2015 -0400

----------------------------------------------------------------------
 .../org/apache/accumulo/test/NamespacesIT.java  | 99 +++++++++++++++-----
 1 file changed, 77 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/ddace504/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java b/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java
index 2a57a7b..6fbf247 100644
--- a/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java
@@ -496,12 +496,38 @@ public class NamespacesIT extends AccumuloIT {
     assertFalse(c.tableOperations().listConstraints(t1).containsKey(constraintClassName));
 
     c.namespaceOperations().addConstraint(namespace, constraintClassName);
-    assertTrue(c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName));
-    assertTrue(c.tableOperations().listConstraints(t1).containsKey(constraintClassName));
-    int num = c.namespaceOperations().listConstraints(namespace).get(constraintClassName);
-    assertEquals(num, (int) c.tableOperations().listConstraints(t1).get(constraintClassName));
-    // doesn't take effect immediately, needs time to propagate to tserver's ZooKeeper cache
-    UtilWaitThread.sleep(250);
+    boolean passed = false;
+    for (int i = 0; i < 5; i++) {
+      if (!c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName))
{
+        Thread.sleep(500);
+        continue;
+      }
+      if (!c.tableOperations().listConstraints(t1).containsKey(constraintClassName)) {
+        Thread.sleep(500);
+        continue;
+      }
+      passed = true;
+      break;
+    }
+    assertTrue("Failed to observe newly-added constraint", passed);
+
+    passed = false;
+    Integer namespaceNum = null;
+    for (int i = 0; i < 5; i++) {
+      namespaceNum = c.namespaceOperations().listConstraints(namespace).get(constraintClassName);
+      if (null == namespaceNum) {
+        Thread.sleep(500);
+        continue;
+      }
+      Integer tableNum = c.tableOperations().listConstraints(t1).get(constraintClassName);
+      if (null == tableNum) {
+        Thread.sleep(500);
+        continue;
+      }
+      assertEquals(namespaceNum, tableNum);
+      passed = true;
+    }
+    assertTrue("Failed to observe constraint in both table and namespace", passed);
 
     Mutation m1 = new Mutation("r1");
     Mutation m2 = new Mutation("r2");
@@ -509,24 +535,53 @@ public class NamespacesIT extends AccumuloIT {
     m1.put("a", "b", new Value("abcde".getBytes(UTF_8)));
     m2.put("e", "f", new Value("123".getBytes(UTF_8)));
     m3.put("c", "d", new Value("zyxwv".getBytes(UTF_8)));
-    BatchWriter bw = c.createBatchWriter(t1, new BatchWriterConfig());
-    bw.addMutations(Arrays.asList(m1, m2, m3));
-    try {
-      bw.close();
-      fail();
-    } catch (MutationsRejectedException e) {
-      assertEquals(1, e.getConstraintViolationSummaries().size());
-      assertEquals(2, e.getConstraintViolationSummaries().get(0).getNumberOfViolatingMutations());
+
+    passed = false;
+    for (int i = 0; i < 5; i++) {
+      BatchWriter bw = c.createBatchWriter(t1, new BatchWriterConfig());
+      bw.addMutations(Arrays.asList(m1, m2, m3));
+      try {
+        bw.close();
+        Thread.sleep(500);
+      } catch (MutationsRejectedException e) {
+        passed = true;
+        assertEquals(1, e.getConstraintViolationSummaries().size());
+        assertEquals(2, e.getConstraintViolationSummaries().get(0).getNumberOfViolatingMutations());
+        break;
+      }
     }
-    c.namespaceOperations().removeConstraint(namespace, num);
-    assertFalse(c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName));
-    assertFalse(c.tableOperations().listConstraints(t1).containsKey(constraintClassName));
-    // doesn't take effect immediately, needs time to propagate to tserver's ZooKeeper cache
-    UtilWaitThread.sleep(250);
 
-    bw = c.createBatchWriter(t1, new BatchWriterConfig());
-    bw.addMutations(Arrays.asList(m1, m2, m3));
-    bw.close();
+    assertTrue("Failed to see mutations rejected after constraint was added", passed);
+
+    assertNotNull("Namespace constraint ID should not be null", namespaceNum);
+    c.namespaceOperations().removeConstraint(namespace, namespaceNum);
+    passed = false;
+    for (int i = 0; i < 5; i++) {
+      if (c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName))
{
+        Thread.sleep(500);
+        continue;
+      }
+      if (c.tableOperations().listConstraints(t1).containsKey(constraintClassName)) {
+        Thread.sleep(500);
+        continue;
+      }
+      passed = true;
+    }
+    assertTrue("Failed to verify that constraint was removed from namespace and table", passed);
+
+    passed = false;
+    for (int i = 0; i < 5; i++) {
+      BatchWriter bw = c.createBatchWriter(t1, new BatchWriterConfig());
+      try {
+        bw.addMutations(Arrays.asList(m1, m2, m3));
+        bw.close();
+      } catch (MutationsRejectedException e) {
+        Thread.sleep(500);
+        continue;
+      }
+      passed = true;
+    }
+    assertTrue("Failed to add mutations that should be allowed", passed);
   }
 
   @Test


Mime
View raw message