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();
}
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);
}
Aggregations