org.apache.hadoop.hbase.HBaseTestingUtility.getHBaseAdmin() - java examples

Here are the examples of the java api org.apache.hadoop.hbase.HBaseTestingUtility.getHBaseAdmin() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

13 View Complete Implementation : TestMetaWithReplicas.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testMetaLookupThreadPoolCreated() throws Exception {
    byte[] TABLE = Bytes.toBytes("testMetaLookupThreadPoolCreated");
    byte[][] FAMILIES = new byte[][] { Bytes.toBytes("foo") };
    if (TEST_UTIL.getHBaseAdmin().tableExists(TABLE)) {
        TEST_UTIL.getHBaseAdmin().disableTable(TABLE);
        TEST_UTIL.getHBaseAdmin().deleteTable(TABLE);
    }
    try (Table htable = TEST_UTIL.createTable(TABLE, FAMILIES, TEST_UTIL.getConfiguration())) {
        byte[] row = "test".getBytes();
        HConnectionImplementation c = ((HConnectionImplementation) ((HTable) htable).connection);
        // check that metalookup pool would get created
        c.relocateRegion(TABLE, row);
        ExecutorService ex = c.getCurrentMetaLookupPool();
        replacedert (ex != null);
    }
}

13 View Complete Implementation : TestEnableTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testRollbackAndDoubleExecution() throws Exception {
    final TableName tableName = TableName.valueOf("testRollbackAndDoubleExecution");
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    final byte[][] splitKeys = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") };
    MasterProcedureTestingUtility.createTable(procExec, tableName, splitKeys, "f1", "f2");
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Start the Enable procedure && kill the executor
    long procId = procExec.submitProcedure(new EnableTableProcedure(procExec.getEnvironment(), tableName, false), nonceGroup, nonce);
    // failing in the middle of proc
    int numberOfSteps = EnableTableState.values().length - 2;
    MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, numberOfSteps, EnableTableState.values());
    MasterProcedureTestingUtility.validateTableIsDisabled(UTIL.getHBaseCluster().getMaster(), tableName);
}

13 View Complete Implementation : TestRegionObserverBypass.java
Copyright Apache License 2.0
Author : fengchen8086
@Before
public void setUp() throws Exception {
    Admin admin = util.getHBaseAdmin();
    if (admin.tableExists(tableName)) {
        if (admin.isTableEnabled(tableName)) {
            admin.disableTable(tableName);
        }
        admin.deleteTable(tableName);
    }
    util.createTable(tableName, new byte[][] { dummy, test });
}

13 View Complete Implementation : TestFlushSnapshotFromClient.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Test snapshotting a table that is online without flushing
 * @throws Exception
 */
@Test(timeout = 30000)
public void testSkipFlushTableSnapshot() throws Exception {
    Admin admin = UTIL.getHBaseAdmin();
    // make sure we don't fail on listing snapshots
    SnapshotTestingUtils.replacedertNoSnapshots(admin);
    // put some stuff in the table
    try (Table table = UTIL.getConnection().getTable(TABLE_NAME)) {
        UTIL.loadTable(table, TEST_FAM);
    }
    LOG.debug("FS state before snapshot:");
    UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);
    // take a snapshot of the enabled table
    String snapshotString = "skipFlushTableSnapshot";
    byte[] snapshot = Bytes.toBytes(snapshotString);
    admin.snapshot(snapshotString, TABLE_NAME, SnapshotDescription.Type.SKIPFLUSH);
    LOG.debug("Snapshot completed.");
    // make sure we have the snapshot
    List<SnapshotDescription> snapshots = SnapshotTestingUtils.replacedertOneSnapshotThatMatches(admin, snapshot, TABLE_NAME);
    // make sure its a valid snapshot
    LOG.debug("FS state after snapshot:");
    UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);
    SnapshotTestingUtils.confirmSnapshotValid(UTIL, snapshots.get(0), TABLE_NAME, TEST_FAM);
    admin.deleteSnapshot(snapshot);
    snapshots = admin.listSnapshots();
    SnapshotTestingUtils.replacedertNoSnapshots(admin);
}

13 View Complete Implementation : TestAddColumnFamilyProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testAddColumnFamily() throws Exception {
    final TableName tableName = TableName.valueOf("testAddColumnFamily");
    final String cf1 = "cf1";
    final String cf2 = "cf2";
    final HColumnDescriptor columnDescriptor1 = new HColumnDescriptor(cf1);
    final HColumnDescriptor columnDescriptor2 = new HColumnDescriptor(cf2);
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f3");
    // Test 1: Add a column family online
    long procId1 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor1), nonceGroup, nonce);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateColumnFamilyAddition(UTIL.getHBaseCluster().getMaster(), tableName, cf1);
    // Test 2: Add a column family offline
    UTIL.getHBaseAdmin().disableTable(tableName);
    long procId2 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor2), nonceGroup + 1, nonce + 1);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId2);
    MasterProcedureTestingUtility.validateColumnFamilyAddition(UTIL.getHBaseCluster().getMaster(), tableName, cf2);
}

13 View Complete Implementation : TestScannerTimeout.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Test that scanner won't miss any rows if the region server it was reading
 * from failed. Before 3686, it would skip rows in the scan.
 * @throws Exception
 */
@Test(timeout = 300000)
public void test3686a() throws Exception {
    LOG.info("START ************ TEST3686A---1");
    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
    LOG.info("START ************ TEST3686A---1111");
    Scan scan = new Scan();
    scan.setCaching(SCANNER_CACHING);
    LOG.info("************ TEST3686A");
    MetaTableAccessor.fullScanMetaAndPrint(TEST_UTIL.getHBaseAdmin().getConnection());
    // Set a very high timeout, we want to test what happens when a RS
    // fails but the region is recovered before the lease times out.
    // Since the RS is already created, this conf is client-side only for
    // this new table
    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
    conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_TIMEOUT * 100);
    Table table = new HTable(conf, TABLE_NAME);
    LOG.info("START ************ TEST3686A---22");
    ResultScanner r = table.getScanner(scan);
    LOG.info("START ************ TEST3686A---33");
    int count = 1;
    r.next();
    LOG.info("START ************ TEST3686A---44");
    // Kill after one call to next(), which got 5 rows.
    rs.abort("die!");
    while (r.next() != null) {
        count++;
    }
    replacedertEquals(NB_ROWS, count);
    r.close();
    table.close();
    LOG.info("************ END TEST3686A");
}

