Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump spotless 2.44.1 and format code #2661

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion operator-framework-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<maven-gpg-plugin.version>3.2.7</maven-gpg-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.11.2</maven-javadoc-plugin.version>
<spotless.version>2.43.0</spotless.version>
<spotless.version>2.44.1</spotless.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;};}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that doesn't seem right

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, interesting, not sure, will take a look a look later, this might be a bug in spotless


public static Class<?> getFirstTypeArgumentFromExtendedClass(Class<?> clazz) {
return getTypeArgumentFromExtendedClassByIndex(clazz, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,26 @@ DetailBuilder<R> markForDelete() {
}


record Detail<R>(Exception error, ReconcileResult<R> 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<R>(
Exception error, ReconcileResult<R>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);
}

Optional<DetailedCondition.Result<?>> getResultForConditionWithType(
Optional<DetailedCondition.Result<?>> getResultForConditionWithType(
Condition.Type conditionType) {
return switch (conditionType) {
case ACTIVATION -> Optional.ofNullable(activationConditionResult);
Expand All @@ -189,5 +196,4 @@ Optional<DetailedCondition.Result<?>> getResultForConditionWithType(
case RECONCILE -> Optional.ofNullable(reconcilePostconditionResult);
};
}
}
}
}}
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,9 @@ private static <T extends HasMetadata> SecondaryToPrimaryMapper<T> 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);};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<maven-install-plugin.version>3.1.3</maven-install-plugin.version>
<git-commit-id-maven-plugin.version>9.0.1</git-commit-id-maven-plugin.version>
<jib-maven-plugin.version>3.4.4</jib-maven-plugin.version>
<spotless.version>2.43.0</spotless.version>
<spotless.version>2.44.1</spotless.version>
</properties>

<dependencyManagement>
Expand Down
Loading