use of com.hazelcast.internal.util.TriTuple 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);
}
}
}
use of com.hazelcast.internal.util.TriTuple in project hazelcast by hazelcast.
the class ConfigFactoryTest method should_create_compact_serialization_config.
@Test
public void should_create_compact_serialization_config() {
Map<String, TriTuple<String, String, String>> registrations = new HashMap<>();
TriTuple<String, String, String> registration = TriTuple.of("a", "b", "c");
registrations.put("b", registration);
CompactSerializationConfig config = ConfigFactory.newCompactSerializationConfig(true, registrations);
assertThat(config.isEnabled()).isTrue();
assertThat(CompactSerializationConfigAccessor.getNamedRegistrations(config)).isEqualTo(registrations);
}
use of com.hazelcast.internal.util.TriTuple in project hazelcast by hazelcast.
the class ClientConfigXmlGenerator method compactSerialization.
private static void compactSerialization(XmlGenerator gen, SerializationConfig serializationConfig) {
CompactSerializationConfig compactSerializationConfig = serializationConfig.getCompactSerializationConfig();
if (!compactSerializationConfig.isEnabled()) {
return;
}
gen.open("compact-serialization", "enabled", compactSerializationConfig.isEnabled());
Map<String, TriTuple<Class, String, CompactSerializer>> registrations = CompactSerializationConfigAccessor.getRegistrations(compactSerializationConfig);
Map<String, TriTuple<String, String, String>> namedRegistries = CompactSerializationConfigAccessor.getNamedRegistrations(compactSerializationConfig);
if (!MapUtil.isNullOrEmpty(registrations) || !MapUtil.isNullOrEmpty(namedRegistries)) {
gen.open("registered-classes");
appendRegisteredClasses(gen, registrations);
appendNamedRegisteredClasses(gen, namedRegistries);
gen.close();
}
gen.close();
}
use of com.hazelcast.internal.util.TriTuple in project hazelcast by hazelcast.
the class CompactStreamSerializer method registerConfiguredSerializers.
private void registerConfiguredSerializers(CompactSerializationConfig compactSerializationConfig) {
Map<String, TriTuple<Class, String, CompactSerializer>> registrations = CompactSerializationConfigAccessor.getRegistrations(compactSerializationConfig);
for (TriTuple<Class, String, CompactSerializer> registration : registrations.values()) {
Class clazz = registration.element1;
String typeName = registration.element2;
CompactSerializer serializer = registration.element3;
if (serializer == null) {
if (javaRecordSerializer.isRecord(clazz)) {
serializer = javaRecordSerializer;
} else {
serializer = reflectiveSerializer;
}
}
CompactSerializableRegistration serializableRegistration = new CompactSerializableRegistration(clazz, typeName, serializer);
classToRegistrationMap.put(clazz, serializableRegistration);
typeNameToRegistrationMap.put(typeName, serializableRegistration);
}
}
use of com.hazelcast.internal.util.TriTuple 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);
}
}
}
Aggregations