13 View Complete Implementation : TestTableSnapshotScanner.java
Copyright Apache License 2.0
Author : fengchen8086
private void testScanner(HBaseTestingUtility util, String snapshotName, int numRegions, boolean shutdownCluster) throws Exception {
    setupCluster();
    TableName tableName = TableName.valueOf("testScanner");
    try {
        createTableAndSnapshot(util, tableName, snapshotName, numRegions);
        if (shutdownCluster) {
            util.shutdownMiniHBaseCluster();
        }
        Path restoreDir = util.getDataTestDirOnTestFS(snapshotName);
        // limit the scan
        Scan scan = new Scan(bbb, yyy);
        TableSnapshotScanner scanner = new TableSnapshotScanner(UTIL.getConfiguration(), restoreDir, snapshotName, scan);
        verifyScanner(scanner, bbb, yyy);
        scanner.close();
    } finally {
        if (!shutdownCluster) {
            util.getHBaseAdmin().deleteSnapshot(snapshotName);
            util.deleteTable(tableName);
            tearDownCluster();
        }
    }
}

13 View Complete Implementation : TestDeleteTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testDoubleDeletedTableWithSameNonce() throws Exception {
    final TableName tableName = TableName.valueOf("testDoubleDeletedTableWithSameNonce");
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    HRegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f");
    UTIL.getHBaseAdmin().disableTable(tableName);
    // delete the table (that exists)
    long procId1 = procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName), nonceGroup, nonce);
    // delete the table (that will no longer exist)
    long procId2 = procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName), nonceGroup, nonce);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    // First delete should succeed
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateTableDeletion(UTIL.getHBaseCluster().getMaster(), tableName, regions, "f");
    // Second delete should not fail, because it is the same delete
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId2);
    replacedertTrue(procId1 == procId2);
}

13 View Complete Implementation : TestCoprocessorTableEndpoint.java
Copyright Apache License 2.0
Author : fengchen8086
private static final void createTable(HTableDescriptor desc) throws Exception {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    admin.createTable(desc, new byte[][] { ROWS[rowSeperator1], ROWS[rowSeperator2] });
    TEST_UTIL.waitUntilAllRegionsreplacedigned(desc.getTableName());
    Table table = TEST_UTIL.getConnection().getTable(desc.getTableName());
    try {
        for (int i = 0; i < ROWSIZE; i++) {
            Put put = new Put(ROWS[i]);
            put.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(i));
            table.put(put);
        }
    } finally {
        table.close();
    }
}

13 View Complete Implementation : TestTableDescriptorModification.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testModifyTable() throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with one family
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
        // Verify the table descriptor
        verifyTableDescriptor(TABLE_NAME, FAMILY_0);
        // Modify the table adding another family and verify the descriptor
        HTableDescriptor modifiedHtd = new HTableDescriptor(TABLE_NAME);
        modifiedHtd.addFamily(new HColumnDescriptor(FAMILY_0));
        modifiedHtd.addFamily(new HColumnDescriptor(FAMILY_1));
        admin.modifyTable(TABLE_NAME, modifiedHtd);
        verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
    } finally {
        admin.deleteTable(TABLE_NAME);
    }
}

13 View Complete Implementation : TestEnableTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testRecoveryAndDoubleExecution() throws Exception {
    final TableName tableName = TableName.valueOf("testRecoveryAndDoubleExecution");
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    final byte[][] splitKeys = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") };
    MasterProcedureTestingUtility.createTable(procExec, tableName, splitKeys, "f1", "f2");
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Start the Enable procedure && kill the executor
    long procId = procExec.submitProcedure(new EnableTableProcedure(procExec.getEnvironment(), tableName, false), nonceGroup, nonce);
    // Restart the executor and execute the step twice
    int numberOfSteps = EnableTableState.values().length;
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId, numberOfSteps, EnableTableState.values());
    MasterProcedureTestingUtility.validateTableIsEnabled(UTIL.getHBaseCluster().getMaster(), tableName);
}

13 View Complete Implementation : TestChangingEncoding.java
Copyright Apache License 2.0
Author : fengchen8086
private void compactAndWait() throws IOException, InterruptedException {
    LOG.debug("Compacting table " + tableName);
    HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
    HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
    admin.majorCompact(tableName);
    // Waiting for the compaction to start, at least .5s.
    final long maxWaitime = System.currentTimeMillis() + 500;
    boolean cont;
    do {
        cont = rs.compactSplitThread.getCompactionQueueSize() == 0;
        Threads.sleep(1);
    } while (cont && System.currentTimeMillis() < maxWaitime);
    while (rs.compactSplitThread.getCompactionQueueSize() > 0) {
        Threads.sleep(1);
    }
    LOG.debug("Compaction queue size reached 0, continuing");
}

13 View Complete Implementation : TestBulkDeleteProtocol.java
Copyright Apache License 2.0
Author : fengchen8086
private Table createTable(TableName tableName) throws IOException {
    HTableDescriptor htd = new HTableDescriptor(tableName);
    HColumnDescriptor hcd = new HColumnDescriptor(FAMILY1);
    // Just setting 10 as I am not testing with more than 10 versions here
    hcd.setMaxVersions(10);
    htd.addFamily(hcd);
    TEST_UTIL.getHBaseAdmin().createTable(htd, Bytes.toBytes(0), Bytes.toBytes(120), 5);
    Table ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
    return ht;
}

13 View Complete Implementation : TestDeleteTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testRecoveryAndDoubleExecution() throws Exception {
    final TableName tableName = TableName.valueOf("testRecoveryAndDoubleExecution");
    // create the table
    byte[][] splitKeys = null;
    HRegionInfo[] regions = MasterProcedureTestingUtility.createTable(getMasterProcedureExecutor(), tableName, splitKeys, "f1", "f2");
    UTIL.getHBaseAdmin().disableTable(tableName);
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Start the Delete procedure && kill the executor
    long procId = procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName), nonceGroup, nonce);
    // Restart the executor and execute the step twice
    // NOTE: the 6 (number of DeleteTableState steps) is hardcoded,
    // so you have to look at this test at least once when you add a new step.
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId, 6, DeleteTableState.values());
    MasterProcedureTestingUtility.validateTableDeletion(UTIL.getHBaseCluster().getMaster(), tableName, regions, "f1", "f2");
}

