Search in sources :

Example 6 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class RecordStorageEngineTest method newTransactionThatFailsWith.

private static TransactionToApply newTransactionThatFailsWith(Exception error) throws IOException {
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    // allow to build validated index updates but fail on actual tx application
    doThrow(error).when(transaction).accept(any());
    long txId = ThreadLocalRandom.current().nextLong(0, 1000);
    TransactionToApply txToApply = new TransactionToApply(transaction);
    FakeCommitment commitment = new FakeCommitment(txId, mock(TransactionIdStore.class));
    commitment.setHasLegacyIndexChanges(false);
    txToApply.commitment(commitment, txId);
    return txToApply;
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment)

Example 7 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class TransactionRepresentationCommitProcessTest method mockedTransaction.

private TransactionToApply mockedTransaction() {
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    return new TransactionToApply(transaction);
}
Also used : TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

Example 8 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedForceLogToDisk.

@Test
public void shouldNotCallTransactionClosedOnFailedForceLogToDisk() throws Exception {
    // GIVEN
    long txId = 3;
    String failureMessage = "Forces a failure";
    FlushablePositionAwareChannel channel = spy(new InMemoryClosableChannel());
    IOException failure = new IOException(failureMessage);
    final Flushable flushable = mock(Flushable.class);
    doAnswer(new Answer<Flushable>() {

        @Override
        public Flushable answer(InvocationOnMock invocation) throws Throwable {
            invocation.callRealMethod();
            return flushable;
        }
    }).when(channel).prepareForFlush();
    doThrow(failure).when(flushable).flush();
    LogFile logFile = mock(LogFile.class);
    when(logFile.getWriter()).thenReturn(channel);
    TransactionMetadataCache metadataCache = new TransactionMetadataCache(10);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    Mockito.reset(databaseHealth);
    TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, metadataCache, transactionIdStore, BYPASS, databaseHealth));
    // WHEN
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    try {
        appender.append(new TransactionToApply(transaction), logAppendEvent);
        fail("Expected append to fail. Something is wrong with the test itself");
    } catch (IOException e) {
        // THEN
        assertSame(failure, e);
        verify(transactionIdStore, times(1)).nextCommittingTransactionId();
        verify(transactionIdStore, times(0)).transactionClosed(eq(txId), anyLong(), anyLong());
        verify(databaseHealth).panic(failure);
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) Flushable(java.io.Flushable) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 9 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class LabelAndIndexUpdateBatchingIT method findCutoffIndex.

private static int findCutoffIndex(Collection<TransactionRepresentation> transactions) throws IOException {
    Iterator<TransactionRepresentation> iterator = transactions.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        TransactionRepresentation tx = iterator.next();
        CommandExtractor extractor = new CommandExtractor();
        tx.accept(extractor);
        List<StorageCommand> commands = extractor.getCommands();
        List<StorageCommand> nodeCommands = commands.stream().filter(command -> command instanceof NodeCommand).collect(toList());
        if (nodeCommands.size() == 1) {
            return i;
        }
    }
    throw new AssertionError("Couldn't find the transaction which would be the cut-off point");
}
Also used : Label(org.neo4j.graphdb.Label) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Iterator(java.util.Iterator) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) Iterators.singleOrNull(org.neo4j.helpers.collection.Iterators.singleOrNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) NULL(org.neo4j.kernel.impl.transaction.tracing.CommitEvent.NULL) Test(org.junit.Test) IOException(java.io.IOException) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ArrayList(java.util.ArrayList) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StorageCommand(org.neo4j.storageengine.api.StorageCommand) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionCursor(org.neo4j.kernel.impl.transaction.log.TransactionCursor) EXTERNAL(org.neo4j.storageengine.api.TransactionApplicationMode.EXTERNAL) Transaction(org.neo4j.graphdb.Transaction) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) StorageCommand(org.neo4j.storageengine.api.StorageCommand) NodeCommand(org.neo4j.kernel.impl.transaction.command.Command.NodeCommand)

Example 10 with TransactionRepresentation

use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedAppendedTransaction.

@Test
public void shouldNotCallTransactionClosedOnFailedAppendedTransaction() throws Exception {
    // GIVEN
    long txId = 3;
    String failureMessage = "Forces a failure";
    FlushablePositionAwareChannel channel = spy(new InMemoryClosableChannel());
    IOException failure = new IOException(failureMessage);
    when(channel.putInt(anyInt())).thenThrow(failure);
    when(logFile.getWriter()).thenReturn(channel);
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    Mockito.reset(databaseHealth);
    TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, databaseHealth));
    // WHEN
    TransactionRepresentation transaction = mock(TransactionRepresentation.class);
    when(transaction.additionalHeader()).thenReturn(new byte[0]);
    try {
        appender.append(new TransactionToApply(transaction), logAppendEvent);
        fail("Expected append to fail. Something is wrong with the test itself");
    } catch (IOException e) {
        // THEN
        assertSame(failure, e);
        verify(transactionIdStore, times(1)).nextCommittingTransactionId();
        verify(transactionIdStore, times(0)).transactionClosed(eq(txId), anyLong(), anyLong());
        verify(databaseHealth).panic(failure);
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)26 Test (org.junit.Test)13 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)12 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)9 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)3 RequestContext (org.neo4j.com.RequestContext)3 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)3 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)2 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ByteBuf (io.netty.buffer.ByteBuf)1