Skip to content

Commit 7e2718a

Browse files
committed
Enhance TestRowCache to ensure eviction count increments only for actually evicted rows
1 parent 7cc5d2a commit 7e2718a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowCache.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,6 @@ public void testGetWithRowCache() throws IOException {
175175

176176
RowCacheKey rowCacheKey = new RowCacheKey(region, rowKey);
177177

178-
// Put a row
179-
Put put = new Put(rowKey);
180-
put.addColumn(CF1, Q1, Bytes.toBytes(0L));
181-
put.addColumn(CF1, Q2, "12".getBytes());
182-
put.addColumn(CF2, Q1, "21".getBytes());
183-
put.addColumn(CF2, Q2, "22".getBytes());
184-
table.put(put);
185-
admin.flush(tableName);
186-
187178
// Initialize metrics
188179
recomputeMetrics();
189180
setCounterBase("Get_num_ops", metricsHelper.getCounter("Get_num_ops", serverSource));
@@ -194,6 +185,19 @@ public void testGetWithRowCache() throws IOException {
194185
setCounterBase(ROW_CACHE_EVICTED_ROW_COUNT,
195186
metricsHelper.getCounter(ROW_CACHE_EVICTED_ROW_COUNT, serverSource));
196187

188+
// Put a row
189+
Put put = new Put(rowKey);
190+
put.addColumn(CF1, Q1, Bytes.toBytes(0L));
191+
put.addColumn(CF1, Q2, "12".getBytes());
192+
put.addColumn(CF2, Q1, "21".getBytes());
193+
put.addColumn(CF2, Q2, "22".getBytes());
194+
table.put(put);
195+
admin.flush(tableName);
196+
recomputeMetrics();
197+
assertCounterDiff(ROW_CACHE_HIT_COUNT, 0);
198+
assertCounterDiff(ROW_CACHE_MISS_COUNT, 0);
199+
assertCounterDiff(ROW_CACHE_EVICTED_ROW_COUNT, 0);
200+
197201
// First get to populate the row cache
198202
result = table.get(get);
199203
recomputeMetrics();
@@ -206,6 +210,7 @@ public void testGetWithRowCache() throws IOException {
206210
// Ensure the get operation from HFile without row cache
207211
assertCounterDiff(ROW_CACHE_HIT_COUNT, 0);
208212
assertCounterDiff(ROW_CACHE_MISS_COUNT, 1);
213+
assertCounterDiff(ROW_CACHE_EVICTED_ROW_COUNT, 0);
209214

210215
// Get from the row cache
211216
result = table.get(get);
@@ -219,6 +224,7 @@ public void testGetWithRowCache() throws IOException {
219224
// Ensure the get operation from the row cache
220225
assertCounterDiff(ROW_CACHE_HIT_COUNT, 1);
221226
assertCounterDiff(ROW_CACHE_MISS_COUNT, 0);
227+
assertCounterDiff(ROW_CACHE_EVICTED_ROW_COUNT, 0);
222228

223229
// Row cache is invalidated by the put operation
224230
assertNotNull(rowCache.getRow(rowCacheKey, true));

0 commit comments

Comments
 (0)