@Override protected Procedure[] execute(final TestProcEnv env) throws ProcedureSuspendedException { LOG.info("EXECUTE " + this + " ntimeouts=" + ntimeouts); if (ntimeouts.get() > maxTimeouts) { setAbortFailure("test", "give up after " + ntimeouts.get()); return null; } event.suspend(); if (event.suspendIfNotReady(this)) { setState(ProcedureState.WAITING_TIMEOUT); throw new ProcedureSuspendedException(); } return null; }
@Override protected Procedure[] execute(final TestProcEnv env) throws ProcedureSuspendedException { LOG.info("EXECUTE " + this + " ntimeouts=" + ntimeouts); if (ntimeouts.get() > maxTimeouts) { setAbortFailure("test", "give up after " + ntimeouts.get()); return null; } event.suspend(); if (event.suspendIfNotReady(this)) { setState(ProcedureState.WAITING_TIMEOUT); throw new ProcedureSuspendedException(); } return null; }
@Override protected Procedure[] execute(final TestProcEnv env) throws ProcedureSuspendedException { LOG.info("EXECUTE " + this + " ntimeouts=" + ntimeouts); if (ntimeouts.get() > maxTimeouts) { setAbortFailure("test", "give up after " + ntimeouts.get()); return null; } event.suspend(); if (event.suspendIfNotReady(this)) { setState(ProcedureState.WAITING_TIMEOUT); throw new ProcedureSuspendedException(); } return null; }
public TestTimeoutEventProcedure(final int timeoutMsec, final int maxTimeouts) { this.maxTimeouts = maxTimeouts; setTimeout(timeoutMsec); }
public TestTimeoutEventProcedure(final int timeoutMsec, final int maxTimeouts) { this.maxTimeouts = maxTimeouts; setTimeout(timeoutMsec); }
/** * Tests being able to suspend a Procedure for N timeouts and then failing.s * Resets the timeout after each elapses. See {@link TestTimeoutEventProcedure} for example * of how to do this sort of trickery with the ProcedureExecutor; i.e. suspend for a while, * check for a condition and if not set, suspend again, etc., ultimately failing or succeeding * eventually. */ @Test public void testTimeoutEventProcedure() throws Exception { final int NTIMEOUTS = 5; TestTimeoutEventProcedure proc = new TestTimeoutEventProcedure(500, NTIMEOUTS); procExecutor.submitProcedure(proc); ProcedureTestingUtility.waitProcedure(procExecutor, proc.getProcId()); ProcedureTestingUtility.assertIsAbortException(procExecutor.getResult(proc.getProcId())); assertEquals(NTIMEOUTS + 1, proc.getTimeoutsCount()); }
@Override protected synchronized boolean setTimeoutFailure(final TestProcEnv env) { int n = ntimeouts.incrementAndGet(); LOG.info("HANDLE TIMEOUT " + this + " ntimeouts=" + n); setState(ProcedureState.RUNNABLE); event.wake((AbstractProcedureScheduler) env.getProcedureScheduler()); return false; }
@Override protected synchronized boolean setTimeoutFailure(final TestProcEnv env) { int n = ntimeouts.incrementAndGet(); LOG.info("HANDLE TIMEOUT " + this + " ntimeouts=" + n); setState(ProcedureState.RUNNABLE); event.wake((AbstractProcedureScheduler) env.getProcedureScheduler()); return false; }
@Override protected void afterReplay(final TestProcEnv env) { if (getState() == ProcedureState.WAITING_TIMEOUT) { event.suspend(); event.suspendIfNotReady(this); } }
@Test public void testTimeoutEventProcedure() throws Exception { final int NTIMEOUTS = 5; TestTimeoutEventProcedure proc = new TestTimeoutEventProcedure(500, NTIMEOUTS); procExecutor.submitProcedure(proc); ProcedureTestingUtility.waitProcedure(procExecutor, proc.getProcId()); ProcedureTestingUtility.assertIsAbortException(procExecutor.getResult(proc.getProcId())); assertEquals(NTIMEOUTS + 1, proc.getTimeoutsCount()); }
private void testTimeoutEventProcedureDoubleExecution(final boolean killIfSuspended) throws Exception { TestTimeoutEventProcedure proc = new TestTimeoutEventProcedure(1000, 3); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExecutor, true); ProcedureTestingUtility.setKillIfSuspended(procExecutor, killIfSuspended); long procId = procExecutor.submitProcedure(proc); ProcedureTestingUtility.testRecoveryAndDoubleExecution(procExecutor, procId, true); ProcedureTestingUtility.assertIsAbortException(procExecutor.getResult(proc.getProcId())); }
private void testTimeoutEventProcedureDoubleExecution(final boolean killIfSuspended) throws Exception { TestTimeoutEventProcedure proc = new TestTimeoutEventProcedure(1000, 3); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExecutor, true); ProcedureTestingUtility.setKillIfSuspended(procExecutor, killIfSuspended); long procId = procExecutor.submitProcedure(proc); ProcedureTestingUtility.testRecoveryAndDoubleExecution(procExecutor, procId, true); ProcedureTestingUtility.assertIsAbortException(procExecutor.getResult(proc.getProcId())); }
@Override protected void afterReplay(final TestProcEnv env) { if (getState() == ProcedureState.WAITING_TIMEOUT) { event.suspend(); event.suspendIfNotReady(this); } }
/** * Tests being able to suspend a Procedure for N timeouts and then failing.s * Resets the timeout after each elapses. See {@link TestTimeoutEventProcedure} for example * of how to do this sort of trickery with the ProcedureExecutor; i.e. suspend for a while, * check for a condition and if not set, suspend again, etc., ultimately failing or succeeding * eventually. */ @Test public void testTimeoutEventProcedure() throws Exception { final int NTIMEOUTS = 5; TestTimeoutEventProcedure proc = new TestTimeoutEventProcedure(500, NTIMEOUTS); procExecutor.submitProcedure(proc); ProcedureTestingUtility.waitProcedure(procExecutor, proc.getProcId()); ProcedureTestingUtility.assertIsAbortException(procExecutor.getResult(proc.getProcId())); assertEquals(NTIMEOUTS + 1, proc.getTimeoutsCount()); }
public TestTimeoutEventProcedure(final int timeoutMsec, final int maxTimeouts) { this.maxTimeouts = maxTimeouts; setTimeout(timeoutMsec); }
@Override protected synchronized boolean setTimeoutFailure(final TestProcEnv env) { int n = ntimeouts.incrementAndGet(); LOG.info("HANDLE TIMEOUT " + this + " ntimeouts=" + n); setState(ProcedureState.RUNNABLE); event.wake((AbstractProcedureScheduler) env.getProcedureScheduler()); return false; }
private void testTimeoutEventProcedureDoubleExecution(final boolean killIfSuspended) throws Exception { TestTimeoutEventProcedure proc = new TestTimeoutEventProcedure(1000, 3); ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExecutor, true); ProcedureTestingUtility.setKillIfSuspended(procExecutor, killIfSuspended); long procId = procExecutor.submitProcedure(proc); ProcedureTestingUtility.testRecoveryAndDoubleExecution(procExecutor, procId, true); ProcedureTestingUtility.assertIsAbortException(procExecutor.getResult(proc.getProcId())); }
@Override protected void afterReplay(final TestProcEnv env) { if (getState() == ProcedureState.WAITING_TIMEOUT) { event.suspend(); event.suspendIfNotReady(this); } }