Example usage for org.apache.hadoop.yarn.util SystemClock SystemClock

List of usage examples for org.apache.hadoop.yarn.util SystemClock SystemClock

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.util SystemClock SystemClock.

Prototype

@Deprecated
    public SystemClock() 

Source Link

Usage

From source file:org.apache.tez.dag.history.recovery.TestRecoveryService.java

License:Apache License

@Test(timeout = 5000)
public void testRecoveryPathExisted() throws IOException {
    Configuration conf = new Configuration();
    ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    AppContext appContext = mock(AppContext.class);
    when(appContext.getCurrentRecoveryDir()).thenReturn(new Path(TEST_ROOT_DIR));
    when(appContext.getClock()).thenReturn(new SystemClock());
    when(appContext.getHadoopShim()).thenReturn(new DefaultHadoopShim());
    when(appContext.getApplicationID()).thenReturn(appId);

    MockRecoveryService recoveryService = new MockRecoveryService(appContext);
    conf.setBoolean(RecoveryService.TEZ_TEST_RECOVERY_DRAIN_EVENTS_WHEN_STOPPED, true);
    recoveryService.init(conf);/*  w  w  w.j  av  a  2s.co  m*/
    recoveryService.start();
    TezDAGID dagId = TezDAGID.getInstance(ApplicationId.newInstance(System.currentTimeMillis(), 1), 1);
    Path dagRecoveryPath = TezCommonUtils.getDAGRecoveryPath(recoveryService.recoveryPath, dagId.toString());
    touchFile(dagRecoveryPath);
    assertFalse(recoveryService.hasRecoveryFailed());
    recoveryService.handle(new DAGHistoryEvent(dagId,
            new TaskStartedEvent(TezTaskID.getInstance(TezVertexID.getInstance(dagId, 1), 1), "v1", 0L, 0L)));
    // wait for recovery event to be handled
    recoveryService.await();
    assertTrue(recoveryService.hasRecoveryFailed());
    // be able to handle recovery event after fatal error
    recoveryService.handle(new DAGHistoryEvent(dagId,
            new TaskStartedEvent(TezTaskID.getInstance(TezVertexID.getInstance(dagId, 1), 1), "v1", 0L, 0L)));
}