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;
}
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);
}
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);
}
}
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");
}
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);
}
}
Aggregations