use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI in project neo4j by neo4j.
the class MasterImplTest method failingToStartTxShouldNotLeadToNPE.
@Test
public void failingToStartTxShouldNotLeadToNPE() throws Throwable {
// Given
MasterImpl.SPI spi = mockedSpi();
DefaultConversationSPI conversationSpi = mockedConversationSpi();
Config config = config();
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
when(spi.isAccessible()).thenReturn(true);
when(conversationSpi.acquireClient()).thenThrow(new RuntimeException("Nope"));
when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
mockEmptyResponse(spi);
MasterImpl instance = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
instance.start();
Response<HandshakeResult> response = instance.handshake(1, newStoreIdForCurrentVersion());
HandshakeResult handshake = response.response();
// When
try {
instance.newLockSession(new RequestContext(handshake.epoch(), 1, 2, 0, 0));
fail("Should have failed.");
} catch (Exception e) {
// Then
assertThat(e, instanceOf(RuntimeException.class));
assertThat(e.getMessage(), equalTo("Nope"));
}
}
use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI in project neo4j by neo4j.
the class MasterImplConversationStopFuzzIT method shouldHandleRandomizedLoad.
@Test
public void shouldHandleRandomizedLoad() throws Throwable {
// Given
DefaultConversationSPI conversationSPI = new DefaultConversationSPI(locks, scheduler);
final ExposedConversationManager conversationManager = new ExposedConversationManager(conversationSPI, config, 100, 0);
ConversationTestMasterSPI conversationTestMasterSPI = new ConversationTestMasterSPI();
MasterImpl master = new MasterImpl(conversationTestMasterSPI, conversationManager, new Monitors().newMonitor(MasterImpl.Monitor.class), config);
life.add(conversationManager);
life.start();
ConversationKiller conversationKiller = new ConversationKiller(conversationManager);
executor.submit(conversationKiller);
List<Callable<Void>> slaveWorkers = workers(master, numberOfWorkers);
List<Future<Void>> workers = executor.invokeAll(slaveWorkers);
// Wait for all workers to complete
for (Future<Void> future : workers) {
future.get();
}
conversationKiller.stop();
assertTrue(executionStatistic.isSuccessfulExecution());
}
use of org.neo4j.kernel.ha.cluster.DefaultConversationSPI 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.kernel.ha.cluster.DefaultConversationSPI 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.kernel.ha.cluster.DefaultConversationSPI 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