use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class OperationExecutorImpl_HandlePacketTest method test_whenGenericOperationPacket.
@Test
public void test_whenGenericOperationPacket() {
initExecutor();
final DummyOperation operation = new DummyOperation(Operation.GENERIC_PARTITION_ID);
final Packet packet = new Packet(serializationService.toBytes(operation), operation.getPartitionId()).setPacketType(Packet.Type.OPERATION);
executor.accept(packet);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
OperationRunner[] genericHandlers = executor.getGenericOperationRunners();
boolean found = false;
for (OperationRunner h : genericHandlers) {
DummyOperationRunner dummyOperationHandler = (DummyOperationRunner) h;
if (dummyOperationHandler.packets.contains(packet)) {
found = true;
break;
}
}
assertTrue("Packet is not found on any of the generic handlers", found);
}
});
}
use of com.hazelcast.internal.nio.Packet 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.accept(packet);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
DummyResponsePacketConsumer responsePacketConsumer = (DummyResponsePacketConsumer) OperationExecutorImpl_HandlePacketTest.this.responsePacketConsumer;
responsePacketConsumer.packets.contains(packet);
responsePacketConsumer.responses.contains(normalResponse);
}
});
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class OutboundResponseHandlerTest method sendResponse_whenNull.
@Test
public void sendResponse_whenNull() {
Operation op = createDummyOperation(10);
ArgumentCaptor<Packet> argument = ArgumentCaptor.forClass(Packet.class);
when(connectionManager.transmit(argument.capture(), eq(thatAddress), anyInt())).thenReturn(true);
// make the call
handler.sendResponse(op, null);
// verify that the right object was send
NormalResponse expected = new NormalResponse(null, op.getCallId(), 0, op.isUrgent());
assertEquals(serializationService.toData(expected), argument.getValue());
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class OutboundResponseHandlerTest method sendResponse_whenNormalResponse.
@Test
public void sendResponse_whenNormalResponse() {
NormalResponse response = new NormalResponse("foo", 10, 1, false);
Operation op = createDummyOperation(response.getCallId());
ArgumentCaptor<Packet> argument = ArgumentCaptor.forClass(Packet.class);
when(connectionManager.transmit(argument.capture(), eq(thatAddress), anyInt())).thenReturn(true);
// make the call
handler.sendResponse(op, response);
// verify that the right object was send
assertEquals(serializationService.toData(response), argument.getValue());
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class OutboundResponseHandlerTest method sendResponse_whenOrdinaryValue.
@Test
public void sendResponse_whenOrdinaryValue() {
Object response = "foobar";
Operation op = createDummyOperation(10);
ArgumentCaptor<Packet> argument = ArgumentCaptor.forClass(Packet.class);
when(connectionManager.transmit(argument.capture(), eq(thatAddress), anyInt())).thenReturn(true);
// make the call
handler.sendResponse(op, response);
// verify that the right object was send
NormalResponse expected = new NormalResponse(response, op.getCallId(), 0, op.isUrgent());
assertEquals(serializationService.toData(expected), argument.getValue());
}
Aggregations