Search in sources :

Example 46 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class PacketTest method raiseFlags.

@Test
public void raiseFlags() {
    Packet packet = new Packet();
    packet.raiseFlags(FLAG_URGENT);
    assertEquals(FLAG_4_0 | FLAG_URGENT, packet.getFlags());
}
Also used : Packet(com.hazelcast.internal.nio.Packet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class PacketIOHelperTest method cloningOfPacket.

/**
 * Verifies that writing a Packet to a ByteBuffer and then reading it from the ByteBuffer, gives the same Packet (content).
 */
@Test
public void cloningOfPacket() {
    Packet originalPacket = new Packet("foobarbaz".getBytes());
    ByteBuffer bb = ByteBuffer.allocate(100);
    boolean written = packetWriter.writeTo(originalPacket, bb);
    assertTrue(written);
    upcast(bb).flip();
    Packet clonedPacket = packetReader.readFrom(bb);
    assertNotNull(clonedPacket);
    assertPacketEquals(originalPacket, clonedPacket);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) SerializationConcurrencyTest(com.hazelcast.internal.serialization.impl.SerializationConcurrencyTest) Test(org.junit.Test)

Example 48 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class PacketIOHelperTest method largeValue.

/**
 * Checks if the packet can deal with a buffer that is very small, but the data is very large, which
 * needs repeated calls to {@link PacketIOHelper#writeTo(Packet, ByteBuffer)} and
 * {@link PacketIOHelper#readFrom(ByteBuffer)}.
 */
@Test
public void largeValue() {
    Packet originalPacket = new Packet(generateRandomString(100000).getBytes());
    Packet clonedPacket;
    ByteBuffer bb = ByteBuffer.allocate(20);
    boolean writeCompleted;
    do {
        writeCompleted = packetWriter.writeTo(originalPacket, bb);
        upcast(bb).flip();
        clonedPacket = packetReader.readFrom(bb);
        upcast(bb).clear();
    } while (!writeCompleted);
    assertNotNull(clonedPacket);
    assertPacketEquals(originalPacket, clonedPacket);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) SerializationConcurrencyTest(com.hazelcast.internal.serialization.impl.SerializationConcurrencyTest) Test(org.junit.Test)

Example 49 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class PacketIOHelperTest method testPacketWriteRead.

private void testPacketWriteRead(Object originalObject) throws IOException {
    InternalSerializationService ss = createSerializationServiceBuilder().build();
    byte[] originalPayload = ss.toBytes(originalObject);
    ByteBuffer buffer = ByteBuffer.allocate(originalPayload.length * 2);
    Packet originalPacket = new Packet(originalPayload);
    assertTrue(packetWriter.writeTo(originalPacket, buffer));
    upcast(buffer).flip();
    SerializationService ss2 = createSerializationServiceBuilder().build();
    Packet clonedPacket = packetReader.readFrom(buffer);
    assertNotNull(clonedPacket);
    Object clonedObject = ss2.toObject(clonedPacket);
    assertEquals(originalPacket, clonedPacket);
    assertEquals(originalObject, clonedObject);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ByteBuffer(java.nio.ByteBuffer)

Example 50 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class OperationThreadTest method testOOME_whenDeserializing.

@Test
public void testOOME_whenDeserializing() throws Exception {
    handlerFactory = mock(OperationRunnerFactory.class);
    OperationRunner handler = mock(OperationRunner.class);
    when(handlerFactory.createGenericRunner()).thenReturn(handler);
    when(handlerFactory.createPartitionRunner(anyInt())).thenReturn(handler);
    initExecutor();
    DummyOperation operation = new DummyOperation(Operation.GENERIC_PARTITION_ID);
    Packet packet = new Packet(serializationService.toBytes(operation), operation.getPartitionId()).setPacketType(Packet.Type.OPERATION);
    doThrow(new OutOfMemoryError()).when(handler).run(packet);
    final int oldCount = OutOfMemoryErrorDispatcher.getOutOfMemoryErrorCount();
    executor.accept(packet);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(oldCount + 1, OutOfMemoryErrorDispatcher.getOutOfMemoryErrorCount());
        }
    });
}
Also used : Packet(com.hazelcast.internal.nio.Packet) OperationRunnerFactory(com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory) AssertTask(com.hazelcast.test.AssertTask) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Packet (com.hazelcast.internal.nio.Packet)65 Test (org.junit.Test)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 Operation (com.hazelcast.spi.impl.operationservice.Operation)11 ByteBuffer (java.nio.ByteBuffer)10 NormalResponse (com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse)9 AssertTask (com.hazelcast.test.AssertTask)6 PacketIOHelper (com.hazelcast.internal.nio.PacketIOHelper)5 SerializationConcurrencyTest (com.hazelcast.internal.serialization.impl.SerializationConcurrencyTest)3 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)3 IOException (java.io.IOException)3 Address (com.hazelcast.cluster.Address)2 MemberHandshake (com.hazelcast.internal.cluster.impl.MemberHandshake)2 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 HeapData (com.hazelcast.internal.serialization.impl.HeapData)2 ServerConnection (com.hazelcast.internal.server.ServerConnection)2 ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)2 OperationRunnerFactory (com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory)2