Search in sources :

Example 1 with MainDTO

use of example.serialization.MainDTO in project hazelcast by hazelcast.

the class CompactTestUtil method createMainDTO.

@Nonnull
static MainDTO createMainDTO() {
    NamedDTO[] nn = new NamedDTO[2];
    nn[0] = new NamedDTO("name", 123);
    nn[1] = new NamedDTO("name", 123);
    InnerDTO inner = new InnerDTO(new boolean[] { true, false }, new byte[] { 0, 1, 2 }, new short[] { 3, 4, 5 }, new int[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 }, new float[] { 0.6543f, -3.56f, 45.67f }, new double[] { 456.456, 789.789, 321.321 }, nn, new BigDecimal[] { new BigDecimal("12345"), new BigDecimal("123456") }, new LocalTime[] { LocalTime.now(), LocalTime.now() }, new LocalDate[] { LocalDate.now(), LocalDate.now() }, new LocalDateTime[] { LocalDateTime.now() }, new OffsetDateTime[] { OffsetDateTime.now() }, new Boolean[] { true, false, null }, new Byte[] { 0, 1, 2, null }, new Short[] { 3, 4, 5, null }, new Integer[] { 9, 8, 7, 6, null }, new Long[] { 0L, 1L, 5L, 7L, 9L, 11L }, new Float[] { 0.6543f, -3.56f, 45.67f }, new Double[] { 456.456, 789.789, 321.321 }, new LocalTime[] { LocalTime.now(), LocalTime.now() }, new LocalDate[] { LocalDate.now(), LocalDate.now(), null }, new LocalDateTime[] { LocalDateTime.now(), null }, new OffsetDateTime[] { OffsetDateTime.now() });
    return new MainDTO((byte) 113, true, (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d, "this is main object created for testing!", inner, new BigDecimal("12312313"), LocalTime.now(), LocalDate.now(), LocalDateTime.now(), OffsetDateTime.now(), (byte) 113, true, (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d);
}
Also used : NamedDTO(example.serialization.NamedDTO) InnerDTO(example.serialization.InnerDTO) MainDTO(example.serialization.MainDTO) BigDecimal(java.math.BigDecimal) Nonnull(javax.annotation.Nonnull)

Example 2 with MainDTO

use of example.serialization.MainDTO in project hazelcast by hazelcast.

the class GenericRecordTest method testGenericRecordToStringValidJson.

@Test
public void testGenericRecordToStringValidJson() throws IOException {
    CompactSerializationConfig compactSerializationConfig = new CompactSerializationConfig();
    compactSerializationConfig.setEnabled(true);
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(new SerializationConfig().setCompactSerializationConfig(compactSerializationConfig)).build();
    MainDTO expectedDTO = createMainDTO();
    expectedDTO.nullableBool = null;
    expectedDTO.p.localDateTimes[0] = null;
    Data data = serializationService.toData(expectedDTO);
    assertTrue(data.isCompact());
    // internal generic record created on the servers on query
    InternalGenericRecord internalGenericRecord = serializationService.readAsInternalGenericRecord(data);
    String string = internalGenericRecord.toString();
    Json.parse(string);
    // generic record read from a remote instance without classes on the classpath
    List<String> excludes = Collections.singletonList("example.serialization");
    FilteringClassLoader classLoader = new FilteringClassLoader(excludes, null);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        InternalSerializationService ss2 = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setClassLoader(classLoader).setConfig(new SerializationConfig().setCompactSerializationConfig(new CompactSerializationConfig())).build();
        GenericRecord genericRecord = ss2.toObject(data);
        Json.parse(genericRecord.toString());
        // generic record build by API
        GenericRecord apiGenericRecord = createCompactGenericRecord(expectedDTO);
        Json.parse(apiGenericRecord.toString());
    } finally {
        Thread.currentThread().setContextClassLoader(contextClassLoader);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) MainDTO(example.serialization.MainDTO) CompactTestUtil.createMainDTO(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) FilteringClassLoader(com.hazelcast.internal.util.FilteringClassLoader) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MainDTO

use of example.serialization.MainDTO in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testGenericRecordHashcode_Equals.

@Test
public void testGenericRecordHashcode_Equals() {
    SerializationService serializationService = createSerializationService();
    MainDTO expectedDTO = createMainDTO();
    GenericRecord expectedGenericRecord = createCompactGenericRecord(expectedDTO);
    Data data = serializationService.toData(expectedGenericRecord);
    Object object = serializationService.toObject(data);
    GenericRecord genericRecord = (GenericRecord) object;
    assertTrue(expectedGenericRecord.equals(genericRecord));
    assertTrue(genericRecord.equals(expectedGenericRecord));
    assertEquals(expectedGenericRecord.hashCode(), genericRecord.hashCode());
}
Also used : MainDTO(example.serialization.MainDTO) CompactTestUtil.createMainDTO(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MainDTO

use of example.serialization.MainDTO in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testAllTypesWithReflectiveSerializer.

@Test
public void testAllTypesWithReflectiveSerializer() {
    SerializationService serializationService = createSerializationService();
    MainDTO expected = createMainDTO();
    Data data = serializationService.toData(expected);
    MainDTO actual = serializationService.toObject(data);
    assertEquals(expected, actual);
}
Also used : MainDTO(example.serialization.MainDTO) CompactTestUtil.createMainDTO(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MainDTO (example.serialization.MainDTO)4 Data (com.hazelcast.internal.serialization.Data)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 CompactTestUtil.createMainDTO (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createMainDTO)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)2 CompactTestUtil.createCompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord)2 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)2 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)1 SerializationConfig (com.hazelcast.config.SerializationConfig)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 InternalGenericRecord (com.hazelcast.internal.serialization.impl.InternalGenericRecord)1 FilteringClassLoader (com.hazelcast.internal.util.FilteringClassLoader)1 InnerDTO (example.serialization.InnerDTO)1 NamedDTO (example.serialization.NamedDTO)1 BigDecimal (java.math.BigDecimal)1 Nonnull (javax.annotation.Nonnull)1