13 View Complete Implementation : TestScannerResource.java
Copyright Apache License 2.0
Author : fengchen8086
@BeforeClreplaced
public static void setUpBeforeClreplaced() throws Exception {
    conf = TEST_UTIL.getConfiguration();
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(conf);
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    context = JAXBContext.newInstance(CellModel.clreplaced, CellSetModel.clreplaced, RowModel.clreplaced, ScannerModel.clreplaced);
    marshaller = context.createMarshaller();
    unmarshaller = context.createUnmarshaller();
    Admin admin = TEST_UTIL.getHBaseAdmin();
    if (admin.tableExists(TABLE)) {
        return;
    }
    HTableDescriptor htd = new HTableDescriptor(TABLE);
    htd.addFamily(new HColumnDescriptor(CFA));
    htd.addFamily(new HColumnDescriptor(CFB));
    admin.createTable(htd);
    expectedRows1 = insertData(TEST_UTIL.getConfiguration(), TABLE, COLUMN_1, 1.0);
    expectedRows2 = insertData(TEST_UTIL.getConfiguration(), TABLE, COLUMN_2, 0.5);
}

13 View Complete Implementation : TestDeleteColumnFamilyProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testRecoveryAndDoubleExecutionOffline() throws Exception {
    final TableName tableName = TableName.valueOf("testRecoveryAndDoubleExecutionOffline");
    final String cf4 = "cf4";
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    // create the table
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1", "f2", "f3", cf4);
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Start the Delete procedure && kill the executor
    long procId = procExec.submitProcedure(new DeleteColumnFamilyProcedure(procExec.getEnvironment(), tableName, cf4.getBytes()), nonceGroup, nonce);
    // Restart the executor and execute the step twice
    int numberOfSteps = DeleteColumnFamilyState.values().length;
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId, numberOfSteps, DeleteColumnFamilyState.values());
    MasterProcedureTestingUtility.validateColumnFamilyDeletion(UTIL.getHBaseCluster().getMaster(), tableName, cf4);
}

13 View Complete Implementation : TestWALReplay.java
Copyright Apache License 2.0
Author : fengchen8086
private void moveRegionAndWait(Region destRegion, HRegionServer destServer) throws InterruptedException, MasterNotRunningException, ZooKeeperConnectionException, IOException {
    HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
    TEST_UTIL.getHBaseAdmin().move(destRegion.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destServer.getServerName().getServerName()));
    while (true) {
        ServerName serverName = master.getreplacedignmentManager().getRegionStates().getRegionServerOfRegion(destRegion.getRegionInfo());
        if (serverName != null && serverName.equals(destServer.getServerName())) {
            TEST_UTIL.replacedertRegionOnServer(destRegion.getRegionInfo(), serverName, 200);
            break;
        }
        Thread.sleep(10);
    }
}

12 View Complete Implementation : TestTableSnapshotInputFormat.java
Copyright Apache License 2.0
Author : fengchen8086
@Override
public void testWithMockedMapReduce(HBaseTestingUtility util, String snapshotName, int numRegions, int expectedNumSplits) throws Exception {
    setupCluster();
    TableName tableName = TableName.valueOf("testWithMockedMapReduce");
    try {
        createTableAndSnapshot(util, tableName, snapshotName, getStartRow(), getEndRow(), numRegions);
        Job job = new Job(util.getConfiguration());
        Path tmpTableDir = util.getRandomDir();
        // limit the scan
        Scan scan = new Scan(getStartRow(), getEndRow());
        TableMapReduceUtil.initTableSnapshotMapperJob(snapshotName, scan, TestTableSnapshotMapper.clreplaced, ImmutableBytesWritable.clreplaced, NullWritable.clreplaced, job, false, tmpTableDir);
        verifyWithMockedMapReduce(job, numRegions, expectedNumSplits, getStartRow(), getEndRow());
    } finally {
        util.getHBaseAdmin().deleteSnapshot(snapshotName);
        util.deleteTable(tableName);
        tearDownCluster();
    }
}

12 View Complete Implementation : TestTruncateTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
private void testSimpleTruncate(final TableName tableName, final boolean preserveSplits) throws Exception {
    final String[] families = new String[] { "f1", "f2" };
    final byte[][] splitKeys = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") };
    HRegionInfo[] regions = MasterProcedureTestingUtility.createTable(getMasterProcedureExecutor(), tableName, splitKeys, families);
    // load and verify that there are rows in the table
    MasterProcedureTestingUtility.loadData(UTIL.getConnection(), tableName, 100, splitKeys, families);
    replacedertEquals(100, UTIL.countRows(tableName));
    // disable the table
    UTIL.getHBaseAdmin().disableTable(tableName);
    // truncate the table
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    long procId = ProcedureTestingUtility.submitAndWait(procExec, new TruncateTableProcedure(procExec.getEnvironment(), tableName, preserveSplits));
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId);
    UTIL.waitUntilAllRegionsreplacedigned(tableName);
    // validate the table regions and layout
    if (preserveSplits) {
        replacedertEquals(1 + splitKeys.length, UTIL.getHBaseAdmin().getTableRegions(tableName).size());
    } else {
        regions = UTIL.getHBaseAdmin().getTableRegions(tableName).toArray(new HRegionInfo[1]);
        replacedertEquals(1, regions.length);
    }
    MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(), tableName, regions, families);
    // verify that there are no rows in the table
    replacedertEquals(0, UTIL.countRows(tableName));
    // verify that the table is read/writable
    MasterProcedureTestingUtility.loadData(UTIL.getConnection(), tableName, 50, splitKeys, families);
    replacedertEquals(50, UTIL.countRows(tableName));
}

12 View Complete Implementation : TestModifyColumnFamilyProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testModifyColumnFamily() throws Exception {
    final TableName tableName = TableName.valueOf("testModifyColumnFamily");
    final String cf1 = "cf1";
    final HColumnDescriptor columnDescriptor = new HColumnDescriptor(cf1);
    int oldBlockSize = columnDescriptor.getBlocksize();
    int newBlockSize = 3 * oldBlockSize;
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, cf1, "f2");
    // Test 1: modify the column family online
    columnDescriptor.setBlocksize(newBlockSize);
    long procId1 = procExec.submitProcedure(new ModifyColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor), nonceGroup, nonce);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateColumnFamilyModification(UTIL.getHBaseCluster().getMaster(), tableName, cf1, columnDescriptor);
    // Test 2: modify the column family offline
    UTIL.getHBaseAdmin().disableTable(tableName);
    columnDescriptor.setBlocksize(newBlockSize * 2);
    long procId2 = procExec.submitProcedure(new ModifyColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor), nonceGroup + 1, nonce + 1);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId2);
    MasterProcedureTestingUtility.validateColumnFamilyModification(UTIL.getHBaseCluster().getMaster(), tableName, cf1, columnDescriptor);
}

