Java Code Examples for org.apache.hadoop.hbase.HBaseTestingUtility#closeRegionAndWAL()

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility#closeRegionAndWAL() . 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: TestKeepDeletes.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * The ExplicitColumnTracker does not support "raw" scanning.
 */
@Test
public void testRawScanWithColumns() throws Exception {
  HTableDescriptor htd = hbu.createTableDescriptor(TableName.valueOf(name.getMethodName()), 0, 3,
      HConstants.FOREVER, KeepDeletedCells.TRUE);
  Region region = hbu.createLocalHRegion(htd, null, null);

  Scan s = new Scan();
  s.setRaw(true);
  s.readAllVersions();
  s.addColumn(c0, c0);

  try {
    region.getScanner(s);
    fail("raw scanner with columns should have failed");
  } catch (org.apache.hadoop.hbase.DoNotRetryIOException dnre) {
    // ok!
  }

  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 2
Source File: TestReadAndWriteRegionInfoFile.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadAndWriteRegionInfoFile() throws IOException, InterruptedException {
  RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
  // Create a region. That'll write the .regioninfo file.
  FSTableDescriptors fsTableDescriptors = new FSTableDescriptors(FS, ROOT_DIR);
  FSTableDescriptors.tryUpdateMetaTableDescriptor(CONF, FS, ROOT_DIR, null);
  HRegion r = HBaseTestingUtility.createRegionAndWAL(ri, ROOT_DIR, CONF,
    fsTableDescriptors.get(TableName.META_TABLE_NAME));
  // Get modtime on the file.
  long modtime = getModTime(r);
  HBaseTestingUtility.closeRegionAndWAL(r);
  Thread.sleep(1001);
  r = HRegion.openHRegion(ROOT_DIR, ri, fsTableDescriptors.get(TableName.META_TABLE_NAME), null,
    CONF);
  // Ensure the file is not written for a second time.
  long modtime2 = getModTime(r);
  assertEquals(modtime, modtime2);
  // Now load the file.
  HRegionFileSystem.loadRegionInfoFileContent(r.getRegionFileSystem().getFileSystem(),
    r.getRegionFileSystem().getRegionDir());
  HBaseTestingUtility.closeRegionAndWAL(r);
}
 
Example 3
Source File: TestScanner.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test that closing a scanner while a client is using it doesn't throw
 * NPEs but instead a UnknownScannerException. HBASE-2503
 */
@Test
public void testRaceBetweenClientAndTimeout() throws Exception {
  try {
    this.region = TEST_UTIL.createLocalHRegion(TESTTABLEDESC, null, null);
    HTestConst.addContent(this.region, HConstants.CATALOG_FAMILY);
    Scan scan = new Scan();
    InternalScanner s = region.getScanner(scan);
    List<Cell> results = new ArrayList<>();
    try {
      s.next(results);
      s.close();
      s.next(results);
      fail("We don't want anything more, we should be failing");
    } catch (UnknownScannerException ex) {
      // ok!
      return;
    }
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(this.region);
  }
}
 
Example 4
Source File: TestScanner.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Tests to do a concurrent flush (using a 2nd thread) while scanning.  This tests both
 * the StoreScanner update readers and the transition from memstore -> snapshot -> store file.
 */
@Test
public void testScanAndRealConcurrentFlush() throws Exception {
  this.region = TEST_UTIL.createLocalHRegion(TESTTABLEDESC, null, null);
  Table hri = new RegionAsTable(region);
  try {
    LOG.info("Added: " +
      HTestConst.addContent(hri, Bytes.toString(HConstants.CATALOG_FAMILY),
        Bytes.toString(HConstants.REGIONINFO_QUALIFIER)));
    int count = count(hri, -1, false);
    assertEquals(count, count(hri, 100, true)); // do a true concurrent background thread flush
  } catch (Exception e) {
    LOG.error("Failed", e);
    throw e;
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(this.region);
  }
}
 
Example 5
Source File: TestWALSplitToHFile.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Pair<TableDescriptor, RegionInfo> setupTableAndRegion() throws IOException {
  final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  final TableDescriptor td = createBasic3FamilyTD(tableName);
  final RegionInfo ri = RegionInfoBuilder.newBuilder(tableName).build();
  final Path tableDir = CommonFSUtils.getTableDir(this.rootDir, tableName);
  deleteDir(tableDir);
  FSTableDescriptors.createTableDescriptorForTableDirectory(fs, tableDir, td, false);
  HRegion region = HBaseTestingUtility.createRegionAndWAL(ri, rootDir, this.conf, td);
  HBaseTestingUtility.closeRegionAndWAL(region);
  return new Pair<>(td, ri);
}
 
Example 6
Source File: TestRowTooBig.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Usecase:
 *  - create a row with 5 large  cells (5 Mb each)
 *  - flush memstore but don't compact storefiles.
 *  - try to Get whole row.
 *
 * OOME happened before we actually get to reading results, but
 * during seeking, as each StoreFile gets it's own scanner,
 * and each scanner seeks after the first KV.
 * @throws IOException
 */
@Test(expected = RowTooBigException.class)
public void testScannersSeekOnFewLargeCells() throws IOException {
  byte[] row1 = Bytes.toBytes("row1");
  byte[] fam1 = Bytes.toBytes("fam1");

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor = TEST_TD;
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(fam1);
  if (tableDescriptor.hasColumnFamily(familyDescriptor.getName())) {
    tableDescriptor.modifyColumnFamily(familyDescriptor);
  } else {
    tableDescriptor.setColumnFamily(familyDescriptor);
  }

  final RegionInfo hri = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  HRegion region = HBaseTestingUtility.createRegionAndWAL(hri, rootRegionDir,
    HTU.getConfiguration(), tableDescriptor);
  try {
    // Add 5 cells to memstore
    for (int i = 0; i < 5 ; i++) {
      Put put = new Put(row1);

      byte[] value = new byte[5 * 1024 * 1024];
      put.addColumn(fam1, Bytes.toBytes("col_" + i), value);
      region.put(put);
      region.flush(true);
    }

    Get get = new Get(row1);
    region.get(get);
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(region);
  }
}
 
Example 7
Source File: TestCoprocessorInterface.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCoprocessorInterface() throws IOException {
  TableName tableName = TableName.valueOf(name.getMethodName());
  byte [][] families = { fam1, fam2, fam3 };

  Configuration hc = initConfig();
  HRegion region = initHRegion(tableName, name.getMethodName(), hc,
    new Class<?>[]{CoprocessorImpl.class}, families);
  for (int i = 0; i < 3; i++) {
    HTestConst.addContent(region, fam3);
    region.flush(true);
  }

  region.compact(false);

  // HBASE-4197
  Scan s = new Scan();
  RegionScanner scanner = region.getCoprocessorHost().postScannerOpen(s, region.getScanner(s));
  assertTrue(scanner instanceof CustomScanner);
  // this would throw an exception before HBASE-4197
  scanner.next(new ArrayList<>());

  HBaseTestingUtility.closeRegionAndWAL(region);
  Coprocessor c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class);

  assertTrue("Coprocessor not started", ((CoprocessorImpl)c).wasStarted());
  assertTrue("Coprocessor not stopped", ((CoprocessorImpl)c).wasStopped());
  assertTrue(((CoprocessorImpl)c).wasOpened());
  assertTrue(((CoprocessorImpl)c).wasClosed());
  assertTrue(((CoprocessorImpl)c).wasFlushed());
  assertTrue(((CoprocessorImpl)c).wasCompacted());
}
 
