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