Skip to content

Commit

Permalink
gh-2887 Test fixed to user correct cache instance due to suffix/name …
Browse files Browse the repository at this point in the history
…change.
  • Loading branch information
GCHQDev404 committed Mar 3, 2023
1 parent 6637570 commit acced35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.graph.GraphSerialisable;

import java.util.Locale;
import java.util.Set;

import static java.util.Objects.isNull;
Expand All @@ -32,7 +33,7 @@
*/
public class FederatedStoreCacheTransient extends Cache<String, Pair<GraphSerialisable, byte[]>> {
public static final String ERROR_ADDING_GRAPH_TO_CACHE_GRAPH_ID_S = "Error adding graph to cache. graphId: %s";
private static final String CACHE_SERVICE_NAME_PREFIX = "federatedStoreGraphs";
public static final String CACHE_SERVICE_NAME_PREFIX = "federatedStoreGraphs";

public FederatedStoreCacheTransient(final String cacheNameSuffix) {
super(getCacheNameFrom(cacheNameSuffix));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,16 +949,16 @@ public void shouldReuseGraphsAlreadyInCache() throws Exception {

// check the store and the cache
assertThat(store.getAllGraphIds(blankUser)).hasSize(1);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME))
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME))
.contains(ACC_ID_2, ACC_ID_2);

// restart the store
store = new FederatedStore();
store.initialise(GRAPH_ID_TEST_FEDERATED_STORE, null, federatedProperties);

// check the graph is already in there from the cache
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME))
.withFailMessage(String.format("Keys: %s did not contain %s", CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME), ACC_ID_2)).contains(ACC_ID_2);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME))
.withFailMessage(String.format("Keys: %s did not contain %s", CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME), ACC_ID_2)).contains(ACC_ID_2);
assertThat(store.getAllGraphIds(blankUser)).hasSize(1);
}

Expand Down Expand Up @@ -1027,14 +1027,14 @@ public void shouldAddGraphsToCache() throws Exception {
final Collection<GraphSerialisable> storeGraphs = store.getGraphs(blankUser, null, new GetAllGraphIds());

// Then
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME)).contains(ACC_ID_1);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME)).contains(ACC_ID_1);
assertThat(storeGraphs).contains(graphToAdd);

// When
store = new FederatedStore();

// Then
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME)).contains(ACC_ID_1);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME)).contains(ACC_ID_1);
}

@Test
Expand All @@ -1057,15 +1057,15 @@ public void shouldAddMultipleGraphsToCache() throws Exception {

// Then
for (int i = 0; i < 10; i++) {
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME)).contains(ACC_ID_1 + i);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME)).contains(ACC_ID_1 + i);
}

// When
store = new FederatedStore();

// Then
for (int i = 0; i < 10; i++) {
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME)).contains(ACC_ID_1 + i);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME)).contains(ACC_ID_1 + i);
}
}

Expand Down Expand Up @@ -1108,7 +1108,7 @@ public void shouldNotAddGraphToLibraryWhenReinitialisingFederatedStoreWithGraphF
// check is in the store
assertThat(store.getAllGraphIds(blankUser)).hasSize(1);
// check is in the cache
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME)).contains(ACC_ID_1);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME)).contains(ACC_ID_1);
// check isn't in the LIBRARY
assertThat(store.getGraphLibrary().get(ACC_ID_1)).isNull();

Expand All @@ -1120,8 +1120,8 @@ public void shouldNotAddGraphToLibraryWhenReinitialisingFederatedStoreWithGraphF
store.setGraphLibrary(library);

// check is in the cache still
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME))
.withFailMessage(String.format("Keys: %s did not contain %s", CacheServiceLoader.getService().getAllKeysFromCache(CACHE_SERVICE_NAME), ACC_ID_1)).contains(ACC_ID_1);
assertThat(CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME))
.withFailMessage(String.format("Keys: %s did not contain %s", CacheServiceLoader.getService().getAllKeysFromCache(CACHE_NAME), ACC_ID_1)).contains(ACC_ID_1);
// check is in the store from the cache
assertThat(store.getAllGraphIds(blankUser)).hasSize(1);
// check the graph isn't in the GraphLibrary
Expand Down

0 comments on commit acced35

Please sign in to comment.