use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SchemaUtils method getSerialiser.
public Serialiser getSerialiser(final String serialiserClassName) throws SerialisationException {
if (serialiserNameToSerialiser.containsKey(serialiserClassName)) {
return serialiserNameToSerialiser.get(serialiserClassName);
} else {
final Serialiser serialiser;
try {
serialiser = (Serialiser) Class.forName(SimpleClassNameIdResolver.getClassName(serialiserClassName)).newInstance();
} catch (final IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new SerialisationException("Failed to instantiate the serialiser: " + serialiserClassName, e);
}
serialiserNameToSerialiser.put(serialiserClassName, serialiser);
return serialiser;
}
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class StoreTest method shouldFindInvalidSerialiser.
@Test
public void shouldFindInvalidSerialiser() throws Exception {
final Class<StringToStringSerialiser> invalidSerialiserClass = StringToStringSerialiser.class;
Schema invalidSchema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("string").destination("invalidString").directed("true").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).type("string", new TypeDefinition.Builder().clazz(String.class).serialiser(new StringSerialiser()).build()).type("invalidString", new TypeDefinition.Builder().clazz(String.class).serialiser(invalidSerialiserClass.newInstance()).build()).type("true", Boolean.class).build();
final StoreProperties properties = mock(StoreProperties.class);
given(properties.getJobExecutorThreadCount()).willReturn(1);
final Class<ToBytesSerialiser> validSerialiserInterface = ToBytesSerialiser.class;
try {
new StoreImpl() {
@Override
protected Class<? extends Serialiser> getRequiredParentSerialiserClass() {
return validSerialiserInterface;
}
}.initialise("graphId", invalidSchema, properties);
fail("Should have thrown exception");
} catch (final SchemaException e) {
assertTrue(e.getMessage().contains(invalidSerialiserClass.getSimpleName()));
}
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldNotReAddClassToFactory.
@Test
public void shouldNotReAddClassToFactory() throws SerialisationException {
// Given / new factory created with only 1 element
final Serialiser[] serialisers = new Serialiser[] { new BooleanSerialiser() };
final SerialisationFactory factory = new SerialisationFactory(serialisers);
// When
factory.addSerialisers(new BooleanSerialiser());
// Then / still has 1 element, BooleanSerialiser already existed
assertEquals(1, factory.getSerialisers().size());
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SerialisationFactoryTest method shouldReturnCustomSerialiserIfCustomSerialiserFound.
@Test
public void shouldReturnCustomSerialiserIfCustomSerialiserFound() throws SerialisationException {
// Given
final Serialiser[] serialisers = new Serialiser[] { new RawDateSerialiser(), new RawDoubleSerialiser(), new RawFloatSerialiser() };
final SerialisationFactory factory = new SerialisationFactory(serialisers);
final Class<?> clazz = Double.class;
// When
final Serialiser serialiser = factory.getSerialiser(clazz);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(RawDoubleSerialiser.class, serialiser.getClass());
}
use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.
the class SerialisationFactoryTest method testAddSerialisers.
@Test
public void testAddSerialisers() throws SerialisationException {
// Given
final Serialiser[] serialisers = new Serialiser[] { new RawDateSerialiser(), new RawDoubleSerialiser(), new RawFloatSerialiser() };
final SerialisationFactory factory = new SerialisationFactory(serialisers);
final Class<?> clazz = String.class;
// When
factory.addSerialisers(new StringSerialiser());
Serialiser serialiser = factory.getSerialiser(clazz);
// Then
assertTrue(serialiser.canHandle(clazz));
assertEquals(StringSerialiser.class, serialiser.getClass());
}
Aggregations