use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class StreamToDiskTest method shouldLetPageCacheHandleRecordStoresAndNativeLabelScanStoreFiles.
@Test
public void shouldLetPageCacheHandleRecordStoresAndNativeLabelScanStoreFiles() throws Exception {
// GIVEN
PageCache pageCache = spy(pageCacheRule.getPageCache(fs));
Monitors monitors = new Monitors();
try (StreamToDisk writer = new StreamToDisk(directory.absolutePath(), fs, pageCache, monitors)) {
ByteBuffer tempBuffer = ByteBuffer.allocate(128);
// WHEN
for (StoreType type : StoreType.values()) {
if (type.isRecordStore()) {
String fileName = type.getStoreFile().fileName(STORE);
writeAndVerifyWrittenThroughPageCache(pageCache, writer, tempBuffer, fileName);
}
}
writeAndVerifyWrittenThroughPageCache(pageCache, writer, tempBuffer, NativeLabelScanStore.FILE_NAME);
}
}
use of org.neo4j.kernel.monitoring.Monitors 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.monitoring.Monitors 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.monitoring.Monitors in project neo4j by neo4j.
the class RemoteStoreTest method shouldSetLastPulledTransactionId.
@Test
public void shouldSetLastPulledTransactionId() throws Exception {
// given
long lastFlushedTxId = 12;
StoreId wantedStoreId = new StoreId(1, 2, 3, 4);
MemberId localhost = new MemberId(UUID.randomUUID());
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
when(storeCopyClient.copyStoreFiles(eq(localhost), eq(wantedStoreId), any(StoreFileStreams.class))).thenReturn(lastFlushedTxId);
TxPullClient txPullClient = mock(TxPullClient.class);
when(txPullClient.pullTransactions(eq(localhost), eq(wantedStoreId), anyLong(), any(TxPullResponseListener.class))).thenReturn(new TxPullRequestResult(SUCCESS_END_OF_STREAM, 13));
TransactionLogCatchUpWriter writer = mock(TransactionLogCatchUpWriter.class);
RemoteStore remoteStore = new RemoteStore(NullLogProvider.getInstance(), mock(FileSystemAbstraction.class), null, storeCopyClient, txPullClient, factory(writer), new Monitors());
// when
remoteStore.copy(localhost, wantedStoreId, new File("destination"));
// then
// the interface is defined as asking for the one preceding
long previousTxId = lastFlushedTxId - 1;
verify(txPullClient).pullTransactions(eq(localhost), eq(wantedStoreId), eq(previousTxId), any(TxPullResponseListener.class));
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class RemoteStoreTest method shouldCloseDownTxLogWriterIfTxStreamingFails.
@Test
public void shouldCloseDownTxLogWriterIfTxStreamingFails() throws Exception {
// given
StoreId storeId = new StoreId(1, 2, 3, 4);
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
TxPullClient txPullClient = mock(TxPullClient.class);
TransactionLogCatchUpWriter writer = mock(TransactionLogCatchUpWriter.class);
RemoteStore remoteStore = new RemoteStore(NullLogProvider.getInstance(), mock(FileSystemAbstraction.class), null, storeCopyClient, txPullClient, factory(writer), new Monitors());
doThrow(StoreCopyFailedException.class).when(txPullClient).pullTransactions(any(MemberId.class), eq(storeId), anyLong(), any(TransactionLogCatchUpWriter.class));
// when
try {
remoteStore.copy(null, storeId, null);
} catch (StoreCopyFailedException e) {
// expected
}
// then
verify(writer).close();
}
Aggregations