/** * Create the specified topics. * * @param topics the names of the topics to create * @throws IllegalStateException if the cluster is not running */ public void createTopics(Set<String> topics) { createTopics(topics.toArray(new String[topics.size()])); }
/** * Create the specified topics. * * @param numPartitions the number of partitions for each topic * @param replicationFactor the replication factor for each topic * @param topics the names of the topics to create */ public void createTopics(int numPartitions, int replicationFactor, Set<String> topics) { createTopics(numPartitions, replicationFactor, topics.toArray(new String[topics.size()])); }
@Test @SkipLongRunning public void shouldStartClusterAndAllowProducersAndConsumersToUseIt() throws Exception { Testing.Debug.enable(); final String topicName = "topicA"; final CountDownLatch completion = new CountDownLatch(2); final int numMessages = 100; final AtomicLong messagesRead = new AtomicLong(0); // Start a cluster and create a topic ... cluster.addBrokers(1).startup(); cluster.createTopics(topicName); // Consume messages asynchronously ... Stopwatch sw = Stopwatch.reusable().start(); cluster.useTo().consumeIntegers(topicName, numMessages, 10, TimeUnit.SECONDS, completion::countDown, (key, value) -> { messagesRead.incrementAndGet(); return true; }); // Produce some messages asynchronously ... cluster.useTo().produceIntegers(topicName, numMessages, 1, completion::countDown); // Wait for both to complete ... if (completion.await(10, TimeUnit.SECONDS)) { sw.stop(); Testing.debug("Both consumer and producer completed normally in " + sw.durations()); } else { Testing.debug("Consumer and/or producer did not completed normally"); } assertThat(messagesRead.get()).isEqualTo(numMessages); }
cluster.createTopics(topicName);
cluster.createTopics(topicName);