Search in sources :

Example 6 with BufferObjectDataOutput

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

the class BufferPoolTest method returnOutputBuffer.

@Test
public void returnOutputBuffer() {
    BufferObjectDataOutput out = mock(BufferObjectDataOutput.class);
    bufferPool.returnOutputBuffer(out);
    // lets see if the item was pushed on the queue
    assertEquals(1, bufferPool.outputQueue.size());
    // we need to make sure clear was called
    verify(out, times(1)).clear();
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with BufferObjectDataOutput

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

the class BufferPoolTest method returnOutputBuffer_whenOverflowing.

@Test
public void returnOutputBuffer_whenOverflowing() {
    for (int k = 0; k < BufferPoolImpl.MAX_POOLED_ITEMS; k++) {
        bufferPool.returnOutputBuffer(mock(BufferObjectDataOutput.class));
    }
    BufferObjectDataOutput out = mock(BufferObjectDataOutput.class);
    bufferPool.returnOutputBuffer(out);
    assertEquals(BufferPoolImpl.MAX_POOLED_ITEMS, bufferPool.outputQueue.size());
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with BufferObjectDataOutput

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

the class BufferPoolTest method takeOutputBuffer_whenNestedInstance.

@Test
public void takeOutputBuffer_whenNestedInstance() {
    BufferObjectDataOutput found1 = bufferPool.takeOutputBuffer();
    BufferObjectDataOutput found2 = bufferPool.takeOutputBuffer();
    assertNotSame(found1, found2);
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with BufferObjectDataOutput

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

the class StringSerializationTest method testNullStringEncodeDecode2.

@Test
public void testNullStringEncodeDecode2() throws Exception {
    BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
    objectDataOutput.writeString(null);
    byte[] bytes = objectDataOutput.toByteArray();
    objectDataOutput.close();
    BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
    String decodedStr = objectDataInput.readString();
    assertNull(decodedStr);
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with BufferObjectDataOutput

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

the class PortableClassVersionTest method testDifferentClassVersionsUsingDataWriteAndRead.

// used in EE, so needs to be package private
static void testDifferentClassVersionsUsingDataWriteAndRead(InternalSerializationService serializationService, InternalSerializationService serializationService2) throws Exception {
    NamedPortable portableV1 = new NamedPortable("portable-v1", 111);
    Data dataV1 = serializationService.toData(portableV1);
    // emulate socket write by writing data to stream
    BufferObjectDataOutput out = serializationService.createObjectDataOutput(1024);
    writeData(out, dataV1);
    byte[] bytes = out.toByteArray();
    // emulate socket read by reading data from stream
    BufferObjectDataInput in = serializationService2.createObjectDataInput(bytes);
    dataV1 = readData(in);
    // serialize new portable version
    NamedPortableV2 portableV2 = new NamedPortableV2("portable-v2", 123, 500);
    Data dataV2 = serializationService2.toData(portableV2);
    NamedPortable v1FromV2 = serializationService.toObject(dataV2);
    assertEquals(portableV2.name, v1FromV2.name);
    assertEquals(portableV2.myint, v1FromV2.myint);
    NamedPortableV2 v2FromV1 = serializationService2.toObject(dataV1);
    assertEquals(portableV1.name, v2FromV1.name);
    assertEquals(portableV1.myint, v2FromV1.myint);
    assertNull(v2FromV1.v);
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) Data(com.hazelcast.internal.serialization.Data) IOUtil.writeData(com.hazelcast.internal.nio.IOUtil.writeData) IOUtil.readData(com.hazelcast.internal.nio.IOUtil.readData) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Aggregations

BufferObjectDataOutput (com.hazelcast.internal.nio.BufferObjectDataOutput)21 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)6 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 IOException (java.io.IOException)3 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 Address (com.hazelcast.cluster.Address)1 Connection (com.hazelcast.internal.nio.Connection)1 IOUtil.readData (com.hazelcast.internal.nio.IOUtil.readData)1 IOUtil.writeData (com.hazelcast.internal.nio.IOUtil.writeData)1 Data (com.hazelcast.internal.serialization.Data)1 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)1 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)1 CompactStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter)1 CompactWithSchemaStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter)1 ExecutionContext (com.hazelcast.jet.impl.execution.ExecutionContext)1 SenderReceiverKey (com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey)1