Java Code Examples for org.apache.hadoop.hbase.HBaseTestingUtility

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility. These examples are extracted from open source projects. 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 Project: hbase   Source File: FlushTableAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getAdmin();

  // Don't try the flush if we're stopping
  if (context.isStopping()) {
    return;
  }

  getLogger().info("Performing action: Flush table " + tableName);
  try {
    admin.flush(tableName);
  } catch (Exception ex) {
    getLogger().warn("Flush failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 2
Source Project: hbase   Source File: TestReadAndWriteRegionInfoFile.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testReadAndWriteRegionInfoFile() throws IOException, InterruptedException {
  RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
  // Create a region. That'll write the .regioninfo file.
  FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(FS, ROOT_DIR);
  FSTableDescriptors.tryUpdateMetaTableDescriptor(CONF, FS, ROOT_DIR, null);
  HRegion r = HBaseTestingUtility.createRegionAndWAL(ri, ROOT_DIR, CONF,
    fsTableDescriptors.get(TableName.META_TABLE_NAME));
  // Get modtime on the file.
  long modtime = getModTime(r);
  HBaseTestingUtility.closeRegionAndWAL(r);
  Thread.sleep(1001);
  r = HRegion.openHRegion(ROOT_DIR, ri, fsTableDescriptors.get(TableName.META_TABLE_NAME), null,
    CONF);
  // Ensure the file is not written for a second time.
  long modtime2 = getModTime(r);
  assertEquals(modtime, modtime2);
  // Now load the file.
  HRegionFileSystem.loadRegionInfoFileContent(r.getRegionFileSystem().getFileSystem(),
    r.getRegionFileSystem().getRegionDir());
  HBaseTestingUtility.closeRegionAndWAL(r);
}
 
Example 3
Source Project: hbase   Source File: SecureTestUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Revoke permissions on a namespace from the given user. Will wait until all active
 * AccessController instances have updated their permissions caches or will
 * throw an exception upon timeout (10 seconds).
 */
public static void revokeFromNamespace(final User caller, final HBaseTestingUtility util,
    final String user, final String namespace,
    final Permission.Action... actions) throws Exception {
  SecureTestUtil.updateACLs(util, new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      Configuration conf = util.getConfiguration();
      try (Connection connection = ConnectionFactory.createConnection(conf, caller)) {
        connection.getAdmin().revoke(new UserPermission(user,
            Permission.newBuilder(namespace).withActions(actions).build()));
      }
      return null;
    }
  });
}
 
Example 4
Source Project: hbase   Source File: CompactTableAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getAdmin();
  boolean major = RandomUtils.nextInt(0, 100) < majorRatio;

  getLogger().info("Performing action: Compact table " + tableName + ", major=" + major);
  try {
    if (major) {
      admin.majorCompact(tableName);
    } else {
      admin.compact(tableName);
    }
  } catch (Exception ex) {
    getLogger().warn("Compaction failed, might be caused by other chaos: " + ex.getMessage());
  }
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
}
 
Example 5
Source Project: hbase   Source File: TestMemStoreSegmentsIterator.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
  Configuration conf = new Configuration();
  HBaseTestingUtility hbaseUtility = new HBaseTestingUtility(conf);
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(FAMILY)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);

  RegionInfo info = RegionInfoBuilder.newBuilder(TableName.valueOf(TABLE)).build();
  Path rootPath = hbaseUtility.getDataTestDir(ROOT_SUB_PATH);
  this.wal = HBaseTestingUtility.createWal(conf, rootPath, info);
  this.region = HRegion.createHRegion(info, rootPath, conf,
    tableDescriptorBuilder.build(), this.wal, true);
  this.store = new HStore(this.region, columnFamilyDescriptor, conf, false);
  this.comparator = CellComparator.getInstance();
  this.compactionKVMax = HConstants.COMPACTION_KV_MAX_DEFAULT;
}
 
Example 6
Source Project: phoenix   Source File: RebuildIndexConnectionPropsIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static synchronized void doSetup() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    hbaseTestUtil = new HBaseTestingUtility(conf);
    Map<String, String> serverProps = new HashMap<>();
    serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    // need at least one retry otherwise test fails
    serverProps.put(QueryServices.INDEX_REBUILD_RPC_RETRIES_COUNTER, Long.toString(NUM_RPC_RETRIES));
    setUpConfigForMiniCluster(conf, new ReadOnlyProps(serverProps.entrySet().iterator()));
    hbaseTestUtil.startMiniCluster();
    // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;
    Properties driverProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
    try (PhoenixConnection phxConn =
            DriverManager.getConnection(url, driverProps).unwrap(PhoenixConnection.class)) {
    }
}
 
