use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class InboundResponseHandlerSupplierTest method whenPacketThrowsException.
// test that is a bad response is send, the processing loop isn't broken
// This test isn't terribly exciting since responses are constructed by
// the system and unlikely to fail.
@Test
public void whenPacketThrowsException() {
supplier = newSupplier(1);
supplier.start();
// create a registered invocation
final Invocation invocation = newInvocation();
invocationRegistry.register(invocation);
final long callId = invocation.op.getCallId();
// the response flag isn't set; so an exception is thrown.
Packet badResponse = new Packet(serializationService.toBytes(new NormalResponse("bad", 1, 0, false))).setPacketType(Packet.Type.OPERATION).setConn(mock(ServerConnection.class));
Consumer<Packet> responseConsumer = supplier.get();
responseConsumer.accept(badResponse);
final Packet goodResponse = new Packet(serializationService.toBytes(new NormalResponse("foo", callId, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE).setConn(mock(ServerConnection.class));
responseConsumer.accept(goodResponse);
assertTrueEventually(() -> {
Invocation inv = invocationRegistry.get(callId);
System.out.println(inv);
assertNull(inv);
});
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class InboundResponseHandlerSupplierTest method whenNoProblemPacket.
private void whenNoProblemPacket(int threadCount) {
supplier = newSupplier(threadCount);
supplier.start();
final Invocation invocation = newInvocation();
invocationRegistry.register(invocation);
final long callId = invocation.op.getCallId();
final Packet response = new Packet(serializationService.toBytes(new NormalResponse("foo", callId, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE).setConn(mock(ServerConnection.class));
supplier.get().accept(response);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
Invocation inv = invocationRegistry.get(callId);
System.out.println(inv);
assertNull(inv);
}
});
assertEquals(1, supplier.responsesNormal());
assertEquals(0, supplier.responsesBackup());
assertEquals(0, supplier.responsesError());
assertEquals(0, supplier.responsesMissing());
assertEquals(0, supplier.responsesTimeout());
assertEquals(0, supplier.responseQueueSize());
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class OperationExecutorImpl_HandlePacketTest method test_whenPartitionSpecificOperationPacket.
@Test
public void test_whenPartitionSpecificOperationPacket() {
initExecutor();
final DummyOperation operation = new DummyOperation(0);
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[] partitionHandlers = executor.getPartitionOperationRunners();
DummyOperationRunner handler = (DummyOperationRunner) partitionHandlers[operation.getPartitionId()];
assertContains(handler.packets, packet);
}
});
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class MockServerConnection method readFromPacket.
private Packet readFromPacket(Packet packet) {
Packet newPacket;
PacketIOHelper packetReader = new PacketIOHelper();
PacketIOHelper packetWriter = new PacketIOHelper();
ByteBuffer buffer = ByteBuffer.allocate(4096);
boolean writeDone;
do {
writeDone = packetWriter.writeTo(packet, buffer);
upcast(buffer).flip();
newPacket = packetReader.readFrom(buffer);
if (buffer.hasRemaining()) {
throw new IllegalStateException("Buffer should be empty! " + buffer);
}
upcast(buffer).clear();
} while (!writeDone);
assertNotNull(newPacket);
newPacket.setConn(otherConnection);
return newPacket;
}
use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.
the class OperationRunnerImplTest method runPacket.
@Test
public void runPacket() throws Exception {
Operation op = new DummyOperation();
setCallId(op, 1000 * 1000);
Packet packet = toPacket(local, remote, op);
operationRunner.run(packet);
}
Aggregations