12 View Complete Implementation : TestTableDescriptorModification.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testDeleteColumn() throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with two families
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_1));
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
        // Verify the table descriptor
        verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
        // Modify the table removing one family and verify the descriptor
        admin.deleteColumn(TABLE_NAME, FAMILY_1);
        verifyTableDescriptor(TABLE_NAME, FAMILY_0);
    } finally {
        admin.deleteTable(TABLE_NAME);
    }
}

12 View Complete Implementation : TestSplitWalDataLoss.java
Copyright Apache License 2.0
Author : fengchen8086
@Before
public void setUp() throws Exception {
    testUtil.getConfiguration().setInt("hbase.regionserver.msginterval", 30000);
    testUtil.getConfiguration().setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, false);
    testUtil.startMiniCluster(2);
    HBaseAdmin admin = testUtil.getHBaseAdmin();
    admin.createNamespace(namespace);
    admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(family)));
    testUtil.waitTableAvailable(tableName);
}

12 View Complete Implementation : TestTableScan.java
Copyright Apache License 2.0
Author : fengchen8086
@BeforeClreplaced
public static void setUpBeforeClreplaced() throws Exception {
    conf = TEST_UTIL.getConfiguration();
    conf.set(Constants.CUSTOM_FILTERS, "CustomFilter:" + CustomFilter.clreplaced.getName());
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(conf);
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    Admin admin = TEST_UTIL.getHBaseAdmin();
    if (!admin.tableExists(TABLE)) {
        HTableDescriptor htd = new HTableDescriptor(TABLE);
        htd.addFamily(new HColumnDescriptor(CFA));
        htd.addFamily(new HColumnDescriptor(CFB));
        admin.createTable(htd);
        expectedRows1 = TestScannerResource.insertData(conf, TABLE, COLUMN_1, 1.0);
        expectedRows2 = TestScannerResource.insertData(conf, TABLE, COLUMN_2, 0.5);
    }
}

12 View Complete Implementation : TestTableSnapshotInputFormat.java
Copyright Apache License 2.0
Author : fengchen8086
@Override
protected void testWithMockedMapReduce(HBaseTestingUtility util, String snapshotName, int numRegions, int expectedNumSplits) throws Exception {
    setupCluster();
    TableName tableName = TableName.valueOf("testWithMockedMapReduce");
    try {
        createTableAndSnapshot(util, tableName, snapshotName, getStartRow(), getEndRow(), numRegions);
        JobConf job = new JobConf(util.getConfiguration());
        Path tmpTableDir = util.getRandomDir();
        TableMapReduceUtil.initTableSnapshotMapJob(snapshotName, COLUMNS, TestTableSnapshotMapper.clreplaced, ImmutableBytesWritable.clreplaced, NullWritable.clreplaced, job, false, tmpTableDir);
        // mapred doesn't support start and end keys? o.O
        verifyWithMockedMapReduce(job, numRegions, expectedNumSplits, getStartRow(), getEndRow());
    } finally {
        util.getHBaseAdmin().deleteSnapshot(snapshotName);
        util.deleteTable(tableName);
        tearDownCluster();
    }
}

12 View Complete Implementation : TestTableDescriptorModification.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testAddColumn() throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with two families
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
        // Verify the table descriptor
        verifyTableDescriptor(TABLE_NAME, FAMILY_0);
        // Modify the table removing one family and verify the descriptor
        admin.addColumn(TABLE_NAME, new HColumnDescriptor(FAMILY_1));
        verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
    } finally {
        admin.deleteTable(TABLE_NAME);
    }
}

12 View Complete Implementation : TestSnapshotFromClient.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Test HBaseAdmin#deleteSnapshots(String) which deletes snapshots whose names match the parameter
 *
 * @throws Exception
 */
@Test(timeout = 300000)
public void testSnapshotDeletionWithRegex() throws Exception {
    Admin admin = UTIL.getHBaseAdmin();
    // make sure we don't fail on listing snapshots
    SnapshotTestingUtils.replacedertNoSnapshots(admin);
    // put some stuff in the table
    HTable table = new HTable(UTIL.getConfiguration(), TABLE_NAME);
    UTIL.loadTable(table, TEST_FAM);
    table.close();
    byte[] snapshot1 = Bytes.toBytes("TableSnapshot1");
    admin.snapshot(snapshot1, TABLE_NAME);
    LOG.debug("Snapshot1 completed.");
    byte[] snapshot2 = Bytes.toBytes("TableSnapshot2");
    admin.snapshot(snapshot2, TABLE_NAME);
    LOG.debug("Snapshot2 completed.");
    String snapshot3 = "3rdTableSnapshot";
    admin.snapshot(Bytes.toBytes(snapshot3), TABLE_NAME);
    LOG.debug(snapshot3 + " completed.");
    // delete the first two snapshots
    admin.deleteSnapshots("TableSnapshot.*");
    List<SnapshotDescription> snapshots = admin.listSnapshots();
    replacedertEquals(1, snapshots.size());
    replacedertEquals(snapshots.get(0).getName(), snapshot3);
    admin.deleteSnapshot(snapshot3);
    admin.close();
}

12 View Complete Implementation : TestTableLockManager.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 600000)
public void testDelete() throws Exception {
    prepareMiniCluster();
    Admin admin = TEST_UTIL.getHBaseAdmin();
    admin.disableTable(TABLE_NAME);
    admin.deleteTable(TABLE_NAME);
    // ensure that znode for the table node has been deleted
    final ZooKeeperWatcher zkWatcher = TEST_UTIL.getZooKeeperWatcher();
    final String znode = ZKUtil.joinZNode(zkWatcher.tableLockZNode, TABLE_NAME.getNamereplacedtring());
    TEST_UTIL.waitFor(5000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            int ver = ZKUtil.checkExists(zkWatcher, znode);
            return ver < 0;
        }
    });
    int ver = ZKUtil.checkExists(zkWatcher, ZKUtil.joinZNode(zkWatcher.tableLockZNode, TABLE_NAME.getNamereplacedtring()));
    replacedertTrue("Unexpected znode version " + ver, ver < 0);
}

12 View Complete Implementation : TestTableDescriptorModification.java
Copyright Apache License 2.0
Author : fengchen8086
private void verifyTableDescriptor(final TableName tableName, final byte[]... families) throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Verify descriptor from master
    HTableDescriptor htd = admin.getTableDescriptor(tableName);
    verifyTableDescriptor(htd, tableName, families);
    // Verify descriptor from HDFS
    MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
    Path tableDir = FSUtils.getTableDir(mfs.getRootDir(), tableName);
    htd = FSTableDescriptors.getTableDescriptorFromFs(mfs.getFileSystem(), tableDir);
    verifyTableDescriptor(htd, tableName, families);
}

