use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.NoopProcedure in project hbase by apache.
the class TestProcedureExecutor method testWorkerStuck.
@Test
public void testWorkerStuck() throws Exception {
// replace the executor
final Configuration conf = new Configuration(htu.getConfiguration());
conf.setFloat("hbase.procedure.worker.add.stuck.percentage", 0.5f);
conf.setInt("hbase.procedure.worker.monitor.interval.msec", 500);
conf.setInt("hbase.procedure.worker.stuck.threshold.msec", 750);
final int NUM_THREADS = 2;
createNewExecutor(conf, NUM_THREADS);
Semaphore latch1 = new Semaphore(2);
latch1.acquire(2);
BusyWaitProcedure busyProc1 = new BusyWaitProcedure(latch1);
Semaphore latch2 = new Semaphore(2);
latch2.acquire(2);
BusyWaitProcedure busyProc2 = new BusyWaitProcedure(latch2);
long busyProcId1 = procExecutor.submitProcedure(busyProc1);
long busyProcId2 = procExecutor.submitProcedure(busyProc2);
long otherProcId = procExecutor.submitProcedure(new NoopProcedure());
// wait until a new worker is being created
int threads1 = waitThreadCount(NUM_THREADS + 1);
LOG.info("new threads got created: " + (threads1 - NUM_THREADS));
assertEquals(NUM_THREADS + 1, threads1);
ProcedureTestingUtility.waitProcedure(procExecutor, otherProcId);
assertEquals(true, procExecutor.isFinished(otherProcId));
ProcedureTestingUtility.assertProcNotFailed(procExecutor, otherProcId);
assertEquals(true, procExecutor.isRunning());
assertEquals(false, procExecutor.isFinished(busyProcId1));
assertEquals(false, procExecutor.isFinished(busyProcId2));
// terminate the busy procedures
latch1.release();
latch2.release();
LOG.info("set keep alive and wait threads being removed");
procExecutor.setKeepAliveTime(500L, TimeUnit.MILLISECONDS);
int threads2 = waitThreadCount(NUM_THREADS);
LOG.info("threads got removed: " + (threads1 - threads2));
assertEquals(NUM_THREADS, threads2);
// terminate the busy procedures
latch1.release();
latch2.release();
// wait for all procs to complete
ProcedureTestingUtility.waitProcedure(procExecutor, busyProcId1);
ProcedureTestingUtility.waitProcedure(procExecutor, busyProcId2);
ProcedureTestingUtility.assertProcNotFailed(procExecutor, busyProcId1);
ProcedureTestingUtility.assertProcNotFailed(procExecutor, busyProcId2);
}
use of org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.NoopProcedure in project hbase by apache.
the class TestSyncReplicationReplayWALManager method testUsedWorkers.
@Test
public void testUsedWorkers() throws ProcedureSuspendedException {
String peerId1 = "1";
String peerId2 = "2";
ServerName sn1 = ServerName.valueOf("host1", 123, 12345);
ServerName sn2 = ServerName.valueOf("host2", 234, 23456);
ServerName sn3 = ServerName.valueOf("host3", 345, 34567);
onlineServers.add(sn1);
manager.registerPeer(peerId1);
manager.registerPeer(peerId2);
// confirm that different peer ids does not affect each other
assertEquals(sn1, manager.acquirePeerWorker(peerId1, new NoopProcedure<>()));
assertEquals(sn1, manager.acquirePeerWorker(peerId2, new NoopProcedure<>()));
onlineServers.add(sn2);
assertEquals(sn2, manager.acquirePeerWorker(peerId1, new NoopProcedure<>()));
assertEquals(sn2, manager.acquirePeerWorker(peerId2, new NoopProcedure<>()));
NoopProcedure<?> proc = new NoopProcedure<>();
try {
manager.acquirePeerWorker(peerId1, proc);
fail("Should suspend");
} catch (ProcedureSuspendedException e) {
// expected
}
manager.releasePeerWorker(peerId1, sn1, scheduler);
assertEquals(1, wokenProcedures.size());
assertSame(proc, wokenProcedures.poll());
assertEquals(sn1, manager.acquirePeerWorker(peerId1, new NoopProcedure<>()));
NoopProcedure<?> proc1 = new NoopProcedure<>();
NoopProcedure<?> proc2 = new NoopProcedure<>();
try {
manager.acquirePeerWorker(peerId1, proc1);
fail("Should suspend");
} catch (ProcedureSuspendedException e) {
// expected
}
try {
manager.acquirePeerWorker(peerId1, proc2);
fail("Should suspend");
} catch (ProcedureSuspendedException e) {
// expected
}
listeners.get(0).serverAdded(sn3);
assertEquals(2, wokenProcedures.size());
assertSame(proc2, wokenProcedures.poll());
assertSame(proc1, wokenProcedures.poll());
}
Aggregations