GafferResultCacheUtil { public static Graph createGraph(final String graphId, final String cacheStorePropertiesPath, final Long timeToLive) { if (null == cacheStorePropertiesPath) { throw new IllegalArgumentException("Gaffer result cache Store properties are required"); } final Graph.Builder graphBuilder = new Graph.Builder() .config(new GraphConfig.Builder() .graphId(graphId) .build()) .storeProperties(cacheStorePropertiesPath) .addSchema(createSchema(timeToLive)); final Graph graph = graphBuilder.build(); if (!graph.hasTrait(StoreTrait.STORE_VALIDATION)) { LOGGER.warn("Gaffer JSON export graph does not have {} trait so results may not be aged off.", StoreTrait.STORE_VALIDATION.name()); } return graph; } private  GafferResultCacheUtil(); static Graph createGraph(final String graphId, final String cacheStorePropertiesPath, final Long timeToLive); static Schema createSchema(final Long timeToLive); static final long ONE_DAY_IN_MILLISECONDS; static final long DEFAULT_TIME_TO_LIVE; }
@Test public void shouldThrowExceptionIfStorePropertiesAreNull() { try { GafferResultCacheUtil.createGraph("graphId", null, GafferResultCacheUtil.DEFAULT_TIME_TO_LIVE); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertNotNull(e.getMessage()); } }
@Test public void shouldCreateGraphWithValidSchema() { final Graph graph = GafferResultCacheUtil.createGraph("graphId", StreamUtil.STORE_PROPERTIES, GafferResultCacheUtil.DEFAULT_TIME_TO_LIVE); final Schema schema = graph.getSchema(); final boolean isValid = schema.validate().isValid(); assertTrue(isValid); assertEquals(GafferResultCacheUtil.DEFAULT_TIME_TO_LIVE, ((AgeOff) schema.getType("timestamp").getValidateFunctions().get(0)).getAgeOffTime()); assertTrue(new ElementValidator(schema).validate(validEdge)); assertFalse(new ElementValidator(schema).validate(oldEdge)); }
@Test public void shouldCreateGraphWithValidSchemaWithoutAgeOff() { final Graph graph = GafferResultCacheUtil.createGraph("graphId", StreamUtil.STORE_PROPERTIES, null); final Schema schema = graph.getSchema(); final boolean isValid = schema.validate().isValid(); assertTrue(isValid); assertNull(schema.getType("timestamp").getValidateFunctions()); assertTrue(new ElementValidator(schema).validate(validEdge)); assertTrue(new ElementValidator(schema).validate(oldEdge)); }