kingswanwho commented on code in PR #2499:
URL: https://github.com/apache/drill/pull/2499#discussion_r1096674511


##########
exec/java-exec/src/test/java/org/apache/drill/test/ClusterTest.java:
##########
@@ -125,4 +132,56 @@ public static void run(String query, Object... args) 
throws Exception {
   public QueryBuilder queryBuilder( ) {
     return client.queryBuilder();
   }
+
+  /**
+   * Utility method which tests given query produces a {@link UserException} 
and the exception message contains
+   * the given message.
+   * @param testSqlQuery Test query
+   * @param expectedErrorMsg Expected error message.
+   */
+  protected static void errorMsgTestHelper(String testSqlQuery, String 
expectedErrorMsg) throws Exception {
+    try {
+      run(testSqlQuery);
+      fail("Expected a UserException when running " + testSqlQuery);
+    } catch (UserException actualException) {
+      try {
+        assertThat("message of UserException when running " + testSqlQuery, 
actualException.getMessage(), containsString(expectedErrorMsg));
+      } catch (AssertionError e) {
+        e.addSuppressed(actualException);
+        throw e;
+      }
+    }
+  }
+
+  protected static void updateClient(Properties properties) {
+    if (client != null) {
+      client.close();
+      client = null;
+    }
+    ClientFixture.ClientBuilder clientBuilder = cluster.clientBuilder();
+    if (properties != null) {
+      for (final String key : properties.stringPropertyNames()) {
+        final String lowerCaseKey = key.toLowerCase();
+        clientBuilder.property(lowerCaseKey, properties.getProperty(key));
+      }
+    }
+    client = clientBuilder.build();
+  }
+
+  protected static void updateClient(final String user) {
+    updateClient(user, null);
+  }
+
+  protected static void updateClient(final String user, final String password) 
{
+    if (client != null) {
+      client.close();
+      client = null;
+    }
+    final Properties properties = new Properties();
+    properties.setProperty(DrillProperties.USER, user);
+    if (password != null) {
+      properties.setProperty(DrillProperties.PASSWORD, password);
+    }
+    updateClient(properties);
+  }

Review Comment:
   Thanks James! I have tried cluster.addClientFixture(), due to this method 
doesn't copy all the client properties from ClusterFixture, so after create a 
new ClientFixture, it still has problem to connect with ClusterFixture. And I 
also tried to modify updateClient method signature to return a ClientFixture, 
however due to the ClusterFixture and ClientFixture started by startCluster() 
are hold by two static variables, and updateClient should be a non-static 
method to refactor into ClientFixture, seems a non-static method return a value 
to static variable made some errors here, and I am still figuring it out. I 
think the feasible way should be started ClientFixture and ClusterFixture 
separately in each test case, so that those two variables are both non-static. 
The drawback here is the code change should be a little too much, but I can 
submit a commit to see whether it works
   



-- 
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: dev-unsubscr...@drill.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to