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