From 4ee3577944e373854acc3a22d07d00da893c47b9 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Thu, 10 Sep 2020 18:22:48 +0800 Subject: [PATCH] improve test for operation log --- .../engine/spark/operation/log/OperationLog.scala | 13 ++++++++----- .../spark/operation/log/OperationLogSuite.scala | 10 +++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLog.scala b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLog.scala index 67f3d11a6..8b716f6b3 100644 --- a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLog.scala +++ b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLog.scala @@ -62,7 +62,7 @@ object OperationLog extends Logging { Files.createDirectories(path) path.toFile.deleteOnExit() } catch { - case NonFatal(e) => + case e: IOException => error(s"Failed to create operation log root directory: $path", e) } } @@ -76,8 +76,7 @@ object OperationLog extends Logging { try { val logPath = Paths.get(LOG_ROOT, sessionHandle.identifier.toString) val logFile = Paths.get(logPath.toAbsolutePath.toString, opHandle.identifier.toString) - Files.createFile(logFile) - info(s"Created operation log file $logFile") + info(s"Creating operation log file $logFile") new OperationLog(logFile) } catch { case e: IOException => @@ -96,8 +95,12 @@ class OperationLog(path: Path) extends Logging { * write log to the operation log file */ def write(msg: String): Unit = synchronized { - writer.write(msg) - writer.flush() + try { + writer.write(msg) + writer.flush() + } catch { + case _: IOException => // TODO: better do nothing? + } } /** diff --git a/externals/kyuubi-spark-sql-engine/src/test/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLogSuite.scala b/externals/kyuubi-spark-sql-engine/src/test/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLogSuite.scala index 080d11fa7..3a595e1e5 100644 --- a/externals/kyuubi-spark-sql-engine/src/test/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLogSuite.scala +++ b/externals/kyuubi-spark-sql-engine/src/test/scala/org/apache/kyuubi/engine/spark/operation/log/OperationLogSuite.scala @@ -23,7 +23,7 @@ import scala.collection.JavaConverters._ import org.apache.hive.service.rpc.thrift.TProtocolVersion -import org.apache.kyuubi.KyuubiFunSuite +import org.apache.kyuubi.{KyuubiFunSuite, KyuubiSQLException} import org.apache.kyuubi.operation.{OperationHandle, OperationType} import org.apache.kyuubi.session.SessionHandle @@ -113,6 +113,14 @@ class OperationLogSuite extends KyuubiFunSuite { OperationType.EXECUTE_STATEMENT, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10) val log = OperationLog.createOperationLog(sHandle, oHandle) assert(log === null) + logRoot.delete() + OperationLog.createOperationLogRootDirectory(sHandle) + val log1 = OperationLog.createOperationLog(sHandle, oHandle) + log1.write("some msg here \n") + log1.close() + log1.write("some msg here again") + val e = intercept[KyuubiSQLException](log1.read(-1)) + assert(e.getMessage.contains(s"${sHandle.identifier}/${oHandle.identifier}")) } }