Search in sources :

Example 1 with EmployeeDTOSerializer

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

the class ConfigXmlGeneratorTest method testCompactSerialization.

@Test
public void testCompactSerialization() {
    Config config = new Config();
    CompactSerializationConfig expected = new CompactSerializationConfig();
    expected.setEnabled(true);
    expected.register(EmployerDTO.class);
    expected.register(EmployeeDTO.class, "employee", new EmployeeDTOSerializer());
    config.getSerializationConfig().setCompactSerializationConfig(expected);
    CompactSerializationConfig actual = getNewConfigViaXMLGenerator(config).getSerializationConfig().getCompactSerializationConfig();
    assertEquals(expected.isEnabled(), actual.isEnabled());
    // Since we don't have APIs of the form register(String) or register(String, String, String) in the
    // compact serialization config, when we read the config from XML/YAML, we store registered classes
    // in a different map.
    Map<String, TriTuple<String, String, String>> namedRegistries = CompactSerializationConfigAccessor.getNamedRegistrations(actual);
    Map<String, TriTuple<Class, String, CompactSerializer>> registrations = CompactSerializationConfigAccessor.getRegistrations(actual);
    for (Map.Entry<String, TriTuple<Class, String, CompactSerializer>> entry : registrations.entrySet()) {
        String key = entry.getKey();
        TriTuple<Class, String, CompactSerializer> expectedRegistration = entry.getValue();
        TriTuple<String, String, String> actualRegistration = namedRegistries.get(key);
        assertEquals(expectedRegistration.element1.getName(), actualRegistration.element1);
        assertEquals(expectedRegistration.element2, actualRegistration.element2);
        CompactSerializer serializer = expectedRegistration.element3;
        if (serializer != null) {
            assertEquals(serializer.getClass().getName(), actualRegistration.element3);
        } else {
            assertNull(actualRegistration.element3);
        }
    }
}
Also used : TlsAuthenticationConfig(com.hazelcast.config.security.TlsAuthenticationConfig) TokenIdentityConfig(com.hazelcast.config.security.TokenIdentityConfig) LdapAuthenticationConfig(com.hazelcast.config.security.LdapAuthenticationConfig) SemaphoreConfig(com.hazelcast.config.cp.SemaphoreConfig) CPSubsystemConfig(com.hazelcast.config.cp.CPSubsystemConfig) SimpleAuthenticationConfig(com.hazelcast.config.security.SimpleAuthenticationConfig) KerberosIdentityConfig(com.hazelcast.config.security.KerberosIdentityConfig) KerberosAuthenticationConfig(com.hazelcast.config.security.KerberosAuthenticationConfig) RealmConfig(com.hazelcast.config.security.RealmConfig) JaasAuthenticationConfig(com.hazelcast.config.security.JaasAuthenticationConfig) JetConfig(com.hazelcast.jet.config.JetConfig) FencedLockConfig(com.hazelcast.config.cp.FencedLockConfig) TriTuple(com.hazelcast.internal.util.TriTuple) EmployeeDTOSerializer(example.serialization.EmployeeDTOSerializer) CompactSerializer(com.hazelcast.nio.serialization.compact.CompactSerializer) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with EmployeeDTOSerializer

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

the class CompactStreamSerializerTest method testDeserializedToGenericRecordWhenClassNotFoundOnClassPath.

@Test
public void testDeserializedToGenericRecordWhenClassNotFoundOnClassPath() {
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.getCompactSerializationConfig().setEnabled(true).register(EmployeeDTO.class, "employee", new EmployeeDTOSerializer());
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig).build();
    EmployeeDTO employeeDTO = new EmployeeDTO(30, 102310312);
    Data data = serializationService.toData(employeeDTO);
    SerializationConfig serializationConfig2 = new SerializationConfig();
    serializationConfig2.getCompactSerializationConfig().setEnabled(true);
    SerializationService readerService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig2).build();
    GenericRecord genericRecord = readerService.toObject(data);
    assertEquals(employeeDTO.getAge(), genericRecord.getInt32("age"));
    assertEquals(employeeDTO.getId(), genericRecord.getInt64("id"));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) EmployeeDTO(example.serialization.EmployeeDTO) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) EmployeeDTOSerializer(example.serialization.EmployeeDTOSerializer) 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 3 with EmployeeDTOSerializer

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

