Search in sources :

Example 11 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable 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 12 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable in project Gaffer by gchq.

the class FederatedStoreTest method populateGraphs.

private List<Collection<GraphSerialisable>> populateGraphs(final int... expectedIds) throws Exception {
    final Collection<GraphSerialisable> expectedGraphs = new ArrayList<>();
    final Collection<GraphSerialisable> unexpectedGraphs = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        GraphSerialisable tempGraph = new GraphSerialisable.Builder().config(new GraphConfig.Builder().graphId("mockGraphId" + i).build()).properties(PROPERTIES_ALT).schema(StreamUtil.openStream(FederatedStoreTest.class, PATH_BASIC_ENTITY_SCHEMA_JSON)).build();
        // Odd ids are disabled by default
        final boolean disabledByDefault = 1 == Math.floorMod(i, 2);
        store.addGraphs(Sets.newHashSet(ALL_USERS), null, true, disabledByDefault, tempGraph);
        for (final int j : expectedIds) {
            if (i == j) {
                expectedGraphs.add(tempGraph);
            }
        }
        if (!expectedGraphs.contains(tempGraph)) {
            unexpectedGraphs.add(tempGraph);
        }
    }
    final List<Collection<GraphSerialisable>> graphLists = new ArrayList<>();
    graphLists.add(expectedGraphs);
    graphLists.add(unexpectedGraphs);
    return graphLists;
}
Also used : GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 13 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable 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 14 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable 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 15 with GraphSerialisable

use of uk.gov.gchq.gaffer.graph.GraphSerialisable in project Gaffer by gchq.

the class FederatedGraphStorageTraitsTest method shouldGetNonCurrentTraitsForAddingUserButSelectedGraphsOnly.

@Test
public void shouldGetNonCurrentTraitsForAddingUserButSelectedGraphsOnly() throws Exception {
    // given
    final GraphSerialisable acc2 = new GraphSerialisable.Builder().graph(acc.getGraph()).config(new GraphConfig(GRAPH_ID_ACCUMULO + 2)).build();
    graphStorage.put(acc, ACCESS_UNUSED_AUTH_AND_USER);
    graphStorage.put(acc2, ACCESS_UNUSED_AUTH_WITH_TEST_USER);
    graphStorage.put(map, ACCESS_UNUSED_AUTH_WITH_TEST_USER);
    getTraits.addOption(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, GRAPH_ID_MAP);
    getTraits.setCurrentTraits(false);
    // when
    final Set<StoreTrait> traits = graphStorage.getTraits(getTraits, testUserContext);
    // then
    assertNotEquals(ACCUMULO_TRAITS, traits, "Returning AccumuloStore traits instead of MapStore");
    assertEquals(Collections.emptySet(), traits.stream().filter(ACCUMULO_TRAITS_EXCLUSIVE_OF_MAP::contains).collect(Collectors.toSet()), "Revealing some hidden traits from the AccumuloStore instead of only MapStore");
    assertEquals(MAP_TRAITS, traits);
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Test(org.junit.jupiter.api.Test)

Aggregations

GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)20 Test (org.junit.jupiter.api.Test)13 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)10 StorageException (uk.gov.gchq.gaffer.federatedstore.exception.StorageException)5 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)5 Builder (uk.gov.gchq.gaffer.store.schema.Schema.Builder)5 StoreTrait (uk.gov.gchq.gaffer.store.StoreTrait)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 Graph (uk.gov.gchq.gaffer.graph.Graph)3 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CacheOperationException (uk.gov.gchq.gaffer.cache.exception.CacheOperationException)2 AddGraph (uk.gov.gchq.gaffer.federatedstore.operation.AddGraph)2 RemoveGraph (uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1