use of com.google.cloud.tools.jib.event.events.TimerEvent in project jib by GoogleContainerTools.
the class TimerEventDispatcherTest method testLogging.
@Test
public void testLogging() {
EventHandlers eventHandlers = EventHandlers.builder().add(TimerEvent.class, timerEventQueue::add).build();
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH);
try (TimerEventDispatcher parentTimerEventDispatcher = new TimerEventDispatcher(eventHandlers, "description", mockClock, null)) {
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH.plusMillis(1));
parentTimerEventDispatcher.lap();
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH.plusMillis(1).plusNanos(1));
try (TimerEventDispatcher ignored = parentTimerEventDispatcher.subTimer("child description")) {
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH.plusMillis(2));
// Laps on close.
}
}
TimerEvent timerEvent = getNextTimerEvent();
verifyNoParent(timerEvent);
verifyStartState(timerEvent);
verifyDescription(timerEvent, "description");
TimerEvent.Timer parentTimer = timerEvent.getTimer();
timerEvent = getNextTimerEvent();
verifyNoParent(timerEvent);
verifyStateFirstLap(timerEvent, State.LAP);
verifyDescription(timerEvent, "description");
timerEvent = getNextTimerEvent();
verifyParent(timerEvent, parentTimer);
verifyStartState(timerEvent);
verifyDescription(timerEvent, "child description");
timerEvent = getNextTimerEvent();
verifyParent(timerEvent, parentTimer);
verifyStateFirstLap(timerEvent, State.FINISHED);
verifyDescription(timerEvent, "child description");
timerEvent = getNextTimerEvent();
verifyNoParent(timerEvent);
verifyStateNotFirstLap(timerEvent, State.FINISHED);
verifyDescription(timerEvent, "description");
Assert.assertTrue(timerEventQueue.isEmpty());
}
use of com.google.cloud.tools.jib.event.events.TimerEvent in project jib by GoogleContainerTools.
the class TimerEventHandlerTest method testAccept.
@Test
public void testAccept() {
TimerEventHandler timerEventHandler = new TimerEventHandler(logMessageQueue::add);
timerEventHandler.accept(new TimerEvent(State.START, ROOT_TIMER, Duration.ZERO, Duration.ZERO, "description"));
timerEventHandler.accept(new TimerEvent(State.LAP, ROOT_TIMER, Duration.ofMillis(10), Duration.ZERO, "description"));
timerEventHandler.accept(new TimerEvent(State.FINISHED, ROOT_TIMER, Duration.ofMillis(100), Duration.ZERO, "description"));
timerEventHandler.accept(new TimerEvent(State.LAP, () -> Optional.of(ROOT_TIMER), Duration.ZERO, Duration.ZERO, "child description"));
String rootStartMessage = logMessageQueue.poll();
Assert.assertNotNull(rootStartMessage);
Assert.assertEquals("TIMING\tdescription", rootStartMessage);
String rootInProgressMessage = logMessageQueue.poll();
Assert.assertNotNull(rootInProgressMessage);
Assert.assertEquals("TIMED\tdescription : 10.0 ms", rootInProgressMessage);
String rootFinishedMessage = logMessageQueue.poll();
Assert.assertNotNull(rootFinishedMessage);
Assert.assertEquals("TIMED\tdescription : 100.0 ms", rootFinishedMessage);
String childMessage = logMessageQueue.poll();
Assert.assertNotNull(childMessage);
Assert.assertEquals("\tTIMED\tchild description : 0.0 ms", childMessage);
Assert.assertTrue(logMessageQueue.isEmpty());
}
use of com.google.cloud.tools.jib.event.events.TimerEvent in project jib by google.
the class TimerEventDispatcherTest method testLogging.
@Test
public void testLogging() {
EventHandlers eventHandlers = EventHandlers.builder().add(TimerEvent.class, timerEventQueue::add).build();
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH);
try (TimerEventDispatcher parentTimerEventDispatcher = new TimerEventDispatcher(eventHandlers, "description", mockClock, null)) {
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH.plusMillis(1));
parentTimerEventDispatcher.lap();
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH.plusMillis(1).plusNanos(1));
try (TimerEventDispatcher ignored = parentTimerEventDispatcher.subTimer("child description")) {
Mockito.when(mockClock.instant()).thenReturn(Instant.EPOCH.plusMillis(2));
// Laps on close.
}
}
TimerEvent timerEvent = getNextTimerEvent();
verifyNoParent(timerEvent);
verifyStartState(timerEvent);
verifyDescription(timerEvent, "description");
TimerEvent.Timer parentTimer = timerEvent.getTimer();
timerEvent = getNextTimerEvent();
verifyNoParent(timerEvent);
verifyStateFirstLap(timerEvent, State.LAP);
verifyDescription(timerEvent, "description");
timerEvent = getNextTimerEvent();
verifyParent(timerEvent, parentTimer);
verifyStartState(timerEvent);
verifyDescription(timerEvent, "child description");
timerEvent = getNextTimerEvent();
verifyParent(timerEvent, parentTimer);
verifyStateFirstLap(timerEvent, State.FINISHED);
verifyDescription(timerEvent, "child description");
timerEvent = getNextTimerEvent();
verifyNoParent(timerEvent);
verifyStateNotFirstLap(timerEvent, State.FINISHED);
verifyDescription(timerEvent, "description");
Assert.assertTrue(timerEventQueue.isEmpty());
}
use of com.google.cloud.tools.jib.event.events.TimerEvent in project jib by google.
the class TimerEventDispatcherTest method getNextTimerEvent.
/**
* Gets the next {@link TimerEvent} on the {@link #timerEventQueue}.
*
* @return the next {@link TimerEvent}
*/
private TimerEvent getNextTimerEvent() {
TimerEvent timerEvent = timerEventQueue.poll();
Assert.assertNotNull(timerEvent);
return timerEvent;
}
use of com.google.cloud.tools.jib.event.events.TimerEvent in project jib by google.
the class TimerEventHandlerTest method testAccept.
@Test
public void testAccept() {
TimerEventHandler timerEventHandler = new TimerEventHandler(logMessageQueue::add);
timerEventHandler.accept(new TimerEvent(State.START, ROOT_TIMER, Duration.ZERO, Duration.ZERO, "description"));
timerEventHandler.accept(new TimerEvent(State.LAP, ROOT_TIMER, Duration.ofMillis(10), Duration.ZERO, "description"));
timerEventHandler.accept(new TimerEvent(State.FINISHED, ROOT_TIMER, Duration.ofMillis(100), Duration.ZERO, "description"));
timerEventHandler.accept(new TimerEvent(State.LAP, () -> Optional.of(ROOT_TIMER), Duration.ZERO, Duration.ZERO, "child description"));
String rootStartMessage = logMessageQueue.poll();
Assert.assertNotNull(rootStartMessage);
Assert.assertEquals("TIMING\tdescription", rootStartMessage);
String rootInProgressMessage = logMessageQueue.poll();
Assert.assertNotNull(rootInProgressMessage);
Assert.assertEquals("TIMED\tdescription : 10.0 ms", rootInProgressMessage);
String rootFinishedMessage = logMessageQueue.poll();
Assert.assertNotNull(rootFinishedMessage);
Assert.assertEquals("TIMED\tdescription : 100.0 ms", rootFinishedMessage);
String childMessage = logMessageQueue.poll();
Assert.assertNotNull(childMessage);
Assert.assertEquals("\tTIMED\tchild description : 0.0 ms", childMessage);
Assert.assertTrue(logMessageQueue.isEmpty());
}
Aggregations