Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class GenericRetryExecution implements RetryExecution {

private final GenericRetry genericRetry;

private int lastAttemptIndex = 0;
private long currentInterval;
private volatile int lastAttemptIndex = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might cause one of the tests fails. It does not do any harm otherwise since we might access those from different threads

private volatile long currentInterval;

public GenericRetryExecution(GenericRetry genericRetry) {
this.genericRetry = genericRetry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ public void executesTheControllerInstantlyAfterErrorIfEventsBuffered() {
PostExecutionControl postExecutionControl =
PostExecutionControl.exceptionDuringExecution(new RuntimeException("test"));

when(eventDispatcherMock.handleExecution(any()))
.thenReturn(postExecutionControl)
.thenReturn(PostExecutionControl.defaultDispatch());

// start processing an event
defaultEventHandlerWithRetry.handleEvent(event);
// buffer an another event
// buffer another event
defaultEventHandlerWithRetry.handleEvent(event);
verify(eventDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(1))
.handleExecution(any());

defaultEventHandlerWithRetry.eventProcessingFinished(executionScope, postExecutionControl);

ArgumentCaptor<ExecutionScope> executionScopeArgumentCaptor =
ArgumentCaptor.forClass(ExecutionScope.class);
Expand Down Expand Up @@ -191,15 +191,14 @@ public void successfulExecutionResetsTheRetry() {
ArgumentCaptor.forClass(ExecutionScope.class);

defaultEventHandlerWithRetry.handleEvent(event);

verify(eventDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(1))
.handleExecution(any());
defaultEventHandlerWithRetry.handleEvent(event);

defaultEventHandlerWithRetry.handleEvent(event);
verify(eventDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(2))
.handleExecution(any());
defaultEventHandlerWithRetry.handleEvent(event);

defaultEventHandlerWithRetry.handleEvent(event);
verify(eventDispatcherMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(3))
.handleExecution(executionScopeArgumentCaptor.capture());
log.info("Finished successfulExecutionResetsTheRetry");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public <T extends HasMetadata> T replace(Class<T> type, T resource) {
return kubernetesClient.resources(type).inNamespace(namespace).replace(resource);
}

public <T extends HasMetadata> T get(Class<T> type, String name) {
return kubernetesClient.resources(type).inNamespace(namespace).withName(name).get();
}


@SuppressWarnings("unchecked")
protected void before(ExtensionContext context) {
namespace = context.getRequiredTestClass().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResource;
import io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResourceController;
import io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResourceSpec;
import io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResourceStatus;
import io.javaoperatorsdk.operator.support.TestUtils;

import static io.javaoperatorsdk.operator.sample.subresource.SubResourceTestCustomResourceStatus.State.SUCCESS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

Expand Down Expand Up @@ -87,7 +87,7 @@ public void updateCustomResourceAfterSubResourceChange() {
awaitStatusUpdated(resource.getMetadata().getName());

// wait for sure, there are no more events
waitXms(200);
waitXms(500);
// there is no event on status update processed
assertThat(TestUtils.getNumberOfExecutions(operator))
.isEqualTo(3);
Expand All @@ -104,7 +104,7 @@ void awaitStatusUpdated(String name) {
assertThat(cr).isNotNull();
assertThat(cr.getStatus()).isNotNull();
assertThat(cr.getStatus().getState())
.isEqualTo(SubResourceTestCustomResourceStatus.State.SUCCESS);
.isEqualTo(SUCCESS);
});
}

Expand Down