Search in sources :

Example 6 with Serialiser

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;
    }
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) BooleanParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.impl.BooleanParquetSerialiser) ParquetSerialiser(uk.gov.gchq.gaffer.parquetstore.serialisation.ParquetSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser)

Example 7 with 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()));
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) Test(org.junit.jupiter.api.Test)

Example 8 with Serialiser

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());
}
Also used : BooleanSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) OrderedIntegerSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser) RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) BooleanSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) Test(org.junit.jupiter.api.Test)

Example 9 with Serialiser

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());
}
Also used : RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) OrderedIntegerSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser) RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) BooleanSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) Test(org.junit.jupiter.api.Test)

Example 10 with Serialiser

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());
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) RawDoubleSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser) OrderedIntegerSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser) RawDateSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) BooleanSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) RawFloatSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser) Test(org.junit.jupiter.api.Test)

Aggregations

Serialiser (uk.gov.gchq.gaffer.serialisation.Serialiser)28 Test (org.junit.jupiter.api.Test)18 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)18 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)16 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)10 BooleanSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser)8 OrderedIntegerSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser)8 RawDateSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser)8 RawDoubleSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser)8 RawFloatSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser)8 StringToStringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser)6 MapSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser)5 RawLongSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser)5 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 ArrayList (java.util.ArrayList)3 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)3 AvroSerialiser (uk.gov.gchq.gaffer.serialisation.AvroSerialiser)3 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2