Example 7
Source Project: hbase   Source File: TestRSGroupMajorCompactionTTL.java    License: 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 8
Source Project: hbase   Source File: TestBucketCache.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRetrieveFromMultipleFiles() throws Exception {
  final Path testDirInitial = createAndGetTestDir();
  final Path newTestDir = new HBaseTestingUtility().getDataTestDir();
  HBASE_TESTING_UTILITY.getTestFileSystem().mkdirs(newTestDir);
  String ioEngineName = new StringBuilder("files:").append(testDirInitial)
          .append("/bucket1.cache").append(FileIOEngine.FILE_DELIMITER).append(newTestDir)
          .append("/bucket2.cache").toString();
  testRetrievalUtils(testDirInitial, ioEngineName);
  int[] smallBucketSizes = new int[]{3 * 1024, 5 * 1024};
  String persistencePath = testDirInitial + "/bucket.persistence";
  BucketCache bucketCache = new BucketCache(ioEngineName, capacitySize, constructedBlockSize,
          smallBucketSizes, writeThreads, writerQLen, persistencePath);
  assertFalse(new File(persistencePath).exists());
  assertEquals(0, bucketCache.getAllocator().getUsedSize());
  assertEquals(0, bucketCache.backingMap.size());
  HBASE_TESTING_UTILITY.cleanupTestDir();
}
 
Example 9
Source Project: phoenix   Source File: ContextClassloaderIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static synchronized void setUpBeforeClass() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    setUpConfigForMiniCluster(conf);
    hbaseTestUtil = new HBaseTestingUtility(conf);
    hbaseTestUtil.startMiniCluster();
    String clientPort = hbaseTestUtil.getConfiguration().get(QueryServices.ZOOKEEPER_PORT_ATTRIB);
    String url = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR + clientPort
            + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM;
    driver = initAndRegisterTestDriver(url, ReadOnlyProps.EMPTY_PROPS);
    
    Connection conn = DriverManager.getConnection(url);
    Statement stmt = conn.createStatement();
    stmt.execute("CREATE TABLE test (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR)");
    stmt.execute("UPSERT INTO test VALUES (1, 'name1')");
    stmt.execute("UPSERT INTO test VALUES (2, 'name2')");
    stmt.close();
    conn.commit();
    conn.close();
    badContextClassloader = new URLClassLoader(new URL[] {
            File.createTempFile("invalid", ".jar").toURI().toURL() }, null);
}
 
Example 10
Source Project: hbase   Source File: TestEnableTable.java    License: Apache License 2.0 6 votes vote down vote up
public static void createTable(HBaseTestingUtility testUtil,
    TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor, byte [][] splitKeys)
    throws Exception {
  // NOTE: We need a latch because admin is not sync,
  // so the postOp coprocessor method may be called after the admin operation returned.
  MasterSyncObserver observer = testUtil.getHBaseCluster().getMaster()
    .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class);
  observer.tableCreationLatch = new CountDownLatch(1);
  Admin admin = testUtil.getAdmin();
  if (splitKeys != null) {
    admin.createTable(tableDescriptor, splitKeys);
  } else {
    admin.createTable(tableDescriptor);
  }
  observer.tableCreationLatch.await();
  observer.tableCreationLatch = null;
  testUtil.waitUntilAllRegionsAssigned(tableDescriptor.getTableName());
}
 
