Skip to content

Commit f6f8994

Browse files
authored
fix: pool size configuration (#2810)
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 0aeb314 commit f6f8994

File tree

2 files changed

+49
-25
lines changed

2 files changed

+49
-25
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,20 @@ public boolean closeClientOnStop() {
254254

255255
@Override
256256
public ExecutorService getExecutorService() {
257-
return overriddenValueOrDefault(executorService, ConfigurationService::getExecutorService);
257+
if (executorService != null) {
258+
return executorService;
259+
} else {
260+
return super.getExecutorService();
261+
}
258262
}
259263

260264
@Override
261265
public ExecutorService getWorkflowExecutorService() {
262-
return overriddenValueOrDefault(
263-
workflowExecutorService, ConfigurationService::getWorkflowExecutorService);
266+
if (workflowExecutorService != null) {
267+
return workflowExecutorService;
268+
} else {
269+
return super.getWorkflowExecutorService();
270+
}
264271
}
265272

266273
@Override

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import java.time.Duration;
44
import java.util.Optional;
55
import java.util.concurrent.Executors;
6+
import java.util.concurrent.ThreadPoolExecutor;
67

78
import org.junit.jupiter.api.Test;
89

910
import io.fabric8.kubernetes.api.model.HasMetadata;
1011
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
1112

13+
import static org.assertj.core.api.Assertions.assertThat;
1214
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1315

1416
class ConfigurationServiceOverriderTest {
@@ -26,30 +28,32 @@ public <R extends HasMetadata> R clone(R object) {
2628
}
2729
};
2830

31+
final BaseConfigurationService config =
32+
new BaseConfigurationService(null) {
33+
@Override
34+
public boolean checkCRDAndValidateLocalModel() {
35+
return false;
36+
}
37+
38+
@Override
39+
public Metrics getMetrics() {
40+
return METRICS;
41+
}
42+
43+
@Override
44+
public Cloner getResourceCloner() {
45+
return CLONER;
46+
}
47+
48+
@Override
49+
public Optional<LeaderElectionConfiguration> getLeaderElectionConfiguration() {
50+
return Optional.of(LEADER_ELECTION_CONFIGURATION);
51+
}
52+
};
53+
2954
@Test
3055
void overrideShouldWork() {
31-
final var config =
32-
new BaseConfigurationService(null) {
33-
@Override
34-
public boolean checkCRDAndValidateLocalModel() {
35-
return false;
36-
}
37-
38-
@Override
39-
public Metrics getMetrics() {
40-
return METRICS;
41-
}
42-
43-
@Override
44-
public Cloner getResourceCloner() {
45-
return CLONER;
46-
}
47-
48-
@Override
49-
public Optional<LeaderElectionConfiguration> getLeaderElectionConfiguration() {
50-
return Optional.of(LEADER_ELECTION_CONFIGURATION);
51-
}
52-
};
56+
5357
final var overridden =
5458
new ConfigurationServiceOverrider(config)
5559
.checkingCRDAndValidateLocalModel(true)
@@ -86,4 +90,17 @@ public <R extends HasMetadata> R clone(R object) {
8690
assertNotEquals(
8791
config.reconciliationTerminationTimeout(), overridden.reconciliationTerminationTimeout());
8892
}
93+
94+
@Test
95+
void threadCountConfiguredProperly() {
96+
final var overridden =
97+
new ConfigurationServiceOverrider(config)
98+
.withConcurrentReconciliationThreads(13)
99+
.withConcurrentWorkflowExecutorThreads(14)
100+
.build();
101+
assertThat(((ThreadPoolExecutor) overridden.getExecutorService()).getMaximumPoolSize())
102+
.isEqualTo(13);
103+
assertThat(((ThreadPoolExecutor) overridden.getWorkflowExecutorService()).getMaximumPoolSize())
104+
.isEqualTo(14);
105+
}
89106
}

0 commit comments

Comments
 (0)