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


Java TestContext.waitFor方法代码示例

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


在下文中一共展示了TestContext.waitFor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNoErrors

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的package包/类
@Test
public void testNoErrors() throws Exception {
  final AtomicInteger threadsRun = new AtomicInteger();

  TestContext ctx = new TestContext();
  for (int i = 0; i < 3; i++) {
    ctx.addThread(new TestingThread(ctx) {
      @Override
      public void doWork() throws Exception {
        threadsRun.incrementAndGet();
      }
    });
  }
  assertEquals(0, threadsRun.get());
  ctx.startThreads();
  long st = Time.now();
  ctx.waitFor(30000);
  long et = Time.now();

  // All threads should have run
  assertEquals(3, threadsRun.get());
  // Test shouldn't have waited the full 30 seconds, since
  // the threads exited faster than that.
  assertTrue("Test took " + (et - st) + "ms",
      et - st < 5000);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:27,代码来源:TestMultithreadedTestUtil.java

示例2: testThreadFails

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的package包/类
@Test
public void testThreadFails() throws Exception {
  TestContext ctx = new TestContext();
  ctx.addThread(new TestingThread(ctx) {
    @Override
    public void doWork() throws Exception {
      fail(FAIL_MSG);
    }
  });
  ctx.startThreads();
  long st = Time.now();
  try {
    ctx.waitFor(30000);
    fail("waitFor did not throw");
  } catch (RuntimeException rte) {
    // expected
    assertEquals(FAIL_MSG, rte.getCause().getMessage());
  }
  long et = Time.now();
  // Test shouldn't have waited the full 30 seconds, since
  // the thread throws faster than that
  assertTrue("Test took " + (et - st) + "ms",
      et - st < 5000);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:25,代码来源:TestMultithreadedTestUtil.java

示例3: testThreadThrowsCheckedException

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的package包/类
@Test
public void testThreadThrowsCheckedException() throws Exception {
  TestContext ctx = new TestContext();
  ctx.addThread(new TestingThread(ctx) {
    @Override
    public void doWork() throws Exception {
      throw new IOException("my ioe");
    }
  });
  ctx.startThreads();
  long st = Time.now();
  try {
    ctx.waitFor(30000);
    fail("waitFor did not throw");
  } catch (RuntimeException rte) {
    // expected
    assertEquals("my ioe", rte.getCause().getMessage());
  }
  long et = Time.now();
  // Test shouldn't have waited the full 30 seconds, since
  // the thread throws faster than that
  assertTrue("Test took " + (et - st) + "ms",
      et - st < 5000);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:25,代码来源:TestMultithreadedTestUtil.java

示例4: testRepeatingThread

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的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

示例5: test

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
  TestContext flippers = new TestContext();
  flippers.addThread(new FailoverThread(flippers));
  TestContext submitters = new TestContext();
  for (int i = 0; i < NUM_THREADS; i++) {
    submitters.addThread(new JobSubmitterThread(submitters, conf));
  }
  flippers.startThreads();
  submitters.startThreads();
  submitters.waitFor(RUNTIME);
  submitters.stop();
  flippers.stop();
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:15,代码来源:TestHAStress.java

示例6: testPipelineRecoveryStress

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的package包/类
/**
 * Stress test for pipeline/lease recovery. Starts a number of
 * threads, each of which creates a file and has another client
 * break the lease. While these threads run, failover proceeds
 * back and forth between two namenodes.
 */
@Test(timeout=STRESS_RUNTIME*3)
public void testPipelineRecoveryStress() throws Exception {
  HAStressTestHarness harness = new HAStressTestHarness();
  // Disable permissions so that another user can recover the lease.
  harness.conf.setBoolean(
      DFSConfigKeys.DFS_PERMISSIONS_ENABLED_KEY, false);
  // This test triggers rapid NN failovers.  The client retry policy uses an
  // exponential backoff.  This can quickly lead to long sleep times and even
  // timeout the whole test.  Cap the sleep time at 1s to prevent this.
  harness.conf.setInt(DFSConfigKeys.DFS_CLIENT_FAILOVER_SLEEPTIME_MAX_KEY,
    1000);

  final MiniDFSCluster cluster = harness.startCluster();
  try {
    cluster.waitActive();
    cluster.transitionToActive(0);
    
    FileSystem fs = harness.getFailoverFs();
    DistributedFileSystem fsAsOtherUser = createFsAsOtherUser(
        cluster, harness.conf);
    
    TestContext testers = new TestContext();
    for (int i = 0; i < STRESS_NUM_THREADS; i++) {
      Path p = new Path("/test-" + i);
      testers.addThread(new PipelineTestThread(
          testers, fs, fsAsOtherUser, p));
    }
    
    // Start a separate thread which will make sure that replication
    // happens quickly by triggering deletion reports and replication
    // work calculation frequently.
    harness.addReplicationTriggerThread(500);
    harness.addFailoverThread(5000);
    harness.startThreads();
    testers.startThreads();
    
    testers.waitFor(STRESS_RUNTIME);
    testers.stop();
    harness.stopThreads();
  } finally {
    System.err.println("===========================\n\n\n\n");
    harness.shutdown();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:51,代码来源:TestPipelinesFailover.java

示例7: testTransitionSynchronization

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的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

示例8: testPipelineRecoveryStress

import org.apache.hadoop.test.MultithreadedTestUtil.TestContext; //导入方法依赖的package包/类
/**
 * Stress test for pipeline/lease recovery. Starts a number of
 * threads, each of which creates a file and has another client
 * break the lease. While these threads run, failover proceeds
 * back and forth between two namenodes.
 */
@Test(timeout=STRESS_RUNTIME*3)
public void testPipelineRecoveryStress() throws Exception {

  // The following section of code is to help debug HDFS-6694 about
  // this test that fails from time to time due to "too many open files".
  //
  LOG.info("HDFS-6694 Debug Data BEGIN");

  String[][] scmds = new String[][] {
    {"/bin/sh", "-c", "ulimit -a"},
    {"hostname"},
    {"ifconfig", "-a"}
  };

  for (String[] scmd: scmds) {
    String scmd_str = StringUtils.join(" ", scmd);
    try {
      ShellCommandExecutor sce = new ShellCommandExecutor(scmd);
      sce.execute();
      LOG.info("'" + scmd_str + "' output:\n" + sce.getOutput());
    } catch (IOException e) {
      LOG.warn("Error when running '" + scmd_str + "'", e);
    }
  }

  LOG.info("HDFS-6694 Debug Data END");

  HAStressTestHarness harness = new HAStressTestHarness();
  // Disable permissions so that another user can recover the lease.
  harness.conf.setBoolean(
      DFSConfigKeys.DFS_PERMISSIONS_ENABLED_KEY, false);
  // This test triggers rapid NN failovers.  The client retry policy uses an
  // exponential backoff.  This can quickly lead to long sleep times and even
  // timeout the whole test.  Cap the sleep time at 1s to prevent this.
  harness.conf.setInt(HdfsClientConfigKeys.Failover.SLEEPTIME_MAX_KEY, 1000);

  final MiniDFSCluster cluster = harness.startCluster();
  try {
    cluster.waitActive();
    cluster.transitionToActive(0);
    
    FileSystem fs = harness.getFailoverFs();
    DistributedFileSystem fsAsOtherUser = createFsAsOtherUser(
        cluster, harness.conf);
    
    TestContext testers = new TestContext();
    for (int i = 0; i < STRESS_NUM_THREADS; i++) {
      Path p = new Path("/test-" + i);
      testers.addThread(new PipelineTestThread(
          testers, fs, fsAsOtherUser, p));
    }
    
    // Start a separate thread which will make sure that replication
    // happens quickly by triggering deletion reports and replication
    // work calculation frequently.
    harness.addReplicationTriggerThread(500);
    harness.addFailoverThread(5000);
    harness.startThreads();
    testers.startThreads();
    
    testers.waitFor(STRESS_RUNTIME);
    testers.stop();
    harness.stopThreads();
  } finally {
    System.err.println("===========================\n\n\n\n");
    harness.shutdown();
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:75,代码来源:TestPipelinesFailover.java


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