diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/KerberizedTestHelper.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/KerberizedTestHelper.scala index d5ba4a05c20..31ed23112cf 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/KerberizedTestHelper.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/KerberizedTestHelper.scala @@ -50,26 +50,33 @@ trait KerberizedTestHelper extends KyuubiFunSuite { private var kdc: MiniKdc = _ private var krb5ConfPath: String = _ - eventually(timeout(60.seconds), interval(1.second)) { - try { - kdc = new MiniKdc(kdcConf, baseDir) - kdc.start() - krb5ConfPath = kdc.getKrb5conf.getAbsolutePath - } catch { - case NonFatal(e) => - if (kdc != null) { - kdc.stop() - kdc = null - } - throw e - } - } - private val keytabFile = new File(baseDir, "kyuubi-test.keytab") protected val testKeytab: String = keytabFile.getAbsolutePath - protected var testPrincipal = s"client/$hostName" - kdc.createPrincipal(keytabFile, testPrincipal) - + protected var testPrincipal: String = _ + + override def beforeAll(): Unit = { + eventually(timeout(60.seconds), interval(1.second)) { + try { + kdc = new MiniKdc(kdcConf, baseDir) + kdc.start() + krb5ConfPath = kdc.getKrb5conf.getAbsolutePath + } catch { + case NonFatal(e) => + if (kdc != null) { + kdc.stop() + kdc = null + } + throw e + } + } + val tempTestPrincipal = s"client/$hostName" + kdc.createPrincipal(keytabFile, tempTestPrincipal) + rewriteKrb5Conf() + testPrincipal = tempTestPrincipal + "@" + kdc.getRealm + info(s"KerberizedTest Principal: $testPrincipal") + info(s"KerberizedTest Keytab: $testKeytab") + super.beforeAll() + } /** * Forked from Apache Spark @@ -113,13 +120,6 @@ trait KerberizedTestHelper extends KyuubiFunSuite { System.lineSeparator() + s" $key=$value" } - rewriteKrb5Conf() - - testPrincipal = testPrincipal + "@" + kdc.getRealm - - info(s"KerberizedTest Principal: $testPrincipal") - info(s"KerberizedTest Keytab: $testKeytab") - override def afterAll(): Unit = { kdc.stop() super.afterAll()