Search in sources :

Example 6 with BufferObjectDataOutput

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

the class StringSerializationTest method testNullStringEncodeDecode2.

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

Example 7 with BufferObjectDataOutput

use of com.hazelcast.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);
    out.writeData(dataV1);
    byte[] bytes = out.toByteArray();
    // emulate socket read by reading data from stream
    BufferObjectDataInput in = serializationService2.createObjectDataInput(bytes);
    dataV1 = in.readData();
    // 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.k, v1FromV2.k);
    NamedPortableV2 v2FromV1 = serializationService2.toObject(dataV1);
    assertEquals(portableV1.name, v2FromV1.name);
    assertEquals(portableV1.k, v2FromV1.k);
    assertNull(v2FromV1.v);
}
Also used : BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Example 8 with BufferObjectDataOutput

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

the class CollectionTxnUtilTest method testWriteRead.

@Test
public void testWriteRead() throws IOException {
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    BufferObjectDataOutput out = ss.createObjectDataOutput();
    CollectionTxnUtil.write(out, operationList);
    BufferObjectDataInput in = ss.createObjectDataInput(out.toByteArray());
    List<Operation> resultList = CollectionTxnUtil.read(in);
    assertEquals(operationList.size(), resultList.size());
    for (int i = 0; i < operationList.size(); i++) {
        assertEquals(operationList.get(i), resultList.get(i));
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) BackupAwareOperation(com.hazelcast.spi.BackupAwareOperation) Operation(com.hazelcast.spi.Operation) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with BufferObjectDataOutput

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

the class RingbufferContainerSerializationTest method clone.

private RingbufferContainer clone(RingbufferContainer original) {
    BufferObjectDataOutput out = serializationService.createObjectDataOutput(100000);
    BufferObjectDataInput in = null;
    try {
        out.writeObject(original);
        byte[] bytes = out.toByteArray();
        sleepMillis(CLOCK_DIFFERENCE_MS);
        in = serializationService.createObjectDataInput(bytes);
        RingbufferContainer clone = in.readObject();
        return clone;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        closeResource(out);
        closeResource(in);
    }
}
Also used : BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Example 10 with BufferObjectDataOutput

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

the class PartitionTableViewTest method test_writeAndReadData.

@Test
public void test_writeAndReadData() throws Exception {
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    PartitionTableView table1 = createRandomPartitionTable();
    BufferObjectDataOutput out = serializationService.createObjectDataOutput();
    PartitionTableView.writeData(table1, out);
    BufferObjectDataInput in = serializationService.createObjectDataInput(out.toByteArray());
    PartitionTableView table2 = PartitionTableView.readData(in);
    assertEquals(table1, table2);
    assertEquals(table1.hashCode(), table2.hashCode());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

BufferObjectDataOutput (com.hazelcast.nio.BufferObjectDataOutput)13 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)6 IOException (java.io.IOException)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)1 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)1 CustomSerializationTest (com.hazelcast.nio.serialization.CustomSerializationTest)1 BackupAwareOperation (com.hazelcast.spi.BackupAwareOperation)1 Operation (com.hazelcast.spi.Operation)1 Constructor (java.lang.reflect.Constructor)1