Search in sources :

Example 6 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema 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 7 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema 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 8 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class AbstractAccumuloElementConverterTest method shouldGetPropertiesFromTimestamp.

@Test
public void shouldGetPropertiesFromTimestamp() 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 timestamp = System.currentTimeMillis();
    final String group = TestGroups.EDGE;
    // When
    final Properties properties = converter.getPropertiesFromTimestamp(group, timestamp);
    // Then
    assertEquals(1, properties.size());
    assertEquals(timestamp, properties.get(AccumuloPropertyNames.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 9 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class ExportToGafferResultCacheHandlerTest method shouldCreateCacheGraph.

@Test
public void shouldCreateCacheGraph() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final long timeToLive = 10000L;
    final ExportToGafferResultCacheHandler handler = new ExportToGafferResultCacheHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setTimeToLive(timeToLive);
    // When
    final Graph graph = handler.createGraph(store);
    // Then
    final Schema schema = graph.getSchema();
    JsonUtil.assertEquals(GafferResultCacheUtil.createSchema(timeToLive).toJson(false), schema.toJson(true));
    assertTrue(schema.validate());
    assertEquals(timeToLive, ((AgeOff) (schema.getType("timestamp").getValidator().getFunctions().get(0).getFunction())).getAgeOffTime());
    assertTrue(new ElementValidator(schema).validate(validEdge));
    assertFalse(new ElementValidator(schema).validate(oldEdge));
    assertTrue(schema.validate());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator) Test(org.junit.Test)

Example 10 with Schema

use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.

the class GetGafferResultCacheExportHandlerTest method shouldCreateCacheGraph.

@Test
public void shouldCreateCacheGraph() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final long timeToLive = 10000L;
    final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setTimeToLive(timeToLive);
    // When
    final Graph graph = handler.createGraph(store);
    // Then
    final Schema schema = graph.getSchema();
    JsonUtil.assertEquals(GafferResultCacheUtil.createSchema(timeToLive).toJson(false), schema.toJson(true));
    assertTrue(schema.validate());
    assertEquals(timeToLive, ((AgeOff) (schema.getType("timestamp").getValidator().getFunctions().get(0).getFunction())).getAgeOffTime());
    assertTrue(new ElementValidator(schema).validate(validEdge));
    assertFalse(new ElementValidator(schema).validate(oldEdge));
    assertTrue(schema.validate());
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) ElementValidator(uk.gov.gchq.gaffer.store.ElementValidator) Test(org.junit.Test)

Aggregations

Schema (uk.gov.gchq.gaffer.store.schema.Schema)86 Test (org.junit.Test)63 SQLContext (org.apache.spark.sql.SQLContext)14 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)13 User (uk.gov.gchq.gaffer.user.User)13 HashSet (java.util.HashSet)12 Filter (org.apache.spark.sql.sources.Filter)12 EqualTo (org.apache.spark.sql.sources.EqualTo)9 MockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore)9 SingleUseMockAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore)9 Element (uk.gov.gchq.gaffer.data.element.Element)9 Store (uk.gov.gchq.gaffer.store.Store)9 Before (org.junit.Before)8 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)8 Graph (uk.gov.gchq.gaffer.graph.Graph)8 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)7 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5