Example 11
Source Project: hbase   Source File: SyncReplicationTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected static void initTestingUtility(HBaseTestingUtility util, String zkParent) {
  util.setZkCluster(ZK_UTIL.getZkCluster());
  Configuration conf = util.getConfiguration();
  conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, zkParent);
  conf.setInt("replication.source.size.capacity", 102400);
  conf.setLong("replication.source.sleepforretries", 100);
  conf.setInt("hbase.regionserver.maxlogs", 10);
  conf.setLong("hbase.master.logcleaner.ttl", 10);
  conf.setInt("zookeeper.recovery.retry", 1);
  conf.setInt("zookeeper.recovery.retry.intervalmill", 10);
  conf.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100);
  conf.setInt("replication.stats.thread.period.seconds", 5);
  conf.setBoolean("hbase.tests.use.shortcircuit.reads", false);
  conf.setLong("replication.sleep.before.failover", 2000);
  conf.setInt("replication.source.maxretriesmultiplier", 10);
  conf.setFloat("replication.source.ratio", 1.0f);
  conf.setBoolean("replication.source.eof.autorecovery", true);
}
 
Example 12
Source Project: hbase   Source File: TestRegionObserverScannerOpenHook.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionObserverFlushTimeStacking() throws Exception {
  byte[] ROW = Bytes.toBytes("testRow");
  byte[] TABLE = Bytes.toBytes(getClass().getName());
  byte[] A = Bytes.toBytes("A");
  byte[][] FAMILIES = new byte[][] { A };

  // Use new HTU to not overlap with the DFS cluster started in #CompactionStacking
  Configuration conf = new HBaseTestingUtility().getConfiguration();
  HRegion region = initHRegion(TABLE, getClass().getName(), conf, FAMILIES);
  RegionCoprocessorHost h = region.getCoprocessorHost();
  h.load(NoDataFromFlush.class, Coprocessor.PRIORITY_HIGHEST, conf);
  h.load(EmptyRegionObsever.class, Coprocessor.PRIORITY_USER, conf);

  // put a row and flush it to disk
  Put put = new Put(ROW);
  put.addColumn(A, A, A);
  region.put(put);
  region.flush(true);
  Get get = new Get(ROW);
  Result r = region.get(get);
  assertNull(
    "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: "
        + r, r.listCells());
  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 13
Source Project: hbase   Source File: TestAccessControlFilter.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws Exception {
  TEST_UTIL = new HBaseTestingUtility();
  Configuration conf = TEST_UTIL.getConfiguration();
  // Up the handlers; this test needs more than usual.
  conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 10);
  enableSecurity(conf);
  verifyConfiguration(conf);

  // We expect 0.98 scanning semantics
  conf.setBoolean(AccessControlConstants.CF_ATTRIBUTE_EARLY_OUT, false);

  TEST_UTIL.startMiniCluster();
  TEST_UTIL.waitTableEnabled(PermissionStorage.ACL_TABLE_NAME.getName(), 50000);

  READER = User.createUserForTesting(conf, "reader", new String[0]);
  LIMITED = User.createUserForTesting(conf, "limited", new String[0]);
  DENIED = User.createUserForTesting(conf, "denied", new String[0]);
}
 
Example 14
Source Project: hbase   Source File: TestScanner.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests to do a sync flush during the middle of a scan. This is testing the StoreScanner
 * update readers code essentially.  This is not highly concurrent, since its all 1 thread.
 * HBase-910.
 */
@Test
public void testScanAndSyncFlush() throws Exception {
  this.region = TEST_UTIL.createLocalHRegion(TESTTABLEDESC, null, null);
  Table hri = new RegionAsTable(region);
  try {
    LOG.info("Added: " +
      HTestConst.addContent(hri, Bytes.toString(HConstants.CATALOG_FAMILY),
        Bytes.toString(HConstants.REGIONINFO_QUALIFIER)));
    int count = count(hri, -1, false);
    assertEquals(count, count(hri, 100, false)); // do a sync flush.
  } catch (Exception e) {
    LOG.error("Failed", e);
    throw e;
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(this.region);
  }
}
 
Example 15
Source Project: hbase   Source File: TestRegionLocationFinder.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  cluster = TEST_UTIL.startMiniCluster(ServerNum);
  table = TEST_UTIL.createTable(tableName, FAMILY, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
  TEST_UTIL.waitTableAvailable(tableName, 1000);
  TEST_UTIL.loadTable(table, FAMILY);

  for (int i = 0; i < ServerNum; i++) {
    HRegionServer server = cluster.getRegionServer(i);
    for (HRegion region : server.getRegions(tableName)) {
      region.flush(true);
    }
  }

  finder.setConf(TEST_UTIL.getConfiguration());
  finder.setServices(cluster.getMaster());
  finder.setClusterMetrics(cluster.getMaster().getClusterMetrics());
}
 
