@Override protected Procedure<ProcEnv>[] execute(ProcEnv env) throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { if (STEP == 0) { STEP = 1; setTimeout(60 * 60 * 1000); setState(ProcedureProtos.ProcedureState.WAITING_TIMEOUT); skipPersistence(); throw new ProcedureSuspendedException(); } else if (STEP == 1) { STEP = 2; if (hasTimeout()) { setFailure("Should not persist the timeout value", new IOException("Should not persist the timeout value")); return null; } setTimeout(2 * 1000); setState(ProcedureProtos.ProcedureState.WAITING_TIMEOUT); // used to confirm that we reset the persist flag before execution throw new ProcedureSuspendedException(); } else { if (!hasTimeout()) { setFailure("Should have persisted the timeout value", new IOException("Should have persisted the timeout value")); } return null; } }
@Override protected Procedure<ProcEnv>[] execute(ProcEnv env) throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { if (STEP == 0) { STEP = 1; setTimeout(60 * 60 * 1000); setState(ProcedureProtos.ProcedureState.WAITING_TIMEOUT); skipPersistence(); throw new ProcedureSuspendedException(); } else if (STEP == 1) { STEP = 2; if (hasTimeout()) { setFailure("Should not persist the timeout value", new IOException("Should not persist the timeout value")); return null; } setTimeout(2 * 1000); setState(ProcedureProtos.ProcedureState.WAITING_TIMEOUT); // used to confirm that we reset the persist flag before execution throw new ProcedureSuspendedException(); } else { if (!hasTimeout()) { setFailure("Should have persisted the timeout value", new IOException("Should have persisted the timeout value")); } return null; } }
@Test public void test() throws Exception { TestProcedure proc = new TestProcedure(); long procId = procExecutor.submitProcedure(proc); htu.waitFor(30000, () -> proc.isWaiting()); ProcedureTestingUtility.restart(procExecutor); htu.waitFor(30000, () -> { Procedure<?> p = procExecutor.getProcedure(procId); return p.isWaiting() || p.isFinished(); }); assertFalse(procExecutor.isFinished(procId)); ProcedureTestingUtility.restart(procExecutor); htu.waitFor(30000, () -> procExecutor.isFinished(procId)); Procedure<ProcEnv> p = procExecutor.getResult(procId); assertTrue(p.isSuccess()); } }
@Override protected synchronized boolean setTimeoutFailure(ProcEnv env) { setState(ProcedureProtos.ProcedureState.RUNNABLE); env.getProcedureExecutor().getProcedureScheduler().addFront(this); return false; }
@Test public void test() throws Exception { TestProcedure proc = new TestProcedure(); long procId = procExecutor.submitProcedure(proc); htu.waitFor(30000, () -> proc.isWaiting()); ProcedureTestingUtility.restart(procExecutor); htu.waitFor(30000, () -> { Procedure<?> p = procExecutor.getProcedure(procId); return p.isWaiting() || p.isFinished(); }); assertFalse(procExecutor.isFinished(procId)); ProcedureTestingUtility.restart(procExecutor); htu.waitFor(30000, () -> procExecutor.isFinished(procId)); Procedure<ProcEnv> p = procExecutor.getResult(procId); assertTrue(p.isSuccess()); } }
@Override protected synchronized boolean setTimeoutFailure(ProcEnv env) { setState(ProcedureProtos.ProcedureState.RUNNABLE); env.getProcedureExecutor().getProcedureScheduler().addFront(this); return false; }