Search in sources :

Example 36 with HBaseTestingUtility

use of org.apache.hadoop.hbase.HBaseTestingUtility in project hbase by apache.

the class TestVisibilityLabelReplicationWithExpAsString method setup.

@Override
@Before
public void setup() throws Exception {
    expected[0] = 4;
    expected[1] = 6;
    expected[2] = 4;
    expected[3] = 0;
    expected[3] = 3;
    expectedVisString[0] = "(\"public\"&\"secret\"&\"topsecret\")|(\"confidential\"&\"topsecret\")";
    expectedVisString[1] = "(\"private\"&\"public\")|(\"private\"&\"topsecret\")|" + "(\"confidential\"&\"public\")|(\"confidential\"&\"topsecret\")";
    expectedVisString[2] = "(!\"topsecret\"&\"secret\")|(!\"topsecret\"&\"confidential\")";
    expectedVisString[3] = "(\"secret\"&\"" + COPYRIGHT + "\\\"" + ACCENT + "\\\\" + SECRET + "\\\"" + "'&\\\\" + "\")";
    // setup configuration
    conf = HBaseConfiguration.create();
    conf.setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, false);
    conf.setInt("hfile.format.version", 3);
    conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
    conf.setInt("replication.source.size.capacity", 10240);
    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);
    setVisibilityLabelServiceImpl(conf, ExpAsStringVisibilityLabelServiceImpl.class);
    conf.setStrings(HConstants.REPLICATION_CODEC_CONF_KEY, KeyValueCodecWithTags.class.getName());
    VisibilityTestUtil.enableVisiblityLabels(conf);
    conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, VisibilityReplication.class.getName());
    conf.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY, SimpleCP.class.getName());
    // Have to reset conf1 in case zk cluster location different
    // than default
    conf.setClass(VisibilityUtils.VISIBILITY_LABEL_GENERATOR_CLASS, SimpleScanLabelGenerator.class, ScanLabelGenerator.class);
    conf.set("hbase.superuser", "admin");
    conf.set("hbase.superuser", User.getCurrent().getShortName());
    SUPERUSER = User.createUserForTesting(conf, User.getCurrent().getShortName(), new String[] { "supergroup" });
    User.createUserForTesting(conf, User.getCurrent().getShortName(), new String[] { "supergroup" });
    USER1 = User.createUserForTesting(conf, "user1", new String[] {});
    TEST_UTIL = new HBaseTestingUtility(conf);
    TEST_UTIL.startMiniZKCluster();
    MiniZooKeeperCluster miniZK = TEST_UTIL.getZkCluster();
    zkw1 = new ZooKeeperWatcher(conf, "cluster1", null, true);
    admin = TEST_UTIL.getAdmin();
    // Base conf2 on conf1 so it gets the right zk cluster.
    conf1 = HBaseConfiguration.create(conf);
    conf1.setInt("hfile.format.version", 3);
    conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
    conf1.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
    conf1.setBoolean("hbase.tests.use.shortcircuit.reads", false);
    conf1.setStrings(HConstants.REPLICATION_CODEC_CONF_KEY, KeyValueCodecWithTags.class.getName());
    conf1.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY, TestCoprocessorForTagsAtSink.class.getName());
    setVisibilityLabelServiceImpl(conf1, ExpAsStringVisibilityLabelServiceImpl.class);
    TEST_UTIL1 = new HBaseTestingUtility(conf1);
    TEST_UTIL1.setZkCluster(miniZK);
    zkw2 = new ZooKeeperWatcher(conf1, "cluster2", null, true);
    TEST_UTIL.startMiniCluster(1);
    // Wait for the labels table to become available
    TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
    TEST_UTIL1.startMiniCluster(1);
    ReplicationPeerConfig rpc = new ReplicationPeerConfig();
    rpc.setClusterKey(TEST_UTIL1.getClusterKey());
    admin.addReplicationPeer("2", rpc);
    HTableDescriptor table = new HTableDescriptor(TABLE_NAME);
    HColumnDescriptor desc = new HColumnDescriptor(fam);
    desc.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
    table.addFamily(desc);
    try (Admin hBaseAdmin = TEST_UTIL.getAdmin()) {
        hBaseAdmin.createTable(table);
    }
    try (Admin hBaseAdmin1 = TEST_UTIL1.getAdmin()) {
        hBaseAdmin1.createTable(table);
    }
    addLabels();
    setAuths(conf);
    setAuths(conf1);
}
Also used : KeyValueCodecWithTags(org.apache.hadoop.hbase.codec.KeyValueCodecWithTags) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) VisibilityReplication(org.apache.hadoop.hbase.security.visibility.VisibilityController.VisibilityReplication) MiniZooKeeperCluster(org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster) ReplicationAdmin(org.apache.hadoop.hbase.client.replication.ReplicationAdmin) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Before(org.junit.Before)

Example 37 with HBaseTestingUtility

use of org.apache.hadoop.hbase.HBaseTestingUtility in project hbase by apache.

the class TestBlocksScanned method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    TEST_UTIL = new HBaseTestingUtility();
}
Also used : HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) Before(org.junit.Before)

