Search in sources :

Example 31 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class KernelTransactionsTest method newKernelTransactions.

private static KernelTransactions newKernelTransactions(Locks locks, StorageEngine storageEngine, TransactionCommitProcess commitProcess, boolean testKernelTransactions) throws Throwable {
    LifeSupport life = new LifeSupport();
    life.start();
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(0, 0, 0));
    Tracers tracers = new Tracers("null", NullLog.getInstance(), new Monitors(), mock(JobScheduler.class));
    StatementLocksFactory statementLocksFactory = new SimpleStatementLocksFactory(locks);
    StatementOperationContainer statementOperationsContianer = new StatementOperationContainer(null, null);
    KernelTransactions transactions;
    if (testKernelTransactions) {
        transactions = createTestTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    } else {
        transactions = createTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
    }
    transactions.start();
    return transactions;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StatementLocksFactory(org.neo4j.kernel.impl.locking.StatementLocksFactory) SimpleStatementLocksFactory(org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TransactionId(org.neo4j.kernel.impl.store.TransactionId) Tracers(org.neo4j.kernel.monitoring.tracing.Tracers)

Example 32 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class TransactionRepresentationCommitProcessTest method shouldSuccessfullyCommitTransactionWithNoCommands.

@Test
public void shouldSuccessfullyCommitTransactionWithNoCommands() throws Exception {
    // GIVEN
    long txId = 11;
    long commitTimestamp = System.currentTimeMillis();
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    TransactionAppender appender = new TestableTransactionAppender(transactionIdStore);
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    StorageEngine storageEngine = mock(StorageEngine.class);
    TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
    PhysicalTransactionRepresentation noCommandTx = new PhysicalTransactionRepresentation(Collections.emptyList());
    noCommandTx.setHeader(new byte[0], -1, -1, -1, -1, -1, -1);
    // WHEN
    commitProcess.commit(new TransactionToApply(noCommandTx), commitEvent, INTERNAL);
    verify(transactionIdStore).transactionCommitted(txId, FakeCommitment.CHECKSUM, FakeCommitment.TIMESTAMP);
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) StorageEngine(org.neo4j.storageengine.api.StorageEngine) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 33 with TransactionIdStore

use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.

the class TransactionRepresentationCommitProcessTest method shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly.

@Test
public void shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    TransactionAppender appender = new TestableTransactionAppender(transactionIdStore);
    long txId = 11;
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    IOException rootCause = new IOException("Mock exception");
    StorageEngine storageEngine = mock(StorageEngine.class);
    doThrow(new IOException(rootCause)).when(storageEngine).apply(any(TransactionToApply.class), any(TransactionApplicationMode.class));
    TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
    TransactionToApply transaction = mockedTransaction();
    // WHEN
    try {
        commitProcess.commit(transaction, commitEvent, INTERNAL);
    } catch (TransactionFailureException e) {
        assertThat(e.getMessage(), containsString("Could not apply the transaction to the store"));
        assertTrue(contains(e, rootCause.getMessage(), rootCause.getClass()));
    }
    // THEN
    // we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked
    verify(transactionIdStore, times(1)).transactionClosed(eq(txId), anyLong(), anyLong());
}
Also used : TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) IOException(java.io.IOException) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.Test)

Aggregations

TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)33 Test (org.junit.Test)23 Monitors (org.neo4j.kernel.monitoring.Monitors)11 StoreId (org.neo4j.kernel.impl.store.StoreId)9 TransactionId (org.neo4j.kernel.impl.store.TransactionId)9 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)9 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)8 IOException (java.io.IOException)7 URI (java.net.URI)7 BranchedDataPolicy (org.neo4j.kernel.ha.BranchedDataPolicy)7 CatchupServerProtocol (org.neo4j.causalclustering.catchup.CatchupServerProtocol)6 StoreId (org.neo4j.causalclustering.identity.StoreId)6 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)6 File (java.io.File)5 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)5 DependencyResolver (org.neo4j.graphdb.DependencyResolver)4 CancellationRequest (org.neo4j.helpers.CancellationRequest)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 PageCache (org.neo4j.io.pagecache.PageCache)4 BranchedDataException (org.neo4j.kernel.ha.BranchedDataException)4