Search in sources :

Example 21 with GraphConfig

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));
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 22 with GraphConfig

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");
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 23 with GraphConfig

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());
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 24 with GraphConfig

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);
    }
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 25 with GraphConfig

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;
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Graph(uk.gov.gchq.gaffer.graph.Graph) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) ProxyProperties(uk.gov.gchq.gaffer.proxystore.ProxyProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema)

Aggregations

GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)37 Graph (uk.gov.gchq.gaffer.graph.Graph)19 Schema (uk.gov.gchq.gaffer.store.schema.Schema)19 GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)18 Test (org.junit.jupiter.api.Test)15 Context (uk.gov.gchq.gaffer.store.Context)8 MapStoreProperties (uk.gov.gchq.gaffer.mapstore.MapStoreProperties)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 StoreTrait (uk.gov.gchq.gaffer.store.StoreTrait)6 Test (org.junit.Test)5 AddGraph (uk.gov.gchq.gaffer.federatedstore.operation.AddGraph)5 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)5 NoAccessPredicate (uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate)4 FederatedStore (uk.gov.gchq.gaffer.federatedstore.FederatedStore)4 FederatedStoreProperties (uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties)4 RemoveGraph (uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph)4 ProxyProperties (uk.gov.gchq.gaffer.proxystore.ProxyProperties)4 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)4 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)4 ArrayList (java.util.ArrayList)3