Search in sources :

Example 1 with FlowLogIdWithTypeAndTimestamp

use of com.sequenceiq.flow.domain.FlowLogIdWithTypeAndTimestamp in project cloudbreak by hortonworks.

the class FlowLogDBServiceTest method doNotCancelTooYoungTerminationFlowForResourceTest.

@Test
public void doNotCancelTooYoungTerminationFlowForResourceTest() {
    Set<FlowLogIdWithTypeAndTimestamp> flowLogs = new HashSet<>();
    FlowLogIdWithTypeAndTimestamp flowLog1 = mock(FlowLogIdWithTypeAndTimestamp.class);
    when(flowLog1.getFlowType()).thenReturn(ClassValue.of(TerminationFlowConfig.class));
    when(flowLog1.getCreated()).thenReturn(11000L);
    flowLogs.add(flowLog1);
    FlowLogIdWithTypeAndTimestamp flowLog2 = mock(FlowLogIdWithTypeAndTimestamp.class);
    when(flowLog2.getFlowType()).thenReturn(ClassValue.of(Class.class));
    flowLogs.add(flowLog2);
    when(flowLogRepository.findAllRunningFlowLogByResourceId(eq(1L))).thenReturn(flowLogs);
    when(applicationFlowInformation.getTerminationFlow()).thenReturn(Collections.singletonList(TerminationFlowConfig.class));
    underTest.cancelTooOldTerminationFlowForResource(1L, 10000L);
    verify(flowLogRepository, times(0)).finalizeByFlowId(eq("flow1"));
    verify(flowLogRepository, times(0)).finalizeByFlowId(eq("flow2"));
    verify(flowLogRepository, times(0)).updateLastLogStatusInFlow(eq(10L), eq(StateStatus.SUCCESSFUL));
}
Also used : FlowLogIdWithTypeAndTimestamp(com.sequenceiq.flow.domain.FlowLogIdWithTypeAndTimestamp) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 2 with FlowLogIdWithTypeAndTimestamp

use of com.sequenceiq.flow.domain.FlowLogIdWithTypeAndTimestamp in project cloudbreak by hortonworks.

the class FlowLogDBServiceTest method cancelTooOldTerminationFlowForResourceTest.

@Test
public void cancelTooOldTerminationFlowForResourceTest() throws TransactionService.TransactionExecutionException {
    Set<FlowLogIdWithTypeAndTimestamp> flowLogs = new LinkedHashSet<>();
    FlowLogIdWithTypeAndTimestamp flowLog2 = mock(FlowLogIdWithTypeAndTimestamp.class);
    when(flowLog2.getFlowType()).thenReturn(ClassValue.of(Class.class));
    flowLogs.add(flowLog2);
    FlowLogIdWithTypeAndTimestamp flowLog1 = mock(FlowLogIdWithTypeAndTimestamp.class);
    when(flowLog1.getFlowType()).thenReturn(ClassValue.of(TerminationFlowConfig.class));
    when(flowLog1.getCreated()).thenReturn(9000L);
    when(flowLog1.getFlowId()).thenReturn("flow1");
    flowLogs.add(flowLog1);
    when(flowLogRepository.findAllRunningFlowLogByResourceId(eq(1L))).thenReturn(flowLogs);
    FlowLog realFlowLog1 = mock(FlowLog.class);
    when(realFlowLog1.getId()).thenReturn(10L);
    when(flowLogRepository.findFirstByFlowIdOrderByCreatedDesc(eq("flow1"))).thenReturn(Optional.of(realFlowLog1));
    when(applicationFlowInformation.getTerminationFlow()).thenReturn(Collections.singletonList(TerminationFlowConfig.class));
    when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> ((Supplier) invocation.getArguments()[0]).get());
    when(nodeConfig.getId()).thenReturn("node1");
    underTest.cancelTooOldTerminationFlowForResource(1L, 10000L);
    verify(flowLogRepository).finalizeByFlowId(eq("flow1"));
    verify(flowLogRepository, times(0)).finalizeByFlowId(eq("flow2"));
    verify(flowLogRepository).updateLastLogStatusInFlow(eq(10L), eq(StateStatus.SUCCESSFUL));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FlowLogIdWithTypeAndTimestamp(com.sequenceiq.flow.domain.FlowLogIdWithTypeAndTimestamp) FlowLog(com.sequenceiq.flow.domain.FlowLog) Supplier(java.util.function.Supplier) Test(org.junit.Test)

Aggregations

FlowLogIdWithTypeAndTimestamp (com.sequenceiq.flow.domain.FlowLogIdWithTypeAndTimestamp)2 LinkedHashSet (java.util.LinkedHashSet)2 Test (org.junit.Test)2 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 HashSet (java.util.HashSet)1 Supplier (java.util.function.Supplier)1