Example 8
Source File: TestRegionObserverStacking.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void testRegionObserverStacking() throws Exception {
  byte[] ROW = Bytes.toBytes("testRow");
  byte[] TABLE = Bytes.toBytes(this.getClass().getSimpleName());
  byte[] A = Bytes.toBytes("A");
  byte[][] FAMILIES = new byte[][] { A } ;

  Configuration conf = TEST_UTIL.getConfiguration();
  HRegion region = initHRegion(TABLE, getClass().getName(),
    conf, FAMILIES);
  RegionCoprocessorHost h = region.getCoprocessorHost();
  h.load(ObserverA.class, Coprocessor.PRIORITY_HIGHEST, conf);
  h.load(ObserverB.class, Coprocessor.PRIORITY_USER, conf);
  h.load(ObserverC.class, Coprocessor.PRIORITY_LOWEST, conf);

  Put put = new Put(ROW);
  put.addColumn(A, A, A);
  region.put(put);

  Coprocessor c = h.findCoprocessor(ObserverA.class.getName());
  long idA = ((ObserverA)c).id;
  c = h.findCoprocessor(ObserverB.class.getName());
  long idB = ((ObserverB)c).id;
  c = h.findCoprocessor(ObserverC.class.getName());
  long idC = ((ObserverC)c).id;

  assertTrue(idA < idB);
  assertTrue(idB < idC);
  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 9
Source File: TestHRegionWithInMemoryFlush.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * A test case of HBASE-21041
 * @throws Exception Exception
 */
@Override
@Test
public void testFlushAndMemstoreSizeCounting() throws Exception {
  byte[] family = Bytes.toBytes("family");
  this.region = initHRegion(tableName, method, CONF, family);
  final WALFactory wals = new WALFactory(CONF, method);
  int count = 0;
  try {
    for (byte[] row : HBaseTestingUtility.ROWS) {
      Put put = new Put(row);
      put.addColumn(family, family, row);
      region.put(put);
      //In memory flush every 1000 puts
      if (count++ % 1000 == 0) {
        ((CompactingMemStore) (region.getStore(family).memstore))
            .flushInMemory();
      }
    }
    region.flush(true);
    // After flush, data size should be zero
    Assert.assertEquals(0, region.getMemStoreDataSize());
    // After flush, a new active mutable segment is created, so the heap size
    // should equal to MutableSegment.DEEP_OVERHEAD
    Assert.assertEquals(MutableSegment.DEEP_OVERHEAD, region.getMemStoreHeapSize());
    // After flush, offheap size should be zero
    Assert.assertEquals(0, region.getMemStoreOffHeapSize());

  } finally {
    HBaseTestingUtility.closeRegionAndWAL(this.region);
    this.region = null;
    wals.close();
  }
}
 
Example 10
Source File: TestWideScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void tearDown() throws IOException {
  if (REGION != null) {
    HBaseTestingUtility.closeRegionAndWAL(REGION);
    REGION = null;
  }
  UTIL.cleanupTestDir();
}
 
Example 11
Source File: TestCompactedHFilesDischarger.java    From hbase with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws IOException {
  counter.set(0);
  scanCompletedCounter.set(0);
  latch = new CountDownLatch(3);
  HBaseTestingUtility.closeRegionAndWAL(region);
  testUtil.cleanupTestDir();
}
 
Example 12
Source File: TestScannerFromBucketCache.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicScanWithOffheapBucketCache() throws IOException {
  setUp(true);
  byte[] row1 = Bytes.toBytes("row1offheap");
  byte[] qf1 = Bytes.toBytes("qualifier1");
  byte[] qf2 = Bytes.toBytes("qualifier2");
  byte[] fam1 = Bytes.toBytes("famoffheap");

  long ts1 = 1; // System.currentTimeMillis();
  long ts2 = ts1 + 1;
  long ts3 = ts1 + 2;

  // Setting up region
  String method = this.getName();
  this.region = initHRegion(tableName, method, conf, test_util, fam1);
  try {
    List<Cell> expected = insertData(row1, qf1, qf2, fam1, ts1, ts2, ts3, false);

    List<Cell> actual = performScan(row1, fam1);
    // Verify result
    for (int i = 0; i < expected.size(); i++) {
      assertFalse(actual.get(i) instanceof ByteBufferKeyValue);
      assertTrue(PrivateCellUtil.equalsIgnoreMvccVersion(expected.get(i), actual.get(i)));
    }
    // Wait for the bucket cache threads to move the data to offheap
    Thread.sleep(500);
    // do the scan again and verify. This time it should be from the bucket cache in offheap mode
    actual = performScan(row1, fam1);
    // Verify result
    for (int i = 0; i < expected.size(); i++) {
      assertTrue(actual.get(i) instanceof ByteBufferKeyValue);
      assertTrue(PrivateCellUtil.equalsIgnoreMvccVersion(expected.get(i), actual.get(i)));
    }

  } catch (InterruptedException e) {
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(this.region);
    this.region = null;
  }
}
 
Example 13
Source File: TestBlocksRead.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test # of blocks read for some simple seek cases.
 */
@Test
public void testBlocksRead() throws Exception {
  byte[] TABLE = Bytes.toBytes("testBlocksRead");
  String FAMILY = "cf1";
  Cell [] kvs;
  this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);

  try {
    putData(FAMILY, "row", "col1", 1);
    putData(FAMILY, "row", "col2", 2);
    putData(FAMILY, "row", "col3", 3);
    putData(FAMILY, "row", "col4", 4);
    putData(FAMILY, "row", "col5", 5);
    putData(FAMILY, "row", "col6", 6);
    putData(FAMILY, "row", "col7", 7);
    region.flush(true);

    // Expected block reads: 1
    // The top block has the KV we are
    // interested. So only 1 seek is needed.
    kvs = getData(FAMILY, "row", "col1", 1);
    assertEquals(1, kvs.length);
    verifyData(kvs[0], "row", "col1", 1);

    // Expected block reads: 2
    // The top block and next block has the KVs we are
    // interested. So only 2 seek is needed.
    kvs = getData(FAMILY, "row", Arrays.asList("col1", "col2"), 2);
    assertEquals(2, kvs.length);
    verifyData(kvs[0], "row", "col1", 1);
    verifyData(kvs[1], "row", "col2", 2);

    // Expected block reads: 3
    // The first 2 seeks is to find out col2. [HBASE-4443]
    // One additional seek for col3
    // So 3 seeks are needed.
    kvs = getData(FAMILY, "row", Arrays.asList("col2", "col3"), 2);
    assertEquals(2, kvs.length);
    verifyData(kvs[0], "row", "col2", 2);
    verifyData(kvs[1], "row", "col3", 3);

    // Expected block reads: 1. [HBASE-4443]&[HBASE-7845]
    kvs = getData(FAMILY, "row", Arrays.asList("col5"), 1);
    assertEquals(1, kvs.length);
    verifyData(kvs[0], "row", "col5", 5);
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(this.region);
    this.region = null;
  }
}
 