12 View Complete Implementation : TestCorruptedRegionStoreFile.java
Copyright Apache License 2.0
Author : fengchen8086
private void setupTable(final TableName tableName) throws IOException {
    // load the table
    Table table = UTIL.createTable(tableName, FAMILY_NAME);
    try {
        rowCount = 0;
        byte[] value = new byte[1024];
        byte[] q = Bytes.toBytes("q");
        while (rowCount < NUM_ROWS) {
            Put put = new Put(Bytes.toBytes(String.format("%010d", rowCount)));
            put.setDurability(Durability.SKIP_WAL);
            put.add(FAMILY_NAME, q, value);
            table.put(put);
            if ((rowCount++ % ROW_PER_FILE) == 0) {
                // flush it
                ((HTable) table).flushCommits();
                UTIL.getHBaseAdmin().flush(tableName);
            }
        }
    } finally {
        UTIL.getHBaseAdmin().flush(tableName);
        table.close();
    }
    replacedertEquals(NUM_ROWS, rowCount);
    // get the store file paths
    storeFiles.clear();
    tableDir = FSUtils.getTableDir(getRootDir(), tableName);
    FSVisitor.visitTableStoreFiles(getFileSystem(), tableDir, new FSVisitor.StoreFileVisitor() {

        @Override
        public void storeFile(final String region, final String family, final String hfile) throws IOException {
            HFileLink link = HFileLink.build(UTIL.getConfiguration(), tableName, region, family, hfile);
            storeFiles.add(link.getOriginPath());
        }
    });
    replacedertTrue("Expected at least " + NUM_FILES + " store files", storeFiles.size() >= NUM_FILES);
    LOG.info("Store files: " + storeFiles);
}

12 View Complete Implementation : TestProcedureAdmin.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testAbortProcedureFailure() throws Exception {
    final TableName tableName = TableName.valueOf("testAbortProcedureFailure");
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    HRegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f");
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Submit an un-abortable procedure
    long procId = procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName), nonceGroup, nonce);
    boolean abortResult = procExec.abort(procId, true);
    replacedertFalse(abortResult);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false);
    ProcedureTestingUtility.restart(procExec);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId);
    // Validate the delete table procedure was not aborted
    MasterProcedureTestingUtility.validateTableDeletion(UTIL.getHBaseCluster().getMaster(), tableName, regions, "f");
}

12 View Complete Implementation : SnapshotTestingUtils.java
Copyright Apache License 2.0
Author : fengchen8086
public static void createTable(final HBaseTestingUtility util, final TableName tableName, int regionReplication, final byte[]... families) throws IOException, InterruptedException {
    HTableDescriptor htd = new HTableDescriptor(tableName);
    htd.setRegionReplication(regionReplication);
    for (byte[] family : families) {
        HColumnDescriptor hcd = new HColumnDescriptor(family);
        htd.addFamily(hcd);
    }
    byte[][] splitKeys = getSplitKeys();
    util.createTable(htd, splitKeys);
    replacedertEquals((splitKeys.length + 1) * regionReplication, util.getHBaseAdmin().getTableRegions(tableName).size());
}

12 View Complete Implementation : TestAddColumnFamilyProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testRecoveryAndDoubleExecutionOffline() throws Exception {
    final TableName tableName = TableName.valueOf("testRecoveryAndDoubleExecutionOffline");
    final String cf4 = "cf4";
    final HColumnDescriptor columnDescriptor = new HColumnDescriptor(cf4);
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    // create the table
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1", "f2", "f3");
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Start the AddColumnFamily procedure && kill the executor
    long procId = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor), nonceGroup, nonce);
    // Restart the executor and execute the step twice
    int numberOfSteps = AddColumnFamilyState.values().length;
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId, numberOfSteps, AddColumnFamilyState.values());
    MasterProcedureTestingUtility.validateColumnFamilyAddition(UTIL.getHBaseCluster().getMaster(), tableName, cf4);
}

12 View Complete Implementation : TestEncryptionKeyRotation.java
Copyright Apache License 2.0
Author : fengchen8086
private void createTableAndFlush(HTableDescriptor htd) throws Exception {
    HColumnDescriptor hcd = htd.getFamilies().iterator().next();
    // Create the test table
    TEST_UTIL.getHBaseAdmin().createTable(htd);
    TEST_UTIL.waitTableAvailable(htd.getName(), 5000);
    // Create a store file
    Table table = new HTable(conf, htd.getTableName());
    try {
        table.put(new Put(Bytes.toBytes("testrow")).add(hcd.getName(), Bytes.toBytes("q"), Bytes.toBytes("value")));
    } finally {
        table.close();
    }
    TEST_UTIL.getHBaseAdmin().flush(htd.getTableName());
}

11 View Complete Implementation : TestFIFOCompactionPolicy.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testPurgeExpiredFiles() throws Exception {
    Configuration conf = TEST_UTIL.getConfiguration();
    conf.setInt(HStore.BLOCKING_STOREFILES_KEY, 10000);
    TEST_UTIL.startMiniCluster(1);
    try {
        Store store = prepareData();
        replacedertEquals(10, store.getStorefilesCount());
        TEST_UTIL.getHBaseAdmin().majorCompact(tableName);
        while (store.getStorefilesCount() > 1) {
            Thread.sleep(100);
        }
        replacedertTrue(store.getStorefilesCount() == 1);
    } finally {
        TEST_UTIL.shutdownMiniCluster();
    }
}

11 View Complete Implementation : RowResourceBase.java
Copyright Apache License 2.0
Author : fengchen8086
@Before
public void beforeMethod() throws Exception {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    if (admin.tableExists(TableName.valueOf(TABLE))) {
        TEST_UTIL.deleteTable(Bytes.toBytes(TABLE));
    }
    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TABLE));
    htd.addFamily(new HColumnDescriptor(CFA));
    htd.addFamily(new HColumnDescriptor(CFB));
    admin.createTable(htd);
}

11 View Complete Implementation : TestFlushSnapshotFromClient.java
Copyright Apache License 2.0
Author : fengchen8086
/**
 * Test simple flush snapshotting a table that is online
 * @throws Exception
 */
