Search in sources :

Example 6 with MockMessagingSpy

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

the class HintsServiceTest method sendHintsAndResponses.

private MockMessagingSpy sendHintsAndResponses(int noOfHints, int noOfResponses) {
    // create spy for hint messages, but only create responses for noOfResponses hints
    MessageIn<HintResponse> messageIn = MessageIn.create(FBUtilities.getBroadcastAddress(), HintResponse.instance, Collections.emptyMap(), MessagingService.Verb.REQUEST_RESPONSE, MessagingService.current_version);
    MockMessagingSpy spy;
    if (noOfResponses != -1) {
        spy = MockMessagingService.when(verb(MessagingService.Verb.HINT)).respondN(messageIn, noOfResponses);
    } else {
        spy = MockMessagingService.when(verb(MessagingService.Verb.HINT)).respond(messageIn);
    }
    // create and write noOfHints using service
    UUID hostId = StorageService.instance.getLocalHostUUID();
    for (int i = 0; i < noOfHints; i++) {
        long now = System.currentTimeMillis();
        DecoratedKey dkey = dk(String.valueOf(i));
        TableMetadata metadata = Schema.instance.getTableMetadata(KEYSPACE, TABLE);
        PartitionUpdate.SimpleBuilder builder = PartitionUpdate.simpleBuilder(metadata, dkey).timestamp(now);
        builder.row("column0").add("val", "value0");
        Hint hint = Hint.create(builder.buildAsMutation(), now);
        HintsService.instance.write(hostId, hint);
    }
    return spy;
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) DecoratedKey(org.apache.cassandra.db.DecoratedKey) UUID(java.util.UUID) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 7 with MockMessagingSpy

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

the class ShadowRoundTest method testDelayedResponse.

@Test
public void testDelayedResponse() {
    Gossiper.instance.buildSeedsList();
    int noOfSeeds = Gossiper.instance.seeds.size();
    final AtomicBoolean ackSend = new AtomicBoolean(false);
    MockMessagingSpy spySyn = MockMessagingService.when(verb(Verb.GOSSIP_DIGEST_SYN)).respondN((msgOut, to) -> {
        // and then respond with remaining ACKs from other seeds
        if (!ackSend.compareAndSet(false, true)) {
            while (!Gossiper.instance.isEnabled()) ;
        }
        HeartBeatState hb = new HeartBeatState(123, 456);
        EndpointState state = new EndpointState(hb);
        GossipDigestAck payload = new GossipDigestAck(Collections.singletonList(new GossipDigest(to, hb.getGeneration(), hb.getHeartBeatVersion())), Collections.singletonMap(to, state));
        logger.debug("Simulating digest ACK response");
        return Message.builder(Verb.GOSSIP_DIGEST_ACK, payload).from(to).build();
    }, noOfSeeds);
    // GossipDigestAckVerbHandler will send ack2 for each ack received (after the shadow round)
    MockMessagingSpy spyAck2 = MockMessagingService.when(verb(Verb.GOSSIP_DIGEST_ACK2)).dontReply();
    // Migration request messages should not be emitted during shadow round
    MockMessagingSpy spyMigrationReq = MockMessagingService.when(verb(Verb.SCHEMA_PULL_REQ)).dontReply();
    try {
        StorageService.instance.initServer();
    } catch (Exception e) {
        assertThat(e.getMessage()).startsWith("Unable to contact any seeds");
    }
    // we expect one SYN for each seed during shadow round + additional SYNs after gossiper has been enabled
    assertTrue(spySyn.messagesIntercepted() > noOfSeeds);
    // we don't expect to emit any GOSSIP_DIGEST_ACK2 or SCHEMA_PULL messages
    assertEquals(0, spyAck2.messagesIntercepted());
    assertEquals(0, spyMigrationReq.messagesIntercepted());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UnknownHostException(java.net.UnknownHostException) Test(org.junit.Test)

Example 8 with MockMessagingSpy

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

the class HintsServiceTest method testPauseAndResume.

@Test
public void testPauseAndResume() throws InterruptedException, ExecutionException {
    HintsService.instance.pauseDispatch();
    // create spy for hint messages
    MockMessagingSpy spy = sendHintsAndResponses(metadata, 100, -1);
    // we should not send any hints while paused
    ListenableFuture<Boolean> noMessagesWhilePaused = spy.interceptNoMsg(15, TimeUnit.SECONDS);
    Futures.addCallback(noMessagesWhilePaused, new MoreFutures.SuccessCallback<Boolean>() {

        public void onSuccess(@Nullable Boolean aBoolean) {
            HintsService.instance.resumeDispatch();
        }
    }, MoreExecutors.directExecutor());
    Futures.allAsList(noMessagesWhilePaused, spy.interceptMessageOut(100), spy.interceptNoMsg(200, TimeUnit.MILLISECONDS)).get();
}
Also used : MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) MoreFutures(com.datastax.driver.core.utils.MoreFutures) Test(org.junit.Test)

Example 9 with MockMessagingSpy

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

the class HintsServiceTest method testPageSeek.

@Test
public void testPageSeek() throws InterruptedException, ExecutionException {
    // create spy for hint messages, stop replying after 12k (should be on 3rd page)
    MockMessagingSpy spy = sendHintsAndResponses(metadata, 20000, 12000);
    // At this point the dispatcher will constantly retry the page we stopped acking,
    // thus we receive the same hints from the page multiple times and in total more than
    // all written hints. Lets just consume them for a while and then pause the dispatcher.
    spy.interceptMessageOut(22000).get();
    HintsService.instance.pauseDispatch();
    Thread.sleep(1000);
    // verify that we have a dispatch offset set for the page we're currently stuck at
    HintsStore store = HintsService.instance.getCatalog().get(StorageService.instance.getLocalHostUUID());
    HintsDescriptor descriptor = store.poll();
    // add again for cleanup during re-instanciation
    store.offerFirst(descriptor);
    InputPosition dispatchOffset = store.getDispatchOffset(descriptor);
    assertTrue(dispatchOffset != null);
    assertTrue(((ChecksummedDataInput.Position) dispatchOffset).sourcePosition > 0);
}
Also used : MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) Test(org.junit.Test)

Example 10 with MockMessagingSpy

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

the class HintsServiceTest method testPageRetry.

@Test
public void testPageRetry() throws InterruptedException, ExecutionException, TimeoutException {
    // create spy for hint messages, but only create responses for 5 hints
    MockMessagingSpy spy = sendHintsAndResponses(metadata, 20, 5);
    Futures.allAsList(// and only wait for the acks before going to the next page
    spy.interceptMessageOut(20), spy.interceptNoMsg(200, TimeUnit.MILLISECONDS), // next tick will trigger a retry of the same page as we only replied with 5/20 acks
    spy.interceptMessageOut(20)).get();
    // marking the destination node as dead should stop sending hints
    failureDetector.isAlive = false;
    spy.interceptNoMsg(20, TimeUnit.SECONDS).get();
}
Also used : MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) Test(org.junit.Test)

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