当前位置: 首页>>代码示例>>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;未经允许,请勿转载。