use of io.javaoperatorsdk.operator.sample.simple.TestCustomResource in project java-operator-sdk by java-operator-sdk.
the class ConcurrencyIT method manyResourcesGetCreatedUpdatedAndDeleted.
@Test
void manyResourcesGetCreatedUpdatedAndDeleted() throws InterruptedException {
log.info("Creating {} new resources", NUMBER_OF_RESOURCES_CREATED);
for (int i = 0; i < NUMBER_OF_RESOURCES_CREATED; i++) {
TestCustomResource tcr = TestUtils.testCustomResourceWithPrefix(String.valueOf(i));
operator.resources(TestCustomResource.class).create(tcr);
}
await().atMost(1, TimeUnit.MINUTES).untilAsserted(() -> {
List<ConfigMap> items = operator.resources(ConfigMap.class).withLabel("managedBy", TestReconciler.class.getSimpleName()).list().getItems();
assertThat(items).hasSize(NUMBER_OF_RESOURCES_CREATED);
});
log.info("Updating {} resources", NUMBER_OF_RESOURCES_UPDATED);
// update some resources
for (int i = 0; i < NUMBER_OF_RESOURCES_UPDATED; i++) {
TestCustomResource tcr = operator.get(TestCustomResource.class, TestUtils.TEST_CUSTOM_RESOURCE_PREFIX + i);
tcr.getSpec().setValue(i + UPDATED_SUFFIX);
operator.resources(TestCustomResource.class).createOrReplace(tcr);
}
// sleep for a short time to make variability to the test, so some updates are not
// executed before delete
Thread.sleep(300);
log.info("Deleting {} resources", NUMBER_OF_RESOURCES_DELETED);
for (int i = 0; i < NUMBER_OF_RESOURCES_DELETED; i++) {
TestCustomResource tcr = TestUtils.testCustomResourceWithPrefix(String.valueOf(i));
operator.resources(TestCustomResource.class).delete(tcr);
}
await().atMost(1, TimeUnit.MINUTES).untilAsserted(() -> {
List<ConfigMap> items = operator.resources(ConfigMap.class).withLabel("managedBy", TestReconciler.class.getSimpleName()).list().getItems();
// reducing configmaps to names only - better for debugging
List<String> itemDescs = items.stream().map(configMap -> configMap.getMetadata().getName()).collect(Collectors.toList());
assertThat(itemDescs).hasSize(NUMBER_OF_RESOURCES_CREATED - NUMBER_OF_RESOURCES_DELETED);
List<TestCustomResource> crs = operator.resources(TestCustomResource.class).list().getItems();
assertThat(crs).hasSize(NUMBER_OF_RESOURCES_CREATED - NUMBER_OF_RESOURCES_DELETED);
});
}
use of io.javaoperatorsdk.operator.sample.simple.TestCustomResource in project java-operator-sdk by java-operator-sdk.
the class ControllerExecutionIT method configMapGetsCreatedForTestCustomResource.
@Test
void configMapGetsCreatedForTestCustomResource() {
operator.getControllerOfType(TestReconciler.class).setUpdateStatus(true);
TestCustomResource resource = TestUtils.testCustomResource();
operator.create(TestCustomResource.class, resource);
awaitResourcesCreatedOrUpdated();
awaitStatusUpdated();
assertThat(TestUtils.getNumberOfExecutions(operator)).isEqualTo(2);
}
use of io.javaoperatorsdk.operator.sample.simple.TestCustomResource in project java-operator-sdk by java-operator-sdk.
the class ControllerExecutionIT method eventIsSkippedChangedOnMetadataOnlyUpdate.
@Test
void eventIsSkippedChangedOnMetadataOnlyUpdate() {
operator.getControllerOfType(TestReconciler.class).setUpdateStatus(false);
TestCustomResource resource = TestUtils.testCustomResource();
operator.create(TestCustomResource.class, resource);
awaitResourcesCreatedOrUpdated();
assertThat(TestUtils.getNumberOfExecutions(operator)).isEqualTo(1);
}
use of io.javaoperatorsdk.operator.sample.simple.TestCustomResource in project java-operator-sdk by java-operator-sdk.
the class EventProcessorTest method executesTheControllerInstantlyAfterErrorIfNewEventsReceived.
@Test
public void executesTheControllerInstantlyAfterErrorIfNewEventsReceived() {
Event event = prepareCREvent();
TestCustomResource customResource = testCustomResource();
overrideData(event.getRelatedCustomResourceID(), customResource);
PostExecutionControl postExecutionControl = PostExecutionControl.exceptionDuringExecution(new RuntimeException("test"));
when(reconciliationDispatcherMock.handleExecution(any())).thenReturn(postExecutionControl).thenReturn(PostExecutionControl.defaultDispatch());
// start processing an event
eventProcessorWithRetry.handleEvent(event);
// handle another event
eventProcessorWithRetry.handleEvent(event);
ArgumentCaptor<ExecutionScope> executionScopeArgumentCaptor = ArgumentCaptor.forClass(ExecutionScope.class);
verify(reconciliationDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(2)).handleExecution(executionScopeArgumentCaptor.capture());
List<ExecutionScope> allValues = executionScopeArgumentCaptor.getAllValues();
assertThat(allValues).hasSize(2);
verify(retryTimerEventSourceMock, never()).scheduleOnce(eq(customResource), eq(GenericRetry.DEFAULT_INITIAL_INTERVAL));
}
use of io.javaoperatorsdk.operator.sample.simple.TestCustomResource in project java-operator-sdk by java-operator-sdk.
the class EventProcessorTest method schedulesAnEventRetryOnException.
@Test
public void schedulesAnEventRetryOnException() {
TestCustomResource customResource = testCustomResource();
ExecutionScope executionScope = new ExecutionScope(customResource, null);
PostExecutionControl postExecutionControl = PostExecutionControl.exceptionDuringExecution(new RuntimeException("test"));
eventProcessorWithRetry.eventProcessingFinished(executionScope, postExecutionControl);
verify(retryTimerEventSourceMock, times(1)).scheduleOnce(eq(customResource), eq(GenericRetry.DEFAULT_INITIAL_INTERVAL));
}
Aggregations