Java Code Examples for org.apache.hadoop.hbase.HBaseTestingUtility#waitFor()

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility#waitFor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncReplicationTestBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected final void waitUntilReplicationDone(HBaseTestingUtility util, int end)
    throws Exception {
  // The reject check is in RSRpcService so we can still read through HRegion
  HRegion region = util.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0);
  util.waitFor(30000, new ExplainingPredicate<Exception>() {

    @Override
    public boolean evaluate() throws Exception {
      return !region.get(new Get(Bytes.toBytes(end - 1))).isEmpty();
    }

    @Override
    public String explainFailure() throws Exception {
      return "Replication has not been catched up yet";
    }
  });
}
 
Example 2
Source File: TestRSGroupsOfflineMode.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  TEST_UTIL = new HBaseTestingUtility();
  RSGroupUtil.enableRSGroup(TEST_UTIL.getConfiguration());
  TEST_UTIL.getConfiguration().set(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, "1");
  StartMiniClusterOption option =
    StartMiniClusterOption.builder().numMasters(2).numRegionServers(3).numDataNodes(3).build();
  TEST_UTIL.startMiniCluster(option);
  cluster = TEST_UTIL.getHBaseCluster();
  master = ((MiniHBaseCluster) cluster).getMaster();
  master.balanceSwitch(false);
  hbaseAdmin = TEST_UTIL.getAdmin();
  // wait till the balancer is in online mode
  TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      return master.isInitialized() &&
        ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline() &&
        master.getServerManager().getOnlineServersList().size() >= 3;
    }
  });
}
 
Example 3
Source File: TestRSGroupMajorCompactionTTL.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
  utility = new HBaseTestingUtility();
  Configuration conf = utility.getConfiguration();
  RSGroupUtil.enableRSGroup(conf);
  conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, NUM_SLAVES_BASE);
  conf.setInt("hbase.hfile.compaction.discharger.interval", 10);
  utility.startMiniCluster(NUM_SLAVES_BASE);
  MiniHBaseCluster cluster = utility.getHBaseCluster();
  final HMaster master = cluster.getMaster();

  //wait for balancer to come online
  utility.waitFor(60000, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() {
      return master.isInitialized() &&
          ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline();
    }
  });
  admin = utility.getAdmin();
}
 
Example 4
Source File: SyncReplicationTestBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected final void waitUntilDeleted(HBaseTestingUtility util, Path remoteWAL) throws Exception {
  MasterFileSystem mfs = util.getMiniHBaseCluster().getMaster().getMasterFileSystem();
  util.waitFor(30000, new ExplainingPredicate<Exception>() {

    @Override
    public boolean evaluate() throws Exception {
      return !mfs.getWALFileSystem().exists(remoteWAL);
    }

    @Override
    public String explainFailure() throws Exception {
      return remoteWAL + " has not been deleted yet";
    }
  });
}
 
Example 5
Source File: SecureTestUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private static void updateACLs(final HBaseTestingUtility util, Callable c) throws Exception {
  // Get the current mtimes for all access controllers
  final Map<AccessController,Long> oldMTimes = getAuthManagerMTimes(util.getHBaseCluster());

  // Run the update action
  c.call();

  // Wait until mtimes for all access controllers have incremented
  util.waitFor(WAIT_TIME, 100, new Predicate<IOException>() {
    @Override
    public boolean evaluate() throws IOException {
      Map<AccessController,Long> mtimes = getAuthManagerMTimes(util.getHBaseCluster());
      for (Map.Entry<AccessController,Long> e: mtimes.entrySet()) {
        if (!oldMTimes.containsKey(e.getKey())) {
          LOG.error("Snapshot of AccessController state does not include instance on region " +
            e.getKey().getRegion().getRegionInfo().getRegionNameAsString());
          // Error out the predicate, we will try again
          return false;
        }
        long old = oldMTimes.get(e.getKey());
        long now = e.getValue();
        if (now <= old) {
          LOG.info("AccessController on region " +
            e.getKey().getRegion().getRegionInfo().getRegionNameAsString() +
            " has not updated: mtime=" + now);
          return false;
        }
      }
      return true;
    }
  });
}
 
Example 6
Source File: AssignmentTestingUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void waitForRsToBeDead(final HBaseTestingUtility util,
    final ServerName serverName) throws Exception {
  util.waitFor(60000, new ExplainingPredicate<Exception>() {
    @Override
    public boolean evaluate() {
      return getMaster(util).getServerManager().isServerDead(serverName);
    }

    @Override
    public String explainFailure() {
      return "Server " + serverName + " is not dead";
    }
  });
}
 
Example 7
Source File: SnapshotTestingUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void waitForTableToBeOnline(final HBaseTestingUtility util,
                                          final TableName tableName)
    throws IOException, InterruptedException {
  HRegionServer rs = util.getRSForFirstRegionInTable(tableName);
  List<HRegion> onlineRegions = rs.getRegions(tableName);
  for (HRegion region : onlineRegions) {
    region.waitForFlushesAndCompactions();
  }
  // Wait up to 60 seconds for a table to be available.
  util.waitFor(60000, util.predicateTableAvailable(tableName));
}
 
