Java Code Examples for org.apache.hadoop.hbase.util.Bytes#random()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#random() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestEncryption.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testSmallBlocks() throws Exception {
  byte[] key = new byte[16];
  Bytes.random(key);
  byte[] iv = new byte[16];
  Bytes.random(iv);
  for (int size: new int[] { 4, 8, 16, 32, 64, 128, 256, 512 }) {
    checkTransformSymmetry(key, iv, getRandomBlock(size));
  }
}
 
Example 2
Source File: TestEncryption.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testLargeBlocks() throws Exception {
  byte[] key = new byte[16];
  Bytes.random(key);
  byte[] iv = new byte[16];
  Bytes.random(iv);
  for (int size: new int[] { 256 * 1024, 512 * 1024, 1024 * 1024 }) {
    checkTransformSymmetry(key, iv, getRandomBlock(size));
  }
}
 
Example 3
Source File: TestEncryption.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testOddSizedBlocks() throws Exception {
  byte[] key = new byte[16];
  Bytes.random(key);
  byte[] iv = new byte[16];
  Bytes.random(iv);
  for (int size: new int[] { 3, 7, 11, 23, 47, 79, 119, 175 }) {
    checkTransformSymmetry(key, iv, getRandomBlock(size));
  }
}
 
Example 4
Source File: TestEncryption.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypicalHFileBlocks() throws Exception {
  byte[] key = new byte[16];
  Bytes.random(key);
  byte[] iv = new byte[16];
  Bytes.random(iv);
  for (int size: new int[] { 4 * 1024, 8 * 1024, 64 * 1024, 128 * 1024 }) {
    checkTransformSymmetry(key, iv, getRandomBlock(size));
  }
}
 
Example 5
Source File: MutableIndexExtendedIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 120000)
public void testCompactNonPhoenixTable() throws Exception {
    if (localIndex || tableDDLOptions.contains("TRANSACTIONAL=true")) return;

    try (Connection conn = getConnection()) {
        // create a vanilla HBase table (non-Phoenix)
        String randomTable = generateUniqueName();
        TableName hbaseTN = TableName.valueOf(randomTable);
        byte[] famBytes = Bytes.toBytes("fam");
        Table hTable = getUtility().createTable(hbaseTN, famBytes);
        TestUtil.addCoprocessor(conn, randomTable, UngroupedAggregateRegionObserver.class);
        Put put = new Put(Bytes.toBytes("row"));
        byte[] value = new byte[1];
        Bytes.random(value);
        put.addColumn(famBytes, Bytes.toBytes("colQ"), value);
        hTable.put(put);

        // major compaction shouldn't cause a timeout or RS abort
        List<HRegion> regions = getUtility().getHBaseCluster().getRegions(hbaseTN);
        HRegion hRegion = regions.get(0);
        hRegion.flush(true);
        HStore store = hRegion.getStore(famBytes);
        store.triggerMajorCompaction();
        store.compactRecentForTestingAssumingDefaultPolicy(1);

        // we should be able to compact syscat itself as well
        regions =
                getUtility().getHBaseCluster().getRegions(
                        TableName.valueOf(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME));
        hRegion = regions.get(0);
        hRegion.flush(true);
        store = hRegion.getStore(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES);
        store.triggerMajorCompaction();
        store.compactRecentForTestingAssumingDefaultPolicy(1);
    }
}
 
Example 6
Source File: TestSizeFailures.java    From hbase with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Uncomment the following lines if more verbosity is needed for
  // debugging (see HBASE-12285 for details).
  //((Log4JLogger)RpcServer.LOG).getLogger().setLevel(Level.ALL);
  //((Log4JLogger)RpcClient.LOG).getLogger().setLevel(Level.ALL);
  //((Log4JLogger)ScannerCallable.LOG).getLogger().setLevel(Level.ALL);
  Configuration conf = TEST_UTIL.getConfiguration();
  TEST_UTIL.startMiniCluster(SLAVES);

  // Write a bunch of data
  TABLENAME = TableName.valueOf("testSizeFailures");
  List<byte[]> qualifiers = new ArrayList<>();
  for (int i = 1; i <= 10; i++) {
    qualifiers.add(Bytes.toBytes(Integer.toString(i)));
  }

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLENAME);
  ColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY);

  tableDescriptor.setColumnFamily(familyDescriptor);
  byte[][] splits = new byte[9][2];
  for (int i = 1; i < 10; i++) {
    int split = 48 + i;
    splits[i - 1][0] = (byte) (split >>> 8);
    splits[i - 1][0] = (byte) (split);
  }
  TEST_UTIL.getAdmin().createTable(tableDescriptor, splits);
  Connection conn = TEST_UTIL.getConnection();

  try (Table table = conn.getTable(TABLENAME)) {
    List<Put> puts = new LinkedList<>();
    for (int i = 0; i < NUM_ROWS; i++) {
      Put p = new Put(Bytes.toBytes(Integer.toString(i)));
      for (int j = 0; j < NUM_COLS; j++) {
        byte[] value = new byte[50];
        Bytes.random(value);
        p.addColumn(FAMILY, Bytes.toBytes(Integer.toString(j)), value);
      }
      puts.add(p);

      if (puts.size() == 1000) {
        table.batch(puts, null);
        puts.clear();
      }
    }

    if (puts.size() > 0) {
      table.batch(puts, null);
    }
  }
}
 
Example 7
Source File: TestEncryption.java    From hbase with Apache License 2.0 4 votes vote down vote up
private byte[] getRandomBlock(int size) {
  byte[] b = new byte[size];
  Bytes.random(b);
  return b;
}