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

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility#startMiniZKCluster() .
Example 1
Project: phoenix   File: UserDefinedFunctionsIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static synchronized void doSetup() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    setUpConfigForMiniCluster(conf);
    util = new HBaseTestingUtility(conf);
    util.startMiniDFSCluster(1);
    util.startMiniZKCluster(1);
    String string = util.getConfiguration().get("fs.defaultFS");
    // PHOENIX-4675 setting the trailing slash implicitly tests that we're doing some path normalization
    conf.set(DYNAMIC_JARS_DIR_KEY, string+"/hbase/tmpjars/");
    util.startMiniHBaseCluster(1, 1);
    UDFExpression.setConfig(conf);

    String clientPort = util.getConfiguration().get(QueryServices.ZOOKEEPER_PORT_ATTRIB);
    url =
            JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + LOCALHOST + JDBC_PROTOCOL_SEPARATOR
                    + clientPort + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM;
    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    props.put(QueryServices.ALLOW_USER_DEFINED_FUNCTIONS_ATTRIB, "true");
    props.put(QueryServices.DYNAMIC_JARS_DIR_KEY,string+"/hbase/tmpjars/");
    driver = initAndRegisterTestDriver(url, new ReadOnlyProps(props.entrySet().iterator()));
}
 
Example 2
Project: hbase   File: TestMasterReplication.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("resource")
private void startMiniClusters(int numClusters) throws Exception {
  Random random = new Random();
  utilities = new HBaseTestingUtility[numClusters];
  configurations = new Configuration[numClusters];
  for (int i = 0; i < numClusters; i++) {
    Configuration conf = new Configuration(baseConfiguration);
    conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/" + i + random.nextInt());
    HBaseTestingUtility utility = new HBaseTestingUtility(conf);
    if (i == 0) {
      utility.startMiniZKCluster();
      miniZK = utility.getZkCluster();
    } else {
      utility.setZkCluster(miniZK);
    }
    utility.startMiniCluster();
    utilities[i] = utility;
    configurations[i] = conf;
    new ZKWatcher(conf, "cluster" + i, null, true);
  }
}
 
Example 3
Project: hbase   File: TestRegionServerAbort.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  testUtil = new HBaseTestingUtility();
  conf = testUtil.getConfiguration();
  conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY,
      StopBlockingRegionObserver.class.getName());
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
      StopBlockingRegionObserver.class.getName());
  // make sure we have multiple blocks so that the client does not prefetch all block locations
  conf.set("dfs.blocksize", Long.toString(100 * 1024));
  // prefetch the first block
  conf.set(DFSConfigKeys.DFS_CLIENT_READ_PREFETCH_SIZE_KEY, Long.toString(100 * 1024));
  conf.set(HConstants.REGION_IMPL, ErrorThrowingHRegion.class.getName());

  testUtil.startMiniZKCluster();
  dfsCluster = testUtil.startMiniDFSCluster(2);
  StartMiniClusterOption option = StartMiniClusterOption.builder().numRegionServers(2).build();
  cluster = testUtil.startMiniHBaseCluster(option);
}
 
Example 4
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Set true to filter replication edits for dropped table
  conf1.setBoolean(REPLICATION_DROP_ON_DELETED_COLUMN_FAMILY_KEY, true);
  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 5
Project: hbase   File: CustomSaslAuthenticationProviderTestBase.java    License: Apache License 2.0 6 votes vote down vote up
private static void createBaseCluster(HBaseTestingUtility util, File keytabFile, MiniKdc kdc)
  throws Exception {
  String servicePrincipal = "hbase/localhost";
  String spnegoPrincipal = "HTTP/localhost";
  kdc.createPrincipal(keytabFile, servicePrincipal);
  util.startMiniZKCluster();

  HBaseKerberosUtils.setSecuredConfiguration(util.getConfiguration(),
    servicePrincipal + "@" + kdc.getRealm(), spnegoPrincipal + "@" + kdc.getRealm());
  HBaseKerberosUtils.setSSLConfiguration(util, SecureTestCluster.class);

  util.getConfiguration().setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
    TokenProvider.class.getName());
  util.startMiniDFSCluster(1);
  Path rootdir = util.getDataTestDirOnTestFS("TestCustomSaslAuthenticationProvider");
  CommonFSUtils.setRootDir(util.getConfiguration(), rootdir);
}
 
