public static Get makeGetForUserQuotas(final String user, final Iterable<TableName> tables, final Iterable<String> namespaces) { Get get = new Get(getUserRowKey(user)); get.addColumn(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS); for (final TableName table: tables) { get.addColumn(QUOTA_FAMILY_INFO, getSettingsQualifierForUserTable(table)); } for (final String ns: namespaces) { get.addColumn(QUOTA_FAMILY_INFO, getSettingsQualifierForUserNamespace(ns)); } return get; }
private void assertValueEquals(int start, int end) throws IOException { for (int i = start; i < end; i++) { assertEquals(i, Bytes.toInt(TABLE.get(new Get(Bytes.toBytes(i))).getValue(FAMILY, QUALIFIER))); } }
@Test public void testPutMaskedAndUserMaxVersion() 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).addColumn(FAMILY, col1, 1000004)); t.delete(new Delete(ROW).addColumn(FAMILY, col1, 1000003)); Result r = t.get(new Get(ROW).setMaxVersions(1)); assertEquals(1, r.size()); assertEquals(1000002, r.rawCells()[0].getTimestamp()); TEST_UTIL.getAdmin().flush(t.getName()); r = t.get(new Get(ROW).setMaxVersions(1)); assertEquals(1, r.size()); assertEquals(1000002, r.rawCells()[0].getTimestamp()); } }
@Test public void testIncrement() throws InterruptedException, ExecutionException { AsyncTable<?> table = ASYNC_CONN.getTable(TABLE_NAME); assertEquals(1L, table.incrementColumnValue(row, FAMILY, QUALIFIER, 1L).get().longValue()); // the second call should have no effect as we always generate the same nonce. assertEquals(1L, table.incrementColumnValue(row, FAMILY, QUALIFIER, 1L).get().longValue()); Result result = table.get(new Get(row)).get(); assertEquals(1L, Bytes.toLong(result.getValue(FAMILY, QUALIFIER))); } }
@Test public void testGetRowConstructor() { byte[] row1 = Bytes.toBytes("testRow"); byte[] row2 = Bytes.toBytes("testtestRow"); ByteBuffer rowBuffer = ByteBuffer.allocate(16); rowBuffer = ByteBuffer.wrap(row1); Get get1 = new Get(rowBuffer); Get get2 = new Get(row2, 4, 7); Assert.assertArrayEquals(get1.getRow(), get2.getRow()); } }
private void run(AtomicBoolean stop) throws InterruptedException, ExecutionException { while (!stop.get()) { for (int i = 0; i < COUNT; i++) { assertEquals(i, Bytes.toInt(TABLE.get(new Get(Bytes.toBytes(String.format("%03d", i)))) .get().getValue(FAMILY, QUALIFIER))); } } }
protected final void assertSum() throws IOException { Result result = TABLE.get(new Get(ROW).addColumn(FAMILY, CQ1).addColumn(FAMILY, CQ2)); assertEquals(THREADS * (1 + UPPER) * UPPER / 2, Bytes.toLong(result.getValue(FAMILY, CQ1))); assertEquals(THREADS * (1 + UPPER) * UPPER, Bytes.toLong(result.getValue(FAMILY, CQ2))); }
private static void assertGet(final HRegion region, byte [] row, byte [] familiy, byte[] qualifier, byte[] value) throws IOException { // run a get and see if the value matches Get get = new Get(row); get.addColumn(familiy, qualifier); Result result = region.get(get); assertEquals(1, result.size()); Cell kv = result.rawCells()[0]; byte[] r = CellUtil.cloneValue(kv); assertTrue(Bytes.compareTo(r, value) == 0); }
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")); }
@Test public void testNullQualifier() { Get get = new Get(ROW); byte[] family = Bytes.toBytes("family"); get.addColumn(family, null); Set<byte[]> qualifiers = get.getFamilyMap().get(family); Assert.assertEquals(1, qualifiers.size()); }
@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 testGetId() { Get get = new Get(ROW); Assert.assertNull("Make sure id is null if unset", get.toMap().get("id")); get.setId("myId"); Assert.assertEquals("myId", get.toMap().get("id")); }
@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); } }
protected final void verifyThroughRegion(HBaseTestingUtility util, int start, int end) throws IOException { HRegion region = util.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0); for (int i = start; i < end; i++) { assertEquals(i, Bytes.toInt(region.get(new Get(Bytes.toBytes(i))).getValue(CF, CQ))); } }