use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class FederatedStoreTest method shouldNotAddGraphToLibraryWhenReinitialisingFederatedStoreWithGraphFromCache.
@Test
public void shouldNotAddGraphToLibraryWhenReinitialisingFederatedStoreWithGraphFromCache() throws Exception {
// Check cache is empty
federatedProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING);
assertNull(CacheServiceLoader.getService());
// initialise FedStore
store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
// add something so it will be in the cache
GraphSerialisable graphToAdd = new GraphSerialisable.Builder().config(new GraphConfig(ACC_ID_1)).properties(PROPERTIES_1).schema(StreamUtil.openStream(FederatedStoreTest.class, PATH_BASIC_EDGE_SCHEMA_JSON)).build();
store.addGraphs(null, TEST_USER_ID, true, graphToAdd);
// check is in the store
assertEquals(1, store.getAllGraphIds(blankUser).size());
// check is in the cache
assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_1));
// check isn't in the LIBRARY
assertNull(store.getGraphLibrary().get(ACC_ID_1));
// restart the store
store = new FederatedStore();
// clear and set the GraphLibrary again
store.setGraphLibrary(library);
// initialise the FedStore
store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
// check is in the cache still
assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_1), "Keys: " + CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME) + " did not contain " + ACC_ID_1);
// check is in the store from the cache
assertEquals(1, store.getAllGraphIds(blankUser).size());
// check the graph isn't in the GraphLibrary
assertNull(store.getGraphLibrary().get(ACC_ID_1));
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class FederatedStoreTest method shouldThrowExceptionWithoutInitialisation.
@Test
public void shouldThrowExceptionWithoutInitialisation() throws StoreException {
federatedProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING);
store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
// Given
GraphSerialisable graphToAdd = new GraphSerialisable.Builder().config(new GraphConfig(ACC_ID_1)).properties(PROPERTIES_ALT).schema(StreamUtil.openStream(FederatedStoreTest.class, PATH_BASIC_EDGE_SCHEMA_JSON)).build();
clearCache();
// When / Then
assertThatExceptionOfType(Exception.class).isThrownBy(() -> store.addGraphs(null, TEST_USER_ID, false, graphToAdd)).withMessageContaining("No cache has been set");
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class FederatedStoreTest method shouldReuseGraphsAlreadyInCache.
@Test
public void shouldReuseGraphsAlreadyInCache() throws Exception {
// Check cache is empty
federatedProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING);
assertNull(CacheServiceLoader.getService());
// initialise FedStore
store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
// add something so it will be in the cache
GraphSerialisable graphToAdd = new GraphSerialisable.Builder().config(new GraphConfig(ACC_ID_2)).properties(PROPERTIES_ALT).schema(StreamUtil.openStream(FederatedStoreTest.class, PATH_BASIC_EDGE_SCHEMA_JSON)).build();
store.addGraphs(null, TEST_USER_ID, true, graphToAdd);
// check the store and the cache
assertEquals(1, store.getAllGraphIds(blankUser).size());
assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_2));
assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_2));
// restart the store
store = new FederatedStore();
store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
// check the graph is already in there from the cache
assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_2), "Keys: " + CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME) + " did not contain " + ACC_ID_2);
assertEquals(1, store.getAllGraphIds(blankUser).size());
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class PublicAccessPredefinedFederatedStore method initialise.
@Override
public void initialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException {
HashMapGraphLibrary.clear();
CacheServiceLoader.shutdown();
ExecutorService.shutdown();
super.initialise(graphId, schema, properties);
try {
// Accumulo store just contains edges
addGraphs(null, User.UNKNOWN_USER_ID, true, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_EDGES)).schema(new Schema.Builder().merge(schema.clone()).entities(Collections.emptyMap()).build()).properties(PROPERTIES).build());
// Accumulo store just contains entities
addGraphs(null, User.UNKNOWN_USER_ID, true, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_ENTITIES)).schema(new Schema.Builder().merge(schema.clone()).edges(Collections.emptyMap()).build()).properties(PROPERTIES).build());
} catch (final StorageException e) {
throw new StoreException(e.getMessage(), e);
}
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class FederatedStoreRecursionIT method createProxyToRestServiceFederatedGraph.
protected void createProxyToRestServiceFederatedGraph() {
final Graph proxyToRestServiceFederatedGraph;
ProxyProperties singleUseFedProperties = new ProxyProperties();
singleUseFedProperties.setStoreClass(SingleUseFederatedStore.class);
singleUseFedProperties.setReadTimeout(120000);
singleUseFedProperties.setConnectTimeout(120000);
proxyToRestServiceFederatedGraph = new Graph.Builder().storeProperties(singleUseFedProperties).addSchema(new Schema()).config(new GraphConfig(PROXY_TO_REST_SERVICE_FEDERATED_GRAPH)).build();
this.proxyToRestServiceFederatedGraph = proxyToRestServiceFederatedGraph;
}
Aggregations