Example 6
Project: envelope   File: TestHBaseOutput.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  utility = new HBaseTestingUtility();
  utility.startMiniZKCluster();
  utility.startMiniHBaseCluster(1,1);
  connection = utility.getConnection();
}
 
Example 7
Project: spliceengine   File: HBaseSITestEnv.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void startCluster(Configuration conf) throws Exception{
    int basePort = getNextBasePort();
    // -> MapR work-around
    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "file:///");
    conf.set("fs.default.name", "file:///");
    conf.set("fs.hdfs.client", "org.apache.hadoop.hdfs.DistributedFileSystem");
    System.setProperty("zookeeper.sasl.client", "false");
    System.setProperty("zookeeper.sasl.serverconfig", "fake");
    // <- MapR work-around
    conf.setInt("hbase.master.port", basePort);
    conf.setInt("hbase.master.info.port", basePort + 1);
    conf.setInt("hbase.regionserver.port", basePort + 2);
    conf.setInt("hbase.regionserver.info.port", basePort + 3);

    testUtility = new HBaseTestingUtility(conf);

    Configuration configuration = testUtility.getConfiguration();
    // -> MapR work-around
    configuration.set(FileSystem.FS_DEFAULT_NAME_KEY, "file:///");
    configuration.set("fs.default.name", "file:///");
    configuration.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
    configuration.set("fs.hdfs.client", "org.apache.hadoop.hdfs.DistributedFileSystem");
    System.setProperty("zookeeper.sasl.client", "false");
    System.setProperty("zookeeper.sasl.serverconfig", "fake");
    // <- MapR work-around
    configuration.setInt("hbase.master.port", basePort);
    configuration.setInt("hbase.master.info.port", basePort + 1);
    configuration.setInt("hbase.regionserver.port", basePort + 2);
    configuration.setInt("hbase.regionserver.info.port", basePort + 3);
    if (FileSystem.class.getProtectionDomain().getCodeSource().getLocation().getPath().contains("mapr")) {
        testUtility.startMiniCluster(1);
    } else {
        testUtility.startMiniZKCluster();
        testUtility.startMiniHBaseCluster(1, 1);
    }
    ZkUtils.getZkManager().initialize(HConfiguration.getConfiguration());
    ZkUtils.initializeZookeeper();
}
 
Example 8
Project: spork   File: TestHBaseStorage.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    // This is needed by Pig
    conf = HBaseConfiguration.create(new Configuration());

    util = new HBaseTestingUtility(conf);
    util.startMiniZKCluster();
    util.startMiniHBaseCluster(1, 1);
}
 
Example 9
Project: hbase   File: TestShadeSaslAuthenticationProvider.java    License: Apache License 2.0 5 votes vote down vote up
static LocalHBaseCluster createCluster(HBaseTestingUtility util, File keytabFile,
    MiniKdc kdc, Map<String,char[]> userDatabase) throws Exception {
  String servicePrincipal = "hbase/localhost";
  String spnegoPrincipal = "HTTP/localhost";
  kdc.createPrincipal(keytabFile, servicePrincipal);
  util.startMiniZKCluster();

  HBaseKerberosUtils.setSecuredConfiguration(util.getConfiguration(),
      servicePrincipal + "@" + kdc.getRealm(), spnegoPrincipal + "@" + kdc.getRealm());
  HBaseKerberosUtils.setSSLConfiguration(util, TestShadeSaslAuthenticationProvider.class);

  util.getConfiguration().setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
      TokenProvider.class.getName());
  util.startMiniDFSCluster(1);
  Path testDir = util.getDataTestDirOnTestFS("TestShadeSaslAuthenticationProvider");
  USER_DATABASE_FILE = new Path(testDir, "user-db.txt");

  createUserDBFile(
      USER_DATABASE_FILE.getFileSystem(CONF), USER_DATABASE_FILE, userDatabase);
  CONF.set(ShadeSaslServerAuthenticationProvider.PASSWORD_FILE_KEY,
      USER_DATABASE_FILE.toString());

  Path rootdir = new Path(testDir, "hbase-root");
  CommonFSUtils.setRootDir(CONF, rootdir);
  LocalHBaseCluster cluster = new LocalHBaseCluster(CONF, 1);
  return cluster;
}
 