Example 38 with HBaseTestingUtility

use of org.apache.hadoop.hbase.HBaseTestingUtility in project hbase by apache.

the class TestCompactionArchiveIOException method setup.

@Before
public void setup() throws Exception {
    testUtil = new HBaseTestingUtility();
    testUtil.startMiniDFSCluster(1);
    testDir = testUtil.getDataTestDirOnTestFS();
    FSUtils.setRootDir(testUtil.getConfiguration(), testDir);
}
Also used : HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) Before(org.junit.Before)

Example 39 with HBaseTestingUtility

use of org.apache.hadoop.hbase.HBaseTestingUtility in project hbase by apache.

the class TestDefaultMemStore method checkShouldFlush.

protected void checkShouldFlush(Configuration conf, boolean expected) throws Exception {
    try {
        EnvironmentEdgeForMemstoreTest edge = new EnvironmentEdgeForMemstoreTest();
        EnvironmentEdgeManager.injectEdge(edge);
        HBaseTestingUtility hbaseUtility = HBaseTestingUtility.createLocalHTU(conf);
        String cf = "foo";
        HRegion region = hbaseUtility.createTestRegion("foobar", new HColumnDescriptor(cf));
        edge.setCurrentTimeMillis(1234);
        Put p = new Put(Bytes.toBytes("r"));
        p.add(KeyValueTestUtil.create("r", cf, "q", 100, "v"));
        region.put(p);
        edge.setCurrentTimeMillis(1234 + 100);
        StringBuffer sb = new StringBuffer();
        assertTrue(!region.shouldFlush(sb));
        edge.setCurrentTimeMillis(1234 + 10000);
        assertTrue(region.shouldFlush(sb) == expected);
    } finally {
        EnvironmentEdgeManager.reset();
    }
}
Also used : HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Put(org.apache.hadoop.hbase.client.Put)

Example 40 with HBaseTestingUtility

use of org.apache.hadoop.hbase.HBaseTestingUtility in project hbase by apache.

the class TestDefaultMemStore method testShouldFlushMeta.

@Test
public void testShouldFlushMeta() throws Exception {
    // write an edit in the META and ensure the shouldFlush (that the periodic memstore
    // flusher invokes) returns true after SYSTEM_CACHE_FLUSH_INTERVAL (even though
    // the MEMSTORE_PERIODIC_FLUSH_INTERVAL is set to a higher value)
    Configuration conf = new Configuration();
    conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, HRegion.SYSTEM_CACHE_FLUSH_INTERVAL * 10);
    HBaseTestingUtility hbaseUtility = HBaseTestingUtility.createLocalHTU(conf);
    Path testDir = hbaseUtility.getDataTestDir();
    EnvironmentEdgeForMemstoreTest edge = new EnvironmentEdgeForMemstoreTest();
    EnvironmentEdgeManager.injectEdge(edge);
    edge.setCurrentTimeMillis(1234);
    WALFactory wFactory = new WALFactory(conf, null, "1234");
    HRegion meta = HRegion.createHRegion(HRegionInfo.FIRST_META_REGIONINFO, testDir, conf, FSTableDescriptors.createMetaTableDescriptor(conf), wFactory.getMetaWAL(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes()));
    HRegionInfo hri = new HRegionInfo(TableName.valueOf(name.getMethodName()), Bytes.toBytes("row_0200"), Bytes.toBytes("row_0300"));
    HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
    desc.addFamily(new HColumnDescriptor("foo".getBytes()));
    HRegion r = HRegion.createHRegion(hri, testDir, conf, desc, wFactory.getWAL(hri.getEncodedNameAsBytes(), hri.getTable().getNamespace()));
    HRegion.addRegionToMETA(meta, r);
    edge.setCurrentTimeMillis(1234 + 100);
    StringBuffer sb = new StringBuffer();
    assertTrue(meta.shouldFlush(sb) == false);
    edge.setCurrentTimeMillis(edge.currentTime() + HRegion.SYSTEM_CACHE_FLUSH_INTERVAL + 1);
    assertTrue(meta.shouldFlush(sb) == true);
}
Also used : Path(org.apache.hadoop.fs.Path) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) WALFactory(org.apache.hadoop.hbase.wal.WALFactory) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Aggregations

HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)136 Configuration (org.apache.hadoop.conf.Configuration)50 BeforeClass (org.junit.BeforeClass)49 Test (org.junit.Test)42 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)35 Path (org.apache.hadoop.fs.Path)29 Admin (org.apache.hadoop.hbase.client.Admin)24 FileSystem (org.apache.hadoop.fs.FileSystem)22 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)20 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)18 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)16 Before (org.junit.Before)14 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)11 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)11 MiniZooKeeperCluster (org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster)10 Table (org.apache.hadoop.hbase.client.Table)8 HFileSystem (org.apache.hadoop.hbase.fs.HFileSystem)8 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)8 FileStatus (org.apache.hadoop.fs.FileStatus)7 Result (org.apache.hadoop.hbase.client.Result)7