Example 14
Source File: TestFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 15
Source File: TestBlocksRead.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test # of blocks read to ensure disabling cache-fill on Scan works.
 */
@Test
public void testBlocksStoredWhenCachingDisabled() throws Exception {
  byte [] TABLE = Bytes.toBytes("testBlocksReadWhenCachingDisabled");
  String FAMILY = "cf1";

  BlockCache blockCache = BlockCacheFactory.createBlockCache(conf);
  this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY, blockCache);

  try {
    putData(FAMILY, "row", "col1", 1);
    putData(FAMILY, "row", "col2", 2);
    region.flush(true);

    // Execute a scan with caching turned off
    // Expected blocks stored: 0
    long blocksStart = blockCache.getBlockCount();
    Scan scan = new Scan();
    scan.setCacheBlocks(false);
    RegionScanner rs = region.getScanner(scan);
    List<Cell> result = new ArrayList<>(2);
    rs.next(result);
    assertEquals(2 * BLOOM_TYPE.length, result.size());
    rs.close();
    long blocksEnd = blockCache.getBlockCount();

    assertEquals(blocksStart, blocksEnd);

    // Execute with caching turned on
    // Expected blocks stored: 2
    blocksStart = blocksEnd;
    scan.setCacheBlocks(true);
    rs = region.getScanner(scan);
    result = new ArrayList<>(2);
    rs.next(result);
    assertEquals(2 * BLOOM_TYPE.length, result.size());
    rs.close();
    blocksEnd = blockCache.getBlockCount();

    assertEquals(2 * BLOOM_TYPE.length, blocksEnd - blocksStart);
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(this.region);
    this.region = null;
  }
}
 
