use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterImplTest method shouldNotEndLockSessionWhereThereIsAnActiveLockAcquisition.
@Test
public void shouldNotEndLockSessionWhereThereIsAnActiveLockAcquisition() throws Throwable {
// GIVEN
CountDownLatch latch = new CountDownLatch(1);
try {
Client client = newWaitingLocksClient(latch);
MasterImpl master = newMasterWithLocksClient(client);
HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
// WHEN
RequestContext context = new RequestContext(handshake.epoch(), 1, 2, 0, 0);
master.newLockSession(context);
Future<Void> acquireFuture = otherThread.execute(state -> {
master.acquireExclusiveLock(context, ResourceTypes.NODE, 1L);
return null;
});
otherThread.get().waitUntilWaiting();
master.endLockSession(context, true);
verify(client, never()).stop();
verify(client, never()).close();
latch.countDown();
acquireFuture.get();
// THEN
verify(client).close();
} finally {
latch.countDown();
}
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterServerTest method shouldCleanExistentLockSessionOnFinishOffChannel.
@Test
public void shouldCleanExistentLockSessionOnFinishOffChannel() throws Exception {
Master master = mock(Master.class);
ConversationManager conversationManager = mock(ConversationManager.class);
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
MasterServer masterServer = new MasterServer(master, mock(LogProvider.class), mock(Server.Configuration.class), mock(TxChecksumVerifier.class), mock(ByteCounterMonitor.class), mock(RequestMonitor.class), conversationManager, logEntryReader);
RequestContext requestContext = new RequestContext(1L, 1, 1, 0, 0L);
masterServer.stopConversation(requestContext);
Mockito.verify(conversationManager).stop(requestContext);
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class ResponsePacker method packTransactionStreamResponse.
public <T> Response<T> packTransactionStreamResponse(RequestContext context, T response) {
final long toStartFrom = context.lastAppliedTransaction() + 1;
final long toEndAt = transactionIdStore.getLastCommittedTransactionId();
TransactionStream transactions = visitor -> {
if (toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt) {
extractTransactions(toStartFrom, filterVisitor(visitor, toEndAt));
}
};
return new TransactionStreamResponse<>(response, storeId.get(), transactions, ResourceReleaser.NO_OP);
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class ResponsePackerIT method shouldPackTheHighestTxCommittedAsObligation.
@Test
public void shouldPackTheHighestTxCommittedAsObligation() throws Exception {
// GIVEN
LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
FileSystemAbstraction fs = fsRule.get();
PageCache pageCache = pageCacheRule.getPageCache(fs);
try (NeoStores neoStore = createNeoStore(fs, pageCache)) {
MetaDataStore store = neoStore.getMetaDataStore();
store.transactionCommitted(2, 111, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(3, 222, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(4, 333, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(5, 444, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(6, 555, BASE_TX_COMMIT_TIMESTAMP);
// skip 7 to emulate the fact we have an hole in the committed tx ids list
final long expectedTxId = 8L;
store.transactionCommitted(expectedTxId, 777, BASE_TX_COMMIT_TIMESTAMP);
ResponsePacker packer = new ResponsePacker(transactionStore, store, Suppliers.singleton(newStoreIdForCurrentVersion()));
// WHEN
Response<Object> response = packer.packTransactionObligationResponse(new RequestContext(0, 0, 0, 0, 0), new Object());
// THEN
assertTrue(response instanceof TransactionObligationResponse);
((TransactionObligationResponse) response).accept(new Response.Handler() {
@Override
public void obligation(long txId) throws IOException {
assertEquals(expectedTxId, txId);
}
@Override
public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
throw new UnsupportedOperationException("not expected");
}
});
}
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class SwitchToSlave method catchUpWithMaster.
private boolean catchUpWithMaster(UpdatePuller updatePuller) throws IllegalArgumentException, InterruptedException {
monitor.catchupStarted();
RequestContext catchUpRequestContext = requestContextFactory.newRequestContext();
userLog.info("Catching up with master. I'm at %s", catchUpRequestContext);
if (!updatePuller.tryPullUpdates()) {
return false;
}
userLog.info("Now caught up with master");
monitor.catchupCompleted();
return true;
}
Aggregations