From e78e5369ed4c5c09f13d709d75f5ef79bc4028af Mon Sep 17 00:00:00 2001 From: ms9698 Date: Thu, 31 Oct 2024 11:20:44 +0000 Subject: [PATCH 01/14] first commit --- .../java/uk/gov/gchq/gaffer/store/Store.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java index d153548bacd..eb4b5576307 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java @@ -385,14 +385,24 @@ public O execute(final Output operation, final Context context) throws Op return execute(OperationChain.wrap(operation), context); } + private boolean isJobOperation(Class operationClass) { + return Job.class.isAssignableFrom(operationClass); + } + protected O execute(final OperationChain operation, final Context context) throws OperationException { try { - addOrUpdateJobDetail(operation, context, null, JobStatus.RUNNING); + if (isJobOperation(operation.getClass())) { + addOrUpdateJobDetail(operation, context, null, JobStatus.RUNNING); + } final O result = (O) handleOperation(operation, context); - addOrUpdateJobDetail(operation, context, null, JobStatus.FINISHED); + if (isJobOperation(operation.getClass())) { + addOrUpdateJobDetail(operation, context, null, JobStatus.FINISHED); + } return result; } catch (final Throwable t) { - addOrUpdateJobDetail(operation, context, t.getMessage(), JobStatus.FAILED); + if (isJobOperation(operation.getClass())) { + addOrUpdateJobDetail(operation, context, t.getMessage(), JobStatus.FAILED); + } throw t; } } @@ -978,21 +988,23 @@ public OperationHandler getOperationHandler(final Class operationChain, final Context context, - final String msg, final JobStatus jobStatus) { + private JobDetail addOrUpdateJobDetail(final OperationChain operationChain, final Context context, final String msg, final JobStatus jobStatus) { + if (!isJobOperation(operationChain.getClass())) { + return null; + } + final JobDetail newJobDetail = new JobDetail(context.getJobId(), context.getUser(), operationChain, jobStatus, msg); - if (nonNull(jobTracker)) { + if (null != jobTracker) { final JobDetail oldJobDetail = jobTracker.getJob(newJobDetail.getJobId(), context.getUser()); if (newJobDetail.getStatus().equals(JobStatus.SCHEDULED_PARENT)) { newJobDetail.setRepeat(null); newJobDetail.setSerialisedOperationChain(operationChain); } - - if (isNull(oldJobDetail)) { + + if (null == oldJobDetail) { jobTracker.addOrUpdateJob(newJobDetail, context.getUser()); } else { - jobTracker.addOrUpdateJob(new JobDetail(oldJobDetail, newJobDetail), context - .getUser()); + jobTracker.addOrUpdateJob(new JobDetail(oldJobDetail, newJobDetail), context.getUser()); } } return newJobDetail; From bfb9e3fb99a7a9253d025170289522ddd4174e45 Mon Sep 17 00:00:00 2001 From: ms9698 Date: Thu, 31 Oct 2024 13:42:48 +0000 Subject: [PATCH 02/14] resolved comments --- .../java/uk/gov/gchq/gaffer/store/Store.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java index eb4b5576307..a600c34b4cb 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java @@ -385,25 +385,12 @@ public O execute(final Output operation, final Context context) throws Op return execute(OperationChain.wrap(operation), context); } - private boolean isJobOperation(Class operationClass) { - return Job.class.isAssignableFrom(operationClass); - } protected O execute(final OperationChain operation, final Context context) throws OperationException { try { - if (isJobOperation(operation.getClass())) { - addOrUpdateJobDetail(operation, context, null, JobStatus.RUNNING); - } final O result = (O) handleOperation(operation, context); - if (isJobOperation(operation.getClass())) { - addOrUpdateJobDetail(operation, context, null, JobStatus.FINISHED); - } return result; - } catch (final Throwable t) { - if (isJobOperation(operation.getClass())) { - addOrUpdateJobDetail(operation, context, t.getMessage(), JobStatus.FAILED); - } - throw t; + } finally { } } @@ -989,10 +976,6 @@ public OperationHandler getOperationHandler(final Class operationChain, final Context context, final String msg, final JobStatus jobStatus) { - if (!isJobOperation(operationChain.getClass())) { - return null; - } - final JobDetail newJobDetail = new JobDetail(context.getJobId(), context.getUser(), operationChain, jobStatus, msg); if (null != jobTracker) { final JobDetail oldJobDetail = jobTracker.getJob(newJobDetail.getJobId(), context.getUser()); From ecf8e960321b3fb978b1dcfa2087db5d5a14d0ae Mon Sep 17 00:00:00 2001 From: ms9698 Date: Thu, 31 Oct 2024 14:03:15 +0000 Subject: [PATCH 03/14] removed clean up --- .../src/main/java/uk/gov/gchq/gaffer/store/Store.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java index a600c34b4cb..62f456e5c86 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java @@ -387,12 +387,10 @@ public O execute(final Output operation, final Context context) throws Op protected O execute(final OperationChain operation, final Context context) throws OperationException { - try { - final O result = (O) handleOperation(operation, context); - return result; - } finally { - } + final O result = (O) handleOperation(operation, context); + return result; } + /** * Executes a given operation job and returns the job detail. From c2fa4ca6c3da21f8cd137ecf7653dcf0481ddd9b Mon Sep 17 00:00:00 2001 From: ms9698 Date: Thu, 31 Oct 2024 14:45:59 +0000 Subject: [PATCH 04/14] removed unrequired test - operation & jobtracker are no longer related --- .../uk/gov/gchq/gaffer/store/StoreTest.java | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java index c01e7241d8c..4218022f122 100644 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java +++ b/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java @@ -256,32 +256,6 @@ public void after() { JSONSerialiser.update(); } - @Test - public void shouldExecuteOperationWhenJobTrackerCacheIsBroken(@Mock final StoreProperties storeProperties) throws Exception { - // Given - ICache mockICache = Mockito.mock(ICache.class); - doThrow(new CacheOperationException("Stubbed class")).when(mockICache).put(any(), any()); - ICacheService mockICacheService = Mockito.spy(ICacheService.class); - given(mockICacheService.getCache(any())).willReturn(mockICache); - - Field field = CacheServiceLoader.class.getDeclaredField("SERVICES"); - field.setAccessible(true); - java.util.Map mockCacheServices = (java.util.Map) field.get(new HashMap<>()); - mockCacheServices.put(JOB_TRACKER_CACHE_SERVICE_NAME, mockICacheService); - - final AddElements addElements = new AddElements(); - final StoreImpl3 store = new StoreImpl3(); - store.initialise("graphId", createSchemaMock(), storeProperties); - - // When - store.execute(addElements, context); - - // Then - verify(addElementsHandler).doOperation(addElements, context, store); - verify(mockICacheService, Mockito.atLeast(1)).getCache(any()); - verify(mockICache, Mockito.atLeast(1)).put(any(), any()); - } - @Test public void shouldCreateStoreWithSpecificCaches() throws SchemaException, StoreException { // Given From ff8b57acb81302bdaf7fb140daf7d77fdb1638ad Mon Sep 17 00:00:00 2001 From: ms9698 Date: Thu, 31 Oct 2024 15:10:28 +0000 Subject: [PATCH 05/14] linting --- .../src/main/java/uk/gov/gchq/gaffer/store/Store.java | 3 --- .../src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java | 7 ------- 2 files changed, 10 deletions(-) diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java index 62f456e5c86..d3af0c49a8d 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java @@ -384,13 +384,11 @@ public void execute(final Operation operation, final Context context) throws Ope public O execute(final Output operation, final Context context) throws OperationException { return execute(OperationChain.wrap(operation), context); } - protected O execute(final OperationChain operation, final Context context) throws OperationException { final O result = (O) handleOperation(operation, context); return result; } - /** * Executes a given operation job and returns the job detail. @@ -981,7 +979,6 @@ private JobDetail addOrUpdateJobDetail(final OperationChain operationChain, f newJobDetail.setRepeat(null); newJobDetail.setSerialisedOperationChain(operationChain); } - if (null == oldJobDetail) { jobTracker.addOrUpdateJob(newJobDetail, context.getUser()); } else { diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java index 4218022f122..7f04529337b 100644 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java +++ b/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java @@ -29,9 +29,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.gchq.gaffer.cache.CacheServiceLoader; -import uk.gov.gchq.gaffer.cache.ICache; -import uk.gov.gchq.gaffer.cache.ICacheService; -import uk.gov.gchq.gaffer.cache.exception.CacheOperationException; import uk.gov.gchq.gaffer.cache.impl.HashMapCacheService; import uk.gov.gchq.gaffer.commonutil.TestGroups; import uk.gov.gchq.gaffer.commonutil.TestPropertyNames; @@ -139,12 +136,10 @@ import uk.gov.gchq.koryphe.ValidationResult; import uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat; -import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -164,13 +159,11 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static uk.gov.gchq.gaffer.jobtracker.JobTracker.JOB_TRACKER_CACHE_SERVICE_NAME; import static uk.gov.gchq.gaffer.store.StoreTrait.INGEST_AGGREGATION; import static uk.gov.gchq.gaffer.store.StoreTrait.ORDERED; import static uk.gov.gchq.gaffer.store.StoreTrait.PRE_AGGREGATION_FILTERING; From 906e3fac9d6831ffcb99d0739035b21c2174f7c1 Mon Sep 17 00:00:00 2001 From: ms9698 Date: Thu, 31 Oct 2024 15:36:06 +0000 Subject: [PATCH 06/14] linting 2 --- core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java index d3af0c49a8d..81384a25a17 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java @@ -384,7 +384,6 @@ public void execute(final Operation operation, final Context context) throws Ope public O execute(final Output operation, final Context context) throws OperationException { return execute(OperationChain.wrap(operation), context); } - protected O execute(final OperationChain operation, final Context context) throws OperationException { final O result = (O) handleOperation(operation, context); return result; From f887d10bb8609cb712242a4004ce53a034856dac Mon Sep 17 00:00:00 2001 From: ms9698 Date: Wed, 13 Nov 2024 09:40:42 +0000 Subject: [PATCH 07/14] delete unrequired test --- .../rest/service/v2/OperationServiceV2IT.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java b/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java index ea5f944f055..1660bc5a9b6 100644 --- a/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java +++ b/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java @@ -105,25 +105,7 @@ public void shouldPropagateStatusInformationContainedInOperationExceptionsThrown // Then assertEquals(SERVICE_UNAVAILABLE.getStatusCode(), response.getStatus()); } - - @Test - public void shouldReturnSameJobIdInHeaderAsGetAllJobDetailsOperation() throws IOException { - // Given - final Graph graph = new Graph.Builder() - .config(StreamUtil.graphConfig(this.getClass())) - .storeProperties(StreamUtil.STORE_PROPERTIES) - .addSchema(new Schema()) - .build(); - - client.reinitialiseGraph(graph); - - // When - final Response response = client.executeOperation(new GetAllJobDetails()); - - // Then - assertTrue(response.readEntity(String.class).contains(response.getHeaderString("job-id"))); - } - + @Test public void shouldReturnAllOperationsAsOperationDetails() throws IOException, ClassNotFoundException { // Given From c46a3f675122c92147af82b62052df7dfbe39aba Mon Sep 17 00:00:00 2001 From: ms9698 Date: Wed, 13 Nov 2024 16:06:06 +0000 Subject: [PATCH 08/14] formatting --- .../gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java b/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java index 1660bc5a9b6..548a45b2969 100644 --- a/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java +++ b/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java @@ -105,7 +105,7 @@ public void shouldPropagateStatusInformationContainedInOperationExceptionsThrown // Then assertEquals(SERVICE_UNAVAILABLE.getStatusCode(), response.getStatus()); } - + @Test public void shouldReturnAllOperationsAsOperationDetails() throws IOException, ClassNotFoundException { // Given From bcc9d4171ad470b50575d0395d27e413e6fb68ce Mon Sep 17 00:00:00 2001 From: ms9698 Date: Wed, 13 Nov 2024 16:15:18 +0000 Subject: [PATCH 09/14] removed unnecessary test --- .../controller/OperationControllerIT.java | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java b/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java index dddbdb24357..cb612d4ada7 100644 --- a/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java +++ b/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java @@ -161,37 +161,6 @@ public void shouldPropagateStatusInformationContainedInOperationExceptionsThrown assertEquals(SERVICE_UNAVAILABLE.getStatusCode(), response.getStatusCode().value()); } - @Test - public void shouldReturnSameJobIdInHeaderAsGetAllJobDetailsOperation() throws IOException { - // Given - StoreProperties properties = new MapStoreProperties(); - properties.setJobTrackerEnabled(true); - properties.setDefaultCacheServiceClass(HashMapCacheService.class.getName()); - - Graph graph = new Graph.Builder() - .config(StreamUtil.graphConfig(this.getClass())) - .storeProperties(properties) - .addSchema(new Schema()) - .build(); - - when(getGraphFactory().getGraph()).thenReturn(graph); - - // When - final ResponseEntity response = post("/graph/operations/execute", - new GetAllJobDetails(), - Set.class); - - // Then - try { - assertTrue(response.getBody().toString().contains(response.getHeaders().get("job-id").get(0))); - } catch (final AssertionError e) { - System.out.println("Job ID was not found in the Header"); - System.out.println("Header was: " + response.getHeaders().get("job-id")); - System.out.println("Body was: " + response.getBody()); - throw e; - } - } - @Test public void shouldCorrectlyStreamExecuteChunked() throws Exception { // Given From a07ca7ece6a31f238e20ba83a0aecc968187d957 Mon Sep 17 00:00:00 2001 From: ms9698 Date: Wed, 13 Nov 2024 16:28:20 +0000 Subject: [PATCH 10/14] removed unused import --- .../rest/integration/controller/OperationControllerIT.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java b/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java index cb612d4ada7..80eb2b1d107 100644 --- a/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java +++ b/rest-api/spring-rest/src/test/java/uk/gov/gchq/gaffer/rest/integration/controller/OperationControllerIT.java @@ -23,7 +23,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; -import uk.gov.gchq.gaffer.cache.impl.HashMapCacheService; import uk.gov.gchq.gaffer.commonutil.StreamUtil; import uk.gov.gchq.gaffer.core.exception.Error; import uk.gov.gchq.gaffer.data.element.Entity; From 0dbba6fe5bbe01dc94d179cc11969a11ae2ad4af Mon Sep 17 00:00:00 2001 From: ms9698 Date: Wed, 13 Nov 2024 16:38:20 +0000 Subject: [PATCH 11/14] updated year --- .../gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java b/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java index 548a45b2969..9ff2dc43137 100644 --- a/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java +++ b/rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/OperationServiceV2IT.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2021 Crown Copyright + * Copyright 2015-2024 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From d7ebdd98a86c417fcd7f537320d0da66fda87d1e Mon Sep 17 00:00:00 2001 From: ms9698 Date: Mon, 18 Nov 2024 15:23:43 +0000 Subject: [PATCH 12/14] formatting for codecov --- core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java index 81384a25a17..31a368c5d00 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java @@ -981,7 +981,8 @@ private JobDetail addOrUpdateJobDetail(final OperationChain operationChain, f if (null == oldJobDetail) { jobTracker.addOrUpdateJob(newJobDetail, context.getUser()); } else { - jobTracker.addOrUpdateJob(new JobDetail(oldJobDetail, newJobDetail), context.getUser()); + jobTracker.addOrUpdateJob(new JobDetail(oldJobDetail, newJobDetail), context + .getUser()); } } return newJobDetail; From f85d4831ee5f87c212193fb3200bf2fd4433350f Mon Sep 17 00:00:00 2001 From: ms9698 Date: Tue, 19 Nov 2024 11:18:42 +0000 Subject: [PATCH 13/14] resolve comments --- core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java index 31a368c5d00..d31fd14e8aa 100644 --- a/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java +++ b/core/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java @@ -972,7 +972,7 @@ public OperationHandler getOperationHandler(final Class operationChain, final Context context, final String msg, final JobStatus jobStatus) { final JobDetail newJobDetail = new JobDetail(context.getJobId(), context.getUser(), operationChain, jobStatus, msg); - if (null != jobTracker) { + if (nonNull(jobTracker)) { final JobDetail oldJobDetail = jobTracker.getJob(newJobDetail.getJobId(), context.getUser()); if (newJobDetail.getStatus().equals(JobStatus.SCHEDULED_PARENT)) { newJobDetail.setRepeat(null); From 1a3c8b010fddd9ab1bbef36a586c7b3a7fc699a8 Mon Sep 17 00:00:00 2001 From: ms9698 Date: Tue, 19 Nov 2024 11:40:34 +0000 Subject: [PATCH 14/14] resolving comments 2 --- .../uk/gov/gchq/gaffer/store/StoreTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java b/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java index 7f04529337b..93b691cd740 100644 --- a/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java +++ b/core/store/src/test/java/uk/gov/gchq/gaffer/store/StoreTest.java @@ -29,6 +29,9 @@ import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.gchq.gaffer.cache.CacheServiceLoader; +import uk.gov.gchq.gaffer.cache.ICache; +import uk.gov.gchq.gaffer.cache.ICacheService; +import uk.gov.gchq.gaffer.cache.exception.CacheOperationException; import uk.gov.gchq.gaffer.cache.impl.HashMapCacheService; import uk.gov.gchq.gaffer.commonutil.TestGroups; import uk.gov.gchq.gaffer.commonutil.TestPropertyNames; @@ -136,10 +139,12 @@ import uk.gov.gchq.koryphe.ValidationResult; import uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat; +import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -159,11 +164,13 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static uk.gov.gchq.gaffer.jobtracker.JobTracker.JOB_TRACKER_CACHE_SERVICE_NAME; import static uk.gov.gchq.gaffer.store.StoreTrait.INGEST_AGGREGATION; import static uk.gov.gchq.gaffer.store.StoreTrait.ORDERED; import static uk.gov.gchq.gaffer.store.StoreTrait.PRE_AGGREGATION_FILTERING; @@ -249,6 +256,32 @@ public void after() { JSONSerialiser.update(); } + @Test + public void shouldExecuteOperationWhenJobTrackerCacheIsBroken(@Mock final StoreProperties storeProperties) throws Exception { + // Given + ICache mockICache = Mockito.mock(ICache.class); + doThrow(new CacheOperationException("Stubbed class")).when(mockICache).put(any(), any()); + ICacheService mockICacheService = Mockito.spy(ICacheService.class); + given(mockICacheService.getCache(any())).willReturn(mockICache); + + Field field = CacheServiceLoader.class.getDeclaredField("SERVICES"); + field.setAccessible(true); + java.util.Map mockCacheServices = (java.util.Map) field.get(new HashMap<>()); + mockCacheServices.put(JOB_TRACKER_CACHE_SERVICE_NAME, mockICacheService); + + final AddElements addElements = new AddElements(); + final StoreImpl3 store = new StoreImpl3(); + store.initialise("graphId", createSchemaMock(), storeProperties); + + // When + store.executeJob(addElements, context); + + // Then + verify(addElementsHandler).doOperation(addElements, context, store); + verify(mockICacheService, Mockito.atLeast(1)).getCache(any()); + verify(mockICache, Mockito.atLeast(1)).put(any(), any()); + }; + @Test public void shouldCreateStoreWithSpecificCaches() throws SchemaException, StoreException { // Given