// Register a worker.long worker1 =mMaster.getWorkerId(NET_ADDRESS_1);mMaster.workerRegister(worker1,ImmutableList.of("MEM"),ImmutableMap.of("MEM",100L),ImmutableMap.of("MEM",10L), NO_BLOCKS_ON_TIERS);// Advance the block master's clock by an hour so that the worker appears lost.mClock.setTimeMs(System.currentTimeMillis() +Constants.HOUR_MS);// Run the lost worker detector.HeartbeatScheduler.await(HeartbeatContext.MASTER_LOST_WORKER_DETECTION,1,TimeUnit.SECONDS);HeartbeatScheduler.schedule(HeartbeatContext.MASTER_LOST_WORKER_DETECTION);HeartbeatScheduler.await(HeartbeatContext.MASTER_LOST_WORKER_DETECTION,1,TimeUnit.SECONDS);
6. 检查类的执行是否正确:
// Make sure the worker is detected as lost.Set<WorkerInfo> info =mMaster.getLostWorkersInfo();Assert.assertEquals(worker1,Iterables.getOnlyElement(info).getId());}
@Testpublicvoidtest() {try (SetAndRestorySystemProperty p =newSetAndRestorySystemProperty("propertyKey","propertyValue")) {// Test something with propertyKey set to propertyValue. }}