• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MultithreadedTestUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testTableDisabledRace

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
/**
 * Test that a connection that is aborted while calling isTableDisabled doesn't NPE
 */
@Test
public void testTableDisabledRace() throws Exception {
  final HConnection connection = new HConnectionRaceTester(TEST_UTIL.getConfiguration(), true);
  MultithreadedTestUtil.TestContext ctx =
    new MultithreadedTestUtil.TestContext(TEST_UTIL.getConfiguration());
  RepeatingTestThread disabledChecker = new RepeatingTestThread(ctx) {
    @Override
    public void doAnAction() throws IOException {
      try {
        connection.isTableDisabled(Bytes.toBytes("tableToCheck"));
      } catch (IOException ioe) {
        // Ignore.  ZK can legitimately fail, only care if we get a NullPointerException
      }
    }
  };
  AbortThread abortThread = new AbortThread(ctx, connection);

  ctx.addThread(disabledChecker);
  ctx.addThread(abortThread);
  ctx.startThreads();
  ctx.waitFor(MILLIS_TO_WAIT_FOR_RACE);
  ctx.stop();
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:27,代码来源:TestHConnection.java


示例2: testGetCurrentNrHRSRace

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
/**
 * Test that a connection that is aborted while calling getCurrentNrNRS doesn't NPE
 */
@Test
public void testGetCurrentNrHRSRace() throws Exception {
  final HConnection connection = new HConnectionRaceTester(TEST_UTIL.getConfiguration(), true);
  MultithreadedTestUtil.TestContext ctx =
    new MultithreadedTestUtil.TestContext(TEST_UTIL.getConfiguration());
  RepeatingTestThread getCurrentNrHRSCaller = new RepeatingTestThread(ctx) {
    @Override
    public void doAnAction() throws IOException {
      try {
        connection.getCurrentNrHRS();
      } catch (IOException ioe) {
        // Ignore.  ZK can legitimately fail, only care if we get a NullPointerException
      }
    }
  };
  AbortThread abortThread = new AbortThread(ctx, connection);

  ctx.addThread(getCurrentNrHRSCaller);
  ctx.addThread(abortThread);
  ctx.startThreads();
  ctx.waitFor(MILLIS_TO_WAIT_FOR_RACE);
  ctx.stop();
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:27,代码来源:TestHConnection.java


示例3: testWriteLockExcludesWriters

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
@Test(timeout = 30000)
public void testWriteLockExcludesWriters() throws Exception {
  final String testName = "testWriteLockExcludesWriters";
  final ZKInterProcessReadWriteLock readWriteLock =
      getReadWriteLock(testName);
  List<Future<Void>> results = Lists.newArrayList();
  for (int i = 0; i < NUM_THREADS; ++i) {
    final String threadDesc = testName + i;
    results.add(executor.submit(new Callable<Void>() {
      @Override
      public Void call() throws IOException {
        ZKInterProcessWriteLock writeLock =
            readWriteLock.writeLock(Bytes.toBytes(threadDesc));
        try {
          writeLock.acquire();
          try {
            // No one else should hold the lock
            assertTrue(isLockHeld.compareAndSet(false, true));
            Thread.sleep(1000);
            // No one else should have released the lock
            assertTrue(isLockHeld.compareAndSet(true, false));
          } finally {
            isLockHeld.set(false);
            writeLock.release();
          }
        } catch (InterruptedException e) {
          LOG.warn(threadDesc + " interrupted", e);
          Thread.currentThread().interrupt();
          throw new InterruptedIOException();
        }
        return null;
      }
    }));

  }
  MultithreadedTestUtil.assertOnFutures(results);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:38,代码来源:TestZKInterProcessReadWriteLock.java


示例4: testReadLockDoesNotExcludeReaders

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
@Test(timeout = 30000)
public void testReadLockDoesNotExcludeReaders() throws Exception {
  final String testName = "testReadLockDoesNotExcludeReaders";
  final ZKInterProcessReadWriteLock readWriteLock =
      getReadWriteLock(testName);
  final CountDownLatch locksAcquiredLatch = new CountDownLatch(NUM_THREADS);
  final AtomicInteger locksHeld = new AtomicInteger(0);
  List<Future<Void>> results = Lists.newArrayList();
  for (int i = 0; i < NUM_THREADS; ++i) {
    final String threadDesc = testName + i;
    results.add(executor.submit(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        ZKInterProcessReadLock readLock =
            readWriteLock.readLock(Bytes.toBytes(threadDesc));
        readLock.acquire();
        try {
          locksHeld.incrementAndGet();
          locksAcquiredLatch.countDown();
          Thread.sleep(1000);
        } finally {
          readLock.release();
          locksHeld.decrementAndGet();
        }
        return null;
      }
    }));
  }
  locksAcquiredLatch.await();
  assertEquals(locksHeld.get(), NUM_THREADS);
  MultithreadedTestUtil.assertOnFutures(results);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:33,代码来源:TestZKInterProcessReadWriteLock.java


示例5: testPutAndCheckAndPutInParallel

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
/**
 * Test written as a verifier for HBASE-7051, CheckAndPut should properly read
 * MVCC.
 *
 * Moved into TestAtomicOperation from its original location, TestHBase7051
 */
@Test
public void testPutAndCheckAndPutInParallel() throws Exception {

  final String tableName = "testPutAndCheckAndPut";
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
  final MockHRegion region = (MockHRegion) TEST_UTIL.createLocalHRegion(Bytes.toBytes(tableName),
      null, null, tableName, conf, false, Durability.SYNC_WAL, null, Bytes.toBytes(family));

  Put[] puts = new Put[1];
  Put put = new Put(Bytes.toBytes("r1"));
  put.add(Bytes.toBytes(family), Bytes.toBytes("q1"), Bytes.toBytes("10"));
  puts[0] = put;

  region.batchMutate(puts, HConstants.NO_NONCE, HConstants.NO_NONCE);
  MultithreadedTestUtil.TestContext ctx =
    new MultithreadedTestUtil.TestContext(conf);
  ctx.addThread(new PutThread(ctx, region));
  ctx.addThread(new CheckAndPutThread(ctx, region));
  ctx.startThreads();
  while (testStep != TestStep.CHECKANDPUT_COMPLETED) {
    Thread.sleep(100);
  }
  ctx.stop();
  Scan s = new Scan();
  RegionScanner scanner = region.getScanner(s);
  List<Cell> results = new ArrayList<Cell>();
  ScannerContext scannerContext = ScannerContext.newBuilder().setBatchLimit(2).build();
  scanner.next(results, scannerContext);
  for (Cell keyValue : results) {
    assertEquals("50",Bytes.toString(CellUtil.cloneValue(keyValue)));
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:40,代码来源:TestAtomicOperation.java


示例6: testPutAndCheckAndPutInParallel

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
@Test
public void testPutAndCheckAndPutInParallel() throws Exception {

  final String tableName = "testPutAndCheckAndPut";
  Configuration conf = HBaseConfiguration.create();
  conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
  final MockHRegion region = (MockHRegion) TestHRegion.initHRegion(Bytes.toBytes(tableName),
      tableName, conf, Bytes.toBytes(family));

  List<Pair<Mutation, Integer>> putsAndLocks = Lists.newArrayList();
  Put[] puts = new Put[1];
  Put put = new Put(Bytes.toBytes("r1"));
  put.add(Bytes.toBytes(family), Bytes.toBytes("q1"), Bytes.toBytes("10"));
  puts[0] = put;
  Pair<Mutation, Integer> pair = new Pair<Mutation, Integer>(puts[0], null);

  putsAndLocks.add(pair);

  region.batchMutate(putsAndLocks.toArray(new Pair[0]));
  MultithreadedTestUtil.TestContext ctx =
    new MultithreadedTestUtil.TestContext(conf);
  ctx.addThread(new PutThread(ctx, region));
  ctx.addThread(new CheckAndPutThread(ctx, region));
  ctx.startThreads();
  while (testStep != TestStep.CHECKANDPUT_COMPLETED) {
    Thread.sleep(100);
  }
  ctx.stop();
  Scan s = new Scan();
  RegionScanner scanner = region.getScanner(s);
  List<KeyValue> results = new ArrayList<KeyValue>();
  scanner.next(results, 2);
  for (KeyValue keyValue : results) {
    assertEquals("50",Bytes.toString(keyValue.getValue()));
  }

}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:38,代码来源:TestHBase7051.java


示例7: hammerSingleKey

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
public static void hammerSingleKey(final BlockCache toBeTested,
    int BlockSize, int numThreads, int numQueries) throws Exception {
  final BlockCacheKey key = new BlockCacheKey("key", 0);
  final byte[] buf = new byte[5 * 1024];
  Arrays.fill(buf, (byte) 5);

  final ByteArrayCacheable bac = new ByteArrayCacheable(buf);
  Configuration conf = new Configuration();
  MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(
      conf);

  final AtomicInteger totalQueries = new AtomicInteger();
  toBeTested.cacheBlock(key, bac);

  for (int i = 0; i < numThreads; i++) {
    TestThread t = new MultithreadedTestUtil.RepeatingTestThread(ctx) {
      @Override
      public void doAnAction() throws Exception {
        ByteArrayCacheable returned = (ByteArrayCacheable) toBeTested
            .getBlock(key, false, false);
        assertArrayEquals(buf, returned.buf);
        totalQueries.incrementAndGet();
      }
    };

    t.setDaemon(true);
    ctx.addThread(t);
  }

  ctx.startThreads();
  while (totalQueries.get() < numQueries && ctx.shouldRun()) {
    Thread.sleep(10);
  }
  ctx.stop();
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:36,代码来源:CacheTestUtils.java


示例8: testPutAndCheckAndPutInParallel

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
/**
 * Test written as a verifier for HBASE-7051, CheckAndPut should properly read
 * MVCC. 
 * 
 * Moved into TestAtomicOperation from its original location, TestHBase7051
 */
@Test
public void testPutAndCheckAndPutInParallel() throws Exception {

  final String tableName = "testPutAndCheckAndPut";
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
  final MockHRegion region = (MockHRegion) TEST_UTIL.createLocalHRegion(Bytes.toBytes(tableName),
      null, null, tableName, conf, false, Durability.SYNC_WAL, null, Bytes.toBytes(family));

  Put[] puts = new Put[1];
  Put put = new Put(Bytes.toBytes("r1"));
  put.add(Bytes.toBytes(family), Bytes.toBytes("q1"), Bytes.toBytes("10"));
  puts[0] = put;
  
  region.batchMutate(puts);
  MultithreadedTestUtil.TestContext ctx =
    new MultithreadedTestUtil.TestContext(conf);
  ctx.addThread(new PutThread(ctx, region));
  ctx.addThread(new CheckAndPutThread(ctx, region));
  ctx.startThreads();
  while (testStep != TestStep.CHECKANDPUT_COMPLETED) {
    Thread.sleep(100);
  }
  ctx.stop();
  Scan s = new Scan();
  RegionScanner scanner = region.getScanner(s);
  List<Cell> results = new ArrayList<Cell>();
  scanner.next(results, 2);
  for (Cell keyValue : results) {
    assertEquals("50",Bytes.toString(CellUtil.cloneValue(keyValue)));
  }

}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:40,代码来源:TestAtomicOperation.java


示例9: hammerSingleKey

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
public static void hammerSingleKey(final BlockCache toBeTested,
    int BlockSize, int numThreads, int numQueries) throws Exception {
  final BlockCacheKey key = new BlockCacheKey("key", 0);
  final byte[] buf = new byte[5 * 1024];
  Arrays.fill(buf, (byte) 5);

  final ByteArrayCacheable bac = new ByteArrayCacheable(buf);
  Configuration conf = new Configuration();
  MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(
      conf);

  final AtomicInteger totalQueries = new AtomicInteger();
  toBeTested.cacheBlock(key, bac);

  for (int i = 0; i < numThreads; i++) {
    TestThread t = new MultithreadedTestUtil.RepeatingTestThread(ctx) {
      @Override
      public void doAnAction() throws Exception {
        ByteArrayCacheable returned = (ByteArrayCacheable) toBeTested
            .getBlock(key, false, false, true);
        assertArrayEquals(buf, returned.buf);
        totalQueries.incrementAndGet();
      }
    };

    t.setDaemon(true);
    ctx.addThread(t);
  }

  ctx.startThreads();
  while (totalQueries.get() < numQueries && ctx.shouldRun()) {
    Thread.sleep(10);
  }
  ctx.stop();
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:36,代码来源:CacheTestUtils.java


示例10: testPutAndCheckAndPutInParallel

import org.apache.hadoop.hbase.MultithreadedTestUtil; //导入依赖的package包/类
/**
 * Test written as a verifier for HBASE-7051, CheckAndPut should properly read
 * MVCC.
 *
 * Moved into TestAtomicOperation from its original location, TestHBase7051
 */
@Test
public void testPutAndCheckAndPutInParallel() throws Exception {
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()))
      .addFamily(new HColumnDescriptor(family));
  this.region = TEST_UTIL.createLocalHRegion(htd, null, null);
  Put[] puts = new Put[1];
  Put put = new Put(Bytes.toBytes("r1"));
  put.addColumn(Bytes.toBytes(family), Bytes.toBytes("q1"), Bytes.toBytes("10"));
  puts[0] = put;

  region.batchMutate(puts, HConstants.NO_NONCE, HConstants.NO_NONCE);
  MultithreadedTestUtil.TestContext ctx =
    new MultithreadedTestUtil.TestContext(conf);
  ctx.addThread(new PutThread(ctx, region));
  ctx.addThread(new CheckAndPutThread(ctx, region));
  ctx.startThreads();
  while (testStep != TestStep.CHECKANDPUT_COMPLETED) {
    Thread.sleep(100);
  }
  ctx.stop();
  Scan s = new Scan();
  RegionScanner scanner = region.getScanner(s);
  List<Cell> results = new ArrayList<>();
  ScannerContext scannerContext = ScannerContext.newBuilder().setBatchLimit(2).build();
  scanner.next(results, scannerContext);
  for (Cell keyValue : results) {
    assertEquals("50",Bytes.toString(CellUtil.cloneValue(keyValue)));
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:38,代码来源:TestAtomicOperation.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JWSObject类代码示例发布时间:2022-05-21
下一篇:
Java MaterialRefreshListener类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap