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


##########
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:
   thanks for writing this up. unfortunately i think you're throwing the 
exception at the wrong level -- 
   
   conn.getTable is called within the current thread (unrelated to futures), so 
throwing an exception on that will just skip your whenComplete altogether. In 
fact I wouldn't be surprised if your `.get()` call below never gets called 
because getAllRegionLocations itself is throwing the exception.
   
   Instead I think you need to go a little deeper with your mocking and have 
something within throw an exception or return an exceptional future.  I think 
maybe it might be enough to have conn.getLocator().getRegionLocations() return 
an exceptional future, but that's just based on a quick look



-- 
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