qiaoandxiang commented on a change in pull request #1310: HBASE-23957 [flakey 
test] client.TestMultiParallel fails to read hbas…
URL: https://github.com/apache/hbase/pull/1310#discussion_r394721724
 
 

 ##########
 File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncClusterAdminApi.java
 ##########
 @@ -65,19 +67,47 @@
   public static final HBaseClassTestRule CLASS_RULE =
       HBaseClassTestRule.forClass(TestAsyncClusterAdminApi.class);
 
-  private final Path cnfPath = 
FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml");
-  private final Path cnf2Path = 
FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml");
-  private final Path cnf3Path = 
FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml");
+  private static Path newCnfPath, newCnf2Path, newCnf3Path;
 
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
+    Path cnfPath = 
FileSystems.getDefault().getPath("target/test-classes/hbase-site.xml");
+    Path cnf2Path = 
FileSystems.getDefault().getPath("target/test-classes/hbase-site2.xml");
+    Path cnf3Path = 
FileSystems.getDefault().getPath("target/test-classes/hbase-site3.xml");
+
+    String absoluteDataPath = TEST_UTIL.getDataTestDir().toString();
+    String dataBasePath = 
System.getProperty(HBaseCommonTestingUtility.BASE_TEST_DIRECTORY_KEY,
+      HBaseCommonTestingUtility.DEFAULT_BASE_TEST_DIRECTORY);
+
+    String dataPath = 
absoluteDataPath.substring(absoluteDataPath.indexOf(dataBasePath));
+    newCnfPath = Paths.get(dataPath + "/hbase-site.xml");
+    newCnf2Path = Paths.get(dataPath + "/hbase-site2.xml");
+    newCnf3Path = Paths.get(dataPath + "/hbase-site3.xml");
+
+    // Copy Files from target/test-classes to data directory, this is to avoid 
messing up
+    // the config file under target/test-class, which is supposed to be 
immutable.
+    Files.createDirectories(Paths.get(dataPath));
+    Files.copy(cnfPath, newCnfPath);
+    Files.copy(cnf2Path, newCnf2Path);
+    Files.copy(cnf3Path, newCnf3Path);
+
+    // Add the new custom config file to Configuration
+    
TEST_UTIL.getConfiguration().addResource(TEST_UTIL.getDataTestDir("hbase-site.xml"));
+
     TEST_UTIL.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0);
     TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 
60000);
     
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 
120000);
     
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
     TEST_UTIL.getConfiguration().setInt(START_LOG_ERRORS_AFTER_COUNT_KEY, 0);
     TEST_UTIL.startMiniCluster(2);
     ASYNC_CONN = 
ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
+
+    // The resources added to TEST_UTIL.conf is lost during Region Server 
Creation, hack it here
+    // again.
+    for (int i = 0; i < 2; i ++) {
+      TEST_UTIL.getMiniHBaseCluster().getRegionServer(i).getConfiguration().
+        addResource(TEST_UTIL.getDataTestDir("hbase-site.xml"));
 
 Review comment:
   The issue is like that, the following code tries to clone a copy of conf for 
region servers. However, it is not really a clone, it just copies attributes 
over and other infos such as resources are lost which is important to test the 
updated config for region servers. Check the history of why cloning 
Configuration is not used (the clone one was used before and got reverted). 
Adding another method in HBaseConfiguration for this testing purpose seems an 
overkill and causes confusion.  Hence the hack in testing code instead of 
making changes in common code.
   
   
https://github.com/apache/hbase/blob/master/hbase-server/src/test/java/org/apache/hadoop/hbase/MiniHBaseCluster.java#L246

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to