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));
}
}
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));
}
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);
}
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);
}
}
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();
}
Aggregations