@Test public void testSimpleLoadWithFileCopy() throws Exception { String testName = tn.getMethodName(); final byte[] TABLE_NAME = Bytes.toBytes("mytable_" + testName); runTest(testName, buildHTD(TableName.valueOf(TABLE_NAME), BloomType.NONE), false, null, new byte[][][] { new byte[][] { Bytes.toBytes("aaaa"), Bytes.toBytes("cccc") }, new byte[][] { Bytes.toBytes("ddd"), Bytes.toBytes("ooo") }, }, false, true, 2); }
@Test public void testDeletedByDeleteFamily() { KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteFamily); sdt.add(kv); timestamp -= 5; kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteColumn); DeleteResult ret = sdt.isDeleted(kv); assertEquals(DeleteResult.FAMILY_DELETED, ret); }
@Test public void testValueLength() { for (int i = 0; i < 1000; ++i) { byte[] v = gen.generateRandomSizeValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes(String.valueOf(rand.nextInt()))); assertTrue(MIN_LEN <= v.length); assertTrue(v.length <= MAX_LEN); } }
@Test public void testPut() throws Exception { byte[] row = Bytes.toBytes("test-row"); // Initialize a result KeyValue[] kvs = new KeyValue[] { new KeyValue(row, Bytes.toBytes("cfa"), Bytes.toBytes("col1"), Bytes.toBytes("cfacol1")), new KeyValue(row, Bytes.toBytes("cfa"), Bytes.toBytes("col2"), Bytes.toBytes("cfacol2")) }; Put expected = new Put(row); for (int i = 0; i < kvs.length; i++) { expected.add(kvs[i]); } PutWritable actual = copy(new PutWritable(expected), new PutWritable()); Assert.assertArrayEquals(expected.getRow(), actual.getPut().getRow()); Assert.assertEquals(expected.getFamilyCellMap().keySet(), actual.getPut().getFamilyCellMap().keySet()); }
@Override public ListLabelsResponse run() throws Exception { ListLabelsResponse response = null; try (Connection conn = ConnectionFactory.createConnection(conf)) { response = VisibilityClient.listLabels(conn, ".*secret"); } catch (Throwable e) { throw new IOException(e); } // Only return the labels that end with 'secret' List<ByteString> labels = response.getLabelList(); assertEquals(2, labels.size()); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes(SECRET)))); assertTrue(labels.contains(ByteString.copyFrom(Bytes.toBytes(TOPSECRET)))); return null; } };
@Override public void run() { try { Put put1 = new Put(Bytes.toBytes("row5")); put1.add(new KeyValue(Bytes.toBytes("row5"), Bytes.toBytes("col"), Bytes.toBytes("q"), l, Bytes.toBytes("version0"))); table.put(put1); try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) { bulkload.doBulkLoad(hfilePath, admin, table, locator); } latch.countDown(); } catch (TableNotFoundException e) { } catch (IOException e) { } } }.start();
@Test public void testDeletedByDeleteColumn() { KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteColumn); sdt.add(kv); timestamp -= 5; kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"), timestamp, KeyValue.Type.DeleteColumn); DeleteResult ret = sdt.isDeleted(kv); assertEquals(DeleteResult.COLUMN_DELETED, ret); }
@Test public void testByteBufferReuse() throws IOException { byte [] someBytes = Bytes.toBytes("some bytes"); ByteBuffer bb = ByteBuffer.allocate(someBytes.length); ByteBuffer bbToReuse = write(bb, someBytes); bbToReuse = write(bbToReuse, Bytes.toBytes("less")); assertTrue(bb == bbToReuse); }
@Test public void testTruncateWithPreserveAfterSplit() throws Exception { String[] families = new String[] { "f1", "f2" }; byte[][] splitKeys = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") }; TableName tableName = TableName.valueOf(name.getMethodName()); RegionInfo[] regions = MasterProcedureTestingUtility.createTable(getMasterProcedureExecutor(), tableName, splitKeys, families); splitAndTruncate(tableName, regions, 1); }
private void verifyRows(Table t, byte[] family, byte[] column) throws IOException { for (int i = 0; i < 10; i++) { byte[] row = Bytes.toBytes("row" + i); Get g = new Get(row).addFamily(family); Result r = t.get(g); Assert.assertNotNull(r); Assert.assertEquals(1, r.size()); Cell cell = r.rawCells()[0]; Assert.assertTrue(CellUtil.matchingQualifier(cell, column)); Assert.assertEquals(Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(), row, 0, row.length), 0); } }
protected void addSystemLabel(Region region, Map<String, Integer> labels, Map<String, List<Integer>> userAuths) throws IOException { if (!labels.containsKey(SYSTEM_LABEL)) { byte[] row = Bytes.toBytes(SYSTEM_LABEL_ORDINAL); Put p = new Put(row); p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY) .setRow(row) .setFamily(LABELS_TABLE_FAMILY) .setQualifier(LABEL_QUALIFIER) .setTimestamp(p.getTimestamp()) .setType(Type.Put) .setValue(Bytes.toBytes(SYSTEM_LABEL)) .build()); region.put(p); labels.put(SYSTEM_LABEL, SYSTEM_LABEL_ORDINAL); } }
@Test public void testRowCountFilter() throws IOException { KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam1"), Bytes.toBytes("a"), 1, Bytes.toBytes("value")); KeyValue kv2 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("fam2"), Bytes.toBytes("a"), 2, Bytes.toBytes("value")); MockNextRowFilter mockNextRowFilter = new MockNextRowFilter(); FilterList filter = new FilterList(Operator.MUST_PASS_ONE, mockNextRowFilter); filter.filterCell(kv1); filter.filterCell(kv2); assertEquals(2, mockNextRowFilter.getHitCount()); }
@Test public void testMultiRowRangeFilter() throws Exception { List<RowRange> ranges = new ArrayList<>(); ranges.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false)); ranges.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false)); ranges.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false)); MultiRowRangeFilter multiRowRangeFilter = new MultiRowRangeFilter(ranges); assertTrue(multiRowRangeFilter.areSerializedFieldsEqual( ProtobufUtil.toFilter(ProtobufUtil.toFilter(multiRowRangeFilter)))); }
@Test(expected=IllegalArgumentException.class) public void testModifyInexistentFamily() { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); byte[] familyName = Bytes.toBytes("cf"); HColumnDescriptor hcd = new HColumnDescriptor(familyName); htd.modifyFamily(hcd); }
private void prefixRowTests(Filter filter, boolean lastFilterAllRemaining) throws Exception { for (char c = FIRST_CHAR; c <= LAST_CHAR; c++) { byte [] t = createRow(c); assertFalse("Failed with character " + c, filter.filterRowKey(KeyValueUtil.createFirstOnRow(t))); assertFalse(filter.filterAllRemaining()); } String yahooSite = "com.yahoo.www"; byte [] yahooSiteBytes = Bytes.toBytes(yahooSite); assertTrue("Failed with character " + yahooSite, filter.filterRowKey(KeyValueUtil.createFirstOnRow(yahooSiteBytes))); assertEquals(filter.filterAllRemaining(), lastFilterAllRemaining); }