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


Java TimerTask.run方法代碼示例

本文整理匯總了Java中java.util.TimerTask.run方法的典型用法代碼示例。如果您正苦於以下問題:Java TimerTask.run方法的具體用法?Java TimerTask.run怎麽用?Java TimerTask.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.TimerTask的用法示例。


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

示例1: testDelayedCondensedExecution

import java.util.TimerTask; //導入方法依賴的package包/類
@Test
public void testDelayedCondensedExecution() throws Exception {
    CondensedQueryExecutor uut = new CondensedQueryExecutor(104, callback, () -> true,
            mockTimer);

    // not yet scheduled anything
    verify(mockTimer, never()).schedule(anyObject(), anyLong());

    uut.trigger();

    // scheduled once
    verify(mockTimer).schedule(anyObject(), eq(104L));

    uut.trigger();
    uut.trigger();
    uut.trigger();
    uut.trigger();
    // still scheduled only once
    verify(mockTimer).schedule(anyObject(), eq(104L));

    TimerTask taskArg = task.getValue();
    taskArg.run();

    // executing must noch change anything for scheduling
    verify(mockTimer).schedule(anyObject(), eq(104L));
    verifyNoMoreInteractions(mockTimer);

    uut.trigger();
    // a second call is scheduled
    verify(mockTimer, times(2)).schedule(anyObject(), eq(104L));

    uut.trigger();
    uut.trigger();
    uut.trigger();
    // no change: second call is scheduled
    verify(mockTimer, times(2)).schedule(anyObject(), eq(104L));

}
 
開發者ID:uweschaefer,項目名稱:factcast,代碼行數:39,代碼來源:CondensedQueryExecutor0Test.java

示例2: testNodeHealthScript

import java.util.TimerTask; //導入方法依賴的package包/類
@Test
public void testNodeHealthScript() throws Exception {
  String errorScript = "echo ERROR\n echo \"Tracker not healthy\"";
  String normalScript = "echo \"I am all fine\"";
  String timeOutScript =
    Shell.WINDOWS ? "@echo off\nping -n 4 127.0.0.1 >nul\necho \"I am fine\""
    : "sleep 4\necho \"I am fine\"";
  Configuration conf = new Configuration();
  writeNodeHealthScriptFile(normalScript, true);
  NodeHealthScriptRunner nodeHealthScriptRunner = new NodeHealthScriptRunner(
          nodeHealthscriptFile.getAbsolutePath(),
          500, 1000, new String[] {});
  nodeHealthScriptRunner.init(conf);
  TimerTask timerTask = nodeHealthScriptRunner.getTimerTask();

  timerTask.run();
  // Normal Script runs successfully
  Assert.assertTrue("Node health status reported unhealthy",
      nodeHealthScriptRunner.isHealthy());
  Assert.assertEquals("", nodeHealthScriptRunner.getHealthReport());

  // Error script.
  writeNodeHealthScriptFile(errorScript, true);
  // Run timer
  timerTask.run();
  Assert.assertFalse("Node health status reported healthy",
      nodeHealthScriptRunner.isHealthy());
  Assert.assertTrue(
      nodeHealthScriptRunner.getHealthReport().contains("ERROR"));
  
  // Healthy script.
  writeNodeHealthScriptFile(normalScript, true);
  timerTask.run();
  Assert.assertTrue("Node health status reported unhealthy",
      nodeHealthScriptRunner.isHealthy());
  Assert.assertEquals("", nodeHealthScriptRunner.getHealthReport());

  // Timeout script.
  writeNodeHealthScriptFile(timeOutScript, true);
  timerTask.run();
  Assert.assertFalse("Node health status reported healthy even after timeout",
  nodeHealthScriptRunner.isHealthy());
  Assert.assertEquals(
          NodeHealthScriptRunner.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG,
          nodeHealthScriptRunner.getHealthReport());
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:47,代碼來源:TestNodeHealthScriptRunner.java


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