kamalcph commented on code in PR #13947:
URL: https://github.com/apache/kafka/pull/13947#discussion_r1292114559


##########
core/src/test/scala/integration/kafka/admin/RemoteTopicCRUDTest.scala:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package kafka.admin
+
+import kafka.integration.KafkaServerTestHarness
+import kafka.server.KafkaConfig
+import kafka.utils.{Logging, TestInfoUtils, TestUtils}
+import org.apache.kafka.clients.CommonClientConfigs
+import org.apache.kafka.clients.admin.Admin
+import org.apache.kafka.common.config.TopicConfig
+import org.apache.kafka.common.errors.UnknownTopicOrPartitionException
+import 
org.apache.kafka.server.log.remote.storage.{NoOpRemoteLogMetadataManager, 
NoOpRemoteStorageManager, RemoteLogManagerConfig}
+import org.junit.jupiter.api.{AfterEach, BeforeEach, Tag, TestInfo}
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.ValueSource
+
+import java.util.Properties
+import scala.collection.Seq
+import scala.util.Random
+import org.junit.jupiter.api.Assertions._
+import org.junit.jupiter.api.function.Executable
+
+import java.util.concurrent.ExecutionException
+
+@Tag("integration")
+class RemoteTopicCRUDTest extends KafkaServerTestHarness with Logging {
+
+  private val numPartitions = 2
+  private val numReplicationFactor = 2
+  private val defaultReplicationFactor = 1.toShort
+  private val numBrokers = 2
+
+  private var testTopicName: String = _
+  private var admin: Admin = _
+
+  /**
+   * Implementations must override this method to return a set of 
KafkaConfigs. This method will be invoked for every
+   * test and should not reuse previous configurations unless they select 
their ports randomly when servers are started.
+   */
+  override def generateConfigs: Seq[KafkaConfig] = 
TestUtils.createBrokerConfigs(
+    numConfigs = numBrokers,
+    zkConnect = zkConnectOrNull,
+    numPartitions = numPartitions,
+    defaultReplicationFactor = defaultReplicationFactor,
+  ).map { props =>
+    props.putAll(overrideProps())
+    KafkaConfig.fromProps(props)
+  }
+
+  override protected def kraftControllerConfigs(): Seq[Properties] = {
+    Seq(overrideProps())
+  }
+
+  @BeforeEach
+  override def setUp(info: TestInfo): Unit = {
+    super.setUp(info)
+    val props = new Properties()
+    props.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers())
+    admin = Admin.create(props)
+    testTopicName = 
s"${info.getTestMethod.get().getName}-${Random.alphanumeric.take(10).mkString}"
+  }
+
+  @AfterEach
+  def close(): Unit = {
+    if (admin != null)
+      admin.close()
+  }
+
+  @ParameterizedTest(name = TestInfoUtils.TestWithParameterizedQuorumName)
+  @ValueSource(strings = Array("zk", "kraft"))
+  def testTopicDeletion(quorum: String): Unit = {
+    val numPartitions = 2
+    val topicConfig = new Properties()
+    topicConfig.put(TopicConfig.REMOTE_LOG_STORAGE_ENABLE_CONFIG, "true")
+    topicConfig.put(TopicConfig.RETENTION_MS_CONFIG, "200")
+    topicConfig.put(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG, "100")
+    TestUtils.createTopicWithAdmin(admin, testTopicName, brokers, 
numPartitions, numReplicationFactor,
+      topicConfig = topicConfig)
+    TestUtils.deleteTopicWithAdmin(admin, testTopicName, brokers)
+    assertThrowsException(classOf[UnknownTopicOrPartitionException],
+      () => TestUtils.describeTopic(admin, testTopicName))
+  }
+
+  private def overrideProps(): Properties = {
+    val props = new Properties()
+    props.put(RemoteLogManagerConfig.REMOTE_LOG_STORAGE_SYSTEM_ENABLE_PROP, 
"true")
+    props.put(RemoteLogManagerConfig.REMOTE_STORAGE_MANAGER_CLASS_NAME_PROP,
+      classOf[NoOpRemoteStorageManager].getName)
+    
props.put(RemoteLogManagerConfig.REMOTE_LOG_METADATA_MANAGER_CLASS_NAME_PROP,
+      classOf[NoOpRemoteLogMetadataManager].getName)

Review Comment:
   Tried to capture the remote log segment deletion events, but couldn't extend 
`NoOpRemoteStorageManager.java` class:
   
   ```
   class MyRemoteStorageManager extends NoOpRemoteStorageManager {
     override def deleteLogSegmentData(remoteLogSegmentMetadata: 
RemoteLogSegmentMetadata): Unit = {
       counter += 1;
     }
   }
   ```  
    Caused by: java.lang.NoSuchMethodException: 
kafka.admin.RemoteTopicCRUDTest$MyRemoteStorageManager.<init>()
        at java.lang.Class.getConstructor0(Class.java:3082)
        at java.lang.Class.getConstructor(Class.java:1825)
        
   Since, remote-storage-manager is instantiated via reflection, it expects 
default constructor. Tried the below ways but it still doesn't work:
   
   1. Used companion object `Object#apply`. 
   2. Added default constructor to `NoOpRemoteStorageManager`
   3. Tried changing the `getDeclaredConstructor` to `getConstructor` in 
RemoteLogManger which uses reflection to instantiate this class.
   



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