Example 10
Project: hbase   File: TestReplicationTrackerZKImpl.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  utility = new HBaseTestingUtility();
  utility.startMiniZKCluster();
  conf = utility.getConfiguration();
  ZKWatcher zk = HBaseTestingUtility.getZooKeeperWatcher(utility);
  ZKUtil.createWithParents(zk, zk.getZNodePaths().rsZNode);
}
 
Example 11
Project: hbase   File: TestGlobalReplicationThrottler.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf1 = HBaseConfiguration.create();
  conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
  conf1.setLong("replication.source.sleepforretries", 100);
  // Each WAL is about 120 bytes
  conf1.setInt(HConstants.REPLICATION_SOURCE_TOTAL_BUFFER_KEY, REPLICATION_SOURCE_QUOTA);
  conf1.setLong("replication.source.per.peer.node.bandwidth", 100L);

  utility1 = new HBaseTestingUtility(conf1);
  utility1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = utility1.getZkCluster();
  new ZKWatcher(conf1, "cluster1", null, true);

  conf2 = new Configuration(conf1);
  conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");

  utility2 = new HBaseTestingUtility(conf2);
  utility2.setZkCluster(miniZK);
  new ZKWatcher(conf2, "cluster2", null, true);

  ReplicationPeerConfig rpc = new ReplicationPeerConfig();
  rpc.setClusterKey(utility2.getClusterKey());

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

  Admin admin1 = ConnectionFactory.createConnection(conf1).getAdmin();
  admin1.addReplicationPeer("peer1", rpc);
  admin1.addReplicationPeer("peer2", rpc);
  admin1.addReplicationPeer("peer3", rpc);
  numOfPeer = admin1.listReplicationPeers().size();
}
 
Example 12
Project: hbase-indexer   File: SepConsumerIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    clusterConf = HBaseConfiguration.create();
    
    // HACK disabled because always on in hbase-2 (see HBASE-16040)
    // clusterConf.setBoolean(HConstants.REPLICATION_ENABLE_KEY, true);
    
    clusterConf.setLong("replication.source.sleepforretries", 50);
    //clusterConf.set("replication.replicationsource.implementation", SepReplicationSource.class.getName());
    clusterConf.setInt("hbase.master.info.port", -1);
    clusterConf.setInt("hbase.regionserver.info.port", -1);

    hbaseTestUtil = new HBaseTestingUtility(clusterConf);

    hbaseTestUtil.startMiniZKCluster(1);
    hbaseTestUtil.startMiniCluster(1);

    HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
    HColumnDescriptor dataColfamDescriptor = new HColumnDescriptor(DATA_COL_FAMILY);
    dataColfamDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
    HColumnDescriptor payloadColfamDescriptor = new HColumnDescriptor(PAYLOAD_COL_FAMILY);
    payloadColfamDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
    tableDescriptor.addFamily(dataColfamDescriptor);
    tableDescriptor.addFamily(payloadColfamDescriptor);

    connection = ConnectionFactory.createConnection(clusterConf);
    connection.getAdmin().createTable(tableDescriptor);
    htable = connection.getTable(TableName.valueOf(TABLE_NAME));
}
 
Example 13
Project: hbase   File: TestVerifyReplicationCrossDiffHdfs.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
  util1 = new HBaseTestingUtility(conf1);
  util1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = util1.getZkCluster();
  conf1 = util1.getConfiguration();

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

  util1.startMiniCluster();
  util2.startMiniCluster();

  createTestingTable(util1.getAdmin());
  createTestingTable(util2.getAdmin());
  addTestingPeer();

  LOG.info("Start to load some data to source cluster.");
  loadSomeData();

  LOG.info("Start mini MapReduce cluster.");
  mapReduceUtil.setZkCluster(miniZK);
  mapReduceUtil.startMiniMapReduceCluster();
}
 
