use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class RingbufferStoreConfigTest method setStoreImplementation.
@Test
public void setStoreImplementation() {
SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
RingbufferStore<Data> store = RingbufferStoreWrapper.create("name", config, OBJECT, serializationService, null);
config.setStoreImplementation(store);
assertEquals(store, config.getStoreImplementation());
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class BinaryCompatibilityFileGenerator method createSerializationService.
private static SerializationService createSerializationService(ByteOrder byteOrder) {
SerializationConfig config = new SerializationConfig();
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomByteArraySerializer()).setTypeClass(CustomByteArraySerializable.class);
config.addSerializerConfig(serializerConfig);
}
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomStreamSerializer()).setTypeClass(CustomStreamSerializable.class);
config.addSerializerConfig(serializerConfig);
}
config.setByteOrder(byteOrder);
ClassDefinition classDefinition = new ClassDefinitionBuilder(ReferenceObjects.PORTABLE_FACTORY_ID, ReferenceObjects.INNER_PORTABLE_CLASS_ID).addIntField("i").addFloatField("f").build();
return new DefaultSerializationServiceBuilder().setConfig(config).setVersion(VERSION).addPortableFactory(ReferenceObjects.PORTABLE_FACTORY_ID, new APortableFactory()).addDataSerializableFactory(ReferenceObjects.IDENTIFIED_DATA_SERIALIZABLE_FACTORY_ID, new ADataSerializableFactory()).addClassDefinition(classDefinition).build();
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PortableTest method test_issue2172_WritePortableArray.
//https://github.com/hazelcast/hazelcast/issues/2172
@Test
public void test_issue2172_WritePortableArray() {
final SerializationService ss = new DefaultSerializationServiceBuilder().setInitialOutputBufferSize(16).build();
final TestObject2[] testObject2s = new TestObject2[100];
for (int i = 0; i < testObject2s.length; i++) {
testObject2s[i] = new TestObject2();
}
final TestObject1 testObject1 = new TestObject1(testObject2s);
ss.toData(testObject1);
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PortableTest method testClassDefinition_getNestedField.
@Test
public void testClassDefinition_getNestedField() throws IOException {
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
PortableContext portableContext = serializationService.getPortableContext();
ChildPortableObject child = new ChildPortableObject(System.nanoTime());
ParentPortableObject parent = new ParentPortableObject(System.currentTimeMillis(), child);
GrandParentPortableObject grandParent = new GrandParentPortableObject(System.nanoTime(), parent);
Data data = serializationService.toData(grandParent);
ClassDefinition classDefinition = portableContext.lookupClassDefinition(data);
FieldDefinition fd = portableContext.getFieldDefinition(classDefinition, "child");
assertNotNull(fd);
assertEquals(FieldType.PORTABLE, fd.getType());
fd = portableContext.getFieldDefinition(classDefinition, "child.child");
assertNotNull(fd);
assertEquals(FieldType.PORTABLE, fd.getType());
fd = portableContext.getFieldDefinition(classDefinition, "child.child.timestamp");
assertNotNull(fd);
assertEquals(FieldType.LONG, fd.getType());
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class SerializationConcurrencyTest method test.
@Test
public void test() throws IOException, InterruptedException {
PortableFactory portableFactory = new PortableFactory() {
@Override
public Portable create(int classId) {
switch(classId) {
case 1:
return new PortablePerson();
case 2:
return new PortableAddress();
}
throw new IllegalArgumentException();
}
};
final SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(FACTORY_ID, portableFactory).build();
final int k = 10;
final AtomicBoolean error = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(k);
ExecutorService ex = Executors.newCachedThreadPool();
for (int i = 0; i < k; i++) {
ex.execute(new Runnable() {
final Random rand = new Random();
public void run() {
try {
for (int j = 0; j < 10000; j++) {
String key = "key" + rnd();
Data dataKey = ss.toData(key);
Assert.assertEquals(key, ss.toObject(dataKey));
Long value = 123L + rnd();
Data dataValue = ss.toData(value);
Assert.assertEquals(value, ss.toObject(dataValue));
Address address = new Address("here here" + rnd(), 13131 + rnd());
Data dataAddress = ss.toData(address);
Assert.assertEquals(address, ss.toObject(dataAddress));
Person person = new Person(13 + rnd(), 199L + rnd(), 56.89d, "mehmet", address);
Data dataPerson = ss.toData(person);
Assert.assertEquals(person, ss.toObject(dataPerson));
PortableAddress portableAddress = new PortableAddress("there there " + rnd(), 90909 + rnd());
Data dataPortableAddress = ss.toData(portableAddress);
Assert.assertEquals(portableAddress, ss.toObject(dataPortableAddress));
PortablePerson portablePerson = new PortablePerson(63 + rnd(), 167L + rnd(), "ahmet", portableAddress);
Data dataPortablePerson = ss.toData(portablePerson);
Assert.assertEquals(portablePerson, ss.toObject(dataPortablePerson));
}
} catch (Exception e) {
e.printStackTrace();
error.set(true);
} finally {
latch.countDown();
}
}
int rnd() {
return rand.nextInt();
}
});
}
latch.await();
ex.shutdown();
if (error.get()) {
throw new AssertionError();
}
}
Aggregations