Search in sources :

Example 1 with MasterImpl

use of org.neo4j.kernel.ha.com.master.MasterImpl in project neo4j by neo4j.

the class MasterEpochTest method shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch.

@Test
public void shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch() throws Throwable {
    // GIVEN
    SPI spi = MasterImplTest.mockedSpi();
    IdAllocation servedIdAllocation = idAllocation(0, 999);
    when(spi.allocateIds(any(IdType.class))).thenReturn(servedIdAllocation);
    when(spi.getTransactionChecksum(anyLong())).thenReturn(10L);
    StoreId storeId = newStoreIdForCurrentVersion();
    MasterImpl master = new MasterImpl(spi, mock(ConversationManager.class), mock(MasterImpl.Monitor.class), Config.embeddedDefaults(stringMap(ClusterSettings.server_id.name(), "1")));
    HandshakeResult handshake = master.handshake(1, storeId).response();
    master.start();
    // WHEN/THEN
    IdAllocation idAllocation = master.allocateIds(context(handshake.epoch()), IdType.NODE).response();
    assertEquals(servedIdAllocation.getHighestIdInUse(), idAllocation.getHighestIdInUse());
    try {
        master.allocateIds(context(handshake.epoch() + 1), IdType.NODE);
        fail("Should fail with invalid epoch");
    } catch (InvalidEpochException e) {
    // Good
    }
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) StoreId(org.neo4j.kernel.impl.store.StoreId) ConversationManager(org.neo4j.kernel.ha.com.master.ConversationManager) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) IdType(org.neo4j.kernel.impl.store.id.IdType) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Example 2 with MasterImpl

use of org.neo4j.kernel.ha.com.master.MasterImpl in project neo4j by neo4j.

the class MasterClientTest method clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest.

@Test
public void clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest() throws Throwable {
    // Given
    MasterImpl master = spy(newMasterImpl(mockMasterImplSpiWith(StoreId.DEFAULT)));
    doReturn(voidResponseWithTransactionLogs()).when(master).newLockSession(any(RequestContext.class));
    newMasterServer(master);
    Dependencies deps = mock(Dependencies.class);
    TransactionCommitProcess commitProcess = mock(TransactionCommitProcess.class);
    when(deps.commitProcess()).thenReturn(commitProcess);
    when(deps.logService()).thenReturn(NullLogService.getInstance());
    when(deps.kernelTransactions()).thenReturn(mock(KernelTransactions.class));
    ResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(deps, DEFAULT_BATCH_SIZE, 0));
    MasterClient masterClient = newMasterClient320(StoreId.DEFAULT, unpacker);
    // When
    masterClient.newLockSession(new RequestContext(1, 2, 3, 4, 5));
    // Then
    verify(commitProcess).commit(any(TransactionToApply.class), any(CommitEvent.class), any(TransactionApplicationMode.class));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) RequestContext(org.neo4j.com.RequestContext) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 MasterImpl (org.neo4j.kernel.ha.com.master.MasterImpl)2 MasterImplTest (org.neo4j.kernel.ha.com.master.MasterImplTest)2 RequestContext (org.neo4j.com.RequestContext)1 ResponseUnpacker (org.neo4j.com.storecopy.ResponseUnpacker)1 TransactionCommittingResponseUnpacker (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker)1 Dependencies (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies)1 ConversationManager (org.neo4j.kernel.ha.com.master.ConversationManager)1 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)1 InvalidEpochException (org.neo4j.kernel.ha.com.master.InvalidEpochException)1 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)1 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)1 IdAllocation (org.neo4j.kernel.ha.id.IdAllocation)1 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 StoreId (org.neo4j.kernel.impl.store.StoreId)1 IdType (org.neo4j.kernel.impl.store.id.IdType)1 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)1 TransactionApplicationMode (org.neo4j.storageengine.api.TransactionApplicationMode)1