Example #1
0
      @Override
      public void run() {
        while (!isStopped()) {
          try {
            List<HRegionInfo> regions =
                MetaScanner.listAllRegions(TEST_UTIL.getConfiguration(), connection, false);

            // select a random region
            HRegionInfo parent = regions.get(random.nextInt(regions.size()));
            if (parent == null || !TABLENAME.equals(parent.getTable())) {
              continue;
            }

            long startKey = 0, endKey = Long.MAX_VALUE;
            byte[] start = parent.getStartKey();
            byte[] end = parent.getEndKey();
            if (!Bytes.equals(HConstants.EMPTY_START_ROW, parent.getStartKey())) {
              startKey = Bytes.toLong(parent.getStartKey());
            }
            if (!Bytes.equals(HConstants.EMPTY_END_ROW, parent.getEndKey())) {
              endKey = Bytes.toLong(parent.getEndKey());
            }
            if (startKey == endKey) {
              continue;
            }

            long midKey =
                BigDecimal.valueOf(startKey)
                    .add(BigDecimal.valueOf(endKey))
                    .divideToIntegralValue(BigDecimal.valueOf(2))
                    .longValue();

            HRegionInfo splita = new HRegionInfo(TABLENAME, start, Bytes.toBytes(midKey));
            HRegionInfo splitb = new HRegionInfo(TABLENAME, Bytes.toBytes(midKey), end);

            MetaTableAccessor.splitRegion(
                connection, parent, splita, splitb, ServerName.valueOf("fooserver", 1, 0));

            Threads.sleep(random.nextInt(200));
          } catch (Throwable e) {
            ex = e;
            Assert.fail(StringUtils.stringifyException(e));
          }
        }
      }
 @Before
 public void beforeMethod() throws Exception {
   if (!initialized) {
     LOG.info("Setting up IntegrationTestGroup");
     LOG.info("Initializing cluster with " + NUM_SLAVES_BASE + " servers");
     TEST_UTIL = new IntegrationTestingUtility();
     ((IntegrationTestingUtility) TEST_UTIL).initializeCluster(NUM_SLAVES_BASE);
     // set shared configs
     admin = TEST_UTIL.getAdmin();
     cluster = TEST_UTIL.getHBaseClusterInterface();
     rsGroupAdmin =
         new VerifyingRSGroupAdminClient(
             rsGroupAdmin.newClient(TEST_UTIL.getConnection()), TEST_UTIL.getConfiguration());
     LOG.info("Done initializing cluster");
     initialized = true;
     // cluster may not be clean
     // cleanup when initializing
     afterMethod();
   }
 }