@Test(timeout = 300000)
public void testFlushTableSnapshotWithProcedure() throws Exception {
    Admin admin = UTIL.getHBaseAdmin();
    // make sure we don't fail on listing snapshots
    SnapshotTestingUtils.replacedertNoSnapshots(admin);
    // put some stuff in the table
    SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, DEFAULT_NUM_ROWS, TEST_FAM);
    LOG.debug("FS state before snapshot:");
    UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);
    // take a snapshot of the enabled table
    String snapshotString = "offlineTableSnapshot";
    byte[] snapshot = Bytes.toBytes(snapshotString);
    Map<String, String> props = new HashMap<String, String>();
    props.put("table", TABLE_NAME.getNamereplacedtring());
    admin.execProcedure(SnapshotManager.ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION, snapshotString, props);
    LOG.debug("Snapshot completed.");
    // make sure we have the snapshot
    List<SnapshotDescription> snapshots = SnapshotTestingUtils.replacedertOneSnapshotThatMatches(admin, snapshot, TABLE_NAME);
    // make sure its a valid snapshot
    LOG.debug("FS state after snapshot:");
    UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);
    SnapshotTestingUtils.confirmSnapshotValid(UTIL, snapshots.get(0), TABLE_NAME, TEST_FAM);
}

11 View Complete Implementation : TestCreateTableHandler.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 300000)
public void testCreateTableCalledTwiceAndFirstOneInProgress() throws Exception {
    final TableName tableName = TableName.valueOf("testCreateTableCalledTwiceAndFirstOneInProgress");
    final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    final HMaster m = cluster.getMaster();
    final HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILYNAME));
    final HRegionInfo[] hRegionInfos = new HRegionInfo[] { new HRegionInfo(desc.getTableName(), null, null) };
    CustomCreateTableHandler handler = new CustomCreateTableHandler(m, m.getMasterFileSystem(), desc, cluster.getConfiguration(), hRegionInfos, m);
    handler.prepare();
    throwException = true;
    handler.process();
    throwException = false;
    CustomCreateTableHandler handler1 = new CustomCreateTableHandler(m, m.getMasterFileSystem(), desc, cluster.getConfiguration(), hRegionInfos, m);
    handler1.prepare();
    handler1.process();
    for (int i = 0; i < 100; i++) {
        if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
            Thread.sleep(200);
        }
    }
    replacedertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
}

11 View Complete Implementation : TestDeleteColumnFamilyProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testDeleteColumnFamilyTwice() throws Exception {
    final TableName tableName = TableName.valueOf("testDeleteColumnFamilyTwice");
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    final String cf2 = "cf2";
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1", cf2);
    // delete the column family that exists
    long procId1 = procExec.submitProcedure(new DeleteColumnFamilyProcedure(procExec.getEnvironment(), tableName, cf2.getBytes()), nonceGroup, nonce);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    // First delete should succeed
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateColumnFamilyDeletion(UTIL.getHBaseCluster().getMaster(), tableName, cf2);
    // delete the column family that does not exist
    long procId2 = procExec.submitProcedure(new DeleteColumnFamilyProcedure(procExec.getEnvironment(), tableName, cf2.getBytes()), nonceGroup + 1, nonce + 1);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    // Second delete should fail with InvalidFamilyOperationException
    ProcedureInfo result = procExec.getResult(procId2);
    replacedertTrue(result.isFailed());
    LOG.debug("Delete online failed with exception: " + result.getExceptionFullMessage());
    replacedertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
    // Try again, this time with table disabled.
    UTIL.getHBaseAdmin().disableTable(tableName);
    long procId3 = procExec.submitProcedure(new DeleteColumnFamilyProcedure(procExec.getEnvironment(), tableName, cf2.getBytes()), nonceGroup + 2, nonce + 2);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId3);
    // Expect fail with InvalidFamilyOperationException
    result = procExec.getResult(procId2);
    replacedertTrue(result.isFailed());
    LOG.debug("Delete offline failed with exception: " + result.getExceptionFullMessage());
    replacedertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
}

11 View Complete Implementation : TestTableDescriptorModification.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testAddSameColumnFamilyTwice() throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with one families
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
        // Verify the table descriptor
        verifyTableDescriptor(TABLE_NAME, FAMILY_0);
        // Modify the table removing one family and verify the descriptor
        admin.addColumn(TABLE_NAME, new HColumnDescriptor(FAMILY_1));
        verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
        try {
            // Add same column family again - expect failure
            admin.addColumn(TABLE_NAME, new HColumnDescriptor(FAMILY_1));
            replacedert.fail("Delete a non-exist column family should fail");
        } catch (InvalidFamilyOperationException e) {
        // Expected.
        }
    } finally {
        admin.deleteTable(TABLE_NAME);
    }
}

11 View Complete Implementation : TestTableDescriptorModification.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testDeleteSameColumnFamilyTwice() throws IOException {
    Admin admin = TEST_UTIL.getHBaseAdmin();
    // Create a table with two families
    HTableDescriptor baseHtd = new HTableDescriptor(TABLE_NAME);
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_0));
    baseHtd.addFamily(new HColumnDescriptor(FAMILY_1));
    admin.createTable(baseHtd);
    admin.disableTable(TABLE_NAME);
    try {
        // Verify the table descriptor
        verifyTableDescriptor(TABLE_NAME, FAMILY_0, FAMILY_1);
        // Modify the table removing one family and verify the descriptor
        admin.deleteColumn(TABLE_NAME, FAMILY_1);
        verifyTableDescriptor(TABLE_NAME, FAMILY_0);
        try {
            // Delete again - expect failure
            admin.deleteColumn(TABLE_NAME, FAMILY_1);
            replacedert.fail("Delete a non-exist column family should fail");
        } catch (Exception e) {
        // Expected.
        }
    } finally {
        admin.deleteTable(TABLE_NAME);
    }
}

11 View Complete Implementation : TestModifyColumnFamilyProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testRecoveryAndDoubleExecutionOffline() throws Exception {
    final TableName tableName = TableName.valueOf("testRecoveryAndDoubleExecutionOffline");
    final String cf3 = "cf3";
    final HColumnDescriptor columnDescriptor = new HColumnDescriptor(cf3);
    int oldBlockSize = columnDescriptor.getBlocksize();
    int newBlockSize = 4 * oldBlockSize;
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    // create the table
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1", "f2", cf3);
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Start the Modify procedure && kill the executor
    columnDescriptor.setBlocksize(newBlockSize);
    long procId = procExec.submitProcedure(new ModifyColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor), nonceGroup, nonce);
    // Restart the executor and execute the step twice
    int numberOfSteps = ModifyColumnFamilyState.values().length;
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId, numberOfSteps, ModifyColumnFamilyState.values());
    MasterProcedureTestingUtility.validateColumnFamilyModification(UTIL.getHBaseCluster().getMaster(), tableName, cf3, columnDescriptor);
}

