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);
}
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());
}
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));
}
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());
}
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());
}
Aggregations