@Test public void shouldSetServerConfigProperty() throws Exception { Properties config = new Properties(); config.put("foo", "bar"); KafkaCluster kafkaCluster = new KafkaCluster().withKafkaConfiguration(config).addBrokers(1); Field kafkaServersField = KafkaCluster.class.getDeclaredField("kafkaServers"); kafkaServersField.setAccessible(true); ConcurrentMap<Integer, KafkaServer> kafkaServers = (ConcurrentMap<Integer, KafkaServer>) kafkaServersField.get(kafkaCluster); Properties serverConfig = kafkaServers.values().iterator().next().config(); assertThat(serverConfig.get("foo")).isEqualTo("bar"); }
@Override public void start() throws Exception { // Kafka setup for the example File dataDir = Testing.Files.createTestingDirectory("cluster"); dataDir.deleteOnExit(); kafkaCluster = new KafkaCluster() .usingDirectory(dataDir) .withPorts(2181, 9092) .addBrokers(1) .deleteDataPriorToStartup(true) .startup(); // Deploy the dashboard JsonObject consumerConfig = new JsonObject((Map) kafkaCluster.useTo() .getConsumerProperties("the_group", "the_client", OffsetResetStrategy.LATEST)); vertx.deployVerticle( DashboardVerticle.class.getName(), new DeploymentOptions().setConfig(consumerConfig) ); // Deploy the metrics collector : 3 times JsonObject producerConfig = new JsonObject((Map) kafkaCluster.useTo() .getProducerProperties("the_producer")); vertx.deployVerticle( MetricsVerticle.class.getName(), new DeploymentOptions().setConfig(producerConfig).setInstances(3) ); }
@Test @SkipLongRunning public void shouldStartClusterWithOneBrokerAndRemoveData() throws Exception { cluster.addBrokers(1).startup(); cluster.onEachDirectory(this::assertValidDataDirectory); cluster.shutdown(); cluster.onEachDirectory(this::assertDoesNotExist); }
@Test @SkipLongRunning public void shouldStartClusterWithMultipleBrokerAndRemoveData() throws Exception { cluster.addBrokers(3).startup(); cluster.onEachDirectory(this::assertValidDataDirectory); cluster.shutdown(); cluster.onEachDirectory(this::assertDoesNotExist); }
@Test @SkipLongRunning public void shouldStartClusterWithMultipleBrokerAndLeaveData() throws Exception { cluster.deleteDataUponShutdown(false).addBrokers(3).startup(); cluster.onEachDirectory(this::assertValidDataDirectory); cluster.shutdown(); cluster.onEachDirectory(this::assertValidDataDirectory); }
@Test @SkipLongRunning public void shouldStartClusterWithOneBrokerAndLeaveData() throws Exception { cluster.deleteDataUponShutdown(false).addBrokers(1).startup(); cluster.onEachDirectory(this::assertValidDataDirectory); cluster.shutdown(); cluster.onEachDirectory(this::assertValidDataDirectory); }
@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.addBrokers(1).startup(); cluster.createTopics(topicName);
cluster.addBrokers(1).startup(); cluster.createTopics(topicName);
@Before public void beforeEach() throws Exception { source = Collect.hashMapOf("server", "my-server"); setLogPosition(0); topicName = "schema-changes-topic"; File dataDir = Testing.Files.createTestingDirectory("history_cluster"); Testing.Files.delete(dataDir); // Configure the extra properties to kafka = new KafkaCluster().usingDirectory(dataDir) .deleteDataPriorToStartup(true) .deleteDataUponShutdown(true) .addBrokers(1) .withKafkaConfiguration(Collect.propertiesOf("auto.create.topics.enable", "false")) .startup(); history = new KafkaDatabaseHistory(); }
@BeforeClass public static void setUp() throws IOException { kafkaCluster = kafkaCluster().deleteDataPriorToStartup(true).addBrokers(1).startup(); }
@BeforeClass public static void setUp() throws IOException { kafkaCluster = kafkaCluster().deleteDataPriorToStartup(true).addBrokers(1).startup(); }
.usingDirectory(dataDir) .withPorts(2181, 9092) .addBrokers(1) .deleteDataPriorToStartup(true) .startup();