use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterImplTest method givenStartedAndAccessibleWhenNewLockSessionThenSucceeds.
@Test
public void givenStartedAndAccessibleWhenNewLockSessionThenSucceeds() throws Throwable {
// Given
MasterImpl.SPI spi = mockedSpi();
Config config = config();
when(spi.isAccessible()).thenReturn(true);
when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
MasterImpl instance = new MasterImpl(spi, mock(ConversationManager.class), mock(MasterImpl.Monitor.class), config);
instance.start();
HandshakeResult handshake = instance.handshake(1, newStoreIdForCurrentVersion()).response();
// When
try {
instance.newLockSession(new RequestContext(handshake.epoch(), 1, 2, 0, 0));
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterImplTest method shouldNotAllowCommitIfThereIsNoMatchingLockSession.
@Test
public void shouldNotAllowCommitIfThereIsNoMatchingLockSession() throws Throwable {
// Given
MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
DefaultConversationSPI conversationSpi = mockedConversationSpi();
Config config = config();
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
when(spi.isAccessible()).thenReturn(true);
when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
mockEmptyResponse(spi);
MasterImpl master = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
master.start();
HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
RequestContext ctx = new RequestContext(handshake.epoch(), 1, 2, 0, 0);
// When
try {
master.commit(ctx, mock(TransactionRepresentation.class));
fail("Should have failed.");
} catch (TransactionNotPresentOnMasterException e) {
// Then
assertThat(e.getMessage(), equalTo(new TransactionNotPresentOnMasterException(ctx).getMessage()));
}
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterImplTest method shouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout.
@Test
public void shouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout() throws Throwable {
//Given
MasterImpl.SPI spi = mockedSpi();
DefaultConversationSPI conversationSpi = mockedConversationSpi();
Monitor monitor = mock(Monitor.class);
Config config = config();
Client client = mock(Client.class);
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
int machineId = 1;
MasterImpl master = new MasterImpl(spi, conversationManager, monitor, config);
when(spi.isAccessible()).thenReturn(true);
when(conversationSpi.acquireClient()).thenReturn(client);
master.start();
HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
RequestContext requestContext = new RequestContext(handshake.epoch(), machineId, 0, 0, 0);
// When
master.newLockSession(requestContext);
master.acquireSharedLock(requestContext, ResourceTypes.NODE, 1L);
conversationManager.stop(requestContext);
master.newLockSession(requestContext);
//Then
Map<Integer, Collection<RequestContext>> transactions = master.getOngoingTransactions();
assertEquals(1, transactions.size());
assertThat(transactions.get(machineId), org.hamcrest.Matchers.hasItem(requestContext));
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterImplTest method shouldStopLockSessionOnFailureWhereThereIsAnActiveLockAcquisition.
@Test
public void shouldStopLockSessionOnFailureWhereThereIsAnActiveLockAcquisition() 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, false);
verify(client).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 MasterImplTest method shouldAllowCommitIfClientHoldsNoLocks.
@Test
public void shouldAllowCommitIfClientHoldsNoLocks() throws Throwable {
// Given
MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
Config config = config();
DefaultConversationSPI conversationSpi = mockedConversationSpi();
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
Client locks = mock(Client.class);
when(locks.trySharedLock(ResourceTypes.SCHEMA, ResourceTypes.schemaResource())).thenReturn(true);
when(spi.isAccessible()).thenReturn(true);
when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
when(conversationSpi.acquireClient()).thenReturn(locks);
mockEmptyResponse(spi);
MasterImpl master = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
master.start();
HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
int no_lock_session = -1;
RequestContext ctx = new RequestContext(handshake.epoch(), 1, no_lock_session, 0, 0);
TransactionRepresentation tx = mock(TransactionRepresentation.class);
// When
master.commit(ctx, tx);
// Then
verify(spi).applyPreparedTransaction(tx);
}
Aggregations