Example 14
Project: hbase   File: TestZKSecretWatcher.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws Exception {
  TEST_UTIL = new HBaseTestingUtility();
  TEST_UTIL.startMiniZKCluster();
  Configuration conf = TEST_UTIL.getConfiguration();

  ZKWatcher zk = newZK(conf, "server1", new MockAbortable());
  AuthenticationTokenSecretManagerForTest[] tmp = new AuthenticationTokenSecretManagerForTest[2];
  tmp[0] = new AuthenticationTokenSecretManagerForTest(
      conf, zk, "server1", 60*60*1000, 60*1000);
  tmp[0].start();

  zk = newZK(conf, "server2", new MockAbortable());
  tmp[1] = new AuthenticationTokenSecretManagerForTest(
      conf, zk, "server2", 60*60*1000, 60*1000);
  tmp[1].start();

  while (KEY_MASTER == null) {
    for (int i=0; i<2; i++) {
      if (tmp[i].isMaster()) {
        KEY_MASTER = tmp[i];
        KEY_SLAVE = tmp[ (i+1) % 2 ];
        break;
      }
    }
    Thread.sleep(500);
  }
  LOG.info("Master is "+KEY_MASTER.getName()+
      ", slave is "+KEY_SLAVE.getName());
}
 
Example 15
Project: hbase   File: TestPerTableCFReplication.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf1 = HBaseConfiguration.create();
  conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
  // smaller block size and capacity to trigger more operations
  // and test them
  conf1.setInt("hbase.regionserver.hlog.blocksize", 1024*20);
  conf1.setInt("replication.source.size.capacity", 1024);
  conf1.setLong("replication.source.sleepforretries", 100);
  conf1.setInt("hbase.regionserver.maxlogs", 10);
  conf1.setLong("hbase.master.logcleaner.ttl", 10);
  conf1.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100);
  conf1.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY,
      "org.apache.hadoop.hbase.replication.TestMasterReplication$CoprocessorCounter");

  utility1 = new HBaseTestingUtility(conf1);
  utility1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = utility1.getZkCluster();
  new ZKWatcher(conf1, "cluster1", null, true);

  conf2 = new Configuration(conf1);
  conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");

  conf3 = new Configuration(conf1);
  conf3.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/3");

  utility2 = new HBaseTestingUtility(conf2);
  utility2.setZkCluster(miniZK);
  new ZKWatcher(conf2, "cluster3", null, true);

  utility3 = new HBaseTestingUtility(conf3);
  utility3.setZkCluster(miniZK);
  new ZKWatcher(conf3, "cluster3", null, true);

  table = new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(famName);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  table.setColumnFamily(familyDescriptor);
  familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(noRepfamName);
  table.setColumnFamily(familyDescriptor);

  tabA = new TableDescriptorBuilder.ModifyableTableDescriptor(tabAName);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f1Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabA.setColumnFamily(familyDescriptor);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f2Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabA.setColumnFamily(familyDescriptor);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f3Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabA.setColumnFamily(familyDescriptor);

  tabB = new TableDescriptorBuilder.ModifyableTableDescriptor(tabBName);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f1Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabB.setColumnFamily(familyDescriptor);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f2Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabB.setColumnFamily(familyDescriptor);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f3Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabB.setColumnFamily(familyDescriptor);

  tabC = new TableDescriptorBuilder.ModifyableTableDescriptor(tabCName);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f1Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabC.setColumnFamily(familyDescriptor);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f2Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabC.setColumnFamily(familyDescriptor);
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(f3Name);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tabC.setColumnFamily(familyDescriptor);

  utility1.startMiniCluster();
  utility2.startMiniCluster();
  utility3.startMiniCluster();
}
 
