Search in sources :

Example 11 with PrepareConsistentRequest

use of org.apache.cassandra.repair.messages.PrepareConsistentRequest in project cassandra by apache.

the class LocalSessionTest method prepareSuccessCase.

@Test
public void prepareSuccessCase() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    // replacing future so we can inspect state before and after anti compaction callback
    sessions.prepareSessionFuture = new AsyncPromise<>();
    Assert.assertFalse(sessions.prepareSessionCalled);
    sessions.handlePrepareMessage(PARTICIPANT1, new PrepareConsistentRequest(sessionID, COORDINATOR, PARTICIPANTS));
    Assert.assertTrue(sessions.prepareSessionCalled);
    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.prepareSessionFuture.trySuccess(null);
    session = sessions.getSession(sessionID);
    Assert.assertNotNull(session);
    Assert.assertEquals(PREPARED, session.getState());
    Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
    // ...and we should have sent a success message back to the coordinator
    assertMessagesSent(sessions, COORDINATOR, new PrepareConsistentResponse(sessionID, PARTICIPANT1, true));
}
Also used : PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) UUID(java.util.UUID) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 12 with PrepareConsistentRequest

use of org.apache.cassandra.repair.messages.PrepareConsistentRequest in project cassandra by apache.

the class LocalSessionTest method prepareWithNonExistantParentSession.

/**
 * If a ParentRepairSession wasn't previously created, we shouldn't
 * create a session locally, but we should send a failure message to
 * the coordinator.
 */
@Test
public void prepareWithNonExistantParentSession() {
    UUID sessionID = UUIDGen.getTimeUUID();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.handlePrepareMessage(PARTICIPANT1, new PrepareConsistentRequest(sessionID, COORDINATOR, PARTICIPANTS));
    Assert.assertNull(sessions.getSession(sessionID));
    assertMessagesSent(sessions, COORDINATOR, new PrepareConsistentResponse(sessionID, PARTICIPANT1, false));
}
Also used : PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) UUID(java.util.UUID) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 13 with PrepareConsistentRequest

use of org.apache.cassandra.repair.messages.PrepareConsistentRequest in project cassandra by apache.

the class LocalSessionTest method isSessionInProgress.

/**
 * Check all states (except failed)
 */
@Test
public void isSessionInProgress() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    // prevent moving to prepared
    sessions.prepareSessionFuture = new AsyncPromise<>();
    sessions.handlePrepareMessage(PARTICIPANT1, new PrepareConsistentRequest(sessionID, COORDINATOR, PARTICIPANTS));
    LocalSession session = sessions.getSession(sessionID);
    Assert.assertNotNull(session);
    Assert.assertEquals(PREPARING, session.getState());
    Assert.assertTrue(sessions.isSessionInProgress(sessionID));
    session.setState(PREPARED);
    Assert.assertTrue(sessions.isSessionInProgress(sessionID));
    session.setState(REPAIRING);
    Assert.assertTrue(sessions.isSessionInProgress(sessionID));
    session.setState(FINALIZE_PROMISED);
    Assert.assertTrue(sessions.isSessionInProgress(sessionID));
    session.setState(FINALIZED);
    Assert.assertFalse(sessions.isSessionInProgress(sessionID));
}
Also used : UUID(java.util.UUID) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Aggregations

PrepareConsistentRequest (org.apache.cassandra.repair.messages.PrepareConsistentRequest)13 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)10 Test (org.junit.Test)10 UUID (java.util.UUID)7 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)6 RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)6 PrepareConsistentResponse (org.apache.cassandra.repair.messages.PrepareConsistentResponse)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 CoordinatedRepairResult (org.apache.cassandra.repair.CoordinatedRepairResult)4 Future (org.apache.cassandra.utils.concurrent.Future)4 Collection (java.util.Collection)3 RepairSessionResult (org.apache.cassandra.repair.RepairSessionResult)3 FailSession (org.apache.cassandra.repair.messages.FailSession)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 BooleanSupplier (java.util.function.BooleanSupplier)2 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)2 KeyspaceRepairManager (org.apache.cassandra.repair.KeyspaceRepairManager)2 FinalizePropose (org.apache.cassandra.repair.messages.FinalizePropose)2