Example 16
Source File: TestMultipleColumnPrefixFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleColumnPrefixFilter() throws IOException {
  String family = "Family";
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(family))
      .setMaxVersions(3)
      .build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  // HRegionInfo info = new HRegionInfo(htd, null, null, false);
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
      getDataTestDir(), TEST_UTIL.getConfiguration(), tableDescriptor);

  List<String> rows = generateRandomWords(100, "row");
  List<String> columns = generateRandomWords(10000, "column");
  long maxTimestamp = 2;

  List<Cell> kvList = new ArrayList<>();

  Map<String, List<Cell>> prefixMap = new HashMap<>();

  prefixMap.put("p", new ArrayList<>());
  prefixMap.put("q", new ArrayList<>());
  prefixMap.put("s", new ArrayList<>());

  String valueString = "ValueString";

  for (String row: rows) {
    Put p = new Put(Bytes.toBytes(row));
    p.setDurability(Durability.SKIP_WAL);
    for (String column: columns) {
      for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
        KeyValue kv = KeyValueTestUtil.create(row, family, column, timestamp,
            valueString);
        p.add(kv);
        kvList.add(kv);
        for (String s: prefixMap.keySet()) {
          if (column.startsWith(s)) {
            prefixMap.get(s).add(kv);
          }
        }
      }
    }
    region.put(p);
  }

  MultipleColumnPrefixFilter filter;
  Scan scan = new Scan();
  scan.readAllVersions();
  byte [][] filter_prefix = new byte [2][];
  filter_prefix[0] = new byte [] {'p'};
  filter_prefix[1] = new byte [] {'q'};

  filter = new MultipleColumnPrefixFilter(filter_prefix);
  scan.setFilter(filter);
  List<Cell> results = new ArrayList<>();
  InternalScanner scanner = region.getScanner(scan);
  while (scanner.next(results))
    ;
  assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size());

  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 17
