Search in sources :

Example 1 with ResponseUnpacker

use of org.neo4j.com.storecopy.ResponseUnpacker in project neo4j by neo4j.

the class TestCommunication method masterResponseShouldNotBeUnpackedIfRequestTypeDoesNotRequire.

@Test
public void masterResponseShouldNotBeUnpackedIfRequestTypeDoesNotRequire() {
    // Given
    ResponseUnpacker responseUnpacker = mock(ResponseUnpacker.class);
    MadeUpClient client = builder.clientWith(responseUnpacker);
    addToLifeAndStart(builder.server(), client);
    // When
    client.sendDataStream(new KnownDataByteChannel(100));
    // Then
    verifyZeroInteractions(responseUnpacker);
}
Also used : ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) Test(org.junit.Test)

Example 2 with ResponseUnpacker

use of org.neo4j.com.storecopy.ResponseUnpacker in project neo4j by neo4j.

the class TestCommunication method masterResponseShouldBeUnpackedIfRequestTypeRequires.

@Test
@SuppressWarnings("rawtypes")
public void masterResponseShouldBeUnpackedIfRequestTypeRequires() throws Exception {
    // Given
    ResponseUnpacker responseUnpacker = mock(ResponseUnpacker.class);
    MadeUpClient client = builder.clientWith(responseUnpacker);
    addToLifeAndStart(builder.server(), client);
    // When
    client.multiply(42, 42);
    // Then
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    verify(responseUnpacker).unpackResponse(captor.capture(), eq(NO_OP_TX_HANDLER));
    assertEquals(storeIdToUse, captor.getValue().getStoreId());
    assertEquals(42 * 42, captor.getValue().response());
}
Also used : ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) Test(org.junit.Test)

Example 3 with ResponseUnpacker

use of org.neo4j.com.storecopy.ResponseUnpacker 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 4 with ResponseUnpacker

use of org.neo4j.com.storecopy.ResponseUnpacker 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)

Aggregations

Test (org.junit.Test)4 ResponseUnpacker (org.neo4j.com.storecopy.ResponseUnpacker)4 RequestContext (org.neo4j.com.RequestContext)2 TransactionCommittingResponseUnpacker (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker)2 MasterImpl (org.neo4j.kernel.ha.com.master.MasterImpl)2 MasterImplTest (org.neo4j.kernel.ha.com.master.MasterImplTest)2 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)2 Response (org.neo4j.com.Response)1 TransactionStreamResponse (org.neo4j.com.TransactionStreamResponse)1 TxHandler (org.neo4j.com.storecopy.ResponseUnpacker.TxHandler)1 Dependencies (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies)1 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)1 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)1 StoreId (org.neo4j.kernel.impl.store.StoreId)1 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)1 TransactionApplicationMode (org.neo4j.storageengine.api.TransactionApplicationMode)1