juliuszsompolski commented on a change in pull request #24985: 
[SPARK-28184][SQL][TEST] Avoid creating new sessions in 
SparkMetadataOperationSuite
URL: https://github.com/apache/spark/pull/24985#discussion_r298247916
 
 

 ##########
 File path: 
sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/SparkMetadataOperationSuite.scala
 ##########
 @@ -17,63 +17,21 @@
 
 package org.apache.spark.sql.hive.thriftserver
 
-import java.util.{Arrays => JArrays, List => JList, Properties}
-
-import org.apache.hive.jdbc.{HiveConnection, HiveQueryResultSet}
-import org.apache.hive.service.auth.PlainSaslHelper
-import org.apache.thrift.protocol.TBinaryProtocol
-import org.apache.thrift.transport.TSocket
+import java.sql.ResultSet
 
 class SparkMetadataOperationSuite extends HiveThriftJdbcTest {
 
   override def mode: ServerMode.Value = ServerMode.binary
 
   test("Spark's own GetSchemasOperation(SparkGetSchemasOperation)") {
-    def testGetSchemasOperation(
-        catalog: String,
-        schemaPattern: String)(f: HiveQueryResultSet => Unit): Unit = {
-      val rawTransport = new TSocket("localhost", serverPort)
-      val connection = new 
HiveConnection(s"jdbc:hive2://localhost:$serverPort", new Properties)
-      val user = System.getProperty("user.name")
-      val transport = PlainSaslHelper.getPlainTransport(user, "anonymous", 
rawTransport)
-      val client = new ThriftserverShimUtils.Client(new 
TBinaryProtocol(transport))
-      transport.open()
-      var rs: HiveQueryResultSet = null
-      try {
-        val openResp = client.OpenSession(new 
ThriftserverShimUtils.TOpenSessionReq)
-        val sessHandle = openResp.getSessionHandle
-        val schemaReq = new ThriftserverShimUtils.TGetSchemasReq(sessHandle)
-
-        if (catalog != null) {
-          schemaReq.setCatalogName(catalog)
-        }
-
-        if (schemaPattern == null) {
-          schemaReq.setSchemaName("%")
-        } else {
-          schemaReq.setSchemaName(schemaPattern)
-        }
-
-        rs = new HiveQueryResultSet.Builder(connection)
-          .setClient(client)
-          .setSessionHandle(sessHandle)
-          .setStmtHandle(client.GetSchemas(schemaReq).getOperationHandle)
-          .build()
-        f(rs)
-      } finally {
-        rs.close()
-        connection.close()
-        transport.close()
-        rawTransport.close()
-      }
-    }
-
-    def checkResult(dbNames: Seq[String], rs: HiveQueryResultSet): Unit = {
+    def checkResult(rs: ResultSet, dbNames: Seq[String]): Unit = {
       if (dbNames.nonEmpty) {
         for (i <- dbNames.indices) {
           assert(rs.next())
           assert(rs.getString("TABLE_SCHEM") === dbNames(i))
         }
+        // Make sure there are no more elements
+        assert(!rs.next())
 
 Review comment:
   +1

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to