public YarnContainerHeartbeatServlet(YarnAppState yarnAppState, ReadableMetricsRegistry registry) { this.yarnAppState = yarnAppState; this.mapper = new ObjectMapper(); this.heartbeatsExpiredCount = registry.newCounter(GROUP, "heartbeats-expired"); }
public YarnContainerHeartbeatServlet(YarnAppState yarnAppState, ReadableMetricsRegistry registry) { this.yarnAppState = yarnAppState; this.mapper = new ObjectMapper(); this.heartbeatsExpiredCount = registry.newCounter(GROUP, "heartbeats-expired"); }
@Test public void testOnMessageUpdatesMetrics() { ReadableMetricsRegistry mockMetricsRegistry = mock(ReadableMetricsRegistry.class); when(this.context.getContainerContext().getContainerMetricsRegistry()).thenReturn(mockMetricsRegistry); Counter mockCounter = mock(Counter.class); Timer mockTimer = mock(Timer.class); when(mockMetricsRegistry.newCounter(anyString(), anyString())).thenReturn(mockCounter); when(mockMetricsRegistry.newTimer(anyString(), anyString())).thenReturn(mockTimer); Object mockTestOpImplOutput = mock(Object.class); OperatorImpl<Object, Object> opImpl = new TestOpImpl(mockTestOpImplOutput); opImpl.init(this.context); // send a message to this operator MessageCollector mockCollector = mock(MessageCollector.class); TaskCoordinator mockCoordinator = mock(TaskCoordinator.class); opImpl.onMessage(mock(Object.class), mockCollector, mockCoordinator); // verify that it updates message count and timer metrics verify(mockCounter, times(1)).inc(); verify(mockTimer, times(1)).update(anyLong()); }
@Test public void testOnTimerUpdatesMetrics() { ReadableMetricsRegistry mockMetricsRegistry = mock(ReadableMetricsRegistry.class); when(this.context.getContainerContext().getContainerMetricsRegistry()).thenReturn(mockMetricsRegistry); Counter mockMessageCounter = mock(Counter.class); Timer mockTimer = mock(Timer.class); when(mockMetricsRegistry.newCounter(anyString(), anyString())).thenReturn(mockMessageCounter); when(mockMetricsRegistry.newTimer(anyString(), anyString())).thenReturn(mockTimer); Object mockTestOpImplOutput = mock(Object.class); OperatorImpl<Object, Object> opImpl = new TestOpImpl(mockTestOpImplOutput); opImpl.init(this.context); // send a message to this operator MessageCollector mockCollector = mock(MessageCollector.class); TaskCoordinator mockCoordinator = mock(TaskCoordinator.class); opImpl.onTimer(mockCollector, mockCoordinator); // verify that it updates metrics verify(mockMessageCounter, times(0)).inc(); verify(mockTimer, times(1)).update(anyLong()); }