HeartSaVioR commented on pull request #29069:
URL: https://github.com/apache/spark/pull/29069#issuecomment-657190799


   @frankyin-factual
   Thanks for the update. The approach looks good. Would you mind if we just 
put everything in the suite, so that we don't need to find things which is only 
used at once?
   
   Below change (+ imports) would make you get rid of new java files:
   
   ```
   class GetCatalogsOperationMock(parentSession: HiveSession)
     extends GetCatalogsOperation(parentSession) {
   
     override def runInternal(): Unit = {}
   
     override def getHandle: OperationHandle = {
       val uuid: UUID = UUID.randomUUID();
       val tHandleIdentifier: THandleIdentifier = new THandleIdentifier()
       tHandleIdentifier.setGuid(getByteBufferFromUUID(uuid));
       tHandleIdentifier.setSecret(getByteBufferFromUUID(uuid));
       val tOperationHandle: TOperationHandle = new TOperationHandle()
       tOperationHandle.setOperationId(tHandleIdentifier);
       tOperationHandle.setOperationType(TOperationType.GET_TYPE_INFO);
       tOperationHandle.setHasResultSetIsSet(false);
       new OperationHandle(tOperationHandle);
     }
   
     private def getByteBufferFromUUID(uuid: UUID): Array[Byte] = {
       val bb: ByteBuffer = ByteBuffer.wrap(new Array[Byte](16))
       bb.putLong(uuid.getMostSignificantBits())
       bb.putLong(uuid.getLeastSignificantBits())
       bb.array();
     }
   }
   
   class OperationManagerMock extends OperationManager {
     private val calledHandles: mutable.Set[OperationHandle] = new 
mutable.HashSet[OperationHandle]()
   
     override def newGetCatalogsOperation(parentSession: HiveSession): 
GetCatalogsOperation = {
       val operation = new GetCatalogsOperationMock(parentSession)
       try {
         val m = classOf[OperationManager].getDeclaredMethod("addOperation", 
classOf[Operation])
         m.setAccessible(true)
         m.invoke(this, operation)
       } catch {
         case e@(_: NoSuchMethodException | _: IllegalAccessException |
                 _: InvocationTargetException) =>
           throw new RuntimeException(e)
       }
       operation
     }
   
     override def closeOperation(opHandle: OperationHandle): Unit = {
       calledHandles.add(opHandle)
       throw new RuntimeException
     }
   
     def getCalledHandles: mutable.Set[OperationHandle] = calledHandles
   }
   ```


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



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

Reply via email to