Example 8
Source File: TestNamespaceAuditor.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void waitForQuotaInitialize(final HBaseTestingUtility util) throws Exception {
  util.waitFor(60000, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      HMaster master = util.getHBaseCluster().getMaster();
      if (master == null) {
        return false;
      }
      MasterQuotaManager quotaManager = master.getMasterQuotaManager();
      return quotaManager != null && quotaManager.isQuotaInitialized();
    }
  });
}
 
Example 9
Source File: UpsertSelectOverlappingBatchesIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
    * Tests that splitting a region is not blocked indefinitely by UPSERT SELECT load
    */
@Test
   public void testSplitDuringUpsertSelect() throws Exception {
       int numUpsertSelectRunners = 4;
       ExecutorService exec = Executors.newFixedThreadPool(numUpsertSelectRunners);
       try (Connection conn = driver.connect(url, props)) {
           final UpsertSelectRunner upsertSelectRunner =
                   new UpsertSelectRunner(dataTable, 0, 105, 1);
           // keep running slow upsert selects
           SlowBatchRegionObserver.SLOW_MUTATE = true;
           for (int i = 0; i < numUpsertSelectRunners; i++) {
               exec.submit(new UpsertSelectLooper(upsertSelectRunner));
               Thread.sleep(300);
           }

           // keep trying to split the region
           final HBaseTestingUtility utility = getUtility();
           final Admin admin = utility.getAdmin();
           final TableName dataTN = TableName.valueOf(dataTable);
           assertEquals(1, utility.getHBaseCluster().getRegions(dataTN).size());
           utility.waitFor(60000L, 1000, new Waiter.Predicate<Exception>() {
               @Override
               public boolean evaluate() throws Exception {
                   try {
                       List<RegionInfo> regions = admin.getRegions(dataTN);
                       if (regions.size() > 1) {
                           LOGGER.info("Found region was split");
                           return true;
                       }
                       if (regions.size() == 0) {
                           // This happens when region in transition or closed
                           LOGGER.info("No region returned");
                           return false;
                       }
                       ;
                       RegionInfo hRegion = regions.get(0);
                       LOGGER.info("Attempting to split region");
                       admin.splitRegionAsync(hRegion.getRegionName(), Bytes.toBytes(2));
                       return false;
                   } catch (NotServingRegionException | DoNotRetryRegionException re) {
                       // during split
                       return false;
                   } 
               }
           });
       } finally {
           SlowBatchRegionObserver.SLOW_MUTATE = false;
           exec.shutdownNow();
           exec.awaitTermination(60, TimeUnit.SECONDS);
       }
   }
 
Example 10
Source File: UpsertSelectOverlappingBatchesIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that UPSERT SELECT doesn't indefinitely block region closes
 */
@Test
public void testRegionCloseDuringUpsertSelect() throws Exception {
    int numUpsertSelectRunners = 4;
    ExecutorService exec = Executors.newFixedThreadPool(numUpsertSelectRunners);
    try (Connection conn = driver.connect(url, props)) {
        final UpsertSelectRunner upsertSelectRunner =
                new UpsertSelectRunner(dataTable, 0, 105, 1);
        // keep running slow upsert selects
        SlowBatchRegionObserver.SLOW_MUTATE = true;
        for (int i = 0; i < numUpsertSelectRunners; i++) {
            exec.submit(new UpsertSelectLooper(upsertSelectRunner));
            Thread.sleep(300);
        }

        final HBaseTestingUtility utility = getUtility();
        // try to close the region while UPSERT SELECTs are happening,
        final HRegionServer dataRs = utility.getHBaseCluster().getRegionServer(0);
        final Admin admin = utility.getAdmin();
        final RegionInfo dataRegion =
                admin.getRegions(TableName.valueOf(dataTable)).get(0);
        LOGGER.info("Closing data table region");
        admin.unassign(dataRegion.getEncodedNameAsBytes(), true);
        // make sure the region is offline
        utility.waitFor(60000L, 1000, new Waiter.Predicate<Exception>() {
            @Override
            public boolean evaluate() throws Exception {
                List<RegionInfo> onlineRegions =
                        admin.getRegions(dataRs.getServerName());
                for (RegionInfo onlineRegion : onlineRegions) {
                    if (onlineRegion.equals(dataRegion)) {
                        LOGGER.info("Data region still online");
                        return false;
                    }
                }
                LOGGER.info("Region is no longer online");
                return true;
            }
        });
    } finally {
        SlowBatchRegionObserver.SLOW_MUTATE = false;
        exec.shutdownNow();
        exec.awaitTermination(60, TimeUnit.SECONDS);
    }
}