public static <TEnv> Throwable assertProcFailed(final ProcedureExecutor<TEnv> procExecutor, final long procId) { Procedure<?> result = procExecutor.getResult(procId); assertTrue("expected procedure result", result != null); return assertProcFailed(result); }
public static <TEnv> void assertProcNotFailed(ProcedureExecutor<TEnv> procExecutor, long procId) { Procedure<?> result = procExecutor.getResult(procId); assertTrue("expected procedure result", result != null); assertProcNotFailed(result); }
@Test public void testAbortNonExistProcedure() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); Random randomGenerator = new Random(); long procId; // Generate a non-existing procedure do { procId = randomGenerator.nextLong(); } while (procExec.getResult(procId) != null); boolean abortResult = procExec.abort(procId, true); assertFalse(abortResult); }
@Test public void testSingleSequentialProc() { List<String> state = new ArrayList<>(); Procedure<Void> subProc2 = new TestSequentialProcedure("subProc2", state); Procedure<Void> subProc1 = new TestSequentialProcedure("subProc1", state, subProc2); Procedure<Void> rootProc = new TestSequentialProcedure("rootProc", state, subProc1); long rootId = ProcedureTestingUtility.submitAndWait(procExecutor, rootProc); // successful state, with 3 execute LOG.info(Objects.toString(state)); Procedure<?> result = procExecutor.getResult(rootId); ProcedureTestingUtility.assertProcNotFailed(result); assertEquals(state.toString(), 3, state.size()); }
public static <TEnv> void assertProcNotYetCompleted(ProcedureExecutor<TEnv> procExecutor, long procId) { assertFalse("expected a running proc", procExecutor.isFinished(procId)); assertEquals(null, procExecutor.getResult(procId)); }
@Test public void testAbortTimeoutWithChildren() { List<String> state = new ArrayList<>(); Procedure<Void> proc = new TestWaitingProcedure("wproc", state, true); proc.setTimeout(2500); long rootId = ProcedureTestingUtility.submitAndWait(procExecutor, proc); LOG.info(Objects.toString(state)); Procedure<?> result = procExecutor.getResult(rootId); assertTrue(state.toString(), result.isFailed()); ProcedureTestingUtility.assertIsTimeoutException(result); assertEquals(state.toString(), 3, state.size()); assertEquals("wproc-execute", state.get(0)); assertEquals("wproc-child-execute", state.get(1)); assertEquals("wproc-rollback", state.get(2)); } }
private void assertProcFailed(long procId) { assertTrue("expected completed proc", procExecutor.isFinished(procId)); Procedure<?> result = procExecutor.getResult(procId); assertEquals(true, result.isFailed()); LOG.info(result.getException().getMessage()); }
@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); }
public static RegionInfo[] createTable(final ProcedureExecutor<MasterProcedureEnv> procExec, final TableName tableName, final byte[][] splitKeys, String... family) throws IOException { TableDescriptor htd = createHTD(tableName, family); RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, splitKeys); long procId = ProcedureTestingUtility.submitAndWait(procExec, new CreateTableProcedure(procExec.getEnvironment(), htd, regions)); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId)); return regions; }
@Test public void testRollbackRetriableFailure() { long procId = ProcedureTestingUtility.submitAndWait(procExecutor, new TestFaultyRollback()); Procedure<?> result = procExecutor.getResult(procId); assertTrue("expected a failure", result.isFailed()); LOG.info(result.getException().getMessage()); Throwable cause = ProcedureTestingUtility.getExceptionCause(result); assertTrue("expected TestProcedureException, got " + cause, cause instanceof TestProcedureException); }
@Test public void testRestoreSnapshotToDifferentTable() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableName restoredTableName = TableName.valueOf(name.getMethodName()); final HTableDescriptor newHTD = createHTableDescriptor(restoredTableName, CF1, CF2); long procId = ProcedureTestingUtility.submitAndWait( procExec, new RestoreSnapshotProcedure(procExec.getEnvironment(), newHTD, snapshot)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Restore snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableNotFoundException); }
@Test public void testRestoreSnapshot() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); long procId = ProcedureTestingUtility.submitAndWait( procExec, new RestoreSnapshotProcedure(procExec.getEnvironment(), snapshotHTD, snapshot)); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId)); validateSnapshotRestore(); }
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())); }
@Test public void testCloneSnapshotToSameTable() throws Exception { // take the snapshot SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot(); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableName clonedTableName = TableName.valueOf(snapshotDesc.getTable()); final TableDescriptor htd = createTableDescriptor(clonedTableName, CF); long procId = ProcedureTestingUtility.submitAndWait( procExec, new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Clone snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableExistsException); }
@Test public void testCloneSnapshot() throws Exception { final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableName clonedTableName = TableName.valueOf("testCloneSnapshot2"); final TableDescriptor htd = createTableDescriptor(clonedTableName, CF); // take the snapshot SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot(); long procId = ProcedureTestingUtility.submitAndWait( procExec, new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc)); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId)); MasterProcedureTestingUtility.validateTableIsEnabled( UTIL.getHBaseCluster().getMaster(), clonedTableName); }
@Test public void testDeleteSystemNamespace() throws Exception { final String namespaceName = NamespaceDescriptor.SYSTEM_NAMESPACE.getName(); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); long procId = procExec.submitProcedure( new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Delete namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
@Test public void testDeleteNonExistNamespace() throws Exception { final String namespaceName = "testDeleteNonExistNamespace"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); validateNamespaceNotExist(namespaceName); long procId = procExec.submitProcedure( new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); // Expect fail with NamespaceNotFoundException Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Delete namespace failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceNotFoundException); }
/** * 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()); }
@Test public void testStateMachineMultipleLevel() throws Exception { long procId = procExecutor.submitProcedure(new TestStateMachineProcedure(true)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExecutor, procId); Procedure<?> result = procExecutor.getResult(procId); ProcedureTestingUtility.assertProcNotFailed(result); assertEquals(19, Bytes.toInt(result.getResult())); assertEquals(4, procExecutor.getLastProcId()); }
@Test public void testCreateSystemNamespace() throws Exception { final NamespaceDescriptor nsd = UTIL.getAdmin().getNamespaceDescriptor(NamespaceDescriptor.SYSTEM_NAMESPACE.getName()); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); long procId = procExec.submitProcedure( new CreateNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Create namespace failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceExistException); }