private long doGets(int maxOps, final Table... tables) throws Exception { int count = 0; try { while (count < maxOps) { Get get = new Get(Bytes.toBytes("row-" + count)); for (final Table table: tables) { table.get(get); } count += tables.length; } } catch (RpcThrottlingException e) { LOG.error("get failed after nRetries=" + count, e); } return count; }
/** * For HADOOP-2579 * @throws IOException */ @Test (expected=TableNotFoundException.class) public void testTableNotFoundExceptionWithoutAnyTables() throws IOException { TableName tableName = TableName .valueOf("testTableNotFoundExceptionWithoutAnyTables"); Table ht = TEST_UTIL.getConnection().getTable(tableName); ht.get(new Get(Bytes.toBytes("e"))); }
@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()); } }
@Override public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { Result result = t.get(g); assertTrue(result.isEmpty()); } return null; } };
void verifyEdit(int familyNum, int putNum, Table table) throws IOException { Result r = table.get(createGet(familyNum, putNum)); byte[] family = FAMILIES[familyNum - 1]; byte[] qf = Bytes.toBytes("q" + familyNum); byte[] val = Bytes.toBytes("val" + familyNum + "-" + putNum); assertNotNull(("Missing Put#" + putNum + " for CF# " + familyNum), r.getFamilyMap(family)); assertNotNull(("Missing Put#" + putNum + " for CF# " + familyNum), r.getFamilyMap(family).get(qf)); assertTrue(("Incorrect value for Put#" + putNum + " for CF# " + familyNum), Arrays.equals(r.getFamilyMap(family).get(qf), val)); }
@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 testGetNoResultNoStaleRegionWithReplica() throws Exception { byte[] b1 = "testGetNoResultNoStaleRegionWithReplica".getBytes(); openRegion(hriSecondary); try { // A get works and is not stale Get g = new Get(b1); Result r = table.get(g); Assert.assertFalse(r.isStale()); } finally { closeRegion(hriSecondary); } }
private void getOneRowAndAssertAllExist(final Table table) throws IOException { Get get = new Get(ROWKEY); Result result = table.get(get); assertTrue("Column A value should be a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))).equals("a")); assertTrue("Column B value should be b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))).equals("b")); assertTrue("Column C value should be c", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))).equals("c")); }
@Override public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { Result result = t.get(g); assertTrue(!result.isEmpty()); } return null; } };
void verifyEdit(int familyNum, int putNum, Table table) throws IOException { Result r = table.get(createGet(familyNum, putNum)); byte[] family = FAMILIES[familyNum - 1]; byte[] qf = Bytes.toBytes("q" + familyNum); byte[] val = Bytes.toBytes("val" + familyNum + "-" + putNum); assertNotNull(("Missing Put#" + putNum + " for CF# " + familyNum), r.getFamilyMap(family)); assertNotNull(("Missing Put#" + putNum + " for CF# " + familyNum), r.getFamilyMap(family).get(qf)); assertTrue(("Incorrect value for Put#" + putNum + " for CF# " + familyNum), Arrays.equals(r.getFamilyMap(family).get(qf), val)); }
@Test public void testExplicitColum() throws IOException { try (Table t = createTable()) { t.put(new Put(ROW).addColumn(FAMILY, col1, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, value)); t.put(new Put(ROW).addColumn(FAMILY, col2, value)); t.put(new Put(ROW).addColumn(FAMILY, col2, value)); t.put(new Put(ROW).addColumn(FAMILY, col2, value)); t.put(new Put(ROW).addColumn(FAMILY, col2, value)); t.put(new Put(ROW).addColumn(FAMILY, col3, value)); t.put(new Put(ROW).addColumn(FAMILY, col3, value)); t.put(new Put(ROW).addColumn(FAMILY, col3, value)); t.put(new Put(ROW).addColumn(FAMILY, col3, value)); Result r = t.get(new Get(ROW).setMaxVersions(3).addColumn(FAMILY, col2)); assertEquals(3, r.size()); TEST_UTIL.getAdmin().flush(t.getName()); r = t.get(new Get(ROW).setMaxVersions(3).addColumn(FAMILY, col2)); assertEquals(3, r.size()); TEST_UTIL.getAdmin().flush(t.getName()); } }
@Test public void testUseRegionWithoutReplica() throws Exception { byte[] b1 = "testUseRegionWithoutReplica".getBytes(); openRegion(hriSecondary); SlowMeCopro.getPrimaryCdl().set(new CountDownLatch(0)); try { Get g = new Get(b1); Result r = table.get(g); Assert.assertFalse(r.isStale()); } finally { closeRegion(hriSecondary); } }
private void getOneRowAndAssertAllButCExist(final Table table) throws IOException { Get get = new Get(ROWKEY); Result result = table.get(get); assertTrue("Column A value should be a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))).equals("a")); assertTrue("Column B value should be b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))).equals("b")); assertTrue("Column C should not exist", result.getValue(FAMILY, Bytes.toBytes("C")) == null); }
@Test public void testDisabledWAL() throws Exception { LOG.info("Writing data to table " + tableName); Put p = new Put(Bytes.toBytes("row")); p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val")); table.put(p); LOG.info("Flushing table " + tableName); TEST_UTIL.flush(tableName); LOG.info("Getting data from table " + tableName); Get get = new Get(Bytes.toBytes("row")); Result result = table.get(get); assertNotNull(result.getValue(fam, Bytes.toBytes("qual"))); } }