Search in sources :

Example 6 with GraphSerialisable

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

the class FederatedStoreTest method shouldAddMultipleGraphsToCache.

@Test
public void shouldAddMultipleGraphsToCache() throws Exception {
    federatedProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING);
    store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
    // Given
    List<GraphSerialisable> graphsToAdd = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        graphsToAdd.add(new GraphSerialisable.Builder().config(new GraphConfig(ACC_ID_1 + i)).properties(PROPERTIES_ALT).schema(StreamUtil.openStream(FederatedStoreTest.class, PATH_BASIC_EDGE_SCHEMA_JSON)).build());
    }
    // When
    store.addGraphs(null, TEST_USER_ID, false, graphsToAdd.toArray(new GraphSerialisable[graphsToAdd.size()]));
    // Then
    for (int i = 0; i < 10; i++) {
        assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_1 + i));
    }
    // When
    store = new FederatedStore();
    // Then
    for (int i = 0; i < 10; i++) {
        assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_1 + i));
    }
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) ArrayList(java.util.ArrayList) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 7 with GraphSerialisable

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

the class FederatedStoreTest method shouldAddGraphsToCache.

@Test
public void shouldAddGraphsToCache() throws Exception {
    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();
    // When
    store.addGraphs(null, TEST_USER_ID, true, graphToAdd);
    // Then
    assertEquals(1, store.getGraphs(blankUser, ACC_ID_1, ignore).size());
    // When
    Collection<Graph> storeGraphs = store.getGraphs(blankUser, null, ignore);
    // Then
    assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_1));
    assertThat(storeGraphs).contains(graphToAdd.getGraph());
    // When
    store = new FederatedStore();
    // Then
    assertTrue(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME).contains(ACC_ID_1));
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Graph(uk.gov.gchq.gaffer.graph.Graph) RemoveGraph(uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) 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 8 with GraphSerialisable

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

the class FederatedGraphStorageTraitsTest method shouldGetCurrentTraitsForAddingUserButSelectedGraphsOnly.

@Test
public void shouldGetCurrentTraitsForAddingUserButSelectedGraphsOnly() 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);
    // 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_CURRENT_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)

Example 9 with GraphSerialisable

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

the class FederatedGraphStorageTest method checkSchemaNotLeakedWhenAlreadyExistsUnderDifferentAccess.

@Test
public void checkSchemaNotLeakedWhenAlreadyExistsUnderDifferentAccess() throws Exception {
    // Given
    Schema schemaNotToBeExposed = new Schema.Builder().type(UNUSUAL_TYPE, String.class).type(DIRECTED_EITHER, Boolean.class).entity(GROUP_ENT, new SchemaEntityDefinition.Builder().vertex(UNUSUAL_TYPE).build()).edge(GROUP_EDGE, new SchemaEdgeDefinition.Builder().source(UNUSUAL_TYPE).destination(UNUSUAL_TYPE).directed(DIRECTED_EITHER).build()).build();
    final GraphSerialisable graph1 = new GraphSerialisable.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID_A).build()).properties(PROPERTIES).schema(schemaNotToBeExposed).build();
    graphStorage.put(graph1, access);
    // When / Then
    try {
        graphStorage.put(graph1, altAccess);
    } catch (StorageException e) {
        assertEquals("Error adding graph " + GRAPH_ID_A + " to storage due to: " + String.format(FederatedGraphStorage.USER_IS_ATTEMPTING_TO_OVERWRITE, GRAPH_ID_A), e.getMessage());
        testNotLeakingContents(e, UNUSUAL_TYPE, GROUP_EDGE, GROUP_ENT);
    }
}
Also used : GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) Test(org.junit.jupiter.api.Test)

Example 10 with GraphSerialisable

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

the class FederatedAdminIT method shouldRemoveGraphFromCache.

@Test
public void shouldRemoveGraphFromCache() throws Exception {
    // given
    FederatedStoreCache federatedStoreCache = new FederatedStoreCache();
    final String graphA = "graphA";
    graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).build(), user);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
    // when
    assertThat(federatedStoreCache.getGraphSerialisableFromCache(graphA)).isNotNull();
    final Boolean removed = graph.execute(new RemoveGraph.Builder().graphId(graphA).build(), user);
    // then
    assertThat(removed).isTrue();
    GraphSerialisable graphSerialisableFromCache = federatedStoreCache.getGraphSerialisableFromCache(graphA);
    assertThat(graphSerialisableFromCache).as(new String(JSONSerialiser.serialise(graphSerialisableFromCache, true))).isNull();
    assertThat(federatedStoreCache.getAllGraphIds()).isEmpty();
}
Also used : AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) FederatedStoreCache(uk.gov.gchq.gaffer.federatedstore.FederatedStoreCache) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) RemoveGraph(uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph) 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