This is an automated email from the ASF dual-hosted git repository.

lupeng pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 23ffe1e4275 HBASE-29725 Refactor the testScan method of 
TestDefaultMemStore (#7473) (#7489)
23ffe1e4275 is described below

commit 23ffe1e42754bbfc21bc37beb95478507e839cee
Author: Liu Xiao <[email protected]>
AuthorDate: Mon Dec 1 18:51:19 2025 +0800

    HBASE-29725 Refactor the testScan method of TestDefaultMemStore (#7473) 
(#7489)
    
    Signed-off-by: Peng Lu <[email protected]>
---
 .../hbase/regionserver/TestCompactingMemStore.java | 15 +++----
 .../TestCompactingToCellFlatMapMemStore.java       | 14 +++---
 .../hbase/regionserver/TestDefaultMemStore.java    | 52 ++++++++++++----------
 3 files changed, 44 insertions(+), 37 deletions(-)

diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java
index fea89e4f94a..62a68d65e67 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java
@@ -81,16 +81,10 @@ public class TestCompactingMemStore extends 
TestDefaultMemStore {
   protected RegionServicesForStores regionServicesForStores;
   protected HStore store;
 
-  
//////////////////////////////////////////////////////////////////////////////
-  // Helpers
-  
//////////////////////////////////////////////////////////////////////////////
-  protected static byte[] makeQualifier(final int i1, final int i2) {
-    return Bytes.toBytes(Integer.toString(i1) + ";" + Integer.toString(i2));
-  }
-
   @After
   public void tearDown() throws Exception {
     chunkCreator.clearChunksInPool();
+    super.tearDown();
   }
 
   @Override
@@ -847,6 +841,12 @@ public class TestCompactingMemStore extends 
TestDefaultMemStore {
     memstore.clearSnapshot(snapshot.getId());
   }
 
+  @Override
+  @Test
+  public void testScan() throws IOException {
+    scanMemStore(memstore, 6635);
+  }
+
   protected int addRowsByKeys(final AbstractMemStore hmc, String[] keys) {
     byte[] fam = Bytes.toBytes("testfamily");
     byte[] qf = Bytes.toBytes("testqualifier");
@@ -925,6 +925,5 @@ public class TestCompactingMemStore extends 
TestDefaultMemStore {
       throws IllegalArgumentIOException {
       compactor.initiateCompactionStrategy(compactionType, conf, "CF_TEST");
     }
-
   }
 }
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java
index a0f653839f1..e73c40f69b9 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java
@@ -69,21 +69,17 @@ public class TestCompactingToCellFlatMapMemStore extends 
TestCompactingMemStore
   // Helpers
   
//////////////////////////////////////////////////////////////////////////////
   public TestCompactingToCellFlatMapMemStore(String type) {
-    if (type == "CHUNK_MAP") {
-      toCellChunkMap = true;
-    } else {
-      toCellChunkMap = false;
-    }
+    toCellChunkMap = "CHUNK_MAP".equals(type);
   }
 
   @Override
   public void tearDown() throws Exception {
     chunkCreator.clearChunksInPool();
+    super.tearDown();
   }
 
   @Override
   public void setUp() throws Exception {
-
     compactingSetUp();
     this.conf = HBaseConfiguration.create();
 
@@ -926,6 +922,12 @@ public class TestCompactingToCellFlatMapMemStore extends 
TestCompactingMemStore
     }
   }
 
+  @Override
+  @Test
+  public void testScan() throws IOException {
+    scanMemStore(memstore, 915);
+  }
+
   private long addRowsByKeysDataSize(final AbstractMemStore hmc, String[] 
keys) {
     byte[] fam = Bytes.toBytes("testfamily");
     byte[] qf = Bytes.toBytes("testqualifier");
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java
index 1d352ebee46..9f71732a8cb 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java
@@ -29,7 +29,6 @@ import java.util.List;
 import java.util.NavigableMap;
 import java.util.Objects;
 import java.util.TreeMap;
-import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
@@ -63,6 +62,7 @@ import org.apache.hadoop.hbase.util.EnvironmentEdge;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 import org.apache.hadoop.hbase.util.FSTableDescriptors;
 import org.apache.hadoop.hbase.wal.WALFactory;
+import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
@@ -91,10 +91,10 @@ public class TestDefaultMemStore {
   public TestName name = new TestName();
   protected AbstractMemStore memstore;
   protected static final int ROW_COUNT = 10;
+  protected static final int SCAN_ROW_COUNT = 25000;
   protected static final int QUALIFIER_COUNT = ROW_COUNT;
   protected static final byte[] FAMILY = Bytes.toBytes("column");
   protected MultiVersionConcurrencyControl mvcc;
-  protected AtomicLong startSeqNum = new AtomicLong(0);
   protected ChunkCreator chunkCreator;
 
   private String getName() {
@@ -110,6 +110,11 @@ public class TestDefaultMemStore {
     this.memstore = new DefaultMemStore();
   }
 
+  @After
+  public void tearDown() throws Exception {
+    this.memstore.close();
+  }
+
   @AfterClass
   public static void tearDownClass() throws Exception {
     ChunkCreator.getInstance().clearChunkIds();
@@ -855,8 +860,8 @@ public class TestDefaultMemStore {
   
//////////////////////////////////////////////////////////////////////////////
   // Helpers
   
//////////////////////////////////////////////////////////////////////////////
-  private static byte[] makeQualifier(final int i1, final int i2) {
-    return Bytes.toBytes(Integer.toString(i1) + ";" + Integer.toString(i2));
+  protected static byte[] makeQualifier(final int i1, final int i2) {
+    return Bytes.toBytes(i1 + ";" + i2);
   }
 
   /**
@@ -1101,15 +1106,13 @@ public class TestDefaultMemStore {
 
   private static void addRows(int count, final MemStore mem) {
     long nanos = System.nanoTime();
-
     for (int i = 0; i < count; i++) {
       if (i % 1000 == 0) {
-
-        System.out.println(i + " Took for 1k usec: " + (System.nanoTime() - 
nanos) / 1000);
+        LOG.info("{} Took for 1k usec: {}", i, (System.nanoTime() - nanos) / 
1000);
         nanos = System.nanoTime();
       }
-      long timestamp = System.currentTimeMillis();
 
+      long timestamp = System.currentTimeMillis();
       for (int ii = 0; ii < QUALIFIER_COUNT; ii++) {
         byte[] row = Bytes.toBytes(i);
         byte[] qf = makeQualifier(i, ii);
@@ -1118,31 +1121,34 @@ public class TestDefaultMemStore {
     }
   }
 
-  static void doScan(MemStore ms, int iteration) throws IOException {
+  private static int doScan(MemStore ms, int iteration) throws IOException {
     long nanos = System.nanoTime();
     KeyValueScanner s = ms.getScanners(0).get(0);
     s.seek(KeyValueUtil.createFirstOnRow(new byte[] {}));
 
-    System.out.println(iteration + " create/seek took: " + (System.nanoTime() 
- nanos) / 1000);
+    LOG.info("Iteration {} create/seek took: {}", iteration, 
(System.nanoTime() - nanos) / 1000);
     int cnt = 0;
-    while (s.next() != null)
+    while (s.next() != null) {
       ++cnt;
-
-    System.out
-      .println(iteration + " took usec: " + (System.nanoTime() - nanos) / 1000 
+ " for: " + cnt);
-
+    }
+    LOG.info("Iteration {} took usec: {} for: {}", iteration, 
(System.nanoTime() - nanos) / 1000,
+      cnt);
+    return cnt;
   }
 
-  public static void main(String[] args) throws IOException {
-    MemStore ms = new DefaultMemStore();
-
+  protected void scanMemStore(MemStore ms, int expectedCount) throws 
IOException {
     long n1 = System.nanoTime();
-    addRows(25000, ms);
-    System.out.println("Took for insert: " + (System.nanoTime() - n1) / 1000);
+    addRows(SCAN_ROW_COUNT, ms);
+    LOG.info("Took for insert: {}", (System.nanoTime() - n1) / 1000);
 
-    System.out.println("foo");
+    for (int i = 0; i < 50; i++) {
+      int cnt = doScan(ms, i);
+      assertEquals(expectedCount, cnt);
+    }
+  }
 
-    for (int i = 0; i < 50; i++)
-      doScan(ms, i);
+  @Test
+  public void testScan() throws IOException {
+    scanMemStore(memstore, SCAN_ROW_COUNT * QUALIFIER_COUNT);
   }
 }

Reply via email to