bbeaudreault commented on code in PR #4335:
URL: https://github.com/apache/hbase/pull/4335#discussion_r849556534


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java:
##########
@@ -460,4 +464,35 @@ public void testConcurrentUpdateCachedLocationOnError() 
throws Exception {
     IntStream.range(0, 100).parallel()
       .forEach(i -> locator.updateCachedLocationOnError(loc, new 
NotServingRegionException()));
   }
+
+  @Test
+  public void testCacheLocationWhenGetAllLocations() throws Exception {
+    createMultiRegionTable();
+    AsyncConnectionImpl conn = (AsyncConnectionImpl)
+      
ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
+    conn.getRegionLocator(TABLE_NAME).getAllRegionLocations().get();
+    List<RegionInfo> regions = TEST_UTIL.getAdmin().getRegions(TABLE_NAME);
+    for (RegionInfo region : regions) {
+      assertNotNull(conn.getLocator().getRegionLocationInCache(TABLE_NAME, 
region.getStartKey()));
+    }
+  }
+
+  @Test
+  public void testCacheLocationExceptionallyWhenGetAllLocations() throws 
Exception {
+    createMultiRegionTable();
+    AsyncConnectionImpl conn = (AsyncConnectionImpl)
+      
ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
+    AsyncConnectionImpl spyConn = Mockito.spy(conn);
+    Mockito.when(spyConn.getTable(TableName.META_TABLE_NAME))

Review Comment:
   > Also, I am a little confused about what you say "it might be enough to 
have conn.getLocator().getRegionLocations() return an exceptional future". From 
my understanding, we will not call this method. Would you mind explaining a 
little more ?
   
   So we're trying to test that your whenComplete is handling exceptions 
appropriately, and whenComplete will only be called once we have a 
CompletableFuture. So I think our goal here is to make one of the async calls 
within the call stack fail. Same as you, at first I thought you could make 
`scan()` throw an exception. But if you look at the call stack, the `scan()` 
call is actually _synchronous_. I think having it throw an exception would 
behave similarly to your original implementation here -- getAllRegionLocations 
would itself throw an exception rather than return an exceptional future (which 
we need for testing your whenComplete handler). 
   
   If you click into the call stack of `scan()` you'll see that the first async 
call in there is `conn.getLocator().getRegionLocations()` 
[here](https://github.com/apache/hbase/blob/master/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java#L457),
 called from AsyncClientScanner 
[here](https://github.com/apache/hbase/blob/master/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncClientScanner.java#L250).
 
   
   So basically if you make getRegionLocations return an exceptional future, i 
believe that will trigger the behavior we desire in the test.
   
   By the way, I think once this works, you'll actually expect an 
ExecutionException in your assertThrows below. The fact that you're getting a 
MockedBadScanResultException directly proves that your whenComplete is not 
being called at all because it's failing before generating a CompletableFuture 
to return rather than async.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to