Search in sources :

Example 1 with ManualClock

use of org.openkilda.stubs.ManualClock in project open-kilda by telstra.

the class NetworkRoundTripDecisionMakerServiceTest method setup.

@Before
public void setup() {
    reset(carrier);
    clock = new ManualClock();
}
Also used : ManualClock(org.openkilda.stubs.ManualClock) Before(org.junit.Before)

Example 2 with ManualClock

use of org.openkilda.stubs.ManualClock in project open-kilda by telstra.

the class MonotonicClockTest method ticks.

@Test
public void ticks() {
    ManualClock baseClock = new ManualClock(Instant.EPOCH, ZoneOffset.UTC);
    when(topologyContext.getThisTaskId()).thenReturn(1);
    when(topologyContext.getComponentId(Mockito.eq((int) Constants.SYSTEM_TASK_ID))).thenReturn(Constants.SYSTEM_COMPONENT_ID);
    when(topologyContext.getComponentOutputFields(Constants.SYSTEM_COMPONENT_ID, Constants.SYSTEM_TICK_STREAM_ID)).thenReturn(new Fields());
    MonotonicClock<TickKinds> bolt = new MonotonicClock<>(new MonotonicClock.ClockConfig<TickKinds>().addTickInterval(TickKinds.EACH_2, 2).addTickInterval(TickKinds.EACH_3, 3), 1, baseClock);
    bolt.prepare(Collections.emptyMap(), topologyContext, output);
    verifyNoMoreInteractions(output);
    final Tuple tickTuple = makeSystemTickTuple();
    // 0 tick
    bolt.execute(tickTuple);
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(0L, 0L, null), arg.subList(0, 3))));
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(0L, 0L, TickKinds.EACH_2), arg.subList(0, 3))));
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(0L, 0L, TickKinds.EACH_3), arg.subList(0, 3))));
    verify(output).ack(tickTuple);
    verifyNoMoreInteractions(output);
    reset(output);
    // 1 tick
    baseClock.adjust(Duration.ofSeconds(1));
    bolt.execute(tickTuple);
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(1000L, 1L, null), arg.subList(0, 3))));
    verify(output).ack(tickTuple);
    verifyNoMoreInteractions(output);
    reset(output);
    // 2 tick
    baseClock.adjust(Duration.ofSeconds(1));
    bolt.execute(tickTuple);
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(2000L, 2L, null), arg.subList(0, 3))));
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(2000L, 1L, TickKinds.EACH_2), arg.subList(0, 3))));
    verify(output).ack(tickTuple);
    verifyNoMoreInteractions(output);
    reset(output);
    // 3 tick
    baseClock.adjust(Duration.ofSeconds(1));
    bolt.execute(tickTuple);
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(3000L, 3L, null), arg.subList(0, 3))));
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(3000L, 1L, TickKinds.EACH_3), arg.subList(0, 3))));
    verify(output).ack(tickTuple);
    verifyNoMoreInteractions(output);
    reset(output);
    // 4 tick
    baseClock.adjust(Duration.ofSeconds(1));
    bolt.execute(tickTuple);
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(4000L, 4L, null), arg.subList(0, 3))));
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(4000L, 2L, TickKinds.EACH_2), arg.subList(0, 3))));
    verify(output).ack(tickTuple);
    verifyNoMoreInteractions(output);
    reset(output);
    // 5 tick
    baseClock.adjust(Duration.ofSeconds(1));
    bolt.execute(tickTuple);
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(5000L, 5L, null), arg.subList(0, 3))));
    verify(output).ack(tickTuple);
    verifyNoMoreInteractions(output);
    reset(output);
    // 6 tick
    baseClock.adjust(Duration.ofSeconds(1));
    bolt.execute(tickTuple);
    // System.out.println(mockingDetails(output).printInvocations());
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(6000L, 6L, null), arg.subList(0, 3))));
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(6000L, 3L, TickKinds.EACH_2), arg.subList(0, 3))));
    verify(output).emit(Mockito.eq(tickTuple), argThat(arg -> Objects.equals(new Values(6000L, 2L, TickKinds.EACH_3), arg.subList(0, 3))));
    verify(output).ack(tickTuple);
    verifyNoMoreInteractions(output);
    reset(output);
}
Also used : BeforeClass(org.junit.BeforeClass) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) TopologyContext(org.apache.storm.task.TopologyContext) RunWith(org.junit.runner.RunWith) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) OutputCollector(org.apache.storm.task.OutputCollector) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Duration(java.time.Duration) ZoneOffset(java.time.ZoneOffset) InMemoryGraphPersistenceManager(org.openkilda.persistence.inmemory.InMemoryGraphPersistenceManager) ManualClock(org.openkilda.stubs.ManualClock) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Fields(org.apache.storm.tuple.Fields) Instant(java.time.Instant) Mockito.verify(org.mockito.Mockito.verify) Objects(java.util.Objects) Mockito(org.mockito.Mockito) Constants(org.apache.storm.Constants) TupleImpl(org.apache.storm.tuple.TupleImpl) Mockito.reset(org.mockito.Mockito.reset) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) ManualClock(org.openkilda.stubs.ManualClock) Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Aggregations

ManualClock (org.openkilda.stubs.ManualClock)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Constants (org.apache.storm.Constants)1 OutputCollector (org.apache.storm.task.OutputCollector)1 TopologyContext (org.apache.storm.task.TopologyContext)1 Fields (org.apache.storm.tuple.Fields)1 Tuple (org.apache.storm.tuple.Tuple)1 TupleImpl (org.apache.storm.tuple.TupleImpl)1 Values (org.apache.storm.tuple.Values)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1