Search in sources :

Example 1 with Dependencies

use of org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies in project neo4j by neo4j.

the class TransactionCommittingResponseUnpackerTest method shouldUnfreezeKernelTransactionsAfterApplyIfBatchIsLarge.

/*
      * Tests that we unfreeze active transactions after commit and after apply of batch if batch length (in time)
      * is larger than safeZone time.
      */
@Test
public void shouldUnfreezeKernelTransactionsAfterApplyIfBatchIsLarge() throws Throwable {
    // GIVEN
    int maxBatchSize = 10;
    long idReuseSafeZoneTime = 100;
    Dependencies dependencies = mock(Dependencies.class);
    TransactionObligationFulfiller fulfiller = mock(TransactionObligationFulfiller.class);
    when(dependencies.obligationFulfiller()).thenReturn(fulfiller);
    when(dependencies.logService()).thenReturn(NullLogService.getInstance());
    KernelTransactions kernelTransactions = mock(KernelTransactions.class);
    when(dependencies.kernelTransactions()).thenReturn(kernelTransactions);
    TransactionCommitProcess commitProcess = mock(TransactionCommitProcess.class);
    when(dependencies.commitProcess()).thenReturn(commitProcess);
    TransactionCommittingResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(dependencies, maxBatchSize, idReuseSafeZoneTime));
    // WHEN
    int txCount = maxBatchSize;
    int doesNotMatter = 1;
    unpacker.unpackResponse(new DummyTransactionResponse(doesNotMatter, txCount, idReuseSafeZoneTime + 1), NO_OP_TX_HANDLER);
    // THEN
    InOrder inOrder = inOrder(commitProcess, kernelTransactions);
    inOrder.verify(commitProcess, times(1)).commit(any(), any(), any());
    inOrder.verify(kernelTransactions, times(1)).unblockNewTransactions();
}
Also used : InOrder(org.mockito.InOrder) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) Test(org.junit.Test)

Example 2 with Dependencies

use of org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies in project neo4j by neo4j.

the class TransactionCommittingResponseUnpackerTest method shouldAwaitTransactionObligationsToBeFulfilled.

@Test
public void shouldAwaitTransactionObligationsToBeFulfilled() throws Throwable {
    // GIVEN
    Dependencies dependencies = mock(Dependencies.class);
    TransactionObligationFulfiller fulfiller = mock(TransactionObligationFulfiller.class);
    when(dependencies.obligationFulfiller()).thenReturn(fulfiller);
    when(dependencies.logService()).thenReturn(NullLogService.getInstance());
    TransactionCommittingResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(dependencies, 10, 0));
    // WHEN
    unpacker.unpackResponse(new DummyObligationResponse(4), NO_OP_TX_HANDLER);
    // THEN
    verify(fulfiller, times(1)).fulfill(4L);
}
Also used : Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) Test(org.junit.Test)

Example 3 with Dependencies

use of org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies 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)

Example 4 with Dependencies

use of org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies in project neo4j by neo4j.

the class TransactionCommittingResponseUnpackerTest method shouldCommitTransactionsInBatches.

@Test
public void shouldCommitTransactionsInBatches() throws Exception {
    // GIVEN
    Dependencies dependencies = mock(Dependencies.class);
    TransactionCountingTransactionCommitProcess commitProcess = new TransactionCountingTransactionCommitProcess();
    when(dependencies.commitProcess()).thenReturn(commitProcess);
    when(dependencies.logService()).thenReturn(NullLogService.getInstance());
    KernelTransactions kernelTransactions = mock(KernelTransactions.class);
    when(dependencies.kernelTransactions()).thenReturn(kernelTransactions);
    TransactionCommittingResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(dependencies, 5, 0));
    // WHEN
    unpacker.unpackResponse(new DummyTransactionResponse(BASE_TX_ID + 1, 7), NO_OP_TX_HANDLER);
    // THEN
    commitProcess.assertBatchSize(5);
    commitProcess.assertBatchSize(2);
    commitProcess.assertNoMoreBatches();
}
Also used : KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Dependencies (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies)4 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)3 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)2 InOrder (org.mockito.InOrder)1 RequestContext (org.neo4j.com.RequestContext)1 ResponseUnpacker (org.neo4j.com.storecopy.ResponseUnpacker)1 TransactionCommittingResponseUnpacker (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker)1 MasterImpl (org.neo4j.kernel.ha.com.master.MasterImpl)1 MasterImplTest (org.neo4j.kernel.ha.com.master.MasterImplTest)1 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)1 TransactionApplicationMode (org.neo4j.storageengine.api.TransactionApplicationMode)1