Search in sources :

Example 11 with MockMessagingSpy

use of org.apache.cassandra.net.MockMessagingSpy in project cassandra by apache.

the class HintsServiceTest method testDispatchHints.

@Test
public void testDispatchHints() throws InterruptedException, ExecutionException {
    long cnt = StorageMetrics.totalHints.getCount();
    // create spy for hint messages
    MockMessagingSpy spy = sendHintsAndResponses(metadata, 100, -1);
    // metrics should have been updated with number of create hints
    assertEquals(cnt + 100, StorageMetrics.totalHints.getCount());
    // wait until hints have been send
    spy.interceptMessageOut(100).get();
    spy.interceptNoMsg(500, TimeUnit.MILLISECONDS).get();
}
Also used : MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) Test(org.junit.Test)

Example 12 with MockMessagingSpy

use of org.apache.cassandra.net.MockMessagingSpy in project cassandra by apache.

the class CoordinatorMessagingTest method testMockedMessagingPrepareTimeout.

@Test
public void testMockedMessagingPrepareTimeout() throws InterruptedException, ExecutionException, TimeoutException, NoSuchRepairSessionException {
    MockMessagingSpy spyPrepare = createPrepareSpy(Collections.emptySet(), Collections.singleton(PARTICIPANT3), new CountDownLatch(0));
    MockMessagingSpy sendFailSessionUnexpectedSpy = createFailSessionSpy(Lists.newArrayList(PARTICIPANT1, PARTICIPANT2, PARTICIPANT3));
    UUID uuid = registerSession(cfs, true, true);
    CoordinatorSession coordinator = ActiveRepairService.instance.consistent.coordinated.registerSession(uuid, PARTICIPANTS, false);
    AtomicBoolean repairSubmitted = new AtomicBoolean(false);
    Promise<CoordinatedRepairResult> repairFuture = AsyncPromise.uncancellable();
    Supplier<Future<CoordinatedRepairResult>> sessionSupplier = () -> {
        repairSubmitted.set(true);
        return repairFuture;
    };
    // coordinator sends prepare requests to create local session and perform anticompaction
    Assert.assertFalse(repairSubmitted.get());
    // execute repair and start prepare phase
    Future<CoordinatedRepairResult> sessionResult = coordinator.execute(sessionSupplier);
    try {
        sessionResult.get(1, TimeUnit.SECONDS);
        fail("Completed session without failure after prepare failed");
    } catch (ExecutionException e) {
        fail("Failed session in prepare failed during timeout from participant");
    } catch (TimeoutException e) {
    // expected
    }
    // we won't send out any fail session message in case of timeouts
    spyPrepare.expectMockedMessage(2).get(100, TimeUnit.MILLISECONDS);
    sendFailSessionUnexpectedSpy.interceptNoMsg(100, TimeUnit.MILLISECONDS);
    Assert.assertFalse(repairSubmitted.get());
    Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
    Assert.assertFalse(ActiveRepairService.instance.consistent.local.isSessionInProgress(uuid));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoordinatedRepairResult(org.apache.cassandra.repair.CoordinatedRepairResult) Future(org.apache.cassandra.utils.concurrent.Future) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) TimeoutException(java.util.concurrent.TimeoutException) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 13 with MockMessagingSpy

use of org.apache.cassandra.net.MockMessagingSpy in project cassandra by apache.

the class CoordinatorMessagingTest method testMockedMessagingPrepareFailure.

private void testMockedMessagingPrepareFailure(CountDownLatch prepareLatch) throws InterruptedException, ExecutionException, TimeoutException, NoSuchRepairSessionException {
    // we expect FailSession messages to all participants
    MockMessagingSpy sendFailSessionExpectedSpy = createFailSessionSpy(Lists.newArrayList(PARTICIPANT1, PARTICIPANT2, PARTICIPANT3));
    UUID uuid = registerSession(cfs, true, true);
    CoordinatorSession coordinator = ActiveRepairService.instance.consistent.coordinated.registerSession(uuid, PARTICIPANTS, false);
    AtomicBoolean repairSubmitted = new AtomicBoolean(false);
    Promise<CoordinatedRepairResult> repairFuture = AsyncPromise.uncancellable();
    Supplier<Future<CoordinatedRepairResult>> sessionSupplier = () -> {
        repairSubmitted.set(true);
        return repairFuture;
    };
    // coordinator sends prepare requests to create local session and perform anticompaction
    Assert.assertFalse(repairSubmitted.get());
    // execute repair and start prepare phase
    Future<CoordinatedRepairResult> sessionResult = coordinator.execute(sessionSupplier);
    prepareLatch.countDown();
    // prepare completed
    try {
        sessionResult.get(1, TimeUnit.SECONDS);
        fail("Completed session without failure after prepare failed");
    } catch (ExecutionException e) {
    }
    sendFailSessionExpectedSpy.interceptMessageOut(3).get(1, TimeUnit.SECONDS);
    Assert.assertFalse(repairSubmitted.get());
    Assert.assertTrue(sessionResult.isDone());
    Assert.assertNotNull(sessionResult.cause());
    Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
    Assert.assertFalse(ActiveRepairService.instance.consistent.local.isSessionInProgress(uuid));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoordinatedRepairResult(org.apache.cassandra.repair.CoordinatedRepairResult) Future(org.apache.cassandra.utils.concurrent.Future) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy)

Aggregations

MockMessagingSpy (org.apache.cassandra.net.MockMessagingSpy)13 Test (org.junit.Test)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 UUID (java.util.UUID)5 CoordinatedRepairResult (org.apache.cassandra.repair.CoordinatedRepairResult)3 Future (org.apache.cassandra.utils.concurrent.Future)3 UnknownHostException (java.net.UnknownHostException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)2 MoreFutures (com.datastax.driver.core.utils.MoreFutures)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 NoPayload (org.apache.cassandra.net.NoPayload)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1