Example 16
Source Project: hbase   Source File: TestSyncReplicationActive.java    License: Apache License 2.0 6 votes vote down vote up
private void verifyNoClusterIdInRemoteLog(HBaseTestingUtility utility, Path remoteDir,
    String peerId) throws Exception {
  FileSystem fs2 = utility.getTestFileSystem();
  FileStatus[] files = fs2.listStatus(new Path(remoteDir, peerId));
  Assert.assertTrue(files.length > 0);
  for (FileStatus file : files) {
    try (
      Reader reader = WALFactory.createReader(fs2, file.getPath(), utility.getConfiguration())) {
      Entry entry = reader.next();
      Assert.assertTrue(entry != null);
      while (entry != null) {
        Assert.assertEquals(entry.getKey().getClusterIds().size(), 0);
        entry = reader.next();
      }
    }
  }
}
 
Example 17
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf1.set(ZOOKEEPER_ZNODE_PARENT, "/1");
  conf1.setInt("replication.source.nb.capacity", 1);
  utility1 = new HBaseTestingUtility(conf1);
  utility1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = utility1.getZkCluster();
  conf1 = utility1.getConfiguration();

  conf2 = HBaseConfiguration.create(conf1);
  conf2.set(ZOOKEEPER_ZNODE_PARENT, "/2");
  utility2 = new HBaseTestingUtility(conf2);
  utility2.setZkCluster(miniZK);

  utility1.startMiniCluster(1);
  utility2.startMiniCluster(1);

  admin1 = utility1.getAdmin();
  admin2 = utility2.getAdmin();
}
 
Example 18
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
  conf1.setInt("replication.source.nb.capacity", 1);
  utility1 = new HBaseTestingUtility(conf1);
  utility1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = utility1.getZkCluster();
  conf1 = utility1.getConfiguration();

  conf2 = HBaseConfiguration.create(conf1);
  conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
  utility2 = new HBaseTestingUtility(conf2);
  utility2.setZkCluster(miniZK);

  utility1.startMiniCluster(1);
  utility2.startMiniCluster(1);

  admin1 = utility1.getAdmin();
  admin2 = utility2.getAdmin();
}
 
Example 19
Source Project: hbase   Source File: TestReplicationKillRS.java    License: Apache License 2.0 6 votes vote down vote up
private static Thread killARegionServer(final HBaseTestingUtility utility, final long timeout,
    final int rs) {
  Thread killer = new Thread() {
    @Override
    public void run() {
      try {
        Thread.sleep(timeout);
        utility.getHBaseCluster().getRegionServer(rs).stop("Stopping as part of the test");
      } catch (Exception e) {
        LOG.error("Couldn't kill a region server", e);
      }
    }
  };
  killer.setDaemon(true);
  killer.start();
  return killer;
}
 
Example 20
Source Project: hbase   Source File: AbstractTestUpdateConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
protected static void addResourceToRegionServerConfiguration(final HBaseTestingUtility testUtil) {
  // When RegionServer is created in MiniHBaseCluster, it uses HBaseConfiguration.create(conf) of
  // the master Configuration. The create() just copies config params over, it does not do
  // a clone for a historic reason. Properties such as resources are lost during this process.
  // Exposing a new method in HBaseConfiguration causes confusion. Instead, the new hbase-site.xml
  // under test-data directory is added to RegionServer's configuration as a workaround.
  for (RegionServerThread rsThread : testUtil.getMiniHBaseCluster().getRegionServerThreads()) {
    rsThread.getRegionServer().getConfiguration().addResource(
      testUtil.getDataTestDir(SERVER_CONFIG));
  }
}
 
Example 21
Source Project: phoenix-omid   Source File: TestSnapshotFilterLL.java    License: Apache License 2.0 5 votes vote down vote up
private void setupHBase() throws Exception {
    LOG.info("--------------------------------------------------------------------------------------------------");
    LOG.info("Setting up HBase");
    LOG.info("--------------------------------------------------------------------------------------------------");
    hbaseTestUtil = new HBaseTestingUtility(hbaseConf);
    LOG.info("--------------------------------------------------------------------------------------------------");
    LOG.info("Creating HBase MiniCluster");
    LOG.info("--------------------------------------------------------------------------------------------------");
    hbaseCluster = hbaseTestUtil.startMiniCluster(1);
}
 
