Search in sources :

Example 1 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldTruncatePropertyBytes.

@Test
public void shouldTruncatePropertyBytes() throws AccumuloElementConversionException {
    // Given
    final Properties properties = new Properties() {

        {
            put(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
            put(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 2);
            put(AccumuloPropertyNames.COLUMN_QUALIFIER_3, 3);
            put(AccumuloPropertyNames.COLUMN_QUALIFIER_4, 4);
        }
    };
    final byte[] bytes = converter.buildColumnQualifier(TestGroups.EDGE, properties);
    // When
    final byte[] truncatedBytes = converter.getPropertiesAsBytesFromColumnQualifier(TestGroups.EDGE, bytes, 2);
    // Then
    final Properties truncatedProperties = new Properties() {

        {
            put(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
            put(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 2);
        }
    };
    assertEquals(truncatedProperties, converter.getPropertiesFromColumnQualifier(TestGroups.EDGE, truncatedBytes));
}
Also used : Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 2 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldBuildTimestampFromDefaultTimeWhenPropertyIsNull.

@Test
public void shouldBuildTimestampFromDefaultTimeWhenPropertyIsNull() throws AccumuloElementConversionException {
    // Given
    // add extra timestamp property to schema
    final Schema schema = new Schema.Builder().json(StreamUtil.schemas(getClass())).build();
    converter = createConverter(new Schema.Builder(schema).type("timestamp", Long.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(AccumuloPropertyNames.TIMESTAMP, "timestamp").build()).timestampProperty(AccumuloPropertyNames.TIMESTAMP).build());
    final Long propertyTimestamp = null;
    final Properties properties = new Properties() {

        {
            put(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
            put(AccumuloPropertyNames.PROP_1, 2);
            put(AccumuloPropertyNames.TIMESTAMP, propertyTimestamp);
        }
    };
    // When
    final long timestamp = converter.buildTimestamp(properties);
    // Then
    assertNotNull(timestamp);
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 3 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldGetEmptyPropertiesFromTimestampWhenNoTimestampPropertyInGroup.

@Test
public void shouldGetEmptyPropertiesFromTimestampWhenNoTimestampPropertyInGroup() throws AccumuloElementConversionException {
    // Given
    // add timestamp property name but don't add the property to the edge group
    final Schema schema = new Schema.Builder().json(StreamUtil.schemas(getClass())).build();
    converter = createConverter(new Schema.Builder(schema).timestampProperty(AccumuloPropertyNames.TIMESTAMP).build());
    final long timestamp = System.currentTimeMillis();
    final String group = TestGroups.EDGE;
    // When
    final Properties properties = converter.getPropertiesFromTimestamp(group, timestamp);
    // Then
    assertEquals(0, properties.size());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 4 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldGetEmptyPropertiesFromTimestampWhenNoTimestampProperty.

@Test
public void shouldGetEmptyPropertiesFromTimestampWhenNoTimestampProperty() throws AccumuloElementConversionException {
    // Given
    final long timestamp = System.currentTimeMillis();
    final String group = TestGroups.EDGE;
    // When
    final Properties properties = converter.getPropertiesFromTimestamp(group, timestamp);
    // Then
    assertEquals(0, properties.size());
}
Also used : Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 5 with Properties

use of uk.gov.gchq.gaffer.data.element.Properties in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldSerialiseAndDeSerialiseBetweenPropertyAndValueWithNullProperty.

@Test
public void shouldSerialiseAndDeSerialiseBetweenPropertyAndValueWithNullProperty() throws AccumuloElementConversionException {
    Properties properties = new Properties();
    properties.put(AccumuloPropertyNames.PROP_1, 5);
    properties.put(AccumuloPropertyNames.PROP_2, null);
    properties.put(AccumuloPropertyNames.PROP_3, 299);
    properties.put(AccumuloPropertyNames.PROP_4, 10);
    properties.put(AccumuloPropertyNames.COUNT, 8);
    final Value value = converter.getValueFromProperties(TestGroups.EDGE, properties);
    final Properties deSerialisedProperties = converter.getPropertiesFromValue(TestGroups.EDGE, value);
    assertEquals(5, deSerialisedProperties.get(AccumuloPropertyNames.PROP_1));
    assertNull(deSerialisedProperties.get(AccumuloPropertyNames.PROP_2));
    assertEquals(299, deSerialisedProperties.get(AccumuloPropertyNames.PROP_3));
    assertEquals(10, deSerialisedProperties.get(AccumuloPropertyNames.PROP_4));
    assertEquals(8, deSerialisedProperties.get(AccumuloPropertyNames.COUNT));
}
Also used : Value(org.apache.accumulo.core.data.Value) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Aggregations

Properties (uk.gov.gchq.gaffer.data.element.Properties)101 Test (org.junit.jupiter.api.Test)58 Value (org.apache.accumulo.core.data.Value)25 Schema (uk.gov.gchq.gaffer.store.schema.Schema)23 Key (org.apache.accumulo.core.data.Key)16 Test (org.junit.Test)16 Edge (uk.gov.gchq.gaffer.data.element.Edge)12 Entity (uk.gov.gchq.gaffer.data.element.Entity)8 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)8 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)8 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)8 AccumuloElementConverter (uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter)7 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)7 LazyProperties (uk.gov.gchq.gaffer.data.element.LazyProperties)7 ArrayList (java.util.ArrayList)5 Element (uk.gov.gchq.gaffer.data.element.Element)5 HashSet (java.util.HashSet)4 ByteSequence (org.apache.accumulo.core.data.ByteSequence)4 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)4