Example 16
Project: hbase   File: TestMultiSlaveReplication.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf1 = HBaseConfiguration.create();
  conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
  // smaller block size and capacity to trigger more operations
  // and test them
  conf1.setInt("hbase.regionserver.hlog.blocksize", 1024*20);
  conf1.setInt("replication.source.size.capacity", 1024);
  conf1.setLong("replication.source.sleepforretries", 100);
  conf1.setInt("hbase.regionserver.maxlogs", 10);
  conf1.setLong("hbase.master.logcleaner.ttl", 10);
  conf1.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100);
  conf1.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY,
      "org.apache.hadoop.hbase.replication.TestMasterReplication$CoprocessorCounter");
  conf1.setInt("hbase.master.cleaner.interval", 5 * 1000);

  utility1 = new HBaseTestingUtility(conf1);
  utility1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = utility1.getZkCluster();
  utility1.setZkCluster(miniZK);
  new ZKWatcher(conf1, "cluster1", null, true);

  conf2 = new Configuration(conf1);
  conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");

  conf3 = new Configuration(conf1);
  conf3.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/3");

  utility2 = new HBaseTestingUtility(conf2);
  utility2.setZkCluster(miniZK);
  new ZKWatcher(conf2, "cluster2", null, true);

  utility3 = new HBaseTestingUtility(conf3);
  utility3.setZkCluster(miniZK);
  new ZKWatcher(conf3, "cluster3", null, true);

  table = new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(famName);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  table.setColumnFamily(familyDescriptor);
  familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(noRepfamName);
  table.setColumnFamily(familyDescriptor);
}
 
