Skip to content

fix: patch for controller event source initialized first #1237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2022
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 @@ -16,6 +16,7 @@

class EventSources<R extends HasMetadata> implements Iterable<NamedEventSource> {

private static final String CONTROLLER_EVENT_SOURCE_KEY = "0";
private final ConcurrentNavigableMap<String, Map<String, EventSource>> sources =
new ConcurrentSkipListMap<>();
private final TimerEventSource<R> retryAndRescheduleTimerEventSource = new TimerEventSource<>();
Expand Down Expand Up @@ -80,6 +81,9 @@ private Class<?> getResourceType(EventSource source) {
}

private String keyFor(EventSource source) {
if (source instanceof ControllerResourceEventSource) {
return CONTROLLER_EVENT_SOURCE_KEY;
}
return keyFor(getResourceType(source));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ void retrievingEventSourceForClassShouldWork() {

// manager is initialized with a controller configured to handle HasMetadata
EventSourceManager manager = initManager();
EventSource source = manager.getResourceEventSourceFor(HasMetadata.class);
assertThat(source).isInstanceOf(ControllerResourceEventSource.class);

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> manager.getResourceEventSourceFor(HasMetadata.class, "unknown_name"));

CachingEventSource eventSource = mock(CachingEventSource.class);
when(eventSource.resourceType()).thenReturn(String.class);
manager.registerEventSource(eventSource);

source = manager.getResourceEventSourceFor(String.class);
var source = manager.getResourceEventSourceFor(String.class);
assertThat(source).isNotNull();
assertEquals(eventSource, source);
}
Expand Down