Search in sources :

Example 1 with NormalResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse in project hazelcast by hazelcast.

the class InboundResponseHandler method handle.

@Override
public void handle(Packet packet) throws Exception {
    Response response = serializationService.toObject(packet);
    Address sender = packet.getConn().getEndPoint();
    try {
        if (response instanceof NormalResponse) {
            NormalResponse normalResponse = (NormalResponse) response;
            notifyNormalResponse(normalResponse.getCallId(), normalResponse.getValue(), normalResponse.getBackupAcks(), sender);
        } else if (response instanceof BackupAckResponse) {
            notifyBackupComplete(response.getCallId());
        } else if (response instanceof CallTimeoutResponse) {
            notifyCallTimeout(response.getCallId(), sender);
        } else if (response instanceof ErrorResponse) {
            ErrorResponse errorResponse = (ErrorResponse) response;
            notifyErrorResponse(errorResponse.getCallId(), errorResponse.getCause(), sender);
        } else {
            logger.severe("Unrecognized response: " + response);
        }
    } catch (Throwable e) {
        logger.severe("While processing response...", e);
    }
}
Also used : CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) Response(com.hazelcast.spi.impl.operationservice.impl.responses.Response) BackupAckResponse(com.hazelcast.spi.impl.operationservice.impl.responses.BackupAckResponse) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse) CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) BackupAckResponse(com.hazelcast.spi.impl.operationservice.impl.responses.BackupAckResponse) Address(com.hazelcast.nio.Address) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 2 with NormalResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse in project hazelcast by hazelcast.

the class AsyncInboundResponseHandlerTest method whenNoProblemPacket.

@Test
public void whenNoProblemPacket() throws Exception {
    final Packet packet = new Packet(serializationService.toBytes(new NormalResponse("foo", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    asyncHandler.handle(packet);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(responsePacketHandler).handle(packet);
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) AssertTask(com.hazelcast.test.AssertTask) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with NormalResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse in project hazelcast by hazelcast.

the class OperationExecutorImpl_HandlePacketTest method test_whenResponsePacket.

@Test
public void test_whenResponsePacket() {
    initExecutor();
    final NormalResponse normalResponse = new NormalResponse(null, 1, 0, false);
    final Packet packet = new Packet(serializationService.toBytes(normalResponse), 0).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    executor.handle(packet);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            DummyResponsePacketHandler responsePacketHandler = (DummyResponsePacketHandler) OperationExecutorImpl_HandlePacketTest.this.responsePacketHandler;
            responsePacketHandler.packets.contains(packet);
            responsePacketHandler.responses.contains(normalResponse);
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) AssertTask(com.hazelcast.test.AssertTask) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with NormalResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse in project hazelcast by hazelcast.

the class AsyncInboundResponseHandlerTest method whenPacketThrowsException.

@Test
public void whenPacketThrowsException() throws Exception {
    final Packet badPacket = new Packet(serializationService.toBytes(new NormalResponse("bad", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    final Packet goodPacket = new Packet(serializationService.toBytes(new NormalResponse("good", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    doThrow(new ExpectedRuntimeException()).when(responsePacketHandler).handle(badPacket);
    asyncHandler.handle(badPacket);
    asyncHandler.handle(goodPacket);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(responsePacketHandler).handle(goodPacket);
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) AssertTask(com.hazelcast.test.AssertTask) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with NormalResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse in project hazelcast by hazelcast.

the class AsyncInboundResponseHandlerTest method whenShutdown.

@Test
public void whenShutdown() throws InterruptedException {
    asyncHandler.shutdown();
    // we need to wait for the responseThread to die first.
    assertJoinable(asyncHandler.responseThread);
    final Packet packet = new Packet(serializationService.toBytes(new NormalResponse("foo", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    asyncHandler.handle(packet);
    assertTrueFiveSeconds(new AssertTask() {

        @Override
        public void run() throws Exception {
            verifyZeroInteractions(responsePacketHandler);
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) AssertTask(com.hazelcast.test.AssertTask) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

NormalResponse (com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse)7 Packet (com.hazelcast.nio.Packet)4 AssertTask (com.hazelcast.test.AssertTask)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 ResponseAlreadySentException (com.hazelcast.spi.exception.ResponseAlreadySentException)2 CallTimeoutResponse (com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse)2 ErrorResponse (com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)2 Address (com.hazelcast.nio.Address)1 BackupAckResponse (com.hazelcast.spi.impl.operationservice.impl.responses.BackupAckResponse)1 Response (com.hazelcast.spi.impl.operationservice.impl.responses.Response)1