11 View Complete Implementation : TestFlushSnapshotFromClient.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 300000)
public void testAsyncFlushSnapshot() throws Exception {
    Admin admin = UTIL.getHBaseAdmin();
    SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("asyncSnapshot").setTable(TABLE_NAME.getNamereplacedtring()).setType(SnapshotDescription.Type.FLUSH).build();
    // take the snapshot async
    admin.takeSnapshotAsync(snapshot);
    // constantly loop, looking for the snapshot to complete
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    SnapshotTestingUtils.waitForSnapshotToComplete(master, snapshot, 200);
    LOG.info(" === Async Snapshot Completed ===");
    UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);
    // make sure we get the snapshot
    SnapshotTestingUtils.replacedertOneSnapshotThatMatches(admin, snapshot);
}

11 View Complete Implementation : TestReplicaWithCluster.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 30000)
public void testCreateDeleteTable() throws IOException {
    // Create table then get the single region for our new table.
    HTableDescriptor hdt = HTU.createTableDescriptor("testCreateDeleteTable");
    hdt.setRegionReplication(NB_SERVERS);
    hdt.addCoprocessor(SlowMeCopro.clreplaced.getName());
    Table table = HTU.createTable(hdt, new byte[][] { f }, HTU.getConfiguration());
    Put p = new Put(row);
    p.add(f, row, row);
    table.put(p);
    Get g = new Get(row);
    Result r = table.get(g);
    replacedert.replacedertFalse(r.isStale());
    try {
        // But if we ask for stale we will get it
        SlowMeCopro.cdl.set(new CountDownLatch(1));
        g = new Get(row);
        g.setConsistency(Consistency.TIMELINE);
        r = table.get(g);
        replacedert.replacedertTrue(r.isStale());
        SlowMeCopro.cdl.get().countDown();
    } finally {
        SlowMeCopro.cdl.get().countDown();
        SlowMeCopro.sleepTime.set(0);
    }
    HTU.getHBaseAdmin().disableTable(hdt.getTableName());
    HTU.deleteTable(hdt.getTableName());
}

10 View Complete Implementation : TestTruncateTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
private void testRecoveryAndDoubleExecution(final TableName tableName, final boolean preserveSplits) throws Exception {
    final String[] families = new String[] { "f1", "f2" };
    // create the table
    final byte[][] splitKeys = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") };
    HRegionInfo[] regions = MasterProcedureTestingUtility.createTable(getMasterProcedureExecutor(), tableName, splitKeys, families);
    // load and verify that there are rows in the table
    MasterProcedureTestingUtility.loadData(UTIL.getConnection(), tableName, 100, splitKeys, families);
    replacedertEquals(100, UTIL.countRows(tableName));
    // disable the table
    UTIL.getHBaseAdmin().disableTable(tableName);
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    // Start the Truncate procedure && kill the executor
    long procId = procExec.submitProcedure(new TruncateTableProcedure(procExec.getEnvironment(), tableName, preserveSplits), nonceGroup, nonce);
    // Restart the executor and execute the step twice
    // NOTE: the 7 (number of TruncateTableState steps) is hardcoded,
    // so you have to look at this test at least once when you add a new step.
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId, 7, TruncateTableState.values());
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false);
    UTIL.waitUntilAllRegionsreplacedigned(tableName);
    // validate the table regions and layout
    if (preserveSplits) {
        replacedertEquals(1 + splitKeys.length, UTIL.getHBaseAdmin().getTableRegions(tableName).size());
    } else {
        regions = UTIL.getHBaseAdmin().getTableRegions(tableName).toArray(new HRegionInfo[1]);
        replacedertEquals(1, regions.length);
    }
    MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(), tableName, regions, families);
    // verify that there are no rows in the table
    replacedertEquals(0, UTIL.countRows(tableName));
    // verify that the table is read/writable
    MasterProcedureTestingUtility.loadData(UTIL.getConnection(), tableName, 50, splitKeys, families);
    replacedertEquals(50, UTIL.countRows(tableName));
}

10 View Complete Implementation : TestAddColumnFamilyProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testAddSameColumnFamilyTwice() throws Exception {
    final TableName tableName = TableName.valueOf("testAddColumnFamilyTwice");
    final String cf2 = "cf2";
    final HColumnDescriptor columnDescriptor = new HColumnDescriptor(cf2);
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f1");
    // add the column family
    long procId1 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor), nonceGroup, nonce);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateColumnFamilyAddition(UTIL.getHBaseCluster().getMaster(), tableName, cf2);
    // add the column family that exists
    long procId2 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor), nonceGroup + 1, nonce + 1);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    // Second add should fail with InvalidFamilyOperationException
    ProcedureInfo result = procExec.getResult(procId2);
    replacedertTrue(result.isFailed());
    LOG.debug("Add failed with exception: " + result.getExceptionFullMessage());
    replacedertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
    // Do the same add the existing column family - this time offline
    UTIL.getHBaseAdmin().disableTable(tableName);
    long procId3 = procExec.submitProcedure(new AddColumnFamilyProcedure(procExec.getEnvironment(), tableName, columnDescriptor), nonceGroup + 2, nonce + 2);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId3);
    // Second add should fail with InvalidFamilyOperationException
    result = procExec.getResult(procId3);
    replacedertTrue(result.isFailed());
    LOG.debug("Add failed with exception: " + result.getExceptionFullMessage());
    replacedertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof InvalidFamilyOperationException);
}

10 View Complete Implementation : TestDeleteTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testDeleteDeletedTable() throws Exception {
    final TableName tableName = TableName.valueOf("testDeleteDeletedTable");
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    HRegionInfo[] regions = MasterProcedureTestingUtility.createTable(procExec, tableName, null, "f");
    UTIL.getHBaseAdmin().disableTable(tableName);
    // delete the table (that exists)
    long procId1 = procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName), nonceGroup, nonce);
    // delete the table (that will no longer exist)
    long procId2 = procExec.submitProcedure(new DeleteTableProcedure(procExec.getEnvironment(), tableName), nonceGroup + 1, nonce + 1);
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId1);
    ProcedureTestingUtility.waitProcedure(procExec, procId2);
    // First delete should succeed
    ProcedureTestingUtility.replacedertProcNotFailed(procExec, procId1);
    MasterProcedureTestingUtility.validateTableDeletion(UTIL.getHBaseCluster().getMaster(), tableName, regions, "f");
    // Second delete should fail with TableNotFound
    ProcedureInfo result = procExec.getResult(procId2);
    replacedertTrue(result.isFailed());
    LOG.debug("Delete failed with exception: " + result.getExceptionFullMessage());
    replacedertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof TableNotFoundException);
}

