use of com.linkedin.kafka.cruisecontrol.servlet.response.ResumeSamplingResult in project cruise-control by linkedin.
the class OperationFutureTest method testGetCompleted.
@Test
public void testGetCompleted() throws InterruptedException {
OperationFuture future = new OperationFuture("testGetCompleted");
TestThread t = new TestThread(future);
t.start();
CruiseControlResponse expectedResponse = new ResumeSamplingResult(null);
future.complete(expectedResponse);
t.join();
assertTrue(future.isDone());
assertEquals(expectedResponse, t.result());
}
use of com.linkedin.kafka.cruisecontrol.servlet.response.ResumeSamplingResult in project cruise-control by linkedin.
the class OperationFutureTest method testCancelInProgressFuture.
@Test
public void testCancelInProgressFuture() throws InterruptedException {
OperationFuture future = new OperationFuture("testCancelInProgressFuture");
AtomicBoolean interrupted = new AtomicBoolean(false);
Semaphore resultIsCalledSemaphore = new Semaphore(1);
resultIsCalledSemaphore.acquire();
// An execution thread that should be interrupted before completing the future.
Thread executionThread = new Thread(new OperationRunnable(null, future) {
@Override
protected CruiseControlResponse getResult() throws Exception {
resultIsCalledSemaphore.release();
try {
synchronized (this) {
while (!interrupted.get()) {
this.wait();
}
}
return new ResumeSamplingResult(null);
} catch (InterruptedException ie) {
interrupted.set(true);
throw ie;
}
}
});
executionThread.start();
TestThread t = new TestThread(future);
t.start();
resultIsCalledSemaphore.acquire();
future.cancel(true);
t.join();
executionThread.join();
assertThat(t.result(), instanceOf(PauseSamplingResult.class));
assertThat(t.exception(), instanceOf(CancellationException.class));
assertTrue(future.isDone());
assertTrue(future.isCancelled());
assertTrue(interrupted.get());
}
Aggregations