Example 17
Project: hbase   File: TestReplicationWithTags.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf1.setInt("hfile.format.version", 3);
  conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
  conf1.setInt("replication.source.size.capacity", 10240);
  conf1.setLong("replication.source.sleepforretries", 100);
  conf1.setInt("hbase.regionserver.maxlogs", 10);
  conf1.setLong("hbase.master.logcleaner.ttl", 10);
  conf1.setInt("zookeeper.recovery.retry", 1);
  conf1.setInt("zookeeper.recovery.retry.intervalmill", 10);
  conf1.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100);
  conf1.setInt("replication.stats.thread.period.seconds", 5);
  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,
      TestCoprocessorForTagsAtSource.class.getName());

  utility1 = new HBaseTestingUtility(conf1);
  utility1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = utility1.getZkCluster();
  // Have to reget conf1 in case zk cluster location different
  // than default
  conf1 = utility1.getConfiguration();
  LOG.info("Setup first Zk");

  // Base conf2 on conf1 so it gets the right zk cluster.
  conf2 = HBaseConfiguration.create(conf1);
  conf2.setInt("hfile.format.version", 3);
  conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
  conf2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
  conf2.setBoolean("hbase.tests.use.shortcircuit.reads", false);
  conf2.setStrings(HConstants.REPLICATION_CODEC_CONF_KEY, KeyValueCodecWithTags.class.getName());
  conf2.setStrings(CoprocessorHost.USER_REGION_COPROCESSOR_CONF_KEY,
          TestCoprocessorForTagsAtSink.class.getName());

  utility2 = new HBaseTestingUtility(conf2);
  utility2.setZkCluster(miniZK);

  LOG.info("Setup second Zk");
  utility1.startMiniCluster(2);
  utility2.startMiniCluster(2);

  connection1 = ConnectionFactory.createConnection(conf1);
  replicationAdmin = connection1.getAdmin();
  ReplicationPeerConfig rpc = new ReplicationPeerConfig();
  rpc.setClusterKey(utility2.getClusterKey());
  replicationAdmin.addReplicationPeer("2", rpc);

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLE_NAME);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY);
  familyDescriptor.setMaxVersions(3);
  familyDescriptor.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
  tableDescriptor.setColumnFamily(familyDescriptor);
  try (Connection conn = ConnectionFactory.createConnection(conf1);
      Admin admin = conn.getAdmin()) {
    admin.createTable(tableDescriptor, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
  }
  try (Connection conn = ConnectionFactory.createConnection(conf2);
      Admin admin = conn.getAdmin()) {
    admin.createTable(tableDescriptor, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
  }
  htable1 = utility1.getConnection().getTable(TABLE_NAME);
  htable2 = utility2.getConnection().getTable(TABLE_NAME);
}
 
Example 18
Project: phoenix   File: MutableIndexReplicationIT.java    License: Apache License 2.0 4 votes vote down vote up
private static void setupConfigsAndStartCluster() throws Exception {
        // cluster-1 lives at regular HBase home, so we don't need to change how phoenix handles
        // lookups
//        conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
        // smaller log roll size to trigger more events
        setUpConfigForMiniCluster(conf1);
        conf1.setFloat("hbase.regionserver.logroll.multiplier", 0.0003f);
        conf1.setInt("replication.source.size.capacity", 10240);
        conf1.setLong("replication.source.sleepforretries", 100);
        conf1.setInt("hbase.regionserver.maxlogs", 10);
        conf1.setLong("hbase.master.logcleaner.ttl", 10);
        conf1.setInt("zookeeper.recovery.retry", 1);
        conf1.setInt("zookeeper.recovery.retry.intervalmill", 10);
        conf1.setBoolean("dfs.support.append", true);
        conf1.setLong(HConstants.THREAD_WAKE_FREQUENCY, 100);
        conf1.setInt("replication.stats.thread.period.seconds", 5);
        conf1.setBoolean("hbase.tests.use.shortcircuit.reads", false);

        utility1 = new HBaseTestingUtility(conf1);
        utility1.startMiniZKCluster();
        MiniZooKeeperCluster miniZK = utility1.getZkCluster();
        // Have to reset conf1 in case zk cluster location different
        // than default
        conf1 = utility1.getConfiguration();
        zkw1 = new ZKWatcher(conf1, "cluster1", null, true);
        admin=ConnectionFactory.createConnection(conf1).getAdmin();
        LOGGER.info("Setup first Zk");

        // Base conf2 on conf1 so it gets the right zk cluster, and general cluster configs
        conf2 = HBaseConfiguration.create(conf1);
        conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
        conf2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
        conf2.setBoolean("dfs.support.append", true);
        conf2.setBoolean("hbase.tests.use.shortcircuit.reads", false);

        utility2 = new HBaseTestingUtility(conf2);
        utility2.setZkCluster(miniZK);
        zkw2 = new ZKWatcher(conf2, "cluster2", null, true);

        LOGGER.info("Setup second Zk");
        utility1.startMiniCluster(2);
        utility2.startMiniCluster(2);
      //replicate from cluster 1 -> cluster 2, but not back again
        admin.addReplicationPeer("1", new ReplicationPeerConfig().setClusterKey(utility2.getClusterKey()));
    }
 
Example 19
Project: hbase   File: TestZKSecretWatcherRefreshKeys.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws Exception {
  TEST_UTIL = new HBaseTestingUtility();
  TEST_UTIL.startMiniZKCluster();
}
 
Example 20
Project: hadoop-arch-book   File: RunLocalTest.java    License: Apache License 2.0 2 votes vote down vote up
public static void main(String[] args) throws Exception{

    HBaseTestingUtility htu = HBaseTestingUtility.createLocalHTU();
    Configuration config = htu.getConfiguration();

    htu.cleanupTestDir();
    htu.startMiniZKCluster();
    htu.startMiniHBaseCluster(1, 1);

    RemoveTables.executeDeleteTables(config);

    CreateTables.executeCreateTables(config);



    //Start up servers
    Server flumeTestServer = startTestFlumeServer(4243);

    List<String> flumePorts = new ArrayList<String>();
    flumePorts.add("127.0.0.1:4243");
    EventReviewServer server = new EventReviewServer(4242, config, flumePorts, false);
    server.startServer();

    EventClient client = new EventClient("127.0.0.1", 4242);
    client.startClient();

    HConnection connection = HConnectionManager.createConnection(config);

    //popoulate initial data
    populateUserProfileData(connection);
    populateValidationRules(connection);

    //populate user events
    UserEvent userEvent = new UserEvent("101", System.currentTimeMillis(),
            "127.0.0.1", "1", "55555",
            "42", 100.0, "101", true);

    client.submitUserEvent(userEvent);

    //shut down servers
    client.closeClient();
    server.closeServer();
    stopTestFlumeServer(flumeTestServer);
    htu.shutdownMiniCluster();

  }