10 View Complete Implementation : TestRegionMergeTransactionOnCluster.java
Copyright Apache License 2.0
Author : fengchen8086
private PairOfSameType<HRegionInfo> requestMergeRegion(HMaster master, TableName tablename, int regionAnum, int regionBnum) throws Exception {
    List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(), master.getConnection(), tablename);
    HRegionInfo regionA = tableRegions.get(regionAnum).getFirst();
    HRegionInfo regionB = tableRegions.get(regionBnum).getFirst();
    TEST_UTIL.getHBaseAdmin().mergeRegions(regionA.getEncodedNameAsBytes(), regionB.getEncodedNameAsBytes(), false);
    return new PairOfSameType<HRegionInfo>(regionA, regionB);
}

10 View Complete Implementation : TestModifyTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testModifyTableAddCF() throws Exception {
    final TableName tableName = TableName.valueOf("testModifyTableAddCF");
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "cf1");
    HTableDescriptor currentHtd = UTIL.getHBaseAdmin().getTableDescriptor(tableName);
    replacedertEquals(1, currentHtd.getFamiliesKeys().size());
    // Test 1: Modify the table descriptor online
    String cf2 = "cf2";
    HTableDescriptor htd = new HTableDescriptor(UTIL.getHBaseAdmin().getTableDescriptor(tableName));
    htd.addFamily(new HColumnDescriptor(cf2));
    long procId = ProcedureTestingUtility.submitAndWait(procExec, new ModifyTableProcedure(procExec.getEnvironment(), htd));
    ProcedureTestingUtility.replacedertProcNotFailed(procExec.getResult(procId));
    currentHtd = UTIL.getHBaseAdmin().getTableDescriptor(tableName);
    replacedertEquals(2, currentHtd.getFamiliesKeys().size());
    replacedertTrue(currentHtd.hasFamily(cf2.getBytes()));
    // Test 2: Modify the table descriptor offline
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    String cf3 = "cf3";
    HTableDescriptor htd2 = new HTableDescriptor(UTIL.getHBaseAdmin().getTableDescriptor(tableName));
    htd2.addFamily(new HColumnDescriptor(cf3));
    long procId2 = ProcedureTestingUtility.submitAndWait(procExec, new ModifyTableProcedure(procExec.getEnvironment(), htd2));
    ProcedureTestingUtility.replacedertProcNotFailed(procExec.getResult(procId2));
    currentHtd = UTIL.getHBaseAdmin().getTableDescriptor(tableName);
    replacedertTrue(currentHtd.hasFamily(cf3.getBytes()));
    replacedertEquals(3, currentHtd.getFamiliesKeys().size());
}

10 View Complete Implementation : TestModifyTableProcedure.java
Copyright Apache License 2.0
Author : fengchen8086
@Test(timeout = 60000)
public void testModifyTableDeleteCF() throws Exception {
    final TableName tableName = TableName.valueOf("testModifyTableAddCF");
    final String cf2 = "cf2";
    final String cf3 = "cf3";
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    MasterProcedureTestingUtility.createTable(procExec, tableName, null, "cf1", cf2, cf3);
    HTableDescriptor currentHtd = UTIL.getHBaseAdmin().getTableDescriptor(tableName);
    replacedertEquals(3, currentHtd.getFamiliesKeys().size());
    // Test 1: Modify the table descriptor
    HTableDescriptor htd = new HTableDescriptor(UTIL.getHBaseAdmin().getTableDescriptor(tableName));
    htd.removeFamily(cf2.getBytes());
    long procId = ProcedureTestingUtility.submitAndWait(procExec, new ModifyTableProcedure(procExec.getEnvironment(), htd));
    ProcedureTestingUtility.replacedertProcNotFailed(procExec.getResult(procId));
    currentHtd = UTIL.getHBaseAdmin().getTableDescriptor(tableName);
    replacedertEquals(2, currentHtd.getFamiliesKeys().size());
    replacedertFalse(currentHtd.hasFamily(cf2.getBytes()));
    // Test 2: Modify the table descriptor offline
    UTIL.getHBaseAdmin().disableTable(tableName);
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    HTableDescriptor htd2 = new HTableDescriptor(UTIL.getHBaseAdmin().getTableDescriptor(tableName));
    htd2.removeFamily(cf3.getBytes());
    long procId2 = ProcedureTestingUtility.submitAndWait(procExec, new ModifyTableProcedure(procExec.getEnvironment(), htd2));
    ProcedureTestingUtility.replacedertProcNotFailed(procExec.getResult(procId2));
    currentHtd = UTIL.getHBaseAdmin().getTableDescriptor(tableName);
    replacedertEquals(1, currentHtd.getFamiliesKeys().size());
    replacedertFalse(currentHtd.hasFamily(cf3.getBytes()));
}

9 View Complete Implementation : TestMultiRespectsLimits.java
Copyright Apache License 2.0
Author : fengchen8086
@Test
public void testMultiLimits() throws Exception {
    final TableName name = TableName.valueOf("testMultiLimits");
    Table t = TEST_UTIL.createTable(name, FAMILY);
    TEST_UTIL.loadTable(t, FAMILY, false);
    // Split the table to make sure that the chunking happens accross regions.
    try (final Admin admin = TEST_UTIL.getHBaseAdmin()) {
        admin.split(name);
        TEST_UTIL.waitFor(60000, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                return admin.getTableRegions(name).size() > 1;
            }
        });
    }
    List<Get> gets = new ArrayList<>(MAX_SIZE);
    for (int i = 0; i < MAX_SIZE; i++) {
        gets.add(new Get(HBaseTestingUtility.ROWS[i]));
    }
    RpcServerInterface rpcServer = TEST_UTIL.getHBaseCluster().getRegionServer(0).getRpcServer();
    BaseSource s = rpcServer.getMetrics().getMetricsSource();
    long startingExceptions = METRICS_replacedERT.getCounter("exceptions", s);
    long startingMultiExceptions = METRICS_replacedERT.getCounter("exceptions.multiResponseTooLarge", s);
    Result[] results = t.get(gets);
    replacedertEquals(MAX_SIZE, results.length);
    // Cells from TEST_UTIL.loadTable have a length of 27.
    // Multiplying by less than that gives an easy lower bound on size.
    // However in reality each kv is being reported as much higher than that.
    METRICS_replacedERT.replacedertCounterGt("exceptions", startingExceptions + ((MAX_SIZE * 25) / MAX_SIZE), s);
    METRICS_replacedERT.replacedertCounterGt("exceptions.multiResponseTooLarge", startingMultiExceptions + ((MAX_SIZE * 25) / MAX_SIZE), s);
}