From b9fb46ef1b78335e548777489d4307fd5bdcb528 Mon Sep 17 00:00:00 2001 From: GCHQDev404 <45399082+GCHQDev404@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:29:12 +0000 Subject: [PATCH] Gh 2890 cache service static instance bug (#2893) * gh-2890 cache service single static instance bug removal. * Revert "gh-2890 cache service single static instance bug removal." This reverts commit 59b23ab041fa62c5f0d6023dd85b1e4fad47399d. * gh-2890 cache service single static instance bug removal. K.I.S.S * gh-2890 cache service single static instance bug removal. K.I.S.S Tests * gh-2890 cache service. delete backwards compatibility 1.12 * gh-2890 cache service single static instance bug removal. K.I.S.S Tests * gh-2890 cache service single static instance bug removal. spotbugs * gh-2890 cache service static instance bug. proof test. * checkstyle * gh-2581 getTraits to use operation, tidy up. --------- Co-authored-by: GCHQDev404 --- .../java/uk/gov/gchq/gaffer/cache/Cache.java | 2 +- .../gchq/gaffer/cache/CacheServiceLoader.java | 6 ++ .../gaffer/cache/CacheServiceLoaderTest.java | 3 +- .../gchq/gaffer/store/StoreProperties.java | 4 ++ .../named/AddNamedViewHandlerTest.java | 6 +- .../named/DeleteNamedViewHandlerTest.java | 2 + .../GetAllNamedOperationsHandlerTest.java | 8 +-- ...erationCacheBackwardCompatibilityTest.java | 68 ------------------ ...medViewCacheBackwardCompatibilityTest.java | 65 ----------------- .../resources/gaffer-1.12.0-cache/cache.ccf | 26 ------- .../indexed-disk-cache/NamedOperation.data | Bin 3237 -> 0 bytes .../indexed-disk-cache/NamedOperation.key | Bin 894 -> 0 bytes .../indexed-disk-cache/NamedView.data | Bin 1224 -> 0 bytes .../indexed-disk-cache/NamedView.key | Bin 651 -> 0 bytes .../indexed-disk-cache/jobTrackerRegion.data | 0 .../indexed-disk-cache/jobTrackerRegion.key | 0 .../namedOperationsRegion.data | 0 .../namedOperationsRegion.key | 0 .../indexed-disk-cache/test.data | 0 .../indexed-disk-cache/test.key | 0 .../FederatedAddGraphHandlerParent.java | 19 ++++- .../FederatedStoreConfiguredGraphIdsTest.java | 15 +++- .../impl/FederatedAddGraphHandlerTest.java | 63 +++++++++++++++- 23 files changed, 115 insertions(+), 172 deletions(-) delete mode 100644 core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedOperationCacheBackwardCompatibilityTest.java delete mode 100644 core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedViewCacheBackwardCompatibilityTest.java delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/cache.ccf delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedOperation.data delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedOperation.key delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedView.data delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedView.key delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/jobTrackerRegion.data delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/jobTrackerRegion.key delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/namedOperationsRegion.data delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/namedOperationsRegion.key delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/test.data delete mode 100644 core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/test.key diff --git a/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/Cache.java b/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/Cache.java index baa095095fb..cfeb4635df4 100644 --- a/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/Cache.java +++ b/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/Cache.java @@ -64,7 +64,7 @@ public Set getAllKeys() { } else { throw new GafferRuntimeException("Cache is not enabled, check it was Initialised"); } - return (null == allKeysFromCache) ? null : Collections.unmodifiableSet(allKeysFromCache); + return (null == allKeysFromCache) ? Collections.emptySet() : Collections.unmodifiableSet(allKeysFromCache); } catch (final Exception e) { throw new GafferRuntimeException("Error getting all keys", e); } diff --git a/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/CacheServiceLoader.java b/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/CacheServiceLoader.java index 5a58b70804d..90a42ac5248 100644 --- a/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/CacheServiceLoader.java +++ b/core/cache/src/main/java/uk/gov/gchq/gaffer/cache/CacheServiceLoader.java @@ -56,6 +56,12 @@ public static void initialise(final Properties properties) { } return; } + + if (isEnabled()) { + LOGGER.debug("Will not initialise as Cache service was already enabled."); + return; + } + try { service = Class.forName(cacheClass).asSubclass(ICacheService.class).newInstance(); diff --git a/core/cache/src/test/java/uk/gov/gchq/gaffer/cache/CacheServiceLoaderTest.java b/core/cache/src/test/java/uk/gov/gchq/gaffer/cache/CacheServiceLoaderTest.java index 2761b8b36f6..ae7c0b6c104 100644 --- a/core/cache/src/test/java/uk/gov/gchq/gaffer/cache/CacheServiceLoaderTest.java +++ b/core/cache/src/test/java/uk/gov/gchq/gaffer/cache/CacheServiceLoaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ public class CacheServiceLoaderTest { @BeforeEach public void before() { serviceLoaderProperties.clear(); + CacheServiceLoader.shutdown(); } @DisplayName("Should not throw NullPointer when Loader is initialised with null properties") diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/StoreProperties.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/StoreProperties.java index bce77f85ee6..5b3f5234d12 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/StoreProperties.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/StoreProperties.java @@ -440,6 +440,10 @@ public void setCacheServiceClass(final String cacheServiceClassString) { set(CACHE_SERVICE_CLASS, cacheServiceClassString); } + public String getCacheServiceClass() { + return getCacheServiceClass(null); + } + public String getCacheServiceClass(final String defaultValue) { return get(CACHE_SERVICE_CLASS, defaultValue); } diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/AddNamedViewHandlerTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/AddNamedViewHandlerTest.java index f3c108fd3ce..9fd9fa03870 100644 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/AddNamedViewHandlerTest.java +++ b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/AddNamedViewHandlerTest.java @@ -16,7 +16,7 @@ package uk.gov.gchq.gaffer.store.operation.handler.named; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -92,8 +92,8 @@ public void before() { given(store.getProperties()).willReturn(new StoreProperties()); } - @AfterAll - public static void tearDown() { + @AfterEach + public void tearDown() { CacheServiceLoader.shutdown(); } diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/DeleteNamedViewHandlerTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/DeleteNamedViewHandlerTest.java index b109f1ab5ac..9ccf67c2401 100644 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/DeleteNamedViewHandlerTest.java +++ b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/DeleteNamedViewHandlerTest.java @@ -64,6 +64,8 @@ public class DeleteNamedViewHandlerTest { @BeforeEach public void before() throws OperationException { + CacheServiceLoader.shutdown(); + properties.set("gaffer.cache.service.class", "uk.gov.gchq.gaffer.cache.impl.HashMapCacheService"); CacheServiceLoader.initialise(properties.getProperties()); diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/GetAllNamedOperationsHandlerTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/GetAllNamedOperationsHandlerTest.java index 69caa200205..999b1b7e6c5 100644 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/GetAllNamedOperationsHandlerTest.java +++ b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/GetAllNamedOperationsHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package uk.gov.gchq.gaffer.store.operation.handler.named; -import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -68,8 +68,8 @@ public class GetAllNamedOperationsHandlerTest { @Mock private Store store; - @AfterAll - public static void tearDown() { + @AfterEach + public void tearDown() { CacheServiceLoader.shutdown(); } diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedOperationCacheBackwardCompatibilityTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedOperationCacheBackwardCompatibilityTest.java deleted file mode 100644 index 62a47cdb5a9..00000000000 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedOperationCacheBackwardCompatibilityTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020-2022 Crown Copyright - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.gchq.gaffer.store.operation.handler.named.cache; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import uk.gov.gchq.gaffer.cache.CacheServiceLoader; -import uk.gov.gchq.gaffer.cache.impl.JcsCacheService; -import uk.gov.gchq.gaffer.cache.util.CacheProperties; -import uk.gov.gchq.gaffer.named.operation.NamedOperationDetail; -import uk.gov.gchq.gaffer.operation.OperationChain; -import uk.gov.gchq.gaffer.operation.impl.add.AddElements; -import uk.gov.gchq.gaffer.user.User; - -import java.util.Properties; - -import static java.util.Arrays.asList; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class NamedOperationCacheBackwardCompatibilityTest { - - private static NamedOperationCache operationCache; - private static final User ADDING_USER = new User("user1"); - private static final String OPERATION_NAME = "TestOperation"; - - @BeforeAll - public static void setUp() { - final Properties properties = new Properties(); - properties.setProperty(CacheProperties.CACHE_SERVICE_CLASS, JcsCacheService.class.getName()); - // Note that this config causes a binary resource file containing data to be loaded into the cache - // This data includes ADDING_USER and OPERATION_NAME - properties.setProperty(CacheProperties.CACHE_CONFIG_FILE, "src/test/resources/gaffer-1.12.0-cache/cache.ccf"); - CacheServiceLoader.initialise(properties); - operationCache = new NamedOperationCache(); - } - - @Test - public void shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12() throws Exception { - final NamedOperationDetail namedOperationDetail = new NamedOperationDetail.Builder() - .operationName(OPERATION_NAME) - .description("standard operation") - .creatorId(ADDING_USER.getUserId()) - .readers(asList("readerAuth1", "readerAuth2")) - .writers(asList("writerAuth1", "writerAuth2")) - .operationChain(new OperationChain.Builder().first(new AddElements()).build()) - .build(); - - final NamedOperationDetail namedOperationDetailFromCacheVersion1_12 = operationCache.getNamedOperation(OPERATION_NAME, ADDING_USER); - - assertEquals(namedOperationDetail.getReadAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getReadAccessPredicate()); - assertEquals(namedOperationDetail.getWriteAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getWriteAccessPredicate()); - } -} diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedViewCacheBackwardCompatibilityTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedViewCacheBackwardCompatibilityTest.java deleted file mode 100644 index 4371ea3cf72..00000000000 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/operation/handler/named/cache/NamedViewCacheBackwardCompatibilityTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2020-2022 Crown Copyright - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.gchq.gaffer.store.operation.handler.named.cache; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import uk.gov.gchq.gaffer.cache.CacheServiceLoader; -import uk.gov.gchq.gaffer.cache.impl.JcsCacheService; -import uk.gov.gchq.gaffer.cache.util.CacheProperties; -import uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail; -import uk.gov.gchq.gaffer.data.elementdefinition.view.View; -import uk.gov.gchq.gaffer.user.User; - -import java.util.Properties; - -import static java.util.Arrays.asList; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class NamedViewCacheBackwardCompatibilityTest { - private static NamedViewCache viewCache; - private static final User ADDING_USER = new User("user1"); - private static final String VIEW_NAME = "TestView"; - - @BeforeAll - public static void setUp() { - final Properties properties = new Properties(); - properties.setProperty(CacheProperties.CACHE_SERVICE_CLASS, JcsCacheService.class.getName()); - // Note that this config causes a binary resource file containing data to be loaded into the cache - // This data includes ADDING_USER and VIEW_NAME - properties.setProperty(CacheProperties.CACHE_CONFIG_FILE, "src/test/resources/gaffer-1.12.0-cache/cache.ccf"); - CacheServiceLoader.initialise(properties); - viewCache = new NamedViewCache(); - } - - @Test - public void shouldReturnExpectedNamedViewDetailUsingCacheDataFromVersion1_12() throws Exception { - final NamedViewDetail namedViewDetail = new NamedViewDetail.Builder() - .name(VIEW_NAME) - .description("standard View") - .creatorId(ADDING_USER.getUserId()) - .writers(asList("writerAuth1", "writerAuth2")) - .view(new View.Builder().build()) - .build(); - - final NamedViewDetail namedViewDetailFromCacheVersion1_12 = viewCache.getNamedView(namedViewDetail.getName(), ADDING_USER); - - assertEquals(namedViewDetail.getOrDefaultReadAccessPredicate(), namedViewDetailFromCacheVersion1_12.getOrDefaultReadAccessPredicate()); - assertEquals(namedViewDetail.getOrDefaultWriteAccessPredicate(), namedViewDetailFromCacheVersion1_12.getOrDefaultWriteAccessPredicate()); - } -} diff --git a/core/store/src/test/resources/gaffer-1.12.0-cache/cache.ccf b/core/store/src/test/resources/gaffer-1.12.0-cache/cache.ccf deleted file mode 100644 index eda0ac1cc8f..00000000000 --- a/core/store/src/test/resources/gaffer-1.12.0-cache/cache.ccf +++ /dev/null @@ -1,26 +0,0 @@ -jcs.default=DC -jcs.default.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes -jcs.default.cacheattributes.MaxObjects=100 -jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache -jcs.default.cacheattributes.DiskUsagePatternName=UPDATE - -# Indexed Disk Cache -jcs.auxiliary.DC=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory -jcs.auxiliary.DC.attributes=org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes -jcs.auxiliary.DC.attributes.DiskPath=src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache -jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000 -jcs.auxiliary.DC.attributes.MaxKeySize=10000 -jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000 -jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true - -# Region for named operations -jcs.region.namedOperationsRegion=DC - -# Region for aging off after 1 week -jcs.region.jobTrackerRegion=DC -jcs.region.jobTrackerRegion.cacheattributes.UseMemoryShrinker=true -jcs.region.jobTrackerRegion.elementattributes.IsEternal=false -jcs.region.jobTrackerRegion.elementattributes.MaxLife=604800 - -# Region for testing the JCS cache service -jcs.region.test=DC diff --git a/core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedOperation.data b/core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedOperation.data deleted file mode 100644 index 3c0a466b86e4b3fc4cdc9a7ecc72174720d08d67..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3237 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 diff --git a/core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedView.key b/core/store/src/test/resources/gaffer-1.12.0-cache/indexed-disk-cache/NamedView.key deleted file mode 100644 index 80988f31f1a918e3f0e5dd9a2f213fd56813f81f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 651 zcmb7Cze@u#6nn)aHUNvfxVgNuKIxcCP+ zyNiOegNwL{qpP#Y^#?jA_=Y5W@8x~p_jmx##mxs~m4t~FKEkN0S%lWHYHr{-JN|Na zKehjq0jCCqNMKUKffmw(ylzUWnj#`eT&aSMk>i{>9s4rP7KIEEj&abWC=i{F;0m<@ zg(wdhw-DD-L@1P^8>2OQE^93txI?F$x5-MoH0D6YhaB#s8YX?K&y6q--OYm*4fK)^ z<7oqrXjt$KquXP2`;4w(bbE{jN*UesgPSsX#B|7Mv85&B;ZKGhwv@yga@$nt9Y&9h zt+{{O@_459~;+&qFwatPlBA&^KTxC@ru8@-|DX0t*#1Oz-w>mxr0z z;_$hrp}M=a+$a?XRezVy76(Hv51j59tMy;3;%>qshUEz&Otlf?geH_AuXnE)Y&D`C o%Jm9Wfn>4Sm*>yQl=QOhkDdGO supportedOperation : graph.getSupportedOperations()) { diff --git a/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/FederatedStoreConfiguredGraphIdsTest.java b/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/FederatedStoreConfiguredGraphIdsTest.java index 6c083985102..d092ef599a2 100644 --- a/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/FederatedStoreConfiguredGraphIdsTest.java +++ b/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/FederatedStoreConfiguredGraphIdsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Crown Copyright + * Copyright 2021-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ package uk.gov.gchq.gaffer.federatedstore; import com.google.common.collect.Lists; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.gov.gchq.gaffer.commonutil.JsonAssert; @@ -52,6 +54,7 @@ import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.contextTestUser; import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadFederatedStoreFrom; import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadStoreProperties; +import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.resetForFederatedTests; import static uk.gov.gchq.gaffer.store.TestTypes.DIRECTED_EITHER; import static uk.gov.gchq.gaffer.user.StoreUser.testUser; @@ -273,4 +276,14 @@ private static Schema getSchema(final String property) { .merge(STRING_SCHEMA) .build(); } + + @AfterAll + public static void after() { + resetForFederatedTests(); + } + + @BeforeEach + public void before() { + resetForFederatedTests(); + } } diff --git a/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/operation/handler/impl/FederatedAddGraphHandlerTest.java b/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/operation/handler/impl/FederatedAddGraphHandlerTest.java index 2e4488b66e3..a849f8a9ee2 100644 --- a/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/operation/handler/impl/FederatedAddGraphHandlerTest.java +++ b/store-implementation/federated-store/src/test/java/uk/gov/gchq/gaffer/federatedstore/operation/handler/impl/FederatedAddGraphHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties; import uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges; import uk.gov.gchq.gaffer.cache.CacheServiceLoader; +import uk.gov.gchq.gaffer.cache.impl.HashMapCacheService; import uk.gov.gchq.gaffer.commonutil.StreamUtil; import uk.gov.gchq.gaffer.commonutil.TestGroups; import uk.gov.gchq.gaffer.data.element.Element; @@ -32,8 +33,10 @@ import uk.gov.gchq.gaffer.federatedstore.operation.AddGraph; import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.hdfs.operation.AddElementsFromHdfs; +import uk.gov.gchq.gaffer.operation.OperationException; import uk.gov.gchq.gaffer.operation.impl.get.GetAllElements; import uk.gov.gchq.gaffer.store.Context; +import uk.gov.gchq.gaffer.store.StoreException; import uk.gov.gchq.gaffer.store.library.GraphLibrary; import uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary; import uk.gov.gchq.gaffer.store.schema.Schema; @@ -61,7 +64,7 @@ public class FederatedAddGraphHandlerTest { private static final String FEDERATEDSTORE_GRAPH_ID = "federatedStore"; private static final String EXPECTED_GRAPH_ID = "testGraphID"; private static final String EXPECTED_GRAPH_ID_2 = "testGraphID2"; - private static final String CACHE_SERVICE_CLASS_STRING = "uk.gov.gchq.gaffer.cache.impl.HashMapCacheService"; + private static final String CACHE_SERVICE_CLASS_STRING = HashMapCacheService.class.getCanonicalName(); private User testUser; private User authUser; private User blankUser; @@ -370,4 +373,60 @@ public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception { assertThat(store.getGraphs(blankUser, null, new AddGraph())).hasSize(1); assertThat(store.getGraphs(testUser, null, new AddGraph())).hasSize(1); } + + /** + * Adding a Graph with Cache previously would erase the static + * cache service used by FederatedStore in the same JVM. + * loosing all graphs and cached info. + * + * @throws StoreException Store.Initialise throws exception. + * @throws OperationException addGraph throws exception. + */ + @Test + public void shouldAddGraphWithACache() throws StoreException, OperationException { + store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties); + final Schema expectedSchema = new Schema.Builder().build(); + + assertThat(store.getGraphs(testUser, null, new AddGraph())).hasSize(0); + + final FederatedAddGraphHandler federatedAddGraphHandler = new FederatedAddGraphHandler(); + final AccumuloProperties properties = new AccumuloProperties(); + properties.setProperties(PROPERTIES.getProperties()); + properties.setCacheServiceClass(CACHE_SERVICE_CLASS_STRING); + + federatedAddGraphHandler.doOperation( + new AddGraph.Builder() + .graphId(EXPECTED_GRAPH_ID) + .schema(expectedSchema) + .storeProperties(properties) + .build(), + new Context(testUser), + store); + + Collection graphs = store.getGraphs(testUser, null, new AddGraph()); + + assertThat(graphs).hasSize(1); + final GraphSerialisable next = graphs.iterator().next(); + assertThat(next.getGraphId()).isEqualTo(EXPECTED_GRAPH_ID); + assertThat(next.getSchema()).isEqualTo(expectedSchema); + + federatedAddGraphHandler.doOperation( + new AddGraph.Builder() + .graphId(EXPECTED_GRAPH_ID_2) + .schema(expectedSchema) + .storeProperties(properties) + .build(), + new Context(testUser), + store); + + graphs = store.getGraphs(testUser, null, new AddGraph()); + + assertThat(graphs).hasSize(2); + final Iterator iterator = graphs.iterator(); + final HashSet set = new HashSet<>(); + while (iterator.hasNext()) { + set.add(iterator.next().getGraphId()); + } + assertThat(set).contains(EXPECTED_GRAPH_ID, EXPECTED_GRAPH_ID_2); + } }