|
| 1 | +package io.javaoperatorsdk.operator; |
| 2 | + |
| 3 | +import java.util.concurrent.TimeUnit; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 7 | + |
| 8 | +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
| 9 | +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; |
| 10 | +import io.javaoperatorsdk.operator.processing.retry.GenericRetry; |
| 11 | +import io.javaoperatorsdk.operator.sample.errorstatushandler.ErrorStatusHandlerTestCustomResource; |
| 12 | +import io.javaoperatorsdk.operator.sample.errorstatushandler.ErrorStatusHandlerTestReconciler; |
| 13 | + |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; |
| 15 | +import static org.awaitility.Awaitility.await; |
| 16 | + |
| 17 | +class ErrorStatusHandlerLastAttemptIT { |
| 18 | + |
| 19 | + public static final int MAX_RETRY_ATTEMPTS = 0; |
| 20 | + ErrorStatusHandlerTestReconciler reconciler = new ErrorStatusHandlerTestReconciler(); |
| 21 | + |
| 22 | + @RegisterExtension |
| 23 | + LocallyRunOperatorExtension operator = |
| 24 | + LocallyRunOperatorExtension.builder() |
| 25 | + .withReconciler(reconciler, |
| 26 | + new GenericRetry().setMaxAttempts(MAX_RETRY_ATTEMPTS).withLinearRetry()) |
| 27 | + .build(); |
| 28 | + |
| 29 | + @Test |
| 30 | + void testErrorMessageSetEventually() { |
| 31 | + ErrorStatusHandlerTestCustomResource resource = |
| 32 | + operator.create(ErrorStatusHandlerTestCustomResource.class, createCustomResource()); |
| 33 | + |
| 34 | + await() |
| 35 | + .atMost(10, TimeUnit.SECONDS) |
| 36 | + .pollInterval(250, TimeUnit.MICROSECONDS) |
| 37 | + .untilAsserted( |
| 38 | + () -> { |
| 39 | + ErrorStatusHandlerTestCustomResource res = |
| 40 | + operator.get(ErrorStatusHandlerTestCustomResource.class, |
| 41 | + resource.getMetadata().getName()); |
| 42 | + assertThat(res.getStatus()).isNotNull(); |
| 43 | + assertThat(res.getStatus().getMessages()) |
| 44 | + .contains(ErrorStatusHandlerTestReconciler.ERROR_STATUS_MESSAGE + 0 + true); |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + public ErrorStatusHandlerTestCustomResource createCustomResource() { |
| 49 | + ErrorStatusHandlerTestCustomResource resource = new ErrorStatusHandlerTestCustomResource(); |
| 50 | + resource.setMetadata( |
| 51 | + new ObjectMetaBuilder() |
| 52 | + .withName("error-status-test") |
| 53 | + .withNamespace(operator.getNamespace()) |
| 54 | + .build()); |
| 55 | + return resource; |
| 56 | + } |
| 57 | + |
| 58 | +} |
0 commit comments