Skip to content
Merged
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 @@ -170,16 +170,40 @@ void create_withDefinitionsWithStringAndMatchingHandler_shouldParseIni() {
}

@Test
void emptyDefinitionStringUsesDefinitionMap() {
void emptyDefinitionStringRoutesThroughDefinitionMap() throws Exception {
DisruptorEventHandlerCreater creater = new DisruptorEventHandlerCreater(mock(ApplicationContext.class));
EventHandlerDefinition definition = new EventHandlerDefinition();
definition.setDefinitions("");
definition.setOrder(0);
definition.setDefinitionMap(Map.of("/**", "handler1"));
Map<String, DisruptorHandler<DisruptorEvent>> handlers = Map.of(
"handler1", mock(DisruptorHandler.class));
definition.setDefinitionMap(Map.of("orders/**", "mapped"));
DisruptorHandler<DisruptorEvent> mapped = mock(DisruptorHandler.class);
DisruptorEventDispatcher dispatcher = creater.createDisruptorEventHandler(
definition, Map.of("mapped", mapped));

DisruptorEvent event = new DisruptorEvent();
event.setNamespace("orders");
event.setTopic("created");
dispatcher.onEvent(event, 0L, true);
verify(mapped).doHandler(eq(event), any());
}

assertThat(creater.createDisruptorEventHandler(definition, handlers)).isNotNull();
@Test
void explicitDefinitionStringRoutesBeforeDefinitionMap() throws Exception {
DisruptorEventHandlerCreater creater = new DisruptorEventHandlerCreater(mock(ApplicationContext.class));
EventHandlerDefinition definition = new EventHandlerDefinition();
definition.setDefinitions("[urls]\norders/** = explicit");
definition.setDefinitionMap(Map.of("orders/**", "fallback"));
DisruptorHandler<DisruptorEvent> explicit = mock(DisruptorHandler.class);
DisruptorHandler<DisruptorEvent> fallback = mock(DisruptorHandler.class);
DisruptorEventDispatcher dispatcher = creater.createDisruptorEventHandler(
definition, Map.of("explicit", explicit, "fallback", fallback));

DisruptorEvent event = new DisruptorEvent();
event.setNamespace("orders");
event.setTopic("created");
dispatcher.onEvent(event, 0L, true);
verify(explicit).doHandler(eq(event), any());
verifyNoInteractions(fallback);
}

@Test
Expand Down
Loading