use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TxPullRequestHandlerTest method shouldRespondWithEndOfStreamIfThereAreNoTransactions.
@Test
public void shouldRespondWithEndOfStreamIfThereAreNoTransactions() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(14L);
LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
// when
txPullRequestHandler.channelRead0(context, new TxPullRequest(14, storeId));
// then
verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_STREAM, 14L));
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TxPullRequestHandlerTest method shouldNotStreamTxEntriesIfStoreIdMismatches.
@Test
public void shouldNotStreamTxEntriesIfStoreIdMismatches() throws Exception {
// given
StoreId serverStoreId = new StoreId(1, 2, 3, 4);
StoreId clientStoreId = new StoreId(5, 6, 7, 8);
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> serverStoreId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
// when
txPullRequestHandler.channelRead0(context, new TxPullRequest(1, clientStoreId));
// then
verify(context, never()).write(ResponseMessageType.TX);
verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
verify(context).write(new TxStreamFinishedResponse(E_STORE_ID_MISMATCH, 15L));
logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", 2L, clientStoreId, serverStoreId));
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class TxPullRequestHandlerTest method shouldRespondWithoutTransactionsIfTheyDoNotExist.
@Test
public void shouldRespondWithoutTransactionsIfTheyDoNotExist() 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)).thenThrow(new NoSuchTransactionException(14));
TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
// when
txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
// then
verify(context, never()).write(ResponseMessageType.TX);
verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
verify(context).write(new TxStreamFinishedResponse(E_TRANSACTION_PRUNED, 15L));
logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d because the transaction does not exist.", 14L));
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class StoreUpgradeIntegrationTest method checkProvidedParameters.
private static void checkProvidedParameters(Store store, GraphDatabaseAPI db) {
try (Transaction ignored = db.beginTx()) {
// count nodes
long nodeCount = count(db.getAllNodes());
assertThat(nodeCount, is(store.expectedNodeCount));
// count indexes
long indexCount = count(db.schema().getIndexes());
assertThat(indexCount, is(store.indexes()));
// check last committed tx
TransactionIdStore txIdStore = db.getDependencyResolver().resolveDependency(TransactionIdStore.class);
long lastCommittedTxId = txIdStore.getLastCommittedTransactionId();
try (Statement statement = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class).getKernelTransactionBoundToThisThread(true).acquireStatement()) {
long countsTxId = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts().txId();
assertEquals(lastCommittedTxId, countsTxId);
assertThat(lastCommittedTxId, is(store.lastTxId));
}
}
}
use of org.neo4j.kernel.impl.transaction.log.TransactionIdStore in project neo4j by neo4j.
the class BoltFactoryImplTest method txIdStoreRefreshedAfterRestart.
@Test
public void txIdStoreRefreshedAfterRestart() throws Throwable {
GraphDatabaseAPI db = newDbMock();
DependencyResolver dependencyResolver = db.getDependencyResolver();
TransactionIdStore txIdStoreBeforeRestart = mock(TransactionIdStore.class);
when(txIdStoreBeforeRestart.getLastClosedTransactionId()).thenReturn(42L);
TransactionIdStore txIdStoreAfterRestart = mock(TransactionIdStore.class);
when(txIdStoreAfterRestart.getLastClosedTransactionId()).thenReturn(4242L);
when(dependencyResolver.resolveDependency(TransactionIdStore.class)).thenReturn(txIdStoreBeforeRestart).thenReturn(txIdStoreAfterRestart);
BoltFactoryImpl boltFactory = newBoltFactory(db);
boltFactory.start();
BoltStateMachine stateMachine1 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
assertEquals(42, stateMachine1.spi.transactionSpi().newestEncounteredTxId());
boltFactory.stop();
boltFactory.start();
BoltStateMachine stateMachine2 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
assertEquals(4242, stateMachine2.spi.transactionSpi().newestEncounteredTxId());
}
Aggregations