From 77f90327c6467dd0446b738f7d5c63f0d013d6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 8 Jan 2025 10:06:57 +0100 Subject: [PATCH 1/2] chore: bump spotless 2.44.1 and format code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- operator-framework-bom/pom.xml | 2 +- .../operator/api/config/Utils.java | 15 +------ .../workflow/BaseWorkflowResult.java | 34 ++++++++------- .../event/source/informer/Mappers.java | 11 +---- .../CRDPresentActivationConditionTest.java | 26 ++++++------ .../processing/event/EventProcessorTest.java | 10 ++--- .../PerResourcePollingEventSourceTest.java | 42 +++++++++---------- pom.xml | 2 +- 8 files changed, 65 insertions(+), 77 deletions(-) diff --git a/operator-framework-bom/pom.xml b/operator-framework-bom/pom.xml index dc28ac8bf2..4a159a69f7 100644 --- a/operator-framework-bom/pom.xml +++ b/operator-framework-bom/pom.xml @@ -45,7 +45,7 @@ 3.2.7 3.3.1 3.11.2 - 2.43.0 + 2.44.1 diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java index ea776f3a6c..5166153a38 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java @@ -97,19 +97,8 @@ public static boolean debugThreadPool() { return getBooleanFromSystemPropsOrDefault(DEBUG_THREAD_POOL_ENV_KEY, false); } - static boolean getBooleanFromSystemPropsOrDefault(String propertyName, boolean defaultValue) { - var property = System.getProperty(propertyName); - if (property == null) { - return defaultValue; - } else { - property = property.trim().toLowerCase(); - return switch (property) { - case "true" -> true; - case "false" -> false; - default -> defaultValue; - }; - } - } + static boolean getBooleanFromSystemPropsOrDefault(String propertyName, + boolean defaultValue) {var property=System.getProperty(propertyName);if(property==null){return defaultValue;}else{property=property.trim().toLowerCase();return switch(property){case"true"->true;case"false"->false;default->defaultValue;};}} public static Class getFirstTypeArgumentFromExtendedClass(Class clazz) { return getTypeArgumentFromExtendedClassByIndex(clazz, 0); diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/BaseWorkflowResult.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/BaseWorkflowResult.java index cf759022dc..ec68b6369d 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/BaseWorkflowResult.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/BaseWorkflowResult.java @@ -168,19 +168,26 @@ DetailBuilder markForDelete() { } - record Detail(Exception error, ReconcileResult reconcileResult, - DetailedCondition.Result activationConditionResult, - DetailedCondition.Result deletePostconditionResult, - DetailedCondition.Result readyPostconditionResult, - DetailedCondition.Result reconcilePostconditionResult, - boolean deleted, boolean visited, boolean markedForDelete) { - - boolean isConditionWithTypeMet(Condition.Type conditionType) { - return getResultForConditionWithType(conditionType).map(DetailedCondition.Result::isSuccess) - .orElse(true); - } + record Detail( + Exception error, ReconcileResultreconcileResult, + DetailedCondition.Result activationConditionResult, + DetailedCondition. + Result deletePostconditionResult, + DetailedCondition. + Result readyPostconditionResult, + DetailedCondition. + Result reconcilePostconditionResult, + boolean deleted, + boolean visited, + boolean markedForDelete) + { + + boolean isConditionWithTypeMet(Condition.Type conditionType) { + return getResultForConditionWithType(conditionType).map(DetailedCondition.Result::isSuccess) + .orElse(true); + } - Optional> getResultForConditionWithType( + Optional> getResultForConditionWithType( Condition.Type conditionType) { return switch (conditionType) { case ACTIVATION -> Optional.ofNullable(activationConditionResult); @@ -189,5 +196,4 @@ Optional> getResultForConditionWithType( case RECONCILE -> Optional.ofNullable(reconcilePostconditionResult); }; } - } -} +}} diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java index db3877376c..3c7ff5bbad 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/Mappers.java @@ -119,16 +119,9 @@ private static SecondaryToPrimaryMapper fromMetadata( } public static ResourceID fromString(String cacheKey) { - if (cacheKey == null) { - return null; - } + if(cacheKey==null){return null;} - final String[] split = cacheKey.split("/"); - return switch (split.length) { - case 1 -> new ResourceID(split[0]); - case 2 -> new ResourceID(split[1], split[0]); - default -> throw new IllegalArgumentException("Cannot extract a ResourceID from " + cacheKey); - }; + final String[]split=cacheKey.split("/");return switch(split.length){case 1->new ResourceID(split[0]);case 2->new ResourceID(split[1],split[0]);default->throw new IllegalArgumentException("Cannot extract a ResourceID from "+cacheKey);}; } /** diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java index 58990214a3..dc5b5f894a 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/CRDPresentActivationConditionTest.java @@ -37,12 +37,12 @@ void setup() { @Test - void checkCRDIfNotCheckedBefore() { - when(checkerMock.checkIfCRDPresent(any(),any())).thenReturn(true); + void checkCRDIfNotCheckedBefore() { + when(checkerMock.checkIfCRDPresent(any(), any())).thenReturn(true); - assertThat(condition.isMet(dr,null,context)).isTrue(); - verify(checkerMock, times(1)).checkIfCRDPresent(any(),any()); - } + assertThat(condition.isMet(dr, null, context)).isTrue(); + verify(checkerMock, times(1)).checkIfCRDPresent(any(), any()); + } @Test void instantMetCallSkipsApiCall() { @@ -65,17 +65,17 @@ void intervalExpiredAPICheckedAgain() throws InterruptedException { } @Test - void crdIsNotCheckedAnymoreIfIfOnceFound() throws InterruptedException { - when(checkerMock.checkIfCRDPresent(any(),any())).thenReturn(true); + void crdIsNotCheckedAnymoreIfIfOnceFound() throws InterruptedException { + when(checkerMock.checkIfCRDPresent(any(), any())).thenReturn(true); - condition.isMet(dr,null,context); - verify(checkerMock, times(1)).checkIfCRDPresent(any(),any()); + condition.isMet(dr, null, context); + verify(checkerMock, times(1)).checkIfCRDPresent(any(), any()); - Thread.sleep(TEST_CHECK_INTERVAL_WITH_SLACK); + Thread.sleep(TEST_CHECK_INTERVAL_WITH_SLACK); - condition.isMet(dr,null,context); - verify(checkerMock, times(1)).checkIfCRDPresent(any(),any()); - } + condition.isMet(dr, null, context); + verify(checkerMock, times(1)).checkIfCRDPresent(any(), any()); + } @Test void crdNotCheckedAnymoreIfCountExpires() throws InterruptedException { diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java index 9f7e390c0a..41c359ae63 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java @@ -421,13 +421,13 @@ void executionOfReconciliationShouldNotStartIfProcessorStopped() throws Interrup o.withConcurrentReconciliationThreads(1); }); eventProcessor = - spy(new EventProcessor(controllerConfiguration(null, rateLimiterMock, configurationService), - reconciliationDispatcherMock, - eventSourceManagerMock, null)); + spy(new EventProcessor(controllerConfiguration(null, rateLimiterMock, configurationService), + reconciliationDispatcherMock, + eventSourceManagerMock, null)); eventProcessor.start(); - eventProcessor.handleEvent(prepareCREvent(new ResourceID("test1","default"))); - eventProcessor.handleEvent(prepareCREvent(new ResourceID("test1","default"))); + eventProcessor.handleEvent(prepareCREvent(new ResourceID("test1", "default"))); + eventProcessor.handleEvent(prepareCREvent(new ResourceID("test1", "default"))); eventProcessor.stop(); // wait until both event should be handled diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java index fd5b85aa16..eb4f7f4c3d 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java @@ -44,9 +44,9 @@ public void setup() { when(context.getPrimaryCache()).thenReturn(resourceCache); setUpSource(new PerResourcePollingEventSource<>(SampleExternalResource.class, context, - new PerResourcePollingConfigurationBuilder<>(supplier, Duration.ofMillis(PERIOD)) - .withCacheKeyMapper(r -> r.getName() + "#" + r.getValue()) - .build())); + new PerResourcePollingConfigurationBuilder<>(supplier, Duration.ofMillis(PERIOD)) + .withCacheKeyMapper(r -> r.getName() + "#" + r.getValue()) + .build())); } @Test @@ -147,44 +147,44 @@ void getsValueFromCacheOrSupplier() { @Test void supportsDynamicPollingDelay() { when(supplier.fetchResources(any())) - .thenReturn(Set.of(SampleExternalResource.testResource1())); - when(supplier.fetchDelay(any(),any())) - .thenReturn(Optional.of(Duration.ofMillis(PERIOD))) - .thenReturn(Optional.of(Duration.ofMillis(PERIOD*2))); + .thenReturn(Set.of(SampleExternalResource.testResource1())); + when(supplier.fetchDelay(any(), any())) + .thenReturn(Optional.of(Duration.ofMillis(PERIOD))) + .thenReturn(Optional.of(Duration.ofMillis(PERIOD * 2))); source.onResourceCreated(testCustomResource); await().pollDelay(Duration.ofMillis(PERIOD)).atMost(Duration.ofMillis((long) (1.5 * PERIOD))) - .pollInterval(Duration.ofMillis(20)) - .untilAsserted(() -> verify(supplier,times(1)).fetchResources(any())); + .pollInterval(Duration.ofMillis(20)) + .untilAsserted(() -> verify(supplier, times(1)).fetchResources(any())); // verifying that it is not called as with normal interval - await().pollDelay(Duration.ofMillis(PERIOD)).atMost(Duration.ofMillis((long) (1.5*PERIOD))) - .pollInterval(Duration.ofMillis(20)) - .untilAsserted(() -> verify(supplier,times(1)).fetchResources(any())); + await().pollDelay(Duration.ofMillis(PERIOD)).atMost(Duration.ofMillis((long) (1.5 * PERIOD))) + .pollInterval(Duration.ofMillis(20)) + .untilAsserted(() -> verify(supplier, times(1)).fetchResources(any())); await().pollDelay(Duration.ofMillis(PERIOD)).atMost(Duration.ofMillis(2 * PERIOD)) - .pollInterval(Duration.ofMillis(20)) - .untilAsserted(() -> verify(supplier,times(2)).fetchResources(any())); + .pollInterval(Duration.ofMillis(20)) + .untilAsserted(() -> verify(supplier, times(2)).fetchResources(any())); } @Test void deleteEventCancelsTheScheduling() { when(supplier.fetchResources(any())) - .thenReturn(Set.of(SampleExternalResource.testResource1())); + .thenReturn(Set.of(SampleExternalResource.testResource1())); source.onResourceCreated(testCustomResource); await().pollDelay(Duration.ofMillis(PERIOD)) - .atMost(Duration.ofMillis((2* PERIOD))) - .pollInterval(Duration.ofMillis(20)) - .untilAsserted(() -> verify(supplier,times(1)).fetchResources(any())); + .atMost(Duration.ofMillis((2 * PERIOD))) + .pollInterval(Duration.ofMillis(20)) + .untilAsserted(() -> verify(supplier, times(1)).fetchResources(any())); when(resourceCache.get(any())).thenReturn(Optional.empty()); source.onResourceDeleted(testCustomResource); // check if not called again - await().pollDelay(Duration.ofMillis(2*PERIOD)) - .atMost(Duration.ofMillis((4* PERIOD))) - .untilAsserted(() -> verify(supplier,times(1)).fetchResources(any())); + await().pollDelay(Duration.ofMillis(2 * PERIOD)) + .atMost(Duration.ofMillis((4 * PERIOD))) + .untilAsserted(() -> verify(supplier, times(1)).fetchResources(any())); } } diff --git a/pom.xml b/pom.xml index dc9cd2ed9f..32a450a5b5 100644 --- a/pom.xml +++ b/pom.xml @@ -91,7 +91,7 @@ 3.1.3 9.0.1 3.4.4 - 2.43.0 + 2.44.1 From e9c52fbf50c984530c15db10a7f1acbda6aeb0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 15 Jan 2025 14:19:42 +0100 Subject: [PATCH 2/2] format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Attila Mészáros --- operator-framework-bom/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/operator-framework-bom/pom.xml b/operator-framework-bom/pom.xml index 4a159a69f7..2a699a5feb 100644 --- a/operator-framework-bom/pom.xml +++ b/operator-framework-bom/pom.xml @@ -45,7 +45,7 @@ 3.2.7 3.3.1 3.11.2 - 2.44.1 + 2.44.2 diff --git a/pom.xml b/pom.xml index 32a450a5b5..ba219d43a2 100644 --- a/pom.xml +++ b/pom.xml @@ -91,7 +91,7 @@ 3.1.3 9.0.1 3.4.4 - 2.44.1 + 2.44.2