Advertisement
Guest User

EmbeddedSingleNodeKafkaClusterTest deleteTopicsAndWait

a guest
Jan 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package io.confluent.examples.streams.kafka;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import io.confluent.kafka.schemaregistry.rest.SchemaRegistryConfig;
  6. import java.util.Properties;
  7. import kafka.server.KafkaConfig;
  8. import org.junit.AfterClass;
  9. import org.junit.ClassRule;
  10. import org.junit.Test;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13.  
  14. public class EmbeddedSingleNodeKafkaClusterTest {
  15.  
  16.   private static final Logger log = LoggerFactory.getLogger(EmbeddedSingleNodeKafkaClusterTest.class);
  17.   @ClassRule
  18.   public static final EmbeddedSingleNodeKafkaCluster CLUSTER = new EmbeddedSingleNodeKafkaCluster(
  19.       new Properties() {
  20.         {
  21.           //Transactions need durability so the defaults require multiple nodes.
  22.           //For testing purposes set transactions to work with a single kafka broker.
  23.           put(KafkaConfig.TransactionsTopicReplicationFactorProp(), "1");
  24.           put(KafkaConfig.TransactionsTopicMinISRProp(), "1");
  25.           put(KafkaConfig.TransactionsTopicPartitionsProp(), "1");
  26.           put(SchemaRegistryConfig.KAFKASTORE_TIMEOUT_CONFIG, "60000");
  27.         }
  28.       });
  29.  
  30.   @AfterClass
  31.   public static void stopCluster() {
  32.     log.info("stopping cluster");
  33.     if (CLUSTER.isRunning()) {
  34.       CLUSTER.stop();
  35.     }
  36.   }
  37.  
  38.   @Test
  39.   public void deleteTopics() throws InterruptedException {
  40.     final String topicName = "topic";
  41.     log.info("Creating topic {}", topicName);
  42.     CLUSTER.createTopic(topicName);
  43.  
  44.     log.info("Successfully created topic. About to delete.");
  45.     final boolean success = CLUSTER.deleteTopicsAndWait(30000, topicName);
  46.  
  47.     log.info("Successful in deleting topic: {}", success);
  48.     assertTrue(success);
  49.  
  50.     log.info("Waiting 60 seconds");
  51.     Thread.sleep(60000);
  52.   }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement