Java Code Examples for reactor.bus.Event#setKey()

The following examples show how to use reactor.bus.Event#setKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Flow2HandlerTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testNewFlow() {
    BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
    given(flowConfig.createFlow(anyString(), anyLong())).willReturn(flow);
    given(flowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
    given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(true);
    given(flow.getCurrentState()).willReturn(flowState);
    Event<Payload> event = new Event<>(payload);
    event.setKey("KEY");
    underTest.accept(event);
    verify(flowConfigurationMap, times(1)).get(anyString());
    verify(runningFlows, times(1)).put(eq(flow), isNull(String.class));
    verify(flowLogService, times(1))
            .save(any(FlowParameters.class), nullable(String.class), eq("KEY"), any(Payload.class), any(), eq(flowConfig.getClass()), eq(flowState));
    verify(flow, times(1)).sendEvent(anyString(), isNull(), any(), any());
}
 
Example 2
Source File: Flow2HandlerTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlowCanNotBeSaved() {
    BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
    given(flowConfig.createFlow(anyString(), anyLong())).willReturn(flow);
    given(flowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
    given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(true);
    given(flow.getCurrentState()).willReturn(flowState);
    Event<Payload> event = new Event<>(payload);
    event.setKey("KEY");
    when(flowLogService.save(any(FlowParameters.class), nullable(String.class), anyString(), any(Payload.class), any(),
            eq(flowConfig.getClass()), eq(flowState))).thenThrow(new RuntimeException("Can't save flow log"));
    underTest.accept(event);
    verify(flowConfigurationMap, times(1)).get(anyString());
    verify(runningFlows, times(1)).put(eq(flow), isNull(String.class));
    verify(flowLogService, times(1))
            .save(any(FlowParameters.class), nullable(String.class), eq("KEY"), any(Payload.class), any(), eq(flowConfig.getClass()), eq(flowState));
    verify(runningFlows, times(1)).remove(anyString());
    verify(flow, times(0)).sendEvent(anyString(), isNull(), any(), any());
}
 
Example 3
Source File: Flow2HandlerTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testNewSyncFlowMaintenanceActive() {
    HelloWorldFlowConfig helloWorldFlowConfig = Mockito.mock(HelloWorldFlowConfig.class);
    given(helloWorldFlowConfig.getFlowTriggerCondition()).willReturn(new DefaultFlowTriggerCondition());

    BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(helloWorldFlowConfig);
    given(helloWorldFlowConfig.createFlow(anyString(), anyLong())).willReturn(flow);
    given(helloWorldFlowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
    given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(true);
    given(flow.getCurrentState()).willReturn(flowState);
    Event<Payload> event = new Event<>(payload);
    event.setKey("KEY");
    event.getHeaders().set(FlowConstants.FLOW_TRIGGER_USERCRN, FLOW_TRIGGER_USERCRN);
    underTest.accept(event);
    verify(flowConfigurationMap, times(1)).get(anyString());
    verify(runningFlows, times(1)).put(eq(flow), isNull(String.class));
    verify(flowLogService, times(1)).save(any(FlowParameters.class), nullable(String.class), eq("KEY"), any(Payload.class), any(),
            ArgumentMatchers.eq(helloWorldFlowConfig.getClass()), eq(flowState));
    verify(flow, times(1)).sendEvent(anyString(), anyString(), any(), any());
}
 
Example 4
Source File: Flow2HandlerTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewFlowButNotHandled() {
    Event<Payload> event = new Event<>(payload);
    event.setKey("KEY");
    underTest.accept(event);
    verify(flowConfigurationMap, times(1)).get(anyString());
    verify(runningFlows, never()).put(any(Flow.class), isNull(String.class));
    verify(flowLogService, never()).save(any(FlowParameters.class), anyString(), anyString(), any(Payload.class), anyMap(), any(), any(FlowState.class));
}