use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource.
@Test
public void lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource() throws Exception {
MasterImpl.SPI spi = mockedSpi();
DefaultConversationSPI conversationSpi = mockedConversationSpi();
Config config = config();
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
conversationManager.start();
Client locks = mock(Client.class);
MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
RequestContext context = createRequestContext(master);
when(conversationSpi.acquireClient()).thenReturn(locks);
ResourceTypes type = ResourceTypes.NODE;
doThrow(new IllegalResourceException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
master.acquireExclusiveLock(context, type, 1);
ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks.
@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks() throws Exception {
MasterImpl.SPI spi = mockedSpi();
DefaultConversationSPI conversationSpi = mockedConversationSpi();
Config config = config();
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
conversationManager.start();
Client locks = mock(Client.class);
MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
RequestContext context = createRequestContext(master);
when(conversationSpi.acquireClient()).thenReturn(locks);
ResourceTypes type = ResourceTypes.NODE;
doThrow(new DeadlockDetectedException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
master.acquireSharedLock(context, type, 1);
ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
use of org.neo4j.com.RequestContext 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.com.RequestContext in project neo4j by neo4j.
the class SlaveTransactionCommitProcessTest method setUp.
@Before
public void setUp() {
lastSeenEventIdentifier = new AtomicInteger(-1);
master = mock(Master.class);
requestContext = new RequestContext(10, 11, 12, 13, 14);
reqFactory = new ConstantRequestContextFactory(requestContext) {
@Override
public RequestContext newRequestContext(int eventIdentifier) {
lastSeenEventIdentifier.set(eventIdentifier);
return super.newRequestContext(eventIdentifier);
}
};
response = new LongResponse(42L);
tx = new PhysicalTransactionRepresentation(Collections.<StorageCommand>emptyList());
tx.setHeader(new byte[] {}, 1, 1, 1, 1, 1, 1337);
commitProcess = new SlaveTransactionCommitProcess(master, reqFactory);
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class StoreCopyResponsePacker method packTransactionStreamResponse.
@Override
public <T> Response<T> packTransactionStreamResponse(RequestContext context, T response) {
final long toStartFrom = mandatoryStartTransactionId;
final long toEndAt = transactionIdStore.getLastCommittedTransactionId();
TransactionStream transactions = visitor -> {
if (toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt) {
monitor.startStreamingTransactions(toStartFrom);
extractTransactions(toStartFrom, filterVisitor(visitor, toEndAt));
monitor.finishStreamingTransactions(toEndAt);
}
};
return new TransactionStreamResponse<>(response, storeId.get(), transactions, ResourceReleaser.NO_OP);
}
Aggregations