use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TransactionStateMachineSPITest method throwsWhenTxAwaitDurationExpires.
@Test
public void throwsWhenTxAwaitDurationExpires() throws Exception {
long lastClosedTransactionId = 100;
TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
Duration txAwaitDuration = Duration.ofSeconds(42);
FakeClock clock = new FakeClock();
AvailabilityGuard availabilityGuard = spy(new AvailabilityGuard(clock, NullLog.getInstance()));
when(availabilityGuard.isAvailable()).then(invocation -> {
boolean available = (boolean) invocation.callRealMethod();
clock.forward(txAwaitDuration.getSeconds() + 1, SECONDS);
return available;
});
TransactionStateMachineSPI txSpi = createTxSpi(txIdStore, txAwaitDuration, availabilityGuard, clock);
Future<Void> result = otherThread.execute(state -> {
txSpi.awaitUpToDate(lastClosedTransactionId + 42);
return null;
});
try {
result.get(20, SECONDS);
} catch (Exception e) {
assertThat(e, instanceOf(ExecutionException.class));
assertThat(e.getCause(), instanceOf(TransactionFailureException.class));
}
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TransactionStateMachineSPITest method fixedTxIdStore.
private static TransactionIdStore fixedTxIdStore(long lastClosedTransactionId) {
TransactionIdStore txIdStore = mock(TransactionIdStore.class);
when(txIdStore.getLastClosedTransactionId()).thenReturn(lastClosedTransactionId);
return txIdStore;
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TxPullRequestHandlerTest method shouldNotStreamTxsAndReportErrorIfTheLocalDatabaseIsNotAvailable.
@Test
public void shouldNotStreamTxsAndReportErrorIfTheLocalDatabaseIsNotAvailable() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> false, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
// when
txPullRequestHandler.channelRead0(context, new TxPullRequest(1, storeId));
// then
verify(context, never()).write(ResponseMessageType.TX);
verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
verify(context).write(new TxStreamFinishedResponse(E_STORE_UNAVAILABLE, 15L));
logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the local database is unavailable.", 2L));
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TxPullRequestHandlerTest method shouldRespondWithBatchOfTransactions.
@Test
public void shouldRespondWithBatchOfTransactions() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
when(logicalTransactionStore.getTransactions(14L)).thenReturn(txCursor(cursor(tx(14), tx(15), tx(16), tx(17))));
TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
// when
txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
// then
verify(context, times(3)).write(ResponseMessageType.TX);
verify(context).write(new TxPullResponse(storeId, tx(14)));
verify(context).write(new TxPullResponse(storeId, tx(15)));
verify(context).write(new TxPullResponse(storeId, tx(16)));
verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_BATCH, 15L));
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class ReadReplicaReplicationIT method transactionIdTracker.
private TransactionIdTracker transactionIdTracker(GraphDatabaseAPI database) {
TransactionIdStore transactionIdStore = database.getDependencyResolver().resolveDependency(TransactionIdStore.class);
AvailabilityGuard availabilityGuard = database.getDependencyResolver().resolveDependency(AvailabilityGuard.class);
return new TransactionIdTracker(transactionIdStore, availabilityGuard, Clock.systemUTC());
}
Aggregations