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());
}
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));
}
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;
}
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");
}
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");
}
Aggregations