use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterClientTest method clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest.
@Test
public void clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest() throws Throwable {
// Given
MasterImpl master = spy(newMasterImpl(mockMasterImplSpiWith(StoreId.DEFAULT)));
doReturn(voidResponseWithTransactionLogs()).when(master).newLockSession(any(RequestContext.class));
newMasterServer(master);
Dependencies deps = mock(Dependencies.class);
TransactionCommitProcess commitProcess = mock(TransactionCommitProcess.class);
when(deps.commitProcess()).thenReturn(commitProcess);
when(deps.logService()).thenReturn(NullLogService.getInstance());
when(deps.kernelTransactions()).thenReturn(mock(KernelTransactions.class));
ResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(deps, DEFAULT_BATCH_SIZE, 0));
MasterClient masterClient = newMasterClient320(StoreId.DEFAULT, unpacker);
// When
masterClient.newLockSession(new RequestContext(1, 2, 3, 4, 5));
// Then
verify(commitProcess).commit(any(TransactionToApply.class), any(CommitEvent.class), any(TransactionApplicationMode.class));
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class MasterClientTest method endLockSessionDoesNotUnpackResponse.
@Test
public void endLockSessionDoesNotUnpackResponse() throws Throwable {
StoreId storeId = new StoreId(1, 2, 3, 4, 5);
long txChecksum = 123;
long lastAppliedTx = 5;
ResponseUnpacker responseUnpacker = mock(ResponseUnpacker.class);
MasterImpl.SPI masterImplSPI = MasterImplTest.mockedSpi(storeId);
when(masterImplSPI.packTransactionObligationResponse(any(RequestContext.class), Matchers.anyObject())).thenReturn(Response.empty());
when(masterImplSPI.getTransactionChecksum(anyLong())).thenReturn(txChecksum);
newMasterServer(masterImplSPI);
MasterClient client = newMasterClient320(storeId, responseUnpacker);
HandshakeResult handshakeResult;
try (Response<HandshakeResult> handshakeResponse = client.handshake(1, storeId)) {
handshakeResult = handshakeResponse.response();
}
verify(responseUnpacker).unpackResponse(any(Response.class), any(TxHandler.class));
reset(responseUnpacker);
RequestContext context = new RequestContext(handshakeResult.epoch(), 1, 1, lastAppliedTx, txChecksum);
client.endLockSession(context, false);
verify(responseUnpacker, never()).unpackResponse(any(Response.class), any(TxHandler.class));
}
use of org.neo4j.com.RequestContext in project neo4j by neo4j.
the class SlaveLocksClient method acquireExclusiveOnMaster.
private void acquireExclusiveOnMaster(ResourceType resourceType, long... resourceIds) {
makeSureTxHasBeenInitialized();
RequestContext requestContext = newRequestContextFor(this);
try (Response<LockResult> response = master.acquireExclusiveLock(requestContext, resourceType, resourceIds)) {
receiveLockResponse(response);
} catch (ComException e) {
throw new DistributedLockFailureException("Cannot get exclusive lock(s) on master", master, e);
}
}
Aggregations