当前位置: 首页>>代码示例>>Java>>正文


Java RepeatingTestThread类代码示例

本文整理汇总了Java中org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread的典型用法代码示例。如果您正苦于以下问题:Java RepeatingTestThread类的具体用法?Java RepeatingTestThread怎么用?Java RepeatingTestThread使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RepeatingTestThread类属于org.apache.hadoop.test.MultithreadedTestUtil包,在下文中一共展示了RepeatingTestThread类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addReplicationTriggerThread

import org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread; //导入依赖的package包/类
/**
 * Add a thread which periodically triggers deletion reports,
 * heartbeats, and NN-side block work.
 * @param interval millisecond period on which to run
 */
public void addReplicationTriggerThread(final int interval) {

  testCtx.addThread(new RepeatingTestThread(testCtx) {
    
    @Override
    public void doAnAction() throws Exception {
      for (DataNode dn : cluster.getDataNodes()) {
        DataNodeTestUtils.triggerDeletionReport(dn);
        DataNodeTestUtils.triggerHeartbeat(dn);
      }
      for (int i = 0; i < 2; i++) {
        NameNode nn = cluster.getNameNode(i);
        BlockManagerTestUtil.computeAllPendingWork(
            nn.getNamesystem().getBlockManager());
      }
      Thread.sleep(interval);
    }
  });
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:HAStressTestHarness.java

示例2: testRepeatingThread

import org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread; //导入依赖的package包/类
@Test
public void testRepeatingThread() throws Exception {
  final AtomicInteger counter = new AtomicInteger();

  TestContext ctx = new TestContext();
  ctx.addThread(new RepeatingTestThread(ctx) {
    @Override
    public void doAnAction() throws Exception {
      counter.incrementAndGet();
    }
  });
  ctx.startThreads();
  long st = Time.now();
  ctx.waitFor(3000);
  ctx.stop();
  long et = Time.now();
  long elapsed = et - st;

  // Test should have waited just about 3 seconds
  assertTrue("Test took " + (et - st) + "ms",
      Math.abs(elapsed - 3000) < 500);
  // Counter should have been incremented lots of times in 3 full seconds
  assertTrue("Counter value = " + counter.get(),
      counter.get() > 1000);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:26,代码来源:TestMultithreadedTestUtil.java

示例3: addFailoverThread

import org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread; //导入依赖的package包/类
/**
 * Add a thread which periodically triggers failover back and forth between
 * the two namenodes.
 */
public void addFailoverThread(final int msBetweenFailovers) {
  testCtx.addThread(new RepeatingTestThread(testCtx) {
    
    @Override
    public void doAnAction() throws Exception {
      System.err.println("==============================\n" +
          "Failing over from 0->1\n" +
          "==================================");
      cluster.transitionToStandby(0);
      cluster.transitionToActive(1);
      
      Thread.sleep(msBetweenFailovers);
      System.err.println("==============================\n" +
          "Failing over from 1->0\n" +
          "==================================");

      cluster.transitionToStandby(1);
      cluster.transitionToActive(0);
      Thread.sleep(msBetweenFailovers);
    }
  });
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:HAStressTestHarness.java

示例4: addFailoverThread

import org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread; //导入依赖的package包/类
/**
 * Add a thread which periodically triggers failover back and forth between the namenodes.
 */
public void addFailoverThread(final int msBetweenFailovers) {
  testCtx.addThread(new RepeatingTestThread(testCtx) {
    @Override
    public void doAnAction() throws Exception {
      // fail over from one namenode to the next, all the way back to the original NN
      for (int i = 0; i < nns; i++) {
        // next node, mod nns so we wrap to the 0th NN on the last iteration
        int next = (i + 1) % nns;
        System.err.println("==============================\n"
            + "[Starting] Failing over from " + i + "->" + next + "\n"
            + "==============================");
        cluster.transitionToStandby(i);
        cluster.transitionToActive(next);
        System.err.println("==============================\n"
            + "[Completed] Failing over from " + i + "->" + next + ". Sleeping for "+
            (msBetweenFailovers/1000) +"sec \n"
            + "==============================");
        Thread.sleep(msBetweenFailovers);
      }
    }
  });
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:26,代码来源:HAStressTestHarness.java

示例5: testTransitionSynchronization

import org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread; //导入依赖的package包/类
/**
 * Regression test for HDFS-2693: when doing state transitions, we need to
 * lock the FSNamesystem so that we don't end up doing any writes while it's
 * "in between" states.
 * This test case starts up several client threads which do mutation operations
 * while flipping a NN back and forth from active to standby.
 */
@Test(timeout=120000)
public void testTransitionSynchronization() throws Exception {
  Configuration conf = new Configuration();
  final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
    .nnTopology(MiniDFSNNTopology.simpleHATopology())
    .numDataNodes(0)
    .build();
  try {
    cluster.waitActive();
    ReentrantReadWriteLock spyLock = NameNodeAdapter.spyOnFsLock(
        cluster.getNameNode(0).getNamesystem());
    Mockito.doAnswer(new GenericTestUtils.SleepAnswer(50))
      .when(spyLock).writeLock();
    
    final FileSystem fs = HATestUtil.configureFailoverFs(
        cluster, conf);
    
    TestContext ctx = new TestContext();
    for (int i = 0; i < 50; i++) {
      final int finalI = i;
      ctx.addThread(new RepeatingTestThread(ctx) {
        @Override
        public void doAnAction() throws Exception {
          Path p = new Path("/test-" + finalI);
          fs.mkdirs(p);
          fs.delete(p, true);
        }
      });
    }
    
    ctx.addThread(new RepeatingTestThread(ctx) {
      @Override
      public void doAnAction() throws Exception {
        cluster.transitionToStandby(0);
        Thread.sleep(50);
        cluster.transitionToActive(0);
      }
    });
    ctx.startThreads();
    ctx.waitFor(20000);
    ctx.stop();
  } finally {
    cluster.shutdown();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:53,代码来源:TestHAStateTransitions.java


注:本文中的org.apache.hadoop.test.MultithreadedTestUtil.RepeatingTestThread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。