Search in sources :

Example 36 with RequestContext

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));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) RequestContext(org.neo4j.com.RequestContext) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Example 37 with RequestContext

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));
}
Also used : Response(org.neo4j.com.Response) TransactionStreamResponse(org.neo4j.com.TransactionStreamResponse) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) TxHandler(org.neo4j.com.storecopy.ResponseUnpacker.TxHandler) StoreId(org.neo4j.kernel.impl.store.StoreId) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) RequestContext(org.neo4j.com.RequestContext) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Example 38 with RequestContext

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);
    }
}
Also used : ComException(org.neo4j.com.ComException) RequestContext(org.neo4j.com.RequestContext)

Aggregations

RequestContext (org.neo4j.com.RequestContext)38 Test (org.junit.Test)21 Config (org.neo4j.kernel.configuration.Config)13 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)12 Response (org.neo4j.com.Response)10 LockResult (org.neo4j.kernel.ha.lock.LockResult)10 StoreId (org.neo4j.kernel.impl.store.StoreId)9 IOException (java.io.IOException)8 StoreWriter (org.neo4j.com.storecopy.StoreWriter)8 DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)8 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)8 Client (org.neo4j.kernel.impl.locking.Locks.Client)8 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)8 ResponseUnpacker (org.neo4j.com.storecopy.ResponseUnpacker)7 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)7 Master (org.neo4j.kernel.ha.com.master.Master)7 RequestMonitor (org.neo4j.com.monitor.RequestMonitor)6 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)6 String.format (java.lang.String.format)5 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4