use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortableUtilsTest method wrongUseOfAnyOperationException.
@Test
public void wrongUseOfAnyOperationException() {
// GIVEN
BufferObjectDataInput in = mock(BufferObjectDataInput.class);
ClassDefinition cd = mock(ClassDefinition.class);
PortableNavigatorContext ctx = new PortableNavigatorContext(in, cd, null);
// WHEN
IllegalArgumentException ex = PortableUtils.createWrongUseOfAnyOperationException(ctx, "person.brain");
// THEN
assertNotNull(ex);
}
use of com.hazelcast.nio.BufferObjectDataInput 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);
}
use of com.hazelcast.nio.BufferObjectDataInput 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);
}
use of com.hazelcast.nio.BufferObjectDataInput 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));
}
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class AbstractSerializationServiceTest method testReadObject_ServiceInactive.
@Test
public void testReadObject_ServiceInactive() throws Exception {
expectedException.expect(HazelcastSerializationException.class);
expectedException.expectCause(Is.is(IsInstanceOf.<Throwable>instanceOf(HazelcastInstanceNotActiveException.class)));
abstractSerializationService.register(StringBuffer.class, new StringBufferSerializer(false));
Data data = abstractSerializationService.toData(new StringBuffer());
abstractSerializationService.dispose();
BufferObjectDataInput in = abstractSerializationService.createObjectDataInput(data);
in.position(HeapData.TYPE_OFFSET);
abstractSerializationService.readObject(in);
}
Aggregations