Source File: TestResettingCounters.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testResettingCounters() throws Exception {
  HBaseTestingUtility htu = new HBaseTestingUtility();
  Configuration conf = htu.getConfiguration();
  FileSystem fs = FileSystem.get(conf);
  byte [] table = Bytes.toBytes(name.getMethodName());
  byte [][] families = new byte [][] {
      Bytes.toBytes("family1"),
      Bytes.toBytes("family2"),
      Bytes.toBytes("family3")
  };
  int numQualifiers = 10;
  byte [][] qualifiers = new byte [numQualifiers][];
  for (int i=0; i<numQualifiers; i++) qualifiers[i] = Bytes.toBytes("qf" + i);
  int numRows = 10;
  byte [][] rows = new byte [numRows][];
  for (int i=0; i<numRows; i++) rows[i] = Bytes.toBytes("r" + i);

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TableName.valueOf(table));
  for (byte[] family : families) {
    tableDescriptor.setColumnFamily(
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family));
  }

  RegionInfo hri = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  String testDir = htu.getDataTestDir() + "/TestResettingCounters/";
  Path path = new Path(testDir);
  if (fs.exists(path)) {
    if (!fs.delete(path, true)) {
      throw new IOException("Failed delete of " + path);
    }
  }
  HRegion region = HBaseTestingUtility.createRegionAndWAL(hri, path, conf, tableDescriptor);
  try {
    Increment odd = new Increment(rows[0]);
    odd.setDurability(Durability.SKIP_WAL);
    Increment even = new Increment(rows[0]);
    even.setDurability(Durability.SKIP_WAL);
    Increment all = new Increment(rows[0]);
    all.setDurability(Durability.SKIP_WAL);
    for (int i=0;i<numQualifiers;i++) {
      if (i % 2 == 0) even.addColumn(families[0], qualifiers[i], 1);
      else odd.addColumn(families[0], qualifiers[i], 1);
      all.addColumn(families[0], qualifiers[i], 1);
    }

    // increment odd qualifiers 5 times and flush
    for (int i=0;i<5;i++) region.increment(odd, HConstants.NO_NONCE, HConstants.NO_NONCE);
    region.flush(true);

    // increment even qualifiers 5 times
    for (int i=0;i<5;i++) region.increment(even, HConstants.NO_NONCE, HConstants.NO_NONCE);

    // increment all qualifiers, should have value=6 for all
    Result result = region.increment(all, HConstants.NO_NONCE, HConstants.NO_NONCE);
    assertEquals(numQualifiers, result.size());
    Cell[] kvs = result.rawCells();
    for (int i=0;i<kvs.length;i++) {
      System.out.println(kvs[i].toString());
      assertTrue(CellUtil.matchingQualifier(kvs[i], qualifiers[i]));
      assertEquals(6, Bytes.toLong(CellUtil.cloneValue(kvs[i])));
    }
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(region);
  }
  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 18
