milleruntime commented on a change in pull request #2467:
URL: https://github.com/apache/accumulo/pull/2467#discussion_r800764709



##########
File path: 
test/src/main/java/org/apache/accumulo/test/fate/zookeeper/FateIT.java
##########
@@ -175,6 +205,170 @@ public void testTransactionStatus() throws Exception {
     }
   }
 
+  @Test
+  public void testCancelWhileNew() throws Exception {
+    final ZooReaderWriter zk = new ZooReaderWriter(szk.getConn(), 30000, 
"secret");
+    final ZooStore<Manager> zooStore = new ZooStore<Manager>(ZK_ROOT + 
Constants.ZFATE, zk);
+    final AgeOffStore<Manager> store = new AgeOffStore<Manager>(zooStore, 
3000);
+
+    Manager manager = createMock(Manager.class);
+    ServerContext sctx = createMock(ServerContext.class);
+    expect(manager.getContext()).andReturn(sctx).anyTimes();
+    expect(sctx.getZooKeeperRoot()).andReturn(ZK_ROOT).anyTimes();
+    expect(sctx.getZooReaderWriter()).andReturn(zk).anyTimes();
+    replay(manager, sctx);
+
+    Fate<Manager> fate = new Fate<Manager>(manager, store, 
TraceRepo::toLogString);
+    try {
+      ConfigurationCopy config = new ConfigurationCopy();
+      config.set(Property.GENERAL_SIMPLETIMER_THREADPOOL_SIZE, "2");
+      config.set(Property.MANAGER_FATE_THREADPOOL_SIZE, "1");
+      fate.startTransactionRunners(config);
+
+      // Wait for the transaction runner to be scheduled.
+      UtilWaitThread.sleep(3000);
+
+      doReady = new CountDownLatch(1);
+      callStarted = new CountDownLatch(1);
+      finishCall = new CountDownLatch(1);
+
+      long txid = fate.startTransaction();
+      LOG.info("Starting test testCancelWhileNew with {}", 
Long.toHexString(txid));
+      assertEquals(TStatus.NEW, getTxStatus(zk, txid));
+      // cancel the transaction
+      assertTrue(fate.cancel(txid));
+      assertTrue(TStatus.FAILED_IN_PROGRESS == getTxStatus(zk, txid)
+          || TStatus.FAILED == getTxStatus(zk, txid));
+      fate.seedTransaction(txid, new TestOperation(NS, TID), true);
+      assertTrue(TStatus.FAILED_IN_PROGRESS == getTxStatus(zk, txid)
+          || TStatus.FAILED == getTxStatus(zk, txid));
+    } finally {
+      fate.shutdown();
+    }
+  }
+
+  @Test
+  public void testCancelWhileSubmitted() throws Exception {
+    final ZooReaderWriter zk = new ZooReaderWriter(szk.getConn(), 30000, 
"secret");
+    final ZooStore<Manager> zooStore = new ZooStore<Manager>(ZK_ROOT + 
Constants.ZFATE, zk);
+    final AgeOffStore<Manager> store = new AgeOffStore<Manager>(zooStore, 
3000);
+
+    Manager manager = createMock(Manager.class);
+    ServerContext sctx = createMock(ServerContext.class);
+    expect(manager.getContext()).andReturn(sctx).anyTimes();
+    expect(sctx.getZooKeeperRoot()).andReturn(ZK_ROOT).anyTimes();
+    expect(sctx.getZooReaderWriter()).andReturn(zk).anyTimes();
+    replay(manager, sctx);
+
+    Fate<Manager> fate = new Fate<Manager>(manager, store, 
TraceRepo::toLogString);
+    try {
+      ConfigurationCopy config = new ConfigurationCopy();
+      config.set(Property.GENERAL_SIMPLETIMER_THREADPOOL_SIZE, "2");
+      config.set(Property.MANAGER_FATE_THREADPOOL_SIZE, "1");
+      fate.startTransactionRunners(config);
+
+      // Wait for the transaction runner to be scheduled.
+      UtilWaitThread.sleep(3000);
+
+      doReady = new CountDownLatch(1);
+      callStarted = new CountDownLatch(1);
+      finishCall = new CountDownLatch(1);
+
+      long txid = fate.startTransaction();
+      LOG.info("Starting test testCancelWhileSubmitted with {}", 
Long.toHexString(txid));
+      assertEquals(TStatus.NEW, getTxStatus(zk, txid));
+      fate.seedTransaction(txid, new TestOperation(NS, TID), true);
+      assertEquals(TStatus.SUBMITTED, getTxStatus(zk, txid));
+      // cancel the transaction
+      assertTrue(fate.cancel(txid));
+      // do the isReady method
+      doReady.countDown();
+      // Check that tx is failing or gets removed
+      boolean nodeRemoved = false;
+      while (!nodeRemoved) {
+        try {
+          TStatus s = getTxStatus(zk, txid);
+          assertTrue(
+              s == TStatus.SUBMITTED || s == TStatus.FAILED_IN_PROGRESS || s 
== TStatus.FAILED);

Review comment:
       Static imports could clean up the formatting here.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to