當前位置: 首頁>>代碼示例>>Java>>正文


Java Timer類代碼示例

本文整理匯總了Java中org.apache.samza.metrics.Timer的典型用法代碼示例。如果您正苦於以下問題:Java Timer類的具體用法?Java Timer怎麽用?Java Timer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Timer類屬於org.apache.samza.metrics包,在下文中一共展示了Timer類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testOnMessageUpdatesMetrics

import org.apache.samza.metrics.Timer; //導入依賴的package包/類
@Test
public void testOnMessageUpdatesMetrics() {
  TaskContextImpl mockTaskContext = mock(TaskContextImpl.class);
  ReadableMetricsRegistry mockMetricsRegistry = mock(ReadableMetricsRegistry.class);
  when(mockTaskContext.getMetricsRegistry()).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(mock(Config.class), mockTaskContext);

  // 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());
}
 
開發者ID:apache,項目名稱:samza,代碼行數:24,代碼來源:TestOperatorImpl.java

示例2: testOnTimerUpdatesMetrics

import org.apache.samza.metrics.Timer; //導入依賴的package包/類
@Test
public void testOnTimerUpdatesMetrics() {
  TaskContextImpl mockTaskContext = mock(TaskContextImpl.class);
  ReadableMetricsRegistry mockMetricsRegistry = mock(ReadableMetricsRegistry.class);
  when(mockTaskContext.getMetricsRegistry()).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(mock(Config.class), mockTaskContext);

  // 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());
}
 
開發者ID:apache,項目名稱:samza,代碼行數:24,代碼來源:TestOperatorImpl.java

示例3: testNoOpMetricsHappyPath

import org.apache.samza.metrics.Timer; //導入依賴的package包/類
@Test
public void testNoOpMetricsHappyPath() {
  NoOpMetricsRegistry registry = new NoOpMetricsRegistry();
  Counter counter1 = registry.newCounter("testc", "a");
  Counter counter2 = registry.newCounter("testc", "b");
  Counter counter3 = registry.newCounter("testc2", "c");

  Gauge<String> gauge1 = registry.newGauge("testg", "a", "1");
  Gauge<String> gauge2 = registry.newGauge("testg", "b", "2");
  Gauge<String> gauge3 = registry.newGauge("testg", "c", "3");
  Gauge<String> gauge4 = registry.newGauge("testg2", "d", "4");

  Timer timer1 = registry.newTimer("testt", "a");
  Timer timer2 = registry.newTimer("testt", "b");
  Timer timer3 = registry.newTimer("testt2", "c");

  counter1.inc();
  counter2.inc(2);
  counter3.inc(4);

  gauge1.set("5");
  gauge2.set("6");
  gauge3.set("7");
  gauge4.set("8");

  timer1.update(1L);
  timer2.update(2L);
  timer3.update(3L);

  assertEquals(1, counter1.getCount());
  assertEquals(2, counter2.getCount());
  assertEquals(4, counter3.getCount());
  assertEquals("5", gauge1.getValue());
  assertEquals("6", gauge2.getValue());
  assertEquals("7", gauge3.getValue());
  assertEquals("8", gauge4.getValue());
  assertEquals(1, timer1.getSnapshot().getAverage(), 0);
  assertEquals(2, timer2.getSnapshot().getAverage(), 0);
  assertEquals(3, timer3.getSnapshot().getAverage(), 0);
}
 
開發者ID:apache,項目名稱:samza,代碼行數:41,代碼來源:TestNoOpMetricsRegistry.java

示例4: newTimer

import org.apache.samza.metrics.Timer; //導入依賴的package包/類
@Override
public Timer newTimer(String s, String s1) {
    return new Timer(s1);
}
 
開發者ID:redBorder,項目名稱:rb-samza-streaming,代碼行數:5,代碼來源:MockMetricsRegistry.java

示例5: newTimer

import org.apache.samza.metrics.Timer; //導入依賴的package包/類
@Override
public Timer newTimer(String group, String name) {
  return new Timer(name);
}
 
開發者ID:apache,項目名稱:samza,代碼行數:5,代碼來源:NoOpMetricsRegistry.java

示例6: newTimer

import org.apache.samza.metrics.Timer; //導入依賴的package包/類
@Override
public Timer newTimer(String group, String name) {
  return null;
}
 
開發者ID:apache,項目名稱:samza,代碼行數:5,代碼來源:TestMetricsRegistry.java


注:本文中的org.apache.samza.metrics.Timer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。