Source File: TestQualifierFilterWithEmptyQualifier.java    From hbase with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 19
Source File: TestSeekBeforeWithReverseScan.java    From hbase with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
  HBaseTestingUtility.closeRegionAndWAL(region);
  testUtil.cleanupTestDir();
}
 
Example 20
Source File: TestIntraRowPagination.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test from client side for scan with maxResultPerCF set
 */
@Test
public void testScanLimitAndOffset() throws Exception {
  //byte [] TABLE = HTestConst.DEFAULT_TABLE_BYTES;
  byte [][] ROWS = HTestConst.makeNAscii(HTestConst.DEFAULT_ROW_BYTES, 2);
  byte [][] FAMILIES = HTestConst.makeNAscii(HTestConst.DEFAULT_CF_BYTES, 3);
  byte [][] QUALIFIERS = HTestConst.makeNAscii(HTestConst.DEFAULT_QUALIFIER_BYTES, 10);

  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(
      TableName.valueOf(HTestConst.DEFAULT_TABLE_BYTES));

  RegionInfo info = RegionInfoBuilder.newBuilder(HTestConst.DEFAULT_TABLE).build();
  for (byte[] family : FAMILIES) {
    ColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
    tableDescriptor.setColumnFamily(familyDescriptor);
  }
  HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
      TEST_UTIL.getConfiguration(), tableDescriptor);
  try {
    Put put;
    Scan scan;
    Result result;
    boolean toLog = true;

    List<Cell> kvListExp = new ArrayList<>();

    int storeOffset = 1;
    int storeLimit = 3;
    for (int r = 0; r < ROWS.length; r++) {
      put = new Put(ROWS[r]);
      for (int c = 0; c < FAMILIES.length; c++) {
        for (int q = 0; q < QUALIFIERS.length; q++) {
          KeyValue kv = new KeyValue(ROWS[r], FAMILIES[c], QUALIFIERS[q], 1,
              HTestConst.DEFAULT_VALUE_BYTES);
          put.add(kv);
          if (storeOffset <= q && q < storeOffset + storeLimit) {
            kvListExp.add(kv);
          }
        }
      }
      region.put(put);
    }

    scan = new Scan();
    scan.setRowOffsetPerColumnFamily(storeOffset);
    scan.setMaxResultsPerColumnFamily(storeLimit);
    RegionScanner scanner = region.getScanner(scan);
    List<Cell> kvListScan = new ArrayList<>();
    List<Cell> results = new ArrayList<>();
    while (scanner.next(results) || !results.isEmpty()) {
      kvListScan.addAll(results);
      results.clear();
    }
    result = Result.create(kvListScan);
    TestScannersFromClientSide.verifyResult(result, kvListExp, toLog,
        "Testing scan with storeOffset and storeLimit");
  } finally {
    HBaseTestingUtility.closeRegionAndWAL(region);
  }
}