Example 22
Source Project: hbase   Source File: TestGetReplicationLoad.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startCluster() throws Exception {
  LOG.info("Starting cluster");
  TEST_UTIL = new HBaseTestingUtility();
  // Set master class and use default values for other options.
  StartMiniClusterOption option = StartMiniClusterOption.builder()
      .masterClass(TestMasterMetrics.MyMaster.class).build();
  TEST_UTIL.startMiniCluster(option);
  cluster = TEST_UTIL.getHBaseCluster();
  LOG.info("Waiting for active/ready master");
  cluster.waitForActiveAndReadyMaster();
  master = cluster.getMaster();
}
 
Example 23
Source Project: hbase   Source File: SecureTestUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Revoke permissions on a table from the given user. Will wait until all active
 * AccessController instances have updated their permissions caches or will
 * throw an exception upon timeout (10 seconds).
 */
public static void revokeFromTable(final HBaseTestingUtility util, final String user,
    final TableName table, final byte[] family, final byte[] qualifier,
    final Permission.Action... actions) throws Exception {
  SecureTestUtil.updateACLs(util, new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      try (Connection connection = ConnectionFactory.createConnection(util.getConfiguration())) {
        connection.getAdmin().revoke(new UserPermission(user, Permission.newBuilder(table)
            .withFamily(family).withQualifier(qualifier).withActions(actions).build()));
      }
      return null;
    }
  });
}
 
Example 24
Source Project: hbase   Source File: AbstractTestUpdateConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
protected static void setUpConfigurationFiles(final HBaseTestingUtility testUtil)
  throws Exception {
  // Before this change, the test will update hbase-site.xml under target/test-classes and
  // trigger a config reload. Since target/test-classes/hbase-site.xml is being used by
  // other testing cases at the same time, this update will break other testing cases so it will
  // be flakey in nature.
  // To avoid this, the change is to make target/test-classes/hbase-site.xml immutable. A new
  // hbase-site.xml will be created under its test data directory, i.e,
  // hbase-server/target/test-data/UUID, this new file will be added as a resource for the
  // config, new update will be applied to this new file and only visible to this specific test
  // case. The target/test-classes/hbase-site.xml will not be changed during the test.

  String absoluteDataPath = testUtil.getDataTestDir().toString();

  // Create test-data directories.
  Files.createDirectories(Paths.get(absoluteDataPath));

  // Copy hbase-site.xml from target/test-class to target/test-data/UUID directory.
  Path configFile = Paths.get("target", "test-classes", SERVER_CONFIG);
  configFileUnderTestDataDir = Paths.get(absoluteDataPath, SERVER_CONFIG);
  Files.copy(configFile, configFileUnderTestDataDir);

  // Copy override config file overrider-hbase-site.xml from target/test-class to
  // target/test-data/UUID directory.
  Path overrideConfigFile = Paths.get("target", "test-classes",
    OVERRIDE_SERVER_CONFIG);
  overrideConfigFileUnderTestDataDir = Paths.get(absoluteDataPath, OVERRIDE_SERVER_CONFIG);
  Files.copy(overrideConfigFile, overrideConfigFileUnderTestDataDir);

  backupConfigFileUnderTestDataDir = Paths.get(absoluteDataPath, BACKUP_SERVER_CONFIG);

  // Add the new custom config file to Configuration
  testUtil.getConfiguration().addResource(testUtil.getDataTestDir(SERVER_CONFIG));
}
 
Example 25
Source Project: hbase   Source File: TestHRegionReplayEvents.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (reader != null) {
    reader.close();
  }

  if (primaryRegion != null) {
    HBaseTestingUtility.closeRegionAndWAL(primaryRegion);
  }
  if (secondaryRegion != null) {
    HBaseTestingUtility.closeRegionAndWAL(secondaryRegion);
  }

  EnvironmentEdgeManagerTestHelper.reset();
}
 
Example 26
Source Project: hbase   Source File: SnapshotTestingUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void confirmSnapshotValid(HBaseTestingUtility testUtil,
    SnapshotProtos.SnapshotDescription snapshotDescriptor, TableName tableName, byte[] family)
    throws IOException {
  MasterFileSystem mfs = testUtil.getHBaseCluster().getMaster().getMasterFileSystem();
  confirmSnapshotValid(snapshotDescriptor, tableName, family, mfs.getRootDir(),
    testUtil.getAdmin(), mfs.getFileSystem());
}
 
