use of io.javaoperatorsdk.operator.api.config.ConfigurationService in project java-operator-sdk by java-operator-sdk.
the class CustomResourceSelectorTest method resourceWatchedByLabel.
@Test
void resourceWatchedByLabel() {
assertThat(server).isNotNull();
assertThat(client).isNotNull();
Operator o1 = new Operator(client, configurationService);
Operator o2 = new Operator(client, configurationService);
try {
AtomicInteger c1 = new AtomicInteger();
AtomicInteger c1err = new AtomicInteger();
AtomicInteger c2 = new AtomicInteger();
AtomicInteger c2err = new AtomicInteger();
o1.register(new MyController(resource -> {
if ("foo".equals(resource.getMetadata().getName())) {
c1.incrementAndGet();
}
if ("bar".equals(resource.getMetadata().getName())) {
c1err.incrementAndGet();
}
}), new MyConfiguration(configurationService, "app=foo"));
o1.start();
o2.register(new MyController(resource -> {
if ("bar".equals(resource.getMetadata().getName())) {
c2.incrementAndGet();
}
if ("foo".equals(resource.getMetadata().getName())) {
c2err.incrementAndGet();
}
}), new MyConfiguration(configurationService, "app=bar"));
o2.start();
client.resources(TestCustomResource.class).inNamespace(NAMESPACE).create(newMyResource("foo", NAMESPACE));
client.resources(TestCustomResource.class).inNamespace(NAMESPACE).create(newMyResource("bar", NAMESPACE));
await().atMost(5, TimeUnit.SECONDS).pollInterval(100, TimeUnit.MILLISECONDS).until(() -> c1.get() == 1 && c1err.get() == 0);
await().atMost(5, TimeUnit.SECONDS).pollInterval(100, TimeUnit.MILLISECONDS).until(() -> c2.get() == 1 && c2err.get() == 0);
assertThrows(ConditionTimeoutException.class, () -> await().atMost(2, TimeUnit.SECONDS).untilAtomic(c1err, is(greaterThan(0))));
assertThrows(ConditionTimeoutException.class, () -> await().atMost(2, TimeUnit.SECONDS).untilAtomic(c2err, is(greaterThan(0))));
} finally {
o1.stop();
o2.stop();
}
}
use of io.javaoperatorsdk.operator.api.config.ConfigurationService in project java-operator-sdk by java-operator-sdk.
the class CustomResourceSelectorTest method setUpResources.
@SuppressWarnings("unchecked")
@BeforeEach
void setUpResources() {
configurationService = spy(ConfigurationService.class);
when(configurationService.checkCRDAndValidateLocalModel()).thenReturn(false);
when(configurationService.getVersion()).thenReturn(new Version("1", "1", new Date()));
when(configurationService.getConfigurationFor(any(MyController.class))).thenReturn(new MyConfiguration(configurationService, null));
}
Aggregations