Search in sources :

Example 1 with MockMessagingSpy

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

the class HintServiceBytemanTest method testListPendingHints.

@Test
@BMRule(name = "Delay delivering hints", targetClass = "DispatchHintsTask", targetMethod = "run", action = "Thread.sleep(DatabaseDescriptor.getHintsFlushPeriodInMS() * 3L)")
public void testListPendingHints() throws InterruptedException, ExecutionException {
    HintsService.instance.resumeDispatch();
    MockMessagingSpy spy = sendHintsAndResponses(metadata, 20000, -1);
    Awaitility.await("For the hints file to flush").atMost(Duration.ofMillis(DatabaseDescriptor.getHintsFlushPeriodInMS() * 2L)).until(() -> !HintsService.instance.getPendingHints().isEmpty());
    List<PendingHintsInfo> pendingHints = HintsService.instance.getPendingHintsInfo();
    assertEquals(1, pendingHints.size());
    PendingHintsInfo info = pendingHints.get(0);
    assertEquals(StorageService.instance.getLocalHostUUID(), info.hostId);
    assertEquals(1, info.totalFiles);
    // there is 1 descriptor with only 1 timestamp
    assertEquals(info.oldestTimestamp, info.newestTimestamp);
    spy.interceptMessageOut(20000).get();
    assertEquals(Collections.emptyList(), HintsService.instance.getPendingHints());
}
Also used : MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Example 2 with MockMessagingSpy

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

the class CoordinatorMessagingTest method testMockedMessagingHappyPath.

@Test
public void testMockedMessagingHappyPath() throws InterruptedException, ExecutionException, TimeoutException, NoSuchRepairSessionException {
    CountDownLatch prepareLatch = createLatch();
    CountDownLatch finalizeLatch = createLatch();
    MockMessagingSpy spyPrepare = createPrepareSpy(Collections.emptySet(), Collections.emptySet(), prepareLatch);
    MockMessagingSpy spyFinalize = createFinalizeSpy(Collections.emptySet(), Collections.emptySet(), finalizeLatch);
    MockMessagingSpy spyCommit = createCommitSpy();
    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);
    Assert.assertFalse(sessionResult.isDone());
    // prepare completed
    prepareLatch.countDown();
    spyPrepare.interceptMessageOut(3).get(1, TimeUnit.SECONDS);
    Assert.assertFalse(sessionResult.isDone());
    // set result from local repair session
    repairFuture.trySuccess(CoordinatedRepairResult.success(Lists.newArrayList(createResult(coordinator), createResult(coordinator), createResult(coordinator))));
    // finalize phase
    finalizeLatch.countDown();
    spyFinalize.interceptMessageOut(3).get(1, TimeUnit.SECONDS);
    // commit phase
    spyCommit.interceptMessageOut(3).get(1, TimeUnit.SECONDS);
    Assert.assertFalse(sessionResult.get().hasFailed());
    // expect no other messages except from intercepted so far
    spyPrepare.interceptNoMsg(100, TimeUnit.MILLISECONDS);
    spyFinalize.interceptNoMsg(100, TimeUnit.MILLISECONDS);
    spyCommit.interceptNoMsg(100, TimeUnit.MILLISECONDS);
    Assert.assertEquals(ConsistentSession.State.FINALIZED, 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) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 3 with MockMessagingSpy

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

the class HintsTestUtil method sendHintsAndResponses.

