From 69ee4c18e8fc69e079479c0602499c560dd2b562 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Mon, 21 Sep 2020 20:38:11 +0800 Subject: [PATCH] kyuubi sql exception test --- .../org/apache/kyuubi/KyuubiSQLException.scala | 5 ++++- .../apache/kyuubi/KyuubiSQLExceptionSuite.scala | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala index f71d5be4b..f33efe972 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/KyuubiSQLException.scala @@ -23,7 +23,7 @@ import scala.collection.JavaConverters._ import org.apache.hive.service.rpc.thrift.{TStatus, TStatusCode} -case class KyuubiSQLException(msg: String, cause: Throwable) extends SQLException(msg, cause) { +class KyuubiSQLException(msg: String, cause: Throwable) extends SQLException(msg, cause) { /** * Converts current object to a [[TStatus]] object * @@ -44,6 +44,9 @@ object KyuubiSQLException { private final val HEAD_MARK: String = "*" private final val SEPARATOR: Char = ':' + def apply(msg: String, throwable: Throwable): KyuubiSQLException = { + new KyuubiSQLException(msg, throwable) + } def apply(cause: Throwable): KyuubiSQLException = { new KyuubiSQLException(cause.getMessage, cause) } diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/KyuubiSQLExceptionSuite.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/KyuubiSQLExceptionSuite.scala index b884bde18..cc91b1f61 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/KyuubiSQLExceptionSuite.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/KyuubiSQLExceptionSuite.scala @@ -17,6 +17,8 @@ package org.apache.kyuubi +import org.apache.hive.service.rpc.thrift.TStatusCode + class KyuubiSQLExceptionSuite extends KyuubiFunSuite { test("KyuubiSQLException") { @@ -28,11 +30,24 @@ class KyuubiSQLExceptionSuite extends KyuubiFunSuite { val e1 = new KyuubiException(msg1, e0) val e2 = new KyuubiSQLException(msg2, e1) assert(e2.toTStatus === KyuubiSQLException.toTStatus(e2)) + val e3 = KyuubiSQLException(e2.toTStatus) assert(e3.getMessage === e2.getMessage) assert(e3.getStackTrace === e2.getStackTrace) assert(e3.getCause.getMessage === e1.getMessage) assert(e3.getCause.getCause.getMessage === e0.getMessage) - } + val ts0 = KyuubiSQLException.toTStatus(e0) + assert(ts0.getStatusCode === TStatusCode.ERROR_STATUS) + assert(ts0.getErrorMessage === msg0) + assert(ts0.getInfoMessages.get(0).startsWith("*")) + + val e4 = KyuubiSQLException(ts0) + assert(e4.getMessage === msg0) + assert(e4.getCause.getStackTrace === e0.getStackTrace) + + val e5 = KyuubiSQLException(e0) + assert(e5.getMessage === msg0) + assert(e5.getCause === e0) + } }