@Override public void run() { try { // wait until t1 has registered the nonce t1NonceRegisteredLatch.await(); // register the nonce t2BeforeNonceRegisteredLatch.countDown(); assertFalse("unexpected non registered nonce", procExecutor.registerNonce(nonceKey) < 0); } catch (Throwable e) { t2Exception.set(e); } finally { t1NonceRegisteredLatch.countDown(); t2BeforeNonceRegisteredLatch.countDown(); } } };
public static <TEnv> long submitProcedure(ProcedureExecutor<TEnv> procExecutor, Procedure proc, final long nonceGroup, final long nonce) { final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); long procId = procExecutor.registerNonce(nonceKey); assertFalse(procId >= 0); return procExecutor.submitProcedure(proc, nonceKey); }
@Test public void testSetFailureResultForNonce() throws IOException { final long nonceGroup = 234; final long nonce = 55555; // check and register the request nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); procExecutor.setFailureResultForNonce(nonceKey, "testProc", User.getCurrent(), new IOException("test failure")); final long procId = procExecutor.registerNonce(nonceKey); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcFailed(result); }
@Override public void run() { try { // release the nonce and wake t2 assertFalse("unexpected already registered nonce", procExecutor.registerNonce(nonceKey) >= 0); t1NonceRegisteredLatch.countDown(); // hold the submission until t2 is registering the nonce t2BeforeNonceRegisteredLatch.await(); Threads.sleep(1000); if (submitProcedure) { CountDownLatch latch = new CountDownLatch(1); TestSingleStepProcedure proc = new TestSingleStepProcedure(); procEnv.setWaitLatch(latch); procExecutor.submitProcedure(proc, nonceKey); Threads.sleep(100); // complete the procedure latch.countDown(); } else { procExecutor.unregisterNonceIfProcedureWasNotSubmitted(nonceKey); } } catch (Throwable e) { t1Exception.set(e); } finally { t1NonceRegisteredLatch.countDown(); t2BeforeNonceRegisteredLatch.countDown(); } } };
@Test public void testRunningProcWithSameNonce() throws Exception { final long nonceGroup = 456; final long nonce = 33333; // register the nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); // Submit a proc and use a latch to prevent the step execution until we submitted proc2 CountDownLatch latch = new CountDownLatch(1); TestSingleStepProcedure proc = new TestSingleStepProcedure(); procEnv.setWaitLatch(latch); long procId = procExecutor.submitProcedure(proc, nonceKey); while (proc.step != 1) Threads.sleep(25); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); // complete the procedure latch.countDown(); // Restart, the procedure is not completed yet ProcedureTestingUtility.restart(procExecutor); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); }
@Test public void testCompletedProcWithSameNonce() throws Exception { final long nonceGroup = 123; final long nonce = 2222; // register the nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); // Submit a proc and wait for its completion Procedure proc = new TestSingleStepProcedure(); long procId = procExecutor.submitProcedure(proc, nonceKey); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // Restart ProcedureTestingUtility.restart(procExecutor); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); }
final long procId = procExec.registerNonce(runnable.getNonceKey()); if (procId >= 0) return procId; // someone already registered the nonce try {
long newNonce = nonceGenerator.newNonce(); NonceKey nonceKey = new NonceKey(nonceGroup, newNonce); procExec.registerNonce(nonceKey);
@Override public void run() { try { // wait until t1 has registered the nonce t1NonceRegisteredLatch.await(); // register the nonce t2BeforeNonceRegisteredLatch.countDown(); assertFalse("unexpected non registered nonce", procExecutor.registerNonce(nonceKey) < 0); } catch (Throwable e) { t2Exception.set(e); } finally { t1NonceRegisteredLatch.countDown(); t2BeforeNonceRegisteredLatch.countDown(); } } };
@Override public void run() { try { // wait until t1 has registered the nonce t1NonceRegisteredLatch.await(); // register the nonce t2BeforeNonceRegisteredLatch.countDown(); assertFalse("unexpected non registered nonce", procExecutor.registerNonce(nonceKey) < 0); } catch (Throwable e) { t2Exception.set(e); } finally { t1NonceRegisteredLatch.countDown(); t2BeforeNonceRegisteredLatch.countDown(); } } };
public static <TEnv> long submitProcedure(ProcedureExecutor<TEnv> procExecutor, Procedure proc, final long nonceGroup, final long nonce) { final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); long procId = procExecutor.registerNonce(nonceKey); assertFalse(procId >= 0); return procExecutor.submitProcedure(proc, nonceKey); }
public static <TEnv> long submitProcedure(ProcedureExecutor<TEnv> procExecutor, Procedure proc, final long nonceGroup, final long nonce) { final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); long procId = procExecutor.registerNonce(nonceKey); assertFalse(procId >= 0); return procExecutor.submitProcedure(proc, nonceKey); }
@Test public void testSetFailureResultForNonce() throws IOException { final long nonceGroup = 234; final long nonce = 55555; // check and register the request nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); procExecutor.setFailureResultForNonce(nonceKey, "testProc", User.getCurrent(), new IOException("test failure")); final long procId = procExecutor.registerNonce(nonceKey); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcFailed(result); }
@Test public void testSetFailureResultForNonce() throws IOException { final long nonceGroup = 234; final long nonce = 55555; // check and register the request nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); procExecutor.setFailureResultForNonce(nonceKey, "testProc", User.getCurrent(), new IOException("test failure")); final long procId = procExecutor.registerNonce(nonceKey); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcFailed(result); }
@Override public void run() { try { // release the nonce and wake t2 assertFalse("unexpected already registered nonce", procExecutor.registerNonce(nonceKey) >= 0); t1NonceRegisteredLatch.countDown(); // hold the submission until t2 is registering the nonce t2BeforeNonceRegisteredLatch.await(); Threads.sleep(1000); if (submitProcedure) { CountDownLatch latch = new CountDownLatch(1); TestSingleStepProcedure proc = new TestSingleStepProcedure(); procEnv.setWaitLatch(latch); procExecutor.submitProcedure(proc, nonceKey); Threads.sleep(100); // complete the procedure latch.countDown(); } else { procExecutor.unregisterNonceIfProcedureWasNotSubmitted(nonceKey); } } catch (Throwable e) { t1Exception.set(e); } finally { t1NonceRegisteredLatch.countDown(); t2BeforeNonceRegisteredLatch.countDown(); } } };
@Override public void run() { try { // release the nonce and wake t2 assertFalse("unexpected already registered nonce", procExecutor.registerNonce(nonceKey) >= 0); t1NonceRegisteredLatch.countDown(); // hold the submission until t2 is registering the nonce t2BeforeNonceRegisteredLatch.await(); Threads.sleep(1000); if (submitProcedure) { CountDownLatch latch = new CountDownLatch(1); TestSingleStepProcedure proc = new TestSingleStepProcedure(); procEnv.setWaitLatch(latch); procExecutor.submitProcedure(proc, nonceKey); Threads.sleep(100); // complete the procedure latch.countDown(); } else { procExecutor.unregisterNonceIfProcedureWasNotSubmitted(nonceKey); } } catch (Throwable e) { t1Exception.set(e); } finally { t1NonceRegisteredLatch.countDown(); t2BeforeNonceRegisteredLatch.countDown(); } } };
@Test public void testRunningProcWithSameNonce() throws Exception { final long nonceGroup = 456; final long nonce = 33333; // register the nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); // Submit a proc and use a latch to prevent the step execution until we submitted proc2 CountDownLatch latch = new CountDownLatch(1); TestSingleStepProcedure proc = new TestSingleStepProcedure(); procEnv.setWaitLatch(latch); long procId = procExecutor.submitProcedure(proc, nonceKey); while (proc.step != 1) Threads.sleep(25); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); // complete the procedure latch.countDown(); // Restart, the procedure is not completed yet ProcedureTestingUtility.restart(procExecutor); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); }
@Test public void testRunningProcWithSameNonce() throws Exception { final long nonceGroup = 456; final long nonce = 33333; // register the nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); // Submit a proc and use a latch to prevent the step execution until we submitted proc2 CountDownLatch latch = new CountDownLatch(1); TestSingleStepProcedure proc = new TestSingleStepProcedure(); procEnv.setWaitLatch(latch); long procId = procExecutor.submitProcedure(proc, nonceKey); while (proc.step != 1) Threads.sleep(25); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); // complete the procedure latch.countDown(); // Restart, the procedure is not completed yet ProcedureTestingUtility.restart(procExecutor); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); }
@Test public void testCompletedProcWithSameNonce() throws Exception { final long nonceGroup = 123; final long nonce = 2222; // register the nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); // Submit a proc and wait for its completion Procedure proc = new TestSingleStepProcedure(); long procId = procExecutor.submitProcedure(proc, nonceKey); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // Restart ProcedureTestingUtility.restart(procExecutor); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); }
@Test public void testCompletedProcWithSameNonce() throws Exception { final long nonceGroup = 123; final long nonce = 2222; // register the nonce final NonceKey nonceKey = procExecutor.createNonceKey(nonceGroup, nonce); assertFalse(procExecutor.registerNonce(nonceKey) >= 0); // Submit a proc and wait for its completion Procedure proc = new TestSingleStepProcedure(); long procId = procExecutor.submitProcedure(proc, nonceKey); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // Restart ProcedureTestingUtility.restart(procExecutor); ProcedureTestingUtility.waitProcedure(procExecutor, procId); // try to register a procedure with the same nonce // we should get back the old procId assertEquals(procId, procExecutor.registerNonce(nonceKey)); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); }