Refine search
@Test public void testFlush() throws IOException { byte[] row = Bytes.toBytes("row"); byte[] cf = Bytes.toBytes("cf"); byte[] cq = Bytes.toBytes("cq"); byte[] value = Bytes.toBytes("value"); TableName name = TableName.valueOf(getClass().getSimpleName()); Table t = util.createTable(name, cf); t.put(new Put(row).addColumn(cf, cq, value)); util.getAdmin().flush(name); assertArrayEquals(value, t.get(new Get(row)).getValue(cf, cq)); } }
@Test public void testSplitShouldNotHappenIfSplitIsDisabledForTable() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor htd = new HTableDescriptor(tableName); htd.addFamily(new HColumnDescriptor("f")); htd.setRegionSplitPolicyClassName(DisabledRegionSplitPolicy.class.getName()); Table table = TEST_UTIL.createTable(htd, null); for(int i = 0; i < 10; i++) { Put p = new Put(Bytes.toBytes("row"+i)); byte[] q1 = Bytes.toBytes("q1"); byte[] v1 = Bytes.toBytes("v1"); p.addColumn(Bytes.toBytes("f"), q1, v1); table.put(p); } this.admin.flush(tableName); try { this.admin.split(tableName, Bytes.toBytes("row5")); Threads.sleep(10000); } catch (Exception e) { // Nothing to do. } // Split should not happen. List<RegionInfo> allRegions = MetaTableAccessor.getTableRegions( this.admin.getConnection(), tableName, true); assertEquals(1, allRegions.size()); }
@Test public void testRoundRobinAssignment() throws Exception { TableName tableName = TableName.valueOf("testRoundRobinAssignment"); HTableDescriptor desc = new HTableDescriptor(tableName); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); admin.createTable(desc, Bytes.toBytes("aaa"), Bytes.toBytes("zzz"), REGION_NUM); TEST_UTIL.waitTableAvailable(tableName); TEST_UTIL.loadTable(admin.getConnection().getTable(tableName), HConstants.CATALOG_FAMILY); admin.flush(tableName); LoadBalancer balancer = master.getLoadBalancer(); List<RegionInfo> regions = admin.getRegions(tableName); regions.addAll(admin.getTableRegions(TableName.META_TABLE_NAME)); List<ServerName> servers = Lists.newArrayList( admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet()); Map<ServerName, List<RegionInfo>> map = balancer.roundRobinAssignment(regions, servers); for (List<RegionInfo> regionInfos : map.values()) { regions.removeAll(regionInfos); } assertEquals("No region should be missed by balancer", 0, regions.size()); }
@Test public void testFlushes() throws Exception { TableName tn = helper.createTableWithRegions(1); // Set a quota QuotaSettings settings = QuotaSettingsFactory.limitTableSpace( tn, SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS); admin.setQuota(settings); // Write some data final long initialSize = 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE; helper.writeData(tn, initialSize); // Make sure a flush happened admin.flush(tn); // We should be able to observe the system recording an increase in size (even // though we know the filesystem scanning did not happen). TEST_UTIL.waitFor(30 * 1000, 500, new SpaceQuotaSnapshotPredicate(conn, tn) { @Override boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception { return snapshot.getUsage() >= initialSize; } }); }
/** * Tests the case where a Scan can throw an IOException in the middle of the seek / reseek leaving * the server side RegionScanner to be in dirty state. The client has to ensure that the * ClientScanner does not get an exception and also sees all the data. * @throws IOException * @throws InterruptedException */ @Test public void testClientScannerIsResetWhenScanThrowsIOException() throws IOException, InterruptedException { reset(); THROW_ONCE.set(true); // throw exceptions only once TableName tableName = TableName.valueOf(name.getMethodName()); try (Table t = TEST_UTIL.createTable(tableName, FAMILY)) { int rowCount = TEST_UTIL.loadTable(t, FAMILY, false); TEST_UTIL.getAdmin().flush(tableName); inject(); int actualRowCount = TEST_UTIL.countRows(t, new Scan().addColumn(FAMILY, FAMILY)); assertEquals(rowCount, actualRowCount); } assertTrue(REQ_COUNT.get() > 0); }
/** * Tests the case where a coprocessor throws a regular IOException in the scan. The expectation is * that the we will keep on retrying, but fail after the retries are exhausted instead of retrying * indefinitely. */ @Test public void testScannerFailsAfterRetriesWhenCoprocessorThrowsIOE() throws IOException, InterruptedException { TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3); TableName tableName = TableName.valueOf(name.getMethodName()); reset(); THROW_ONCE.set(false); // throw exceptions in every retry try (Table t = TEST_UTIL.createTable(tableName, FAMILY)) { TEST_UTIL.loadTable(t, FAMILY, false); TEST_UTIL.getAdmin().flush(tableName); inject(); TEST_UTIL.countRows(t, new Scan().addColumn(FAMILY, FAMILY)); fail("Should have thrown an exception"); } catch (DoNotRetryIOException expected) { assertThat(expected, instanceOf(ScannerResetException.class)); // expected } assertTrue(REQ_COUNT.get() >= 3); }
/** * Tests the case where a coprocessor throws a DoNotRetryIOException in the scan. The expectation * is that the exception will bubble up to the client scanner instead of being retried. */ @Test public void testScannerThrowsExceptionWhenCoprocessorThrowsDNRIOE() throws IOException, InterruptedException { reset(); IS_DO_NOT_RETRY.set(true); TableName tableName = TableName.valueOf(name.getMethodName()); try (Table t = TEST_UTIL.createTable(tableName, FAMILY)) { TEST_UTIL.loadTable(t, FAMILY, false); TEST_UTIL.getAdmin().flush(tableName); inject(); TEST_UTIL.countRows(t, new Scan().addColumn(FAMILY, FAMILY)); fail("Should have thrown an exception"); } catch (DoNotRetryIOException expected) { // expected } assertTrue(REQ_COUNT.get() > 0); }
@Test public void testgetColumnHint() throws IOException { try (Table t = createTable()) { t.setOperationTimeout(10000); t.setRpcTimeout(10000); t.put(new Put(ROW).addColumn(FAMILY, col1, 100, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 101, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 102, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 103, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 104, value)); t.put(new Put(ROW2).addColumn(FAMILY, col1, 104, value)); TEST_UTIL.getAdmin().flush(t.getName()); t.delete(new Delete(ROW).addColumn(FAMILY, col1)); } }
@Test public void testSplitFlushCompactUnknownTable() throws InterruptedException { final TableName unknowntable = TableName.valueOf(name.getMethodName()); Exception exception = null; try { this.admin.compact(unknowntable); } catch (IOException e) { exception = e; } assertTrue(exception instanceof TableNotFoundException); exception = null; try { this.admin.flush(unknowntable); } catch (IOException e) { exception = e; } assertTrue(exception instanceof TableNotFoundException); exception = null; try { this.admin.split(unknowntable); } catch (IOException e) { exception = e; } assertTrue(exception instanceof TableNotFoundException); }
@Test public void testMajorCompaction() throws Exception { TableName tn = helper.createTableWithRegions(1); // Set a quota QuotaSettings settings = QuotaSettingsFactory.limitTableSpace( tn, SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS); admin.setQuota(settings); // Write some data and flush it to disk. final long sizePerBatch = 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE; helper.writeData(tn, sizePerBatch); admin.flush(tn); // Write the same data again, flushing it to a second file helper.writeData(tn, sizePerBatch); admin.flush(tn); // After two flushes, both hfiles would contain similar data. We should see 2x the data. TEST_UTIL.waitFor(30 * 1000, 500, new SpaceQuotaSnapshotPredicate(conn, tn) { @Override boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception { return snapshot.getUsage() >= 2L * sizePerBatch; } }); // Rewrite the two files into one. admin.majorCompact(tn); // After we major compact the table, we should notice quickly that the amount of data in the // table is much closer to reality (the duplicate entries across the two files are removed). TEST_UTIL.waitFor(30 * 1000, 500, new SpaceQuotaSnapshotPredicate(conn, tn) { @Override boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception { return snapshot.getUsage() >= sizePerBatch && snapshot.getUsage() <= 2L * sizePerBatch; } }); }
@Test public void test() throws IOException, KeeperException, InterruptedException { long now = System.currentTimeMillis(); put(0, 100, now - 10000); assertValueEquals(0, 100); setExpireBefore(now - 5000); Thread.sleep(5000); UTIL.getAdmin().flush(NAME); assertNotExists(0, 100); put(0, 50, now - 1000); UTIL.getAdmin().flush(NAME); put(50, 100, now - 100); UTIL.getAdmin().flush(NAME); assertValueEquals(0, 100); setExpireBefore(now - 500); Thread.sleep(5000); UTIL.getAdmin().majorCompact(NAME); UTIL.waitFor(30000, () -> UTIL.getHBaseCluster().getRegions(NAME).iterator().next() .getStore(FAMILY).getStorefilesCount() == 1); assertNotExists(0, 50); assertValueEquals(50, 100); } }
@Test public void testPutAndDeleteVersions() throws IOException { try (Table t = createTable()) { t.put(new Put(ROW).addColumn(FAMILY, col1, 1000001, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000002, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000003, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000004, value)); t.delete(new Delete(ROW).addColumns(FAMILY, col1, 2000000)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000000, value)); TEST_UTIL.getAdmin().flush(t.getName()); Result r = t.get(new Get(ROW).setMaxVersions(3)); assertEquals(1, r.size()); assertEquals(1000000, r.rawCells()[0].getTimestamp()); } }
@Test public void testTimeRange() throws IOException { try (Table t = createTable()) { t.put(new Put(ROW).addColumn(FAMILY, col1, 1000001, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000002, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000003, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000004, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000005, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000006, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000007, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000008, value)); Result r = t.get(new Get(ROW).setMaxVersions(3).setTimeRange(0, 1000005)); assertEquals(0, r.size()); TEST_UTIL.getAdmin().flush(t.getName()); r = t.get(new Get(ROW).setMaxVersions(3).setTimeRange(0, 1000005)); assertEquals(0, r.size()); } }