the class ClientConfigXmlGeneratorTest method testCompactSerialization.

@Test
public void testCompactSerialization() {
    CompactSerializationConfig expected = new CompactSerializationConfig();
    expected.setEnabled(true);
    expected.register(EmployerDTO.class);
    expected.register(EmployeeDTO.class, "employee", new EmployeeDTOSerializer());
    clientConfig.getSerializationConfig().setCompactSerializationConfig(expected);
    CompactSerializationConfig actual = newConfigViaGenerator().getSerializationConfig().getCompactSerializationConfig();
    assertEquals(expected.isEnabled(), actual.isEnabled());
    // Since we don't have APIs of the form register(String) or register(String, String, String) in the
    // compact serialization config, when we read the config from XML/YAML, we store registered classes
    // in a different map.
    Map<String, TriTuple<String, String, String>> namedRegistrations = CompactSerializationConfigAccessor.getNamedRegistrations(actual);
    Map<String, TriTuple<Class, String, CompactSerializer>> registrations = CompactSerializationConfigAccessor.getRegistrations(actual);
    for (Map.Entry<String, TriTuple<Class, String, CompactSerializer>> entry : registrations.entrySet()) {
        String key = entry.getKey();
        TriTuple<Class, String, CompactSerializer> expectedRegistration = entry.getValue();
        TriTuple<String, String, String> actualRegistration = namedRegistrations.get(key);
        assertEquals(expectedRegistration.element1.getName(), actualRegistration.element1);
        assertEquals(expectedRegistration.element2, actualRegistration.element2);
        CompactSerializer serializer = expectedRegistration.element3;
        if (serializer != null) {
            assertEquals(serializer.getClass().getName(), actualRegistration.element3);
        } else {
            assertNull(actualRegistration.element3);
        }
    }
}
Also used : TriTuple(com.hazelcast.internal.util.TriTuple) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) EmployeeDTOSerializer(example.serialization.EmployeeDTOSerializer) CompactSerializer(com.hazelcast.nio.serialization.compact.CompactSerializer) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with EmployeeDTOSerializer

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

the class CompactStreamSerializerTest method testWithExplicitSerializer.

@Test
public void testWithExplicitSerializer() {
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.getCompactSerializationConfig().setEnabled(true).register(EmployeeDTO.class, "employee", new EmployeeDTOSerializer());
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig).build();
    EmployeeDTO employeeDTO = new EmployeeDTO(30, 102310312);
    Data data = serializationService.toData(employeeDTO);
    Object object = serializationService.toObject(data);
    EmployeeDTO actual = (EmployeeDTO) object;
    assertEquals(employeeDTO, actual);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) EmployeeDTO(example.serialization.EmployeeDTO) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) EmployeeDTOSerializer(example.serialization.EmployeeDTOSerializer) 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

ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 EmployeeDTOSerializer (example.serialization.EmployeeDTOSerializer)4 Test (org.junit.Test)4 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 Data (com.hazelcast.internal.serialization.Data)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationService (com.hazelcast.internal.serialization.SerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 TriTuple (com.hazelcast.internal.util.TriTuple)2 CompactSerializer (com.hazelcast.nio.serialization.compact.CompactSerializer)2 EmployeeDTO (example.serialization.EmployeeDTO)2 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)2 Map (java.util.Map)2 CPSubsystemConfig (com.hazelcast.config.cp.CPSubsystemConfig)1 FencedLockConfig (com.hazelcast.config.cp.FencedLockConfig)1 SemaphoreConfig (com.hazelcast.config.cp.SemaphoreConfig)1 JaasAuthenticationConfig (com.hazelcast.config.security.JaasAuthenticationConfig)1 KerberosAuthenticationConfig (com.hazelcast.config.security.KerberosAuthenticationConfig)1