improve test for operation log

This commit is contained in:
Kent Yao 2020-09-10 18:22:48 +08:00
parent 13706c3c3a
commit 4ee3577944
2 changed files with 17 additions and 6 deletions

View File

@ -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?
}
}
/**

View File

@ -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}"))
}
}