Skip to content

Commit 84f1e63

Browse files
rmdmattinglyeab148Evie Boland
authored
HBASE-28842 TestRequestAttributes should fail when expected (#6255) (#6267)
Signed-off-by: Ray Mattingly <rmattingly@apache.org> Signed-off-by: Nick Dimiduk <ndimiduk@apache.org> Co-authored-by: eab148 <54775485+eab148@users.noreply.github.com> Co-authored-by: Evie Boland <eboland@hubspot.com>
1 parent c1277d3 commit 84f1e63

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRequestAttributes.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class TestRequestAttributes {
8787
ROW_KEY_TO_REQUEST_ATTRIBUTES.put(ROW_KEY5, addRandomRequestAttributes());
8888
ROW_KEY_TO_REQUEST_ATTRIBUTES.put(ROW_KEY6, addRandomRequestAttributes());
8989
ROW_KEY_TO_REQUEST_ATTRIBUTES.put(ROW_KEY7, addRandomRequestAttributes());
90-
ROW_KEY_TO_REQUEST_ATTRIBUTES.put(ROW_KEY8, new HashMap<>());
90+
ROW_KEY_TO_REQUEST_ATTRIBUTES.put(ROW_KEY8, new HashMap<String, byte[]>());
9191
}
9292
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(100);
9393
private static final byte[] FAMILY = Bytes.toBytes("0");
@@ -316,20 +316,26 @@ public Optional<RegionObserver> getRegionObserver() {
316316
@Override
317317
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get get,
318318
List<Cell> result) throws IOException {
319-
validateRequestAttributes(getRequestAttributesForRowKey(get.getRow()));
319+
if (!isValidRequestAttributes(getRequestAttributesForRowKey(get.getRow()))) {
320+
throw new IOException("Incorrect request attributes");
321+
}
320322
}
321323

322324
@Override
323325
public boolean preScannerNext(ObserverContext<RegionCoprocessorEnvironment> c,
324326
InternalScanner s, List<Result> result, int limit, boolean hasNext) throws IOException {
325-
validateRequestAttributes(REQUEST_ATTRIBUTES_SCAN);
327+
if (!isValidRequestAttributes(REQUEST_ATTRIBUTES_SCAN)) {
328+
throw new IOException("Incorrect request attributes");
329+
}
326330
return hasNext;
327331
}
328332

329333
@Override
330334
public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit)
331335
throws IOException {
332-
validateRequestAttributes(getRequestAttributesForRowKey(put.getRow()));
336+
if (!isValidRequestAttributes(getRequestAttributesForRowKey(put.getRow()))) {
337+
throw new IOException("Incorrect request attributes");
338+
}
333339
}
334340

335341
private Map<String, byte[]> getRequestAttributesForRowKey(byte[] rowKey) {
@@ -341,20 +347,21 @@ private Map<String, byte[]> getRequestAttributesForRowKey(byte[] rowKey) {
341347
return null;
342348
}
343349

344-
private void validateRequestAttributes(Map<String, byte[]> requestAttributes) {
350+
private boolean isValidRequestAttributes(Map<String, byte[]> requestAttributes) {
345351
RpcCall rpcCall = RpcServer.getCurrentCall().get();
346352
Map<String, byte[]> attrs = rpcCall.getRequestAttributes();
347353
if (attrs.size() != requestAttributes.size()) {
348-
return;
354+
return false;
349355
}
350356
for (Map.Entry<String, byte[]> attr : attrs.entrySet()) {
351357
if (!requestAttributes.containsKey(attr.getKey())) {
352-
return;
358+
return false;
353359
}
354360
if (!Arrays.equals(requestAttributes.get(attr.getKey()), attr.getValue())) {
355-
return;
361+
return false;
356362
}
357363
}
364+
return true;
358365
}
359366
}
360367
}

0 commit comments

Comments
 (0)