Search in sources :

Example 1 with HEALTHY

use of org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY in project open-kilda by telstra.

the class ActionServiceTest method shouldBecomeHealthyAndSendSyncRequest.

@Test
public void shouldBecomeHealthyAndSendSyncRequest() {
    Duration tier2Failed = Duration.ofNanos(flow.getMaxLatencyTier2() * 2);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, tier2Failed);
    service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, tier2Failed);
    Duration healthy = Duration.ofNanos((long) (flow.getMaxLatency() * (1 - THRESHOLD)) - 5);
    for (int i = 0; i < 10; i++) {
        clock.adjust(Duration.ofSeconds(10));
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, healthy);
        service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, healthy.minus(NANOSECOND));
        service.processTick();
        if (i == 0) {
            assertTrue(service.fsms.values().stream().allMatch(fsm -> UNSTABLE.equals(fsm.getCurrentState())));
        }
    }
    assertEquals(2, service.fsms.values().size());
    assertTrue(service.fsms.values().stream().allMatch(fsm -> HEALTHY.equals(fsm.getCurrentState())));
    FlowStats actual = flowStatsRepository.findByFlowId(flow.getFlowId()).orElseThrow(() -> new IllegalStateException("Flow not found"));
    assertEquals(healthy.getNano(), actual.getForwardLatency().intValue());
    assertEquals(healthy.minus(NANOSECOND).getNano(), actual.getReverseLatency().intValue());
    verify(carrier, times(2)).sendFlowSyncRequest(flow.getFlowId());
    verifyNoMoreInteractions(carrier);
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Arrays(java.util.Arrays) FlowStats(org.openkilda.model.FlowStats) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) HEALTHY(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.HEALTHY) Mock(org.mockito.Mock) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) RunWith(org.junit.runner.RunWith) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) TIER_2_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_2_FAILED) TIER_1_FAILED(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.TIER_1_FAILED) FlowLatencyMonitoringFsm(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm) Flow(org.openkilda.model.Flow) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) UNSTABLE(org.openkilda.wfm.topology.flowmonitoring.fsm.FlowLatencyMonitoringFsm.State.UNSTABLE) FlowDefaults(org.openkilda.persistence.dummy.FlowDefaults) Duration(java.time.Duration) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceDummyEntityFactory(org.openkilda.persistence.dummy.PersistenceDummyEntityFactory) Before(org.junit.Before) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowOperationsCarrier(org.openkilda.wfm.topology.flowmonitoring.bolt.FlowOperationsCarrier) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ManualClock(org.openkilda.stubs.ManualClock) UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) SwitchId(org.openkilda.model.SwitchId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) FlowStats(org.openkilda.model.FlowStats) Duration(java.time.Duration) FlowEndpoint(org.openkilda.model.FlowEndpoint) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

Duration (java.time.Duration)1 Arrays (java.util.Arrays)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 Mock (org.mockito.Mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1 UpdateFlowCommand (org.openkilda.messaging.info.flow.UpdateFlowCommand)1 FlowPathDto (org.openkilda.messaging.model.FlowPathDto)1 PathNodePayload (org.openkilda.messaging.payload.flow.PathNodePayload)1 Flow (org.openkilda.model.Flow)1 FlowEndpoint (org.openkilda.model.FlowEndpoint)1 FlowStats (org.openkilda.model.FlowStats)1 KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)1 PathComputationStrategy (org.openkilda.model.PathComputationStrategy)1