Search in sources :

Example 1 with ResumeSamplingResult

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());
}
Also used : CruiseControlResponse(com.linkedin.cruisecontrol.servlet.response.CruiseControlResponse) ResumeSamplingResult(com.linkedin.kafka.cruisecontrol.servlet.response.ResumeSamplingResult) Test(org.junit.Test)

Example 2 with ResumeSamplingResult

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());
}
Also used : CruiseControlResponse(com.linkedin.cruisecontrol.servlet.response.CruiseControlResponse) Semaphore(java.util.concurrent.Semaphore) CancellationException(java.util.concurrent.CancellationException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CancellationException(java.util.concurrent.CancellationException) ResumeSamplingResult(com.linkedin.kafka.cruisecontrol.servlet.response.ResumeSamplingResult) PauseSamplingResult(com.linkedin.kafka.cruisecontrol.servlet.response.PauseSamplingResult) Test(org.junit.Test)

Aggregations

CruiseControlResponse (com.linkedin.cruisecontrol.servlet.response.CruiseControlResponse)2 ResumeSamplingResult (com.linkedin.kafka.cruisecontrol.servlet.response.ResumeSamplingResult)2 Test (org.junit.Test)2 PauseSamplingResult (com.linkedin.kafka.cruisecontrol.servlet.response.PauseSamplingResult)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Semaphore (java.util.concurrent.Semaphore)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1