@Test public void testParsingClusterVersion() throws Exception { final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<ClusterVersion Version=\"2.0.0\"/>"; Client client = mock(Client.class); RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null); Response resp = new Response(200, null, Bytes.toBytes(xml)); when(client.get("/version/cluster", Constants.MIMETYPE_XML)).thenReturn(resp); StorageClusterVersionModel cv = admin.getClusterVersion(); assertEquals("2.0.0", cv.getVersion()); }
@Test public void testGetZooKeeperClusterKey() { Configuration conf = HBaseConfiguration.create(); conf.set(HConstants.ZOOKEEPER_QUORUM, "\tlocalhost\n"); conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, "3333"); conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "hbase"); String clusterKey = ZKConfig.getZooKeeperClusterKey(conf, "test"); assertTrue(!clusterKey.contains("\t") && !clusterKey.contains("\n")); assertEquals("localhost:3333:hbase,test", clusterKey); }
public static void main(String[] args) throws Throwable { int rowCount = 100; byte[] family = Bytes.toBytes("family"); Configuration conf = HBaseConfiguration.create(); TableName tableName = TableName.valueOf("ExportEndpointExample"); try (Connection con = ConnectionFactory.createConnection(conf); Admin admin = con.getAdmin()) { byte[] bs = Bytes.toBytes(row); Put put = new Put(bs); put.addColumn(family, bs, bs); final long totalOutputRows = result.values().stream().mapToLong(v -> v.getRowCount()).sum(); final long totalOutputCells = result.values().stream().mapToLong(v -> v.getCellCount()).sum(); System.out.println("table:" + tableName); System.out.println("output:" + output); System.out.println("total rows:" + totalOutputRows); System.out.println("total cells:" + totalOutputCells);
@Test public void TestCellCounterWithoutOutputDir() throws Exception { String[] args = new String[] { "tableName" }; assertEquals("CellCounter should exit with -1 as output directory is not specified.", -1, ToolRunner.run(HBaseConfiguration.create(), new CellCounter(), args)); } }
@Test public void testExecutorService() throws Exception { int maxThreads = 5; when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create()); assertEquals(0, pool.getPoolSize()); assertEquals(maxThreads, counter.get()); assertEquals(maxThreads, pool.getPoolSize()); System.out.println("Waiting for all event handlers to finish..."); Thread.sleep(sleepInterval); tries++;
public static void main(String[] args) throws Exception { Configuration config = HBaseConfiguration.create(); if (args.length > 0) { config.set("hbase.rootdir", args[0]); } HTable table = new HTable(config, "WordCount"); for (String word : WordSpout.words) { Get get = new Get(Bytes.toBytes(word)); Result result = table.get(get); byte[] countBytes = result.getValue(Bytes.toBytes("cf"), Bytes.toBytes("count")); byte[] wordBytes = result.getValue(Bytes.toBytes("cf"), Bytes.toBytes("word")); String wordStr = Bytes.toString(wordBytes); System.out.println(wordStr); long count = Bytes.toLong(countBytes); System.out.println("Word: '" + wordStr + "', Count: " + count); } } }
@Test public void testZKConfigLoading() throws Exception { Configuration conf = HBaseConfiguration.create(); // Test that we read only from the config instance // (i.e. via hbase-default.xml and hbase-site.xml) conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2181); Properties props = ZKConfig.makeZKProps(conf); assertEquals("Property client port should have been default from the HBase config", "2181", props.getProperty("clientPort")); }
private static void transformFile(Path input, Path output) throws IOException { Configuration conf = HBaseConfiguration.create(); FileSystem inFS = input.getFileSystem(conf); FileSystem outFS = output.getFileSystem(conf); WAL.Reader in = WALFactory.createReaderIgnoreCustomClass(inFS, input, conf); WALProvider.Writer out = null; try { if (!(in instanceof ReaderBase)) { System.err.println("Cannot proceed, invalid reader type: " + in.getClass().getName()); return; } boolean compress = ((ReaderBase)in).hasCompression(); conf.setBoolean(HConstants.ENABLE_WAL_COMPRESSION, !compress); out = WALFactory.createWALWriter(outFS, output, conf); WAL.Entry e = null; while ((e = in.next()) != null) out.append(e); } finally { in.close(); if (out != null) { out.close(); out = null; } } }
@Test public void testCallQueueTooBigExceptionDoesntTriggerPffe() throws Exception { Admin admin = TEST_UTIL.getAdmin(); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(Bytes .toBytes(tableName))); desc.addFamily(new HColumnDescriptor(FAMILY)); admin.createTable(desc, Bytes.toBytes("aaaa"), Bytes.toBytes("zzzz"), 3); Configuration newConf = HBaseConfiguration.create(TEST_UTIL.getConfiguration()); newConf.setInt("hbase.ipc.server.max.callqueue.length", 0); srs.onConfigurationChange(newConf); try (Table table = connection.getTable(TableName.valueOf(tableName))) { Get get = new Get(new byte[1]); table.get(get); assertEquals("We should have not entered PFFE mode on CQTBE, but we did;" + " number of times this mode should have been entered:", 0, CallQueueTooBigPffeInterceptor.numCallQueueTooBig.get()); newConf = HBaseConfiguration.create(TEST_UTIL.getConfiguration()); newConf.setInt("hbase.ipc.server.max.callqueue.length", 250); srs.onConfigurationChange(newConf);
commandLine = cmdLineParser.parse(options, args); } catch (ParseException parseException) { System.out.println( "ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException); System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args)); printUsage(options); return; Configuration configuration = HBaseConfiguration.create(); int concurrency = Integer.parseInt(commandLine.getOptionValue("servers")); long minModTime = Long.parseLong( long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000))); configuration.set(HConstants.HBASE_DIR, rootDir); configuration.set(HConstants.ZOOKEEPER_QUORUM, quorum); new MajorCompactor(configuration, TableName.valueOf(tableName), families, concurrency, minModTime, sleep);
@Test public void testInvalidAcceptFactorConfig() throws IOException { float[] configValues = {-1f, 0.2f, 0.86f, 1.05f}; boolean[] expectedOutcomes = {false, false, true, false}; Map<String, float[]> configMappings = ImmutableMap.of(BucketCache.ACCEPT_FACTOR_CONFIG_NAME, configValues); Configuration conf = HBaseConfiguration.create(); checkConfigValues(conf, configMappings, expectedOutcomes); }
@Test public void testRpcTimeout() throws IOException { Configuration localConfig = HBaseConfiguration.create(this.conf); localConfig.set("hbase.client.connection.impl", RpcTimeoutConnection.class.getName()); int pause = 10; localConfig.setInt("hbase.client.pause", pause); try { table.exists(new Get(Bytes.toBytes("abc"))); } catch (SocketTimeoutException e) {
@Test public void testCreateBasedOnConfig() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.set(StoreEngine.STORE_ENGINE_CLASS_KEY, TestStoreEngine.class.getName()); StripeStoreEngine se = createEngine(conf); assertTrue(se.getCompactionPolicy() instanceof StripeCompactionPolicy); }
@Test public void testScanQueueWithZeroScanRatio() throws Exception { Configuration schedConf = HBaseConfiguration.create(); schedConf.setFloat(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 1.0f); schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0.5f); schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0f); PriorityFunction priority = mock(PriorityFunction.class); when(priority.getPriority(any(), any(), any())).thenReturn(HConstants.NORMAL_QOS); RpcScheduler scheduler = new SimpleRpcScheduler(schedConf, 2, 1, 1, priority, HConstants.QOS_THRESHOLD); assertNotEquals(null, scheduler); }
@Test public void testNoStripesFromFlush() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setBoolean(StripeStoreConfig.FLUSH_TO_L0_KEY, true); StripeCompactionPolicy policy = createPolicy(conf); StripeInformationProvider si = createStripesL0Only(0, 0); KeyValue[] input = new KeyValue[] { KV_A, KV_B, KV_C, KV_D, KV_E }; KeyValue[][] expected = new KeyValue[][] { input }; verifyFlush(policy, si, input, expected, null); }
@Test public void testAlternateBufferedMutatorImpl() throws IOException { BufferedMutatorParams params = new BufferedMutatorParams(TableName.valueOf(name.getMethodName())); Configuration conf = HBaseConfiguration.create(); conf.set(AsyncRegistryFactory.REGISTRY_IMPL_CONF_KEY, DoNothingAsyncRegistry.class.getName()); try (Connection connection = ConnectionFactory.createConnection(conf)) { BufferedMutator bm = connection.getBufferedMutator(params); // Assert we get default BM if nothing specified. assertTrue(bm instanceof BufferedMutatorImpl); // Now try and set my own BM implementation. params.implementationClassName(MyBufferedMutator.class.getName()); bm = connection.getBufferedMutator(params); assertTrue(bm instanceof MyBufferedMutator); } // Now try creating a Connection after setting an alterate BufferedMutator into // the configuration and confirm we get what was expected. conf.set(BufferedMutator.CLASSNAME_KEY, MyBufferedMutator.class.getName()); try (Connection connection = ConnectionFactory.createConnection(conf)) { BufferedMutator bm = connection.getBufferedMutator(params); assertTrue(bm instanceof MyBufferedMutator); } } }
@Test public void testNothingToCompactFromL0() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setInt(StripeStoreConfig.MIN_FILES_L0_KEY, 4); StripeCompactionPolicy.StripeInformationProvider si = createStripesL0Only(3, 10); StripeCompactionPolicy policy = createPolicy(conf); verifyNoCompaction(policy, si); si = createStripes(3, KEY_A); verifyNoCompaction(policy, si); }