static MockMessagingSpy sendHintsAndResponses(TableMetadata metadata, int noOfHints, int noOfResponses) {
    // create spy for hint messages, but only create responses for noOfResponses hints
    Message<NoPayload> message = Message.internalResponse(HINT_RSP, NoPayload.noPayload);
    MockMessagingSpy spy;
    if (noOfResponses != -1) {
        spy = MockMessagingService.when(verb(HINT_REQ)).respondN(message, noOfResponses);
    } else {
        spy = MockMessagingService.when(verb(HINT_REQ)).respond(message);
    }
    // create and write noOfHints using service
    UUID hostId = StorageService.instance.getLocalHostUUID();
    for (int i = 0; i < noOfHints; i++) {
        long now = Clock.Global.currentTimeMillis();
        DecoratedKey dkey = dk(String.valueOf(i));
        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 : DecoratedKey(org.apache.cassandra.db.DecoratedKey) UUID(java.util.UUID) NoPayload(org.apache.cassandra.net.NoPayload) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 4 with MockMessagingSpy

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

the class ShadowRoundTest method testPreviouslyAssassinatedInShadow.

@Test
public void testPreviouslyAssassinatedInShadow() {
    final AtomicBoolean ackSend = new AtomicBoolean(false);
    MockMessagingSpy spySyn = MockMessagingService.when(verb(Verb.GOSSIP_DIGEST_SYN)).respondN((msgOut, to) -> {
        // ACK with self assassinated in shadow round
        if (!ackSend.compareAndSet(false, true)) {
            while (!Gossiper.instance.isEnabled()) ;
        }
        HeartBeatState hb = new HeartBeatState(123, 456);
        EndpointState state = new EndpointState(hb);
        state.addApplicationState(ApplicationState.STATUS_WITH_PORT, VersionedValue.unsafeMakeVersionedValue(VersionedValue.STATUS_LEFT, 1));
        GossipDigestAck payload = new GossipDigestAck(Collections.singletonList(new GossipDigest(FBUtilities.getBroadcastAddressAndPort(), hb.getGeneration(), hb.getHeartBeatVersion())), Collections.singletonMap(FBUtilities.getBroadcastAddressAndPort(), state));
        logger.debug("Simulating bad digest ACK reply");
        return Message.builder(Verb.GOSSIP_DIGEST_ACK, payload).from(to).build();
    }, 1);
    System.setProperty(Config.PROPERTY_PREFIX + "auto_bootstrap", "false");
    StorageService.instance.checkForEndpointCollision(SystemKeyspace.getOrInitializeLocalHostId(), SystemKeyspace.loadHostIds().keySet());
    System.clearProperty(Config.PROPERTY_PREFIX + "auto_bootstrap");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) Test(org.junit.Test)

Example 5 with MockMessagingSpy

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

the class ShadowRoundTest method testBadAckInShadow.

@Test
public void testBadAckInShadow() {
    final AtomicBoolean ackSend = new AtomicBoolean(false);
    MockMessagingSpy spySyn = MockMessagingService.when(verb(Verb.GOSSIP_DIGEST_SYN)).respondN((msgOut, to) -> {
        // ACK with bad data in shadow round
        if (!ackSend.compareAndSet(false, true)) {
            while (!Gossiper.instance.isEnabled()) ;
        }
        InetAddressAndPort junkaddr;
        try {
            junkaddr = InetAddressAndPort.getByName("1.1.1.1");
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        HeartBeatState hb = new HeartBeatState(123, 456);
        EndpointState state = new EndpointState(hb);
        List<GossipDigest> gDigests = new ArrayList<GossipDigest>();
        gDigests.add(new GossipDigest(FBUtilities.getBroadcastAddressAndPort(), hb.getGeneration(), hb.getHeartBeatVersion()));
        gDigests.add(new GossipDigest(junkaddr, hb.getGeneration(), hb.getHeartBeatVersion()));
        Map<InetAddressAndPort, EndpointState> smap = new HashMap<InetAddressAndPort, EndpointState>() {

            {
                put(FBUtilities.getBroadcastAddressAndPort(), state);
                put(junkaddr, state);
            }
        };
        GossipDigestAck payload = new GossipDigestAck(gDigests, smap);
        logger.debug("Simulating bad digest ACK reply");
        return Message.builder(Verb.GOSSIP_DIGEST_ACK, payload).from(to).build();
    }, 1);
    System.setProperty(Config.PROPERTY_PREFIX + "auto_bootstrap", "false");
    try {
        StorageService.instance.checkForEndpointCollision(SystemKeyspace.getOrInitializeLocalHostId(), SystemKeyspace.loadHostIds().keySet());
    } catch (Exception e) {
        assertEquals("Unable to gossip with any peers", e.getMessage());
    }
    System.clearProperty(Config.PROPERTY_PREFIX + "auto_bootstrap");
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UnknownHostException(java.net.UnknownHostException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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