Example 27
Source Project: hbase   Source File: TestMetaTableMetrics.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  // Set system coprocessor so it can be applied to meta regions
  UTIL.getConfiguration().set("hbase.coprocessor.region.classes",
    MetaTableMetrics.class.getName());
  conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, JMXListener.class.getName());
  Random rand = new Random();
  for (int i = 0; i < 10; i++) {
    do {
      int sign = i % 2 == 0 ? 1 : -1;
      connectorPort += sign * rand.nextInt(100);
    } while (!HBaseTestingUtility.available(connectorPort));
    try {
      conf.setInt("regionserver.rmi.registry.port", connectorPort);
      UTIL.startMiniCluster(1);
      break;
    } catch (Exception e) {
      LOG.debug("Encountered exception when starting cluster. Trying port {}", connectorPort, e);
      try {
        // this is to avoid "IllegalStateException: A mini-cluster is already running"
        UTIL.shutdownMiniCluster();
      } catch (Exception ex) {
        LOG.debug("Encountered exception shutting down cluster", ex);
      }
    }
  }
}
 
Example 28
Source Project: hbase   Source File: ChangeSplitPolicyAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void perform() throws Exception {
  HBaseTestingUtility util = context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getAdmin();

  getLogger().info("Performing action: Change split policy of table " + tableName);
  TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
  String chosenPolicy = possiblePolicies[random.nextInt(possiblePolicies.length)];
  builder.setRegionSplitPolicyClassName(chosenPolicy);
  getLogger().info("Changing "  + tableName + " split policy to " + chosenPolicy);
  admin.modifyTable(builder.build());
}
 
Example 29
Source Project: hbase   Source File: TestIncrementsFromClientSide.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test batch increment result when there are duplicate rpc request.
 */
@Test
public void testDuplicateBatchIncrement() throws Exception {
  TableDescriptorBuilder.ModifyableTableDescriptor mtd =
    TEST_UTIL.createModifyableTableDescriptor(name.getMethodName());
  Map<String, String> kvs = new HashMap<>();
  kvs.put(SleepAtFirstRpcCall.SLEEP_TIME_CONF_KEY, "2000");
  mtd.setCoprocessor(CoprocessorDescriptorBuilder
    .newBuilder(SleepAtFirstRpcCall.class.getName())
    .setPriority(1)
    .setProperties(kvs)
    .build());
  TEST_UTIL.createTable(mtd, new byte[][] { ROW }).close();

  Configuration c = new Configuration(TEST_UTIL.getConfiguration());
  c.setInt(HConstants.HBASE_CLIENT_PAUSE, 50);
  // Client will retry beacuse rpc timeout is small than the sleep time of first rpc call
  c.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 1500);

  try (Connection connection = ConnectionFactory.createConnection(c);
    Table table = connection.getTableBuilder(TableName.valueOf(name.getMethodName()), null)
      .setOperationTimeout(3 * 1000).build()) {
    Increment inc = new Increment(ROW);
    inc.addColumn(HBaseTestingUtility.fam1, QUALIFIER, 1);

    // Batch increment
    Object[] results = new Object[1];
    table.batch(Collections.singletonList(inc), results);

    Cell[] cells = ((Result) results[0]).rawCells();
    assertEquals(1, cells.length);
    assertIncrementKey(cells[0], ROW, HBaseTestingUtility.fam1, QUALIFIER, 1);

    // Verify expected result
    Result readResult = table.get(new Get(ROW));
    cells = readResult.rawCells();
    assertEquals(1, cells.length);
    assertIncrementKey(cells[0], ROW, HBaseTestingUtility.fam1, QUALIFIER, 1);
  }
}
 
Example 30
Source Project: hbase   Source File: TestRegionObserverBypass.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Stack up three coprocessors just so I can check bypass skips subsequent calls.
  Configuration conf = HBaseConfiguration.create();
  conf.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY,
      new String [] {TestCoprocessor.class.getName(),
        TestCoprocessor2.class.getName(),
        TestCoprocessor3.class.getName()});
  util = new HBaseTestingUtility(conf);
  util.startMiniCluster();
}