use of org.apache.cassandra.repair.messages.FailSession in project cassandra by apache.
the class CoordinatorSessionTest method multipleFailures.
/**
* Coordinator should only send out failures messages once
*/
@Test
public void multipleFailures() {
InstrumentedCoordinatorSession coordinator = createInstrumentedSession();
Assert.assertEquals(PREPARING, coordinator.getState());
Assert.assertTrue(coordinator.sentMessages.isEmpty());
coordinator.fail();
Assert.assertEquals(FAILED, coordinator.getState());
for (InetAddress participant : PARTICIPANTS) {
assertMessageSent(coordinator, participant, new FailSession(coordinator.sessionID));
}
coordinator.sentMessages.clear();
coordinator.fail();
Assert.assertEquals(FAILED, coordinator.getState());
Assert.assertTrue(coordinator.sentMessages.isEmpty());
}
use of org.apache.cassandra.repair.messages.FailSession in project cassandra by apache.
the class CoordinatorSessionsTest method handleFailureMessage.
@Test
public void handleFailureMessage() {
InstrumentedCoordinatorSessions sessions = new InstrumentedCoordinatorSessions();
UUID sessionID = registerSession();
InstrumentedCoordinatorSession session = sessions.registerSession(sessionID, PARTICIPANTS);
Assert.assertEquals(0, session.failCalls);
sessions.handleFailSessionMessage(new FailSession(sessionID));
Assert.assertEquals(1, session.failCalls);
}
use of org.apache.cassandra.repair.messages.FailSession in project cassandra by apache.
the class LocalSessionTest method prepareAntiCompactFailure.
/**
* If anti compactionn fails, we should fail the session locally,
* and send a failure message back to the coordinator
*/
@Test
public void prepareAntiCompactFailure() {
UUID sessionID = registerSession();
InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
sessions.start();
// replacing future so we can inspect state before and after anti compaction callback
sessions.pendingAntiCompactionFuture = SettableFuture.create();
Assert.assertFalse(sessions.submitPendingAntiCompactionCalled);
sessions.handlePrepareMessage(PARTICIPANT1, new PrepareConsistentRequest(sessionID, COORDINATOR, PARTICIPANTS));
Assert.assertTrue(sessions.submitPendingAntiCompactionCalled);
Assert.assertTrue(sessions.sentMessages.isEmpty());
// anti compaction hasn't finished yet, so state in memory and on disk should be PREPARING
LocalSession session = sessions.getSession(sessionID);
Assert.assertNotNull(session);
Assert.assertEquals(PREPARING, session.getState());
Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
// anti compaction has now finished, so state in memory and on disk should be PREPARED
sessions.pendingAntiCompactionFuture.setException(new RuntimeException());
session = sessions.getSession(sessionID);
Assert.assertNotNull(session);
Assert.assertEquals(FAILED, session.getState());
Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
// ...and we should have sent a success message back to the coordinator
assertMessagesSent(sessions, COORDINATOR, new FailSession(sessionID));
}
use of org.apache.cassandra.repair.messages.FailSession in project cassandra by apache.
the class LocalSessionTest method finalizeProposeNonExistantSessionFailure.
@Test
public void finalizeProposeNonExistantSessionFailure() {
InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
UUID fakeID = UUIDGen.getTimeUUID();
sessions.handleFinalizeProposeMessage(COORDINATOR, new FinalizePropose(fakeID));
Assert.assertNull(sessions.getSession(fakeID));
assertMessagesSent(sessions, COORDINATOR, new FailSession(fakeID));
}
use of org.apache.cassandra.repair.messages.FailSession in project cassandra by apache.
the class CoordinatorSessionTest method failedRepairs.
@Test
public void failedRepairs() {
InstrumentedCoordinatorSession coordinator = createInstrumentedSession();
Executor executor = MoreExecutors.directExecutor();
AtomicBoolean repairSubmitted = new AtomicBoolean(false);
SettableFuture<List<RepairSessionResult>> repairFuture = SettableFuture.create();
Supplier<ListenableFuture<List<RepairSessionResult>>> sessionSupplier = () -> {
repairSubmitted.set(true);
return repairFuture;
};
// coordinator sends prepare requests to create local session and perform anticompaction
AtomicBoolean hasFailures = new AtomicBoolean(false);
Assert.assertFalse(repairSubmitted.get());
Assert.assertTrue(coordinator.sentMessages.isEmpty());
ListenableFuture sessionResult = coordinator.execute(executor, sessionSupplier, hasFailures);
for (InetAddress participant : PARTICIPANTS) {
PrepareConsistentRequest expected = new PrepareConsistentRequest(coordinator.sessionID, COORDINATOR, new HashSet<>(PARTICIPANTS));
assertMessageSent(coordinator, participant, expected);
}
// participants respond to coordinator, and repair begins once all participants have responded with success
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
coordinator.handlePrepareResponse(PARTICIPANT1, true);
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
coordinator.handlePrepareResponse(PARTICIPANT2, true);
Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
// set the setRepairing callback to verify the correct state when it's called
Assert.assertFalse(coordinator.setRepairingCalled);
coordinator.onSetRepairing = () -> Assert.assertEquals(PREPARED, coordinator.getState());
coordinator.handlePrepareResponse(PARTICIPANT3, true);
Assert.assertTrue(coordinator.setRepairingCalled);
Assert.assertTrue(repairSubmitted.get());
Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
ArrayList<RepairSessionResult> results = Lists.newArrayList(createResult(coordinator), null, createResult(coordinator));
coordinator.sentMessages.clear();
Assert.assertFalse(coordinator.failCalled);
coordinator.onFail = () -> Assert.assertEquals(REPAIRING, coordinator.getState());
repairFuture.set(results);
Assert.assertTrue(coordinator.failCalled);
// all participants should have been notified of session failure
for (InetAddress participant : PARTICIPANTS) {
RepairMessage expected = new FailSession(coordinator.sessionID);
assertMessageSent(coordinator, participant, expected);
}
Assert.assertTrue(sessionResult.isDone());
Assert.assertTrue(hasFailures.get());
}
Aggregations