chia7712 commented on code in PR #16858:
URL: https://github.com/apache/kafka/pull/16858#discussion_r1729742192


##########
core/src/test/scala/integration/kafka/api/SaslSslAdminIntegrationTest.scala:
##########
@@ -520,6 +524,44 @@ class SaslSslAdminIntegrationTest extends 
BaseAdminIntegrationTest with SaslSetu
     }
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("zk", "kraft"))
+  def testExpireDelegationToken(quorum: String): Unit = {
+    client = createAdminClient
+    val createDelegationTokenOptions = new CreateDelegationTokenOptions()
+
+    // Test expiration for non-exists token
+    TestUtils.assertFutureExceptionTypeEquals(
+      client.expireDelegationToken("".getBytes()).expiryTimestamp(),
+      classOf[DelegationTokenNotFoundException]
+    )
+
+    // Test expiring the token immediately
+    val token1Future = 
client.createDelegationToken(createDelegationTokenOptions).delegationToken()
+    TestUtils.waitUntilTrue(() => token1Future.isDone, "Take too long to 
complete future", 500)
+    val expireTokeOptions = new ExpireDelegationTokenOptions()
+    val token1ExpireFuture = 
client.expireDelegationToken(token1Future.get().hmac(), 
expireTokeOptions.expiryTimePeriodMs(-1)).expiryTimestamp()
+    TestUtils.waitUntilTrue(() => token1ExpireFuture.isDone , "Take too long 
to complete future", 500)
+    assertTrue(token1ExpireFuture.get() < System.currentTimeMillis())
+
+    // Test expiring the expired token
+    val token2 = 
client.createDelegationToken(createDelegationTokenOptions.maxlifeTimeMs(1000)).delegationToken().get()
+    // Ensure current time > maxLifeTimeMs of token
+    Thread.sleep(1000)
+    TestUtils.assertFutureExceptionTypeEquals(
+      client.expireDelegationToken(token2.hmac(), 
expireTokeOptions.expiryTimePeriodMs(1)).expiryTimestamp(),
+      classOf[DelegationTokenExpiredException]
+    )
+
+    // Test shortening the expiryTimestamp
+    val token3Future = 
client.createDelegationToken(createDelegationTokenOptions).delegationToken()

Review Comment:
   ```scala
       // Test shortening the expiryTimestamp
       val token3 = 
client.createDelegationToken(createDelegationTokenOptions).delegationToken().get()
       assertTrue(client.expireDelegationToken(token3.hmac(), 
expireTokeOptions.expiryTimePeriodMs(200)).expiryTimestamp().get() < 
token3.tokenInfo().expiryTimestamp())
   ```



##########
core/src/test/scala/integration/kafka/api/SaslSslAdminIntegrationTest.scala:
##########
@@ -520,6 +524,44 @@ class SaslSslAdminIntegrationTest extends 
BaseAdminIntegrationTest with SaslSetu
     }
   }
 
+  @ParameterizedTest
+  @ValueSource(strings = Array("zk", "kraft"))
+  def testExpireDelegationToken(quorum: String): Unit = {
+    client = createAdminClient
+    val createDelegationTokenOptions = new CreateDelegationTokenOptions()
+
+    // Test expiration for non-exists token
+    TestUtils.assertFutureExceptionTypeEquals(
+      client.expireDelegationToken("".getBytes()).expiryTimestamp(),
+      classOf[DelegationTokenNotFoundException]
+    )
+
+    // Test expiring the token immediately
+    val token1Future = 
client.createDelegationToken(createDelegationTokenOptions).delegationToken()
+    TestUtils.waitUntilTrue(() => token1Future.isDone, "Take too long to 
complete future", 500)
+    val expireTokeOptions = new ExpireDelegationTokenOptions()
+    val token1ExpireFuture = 
client.expireDelegationToken(token1Future.get().hmac(), 
expireTokeOptions.expiryTimePeriodMs(-1)).expiryTimestamp()

Review Comment:
   ```scala
       val token1 = 
client.createDelegationToken(createDelegationTokenOptions).delegationToken().get()
       val expireTokeOptions = new ExpireDelegationTokenOptions()
       assertTrue(client.expireDelegationToken(token1.hmac(), 
expireTokeOptions.expiryTimePeriodMs(-1)).expiryTimestamp().get() < 
System.currentTimeMillis())
   ```



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

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to