|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package io.openmessaging.benchmark.driver.kafka; |
| 15 | + |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; |
| 17 | + |
| 18 | +import java.nio.file.Files; |
| 19 | +import java.nio.file.Path; |
| 20 | +import org.junit.jupiter.api.io.TempDir; |
| 21 | +import org.junit.jupiter.params.ParameterizedTest; |
| 22 | +import org.junit.jupiter.params.provider.CsvSource; |
| 23 | + |
| 24 | +class KafkaBenchmarkDriverTest { |
| 25 | + @TempDir Path tempDir; |
| 26 | + |
| 27 | + @ParameterizedTest |
| 28 | + @CsvSource({ |
| 29 | + "client.id=test_az={zone.id},\"\",\"\",test_az=az0,test_az=az0", |
| 30 | + "client.id=test_az={zone.id},client.id=prod_az={zone.id},client.id=cons_az={zone.id},prod_az=az0,cons_az=az0", |
| 31 | + "\"\",client.id=prod_az={zone.id},client.id=cons_az={zone.id},prod_az=az0,cons_az=az0", |
| 32 | + "\"\",client.id=prod_az={zone.id},\"\",prod_az=az0,", |
| 33 | + "\"\",\"\",client.id=cons_az={zone.id},,cons_az=az0" |
| 34 | + }) |
| 35 | + void testInitClientIdWithZoneId( |
| 36 | + String commonConfig, |
| 37 | + String producerConfig, |
| 38 | + String consumerConfig, |
| 39 | + String producerClientId, |
| 40 | + String consumerClientId) |
| 41 | + throws Exception { |
| 42 | + // Given these configs |
| 43 | + final Path configPath = tempDir.resolve("config"); |
| 44 | + Config config = new Config(); |
| 45 | + config.replicationFactor = 1; |
| 46 | + config.commonConfig = "bootstrap.servers=localhost:9092\n" + commonConfig; |
| 47 | + config.producerConfig = producerConfig; |
| 48 | + config.consumerConfig = consumerConfig; |
| 49 | + config.topicConfig = ""; |
| 50 | + |
| 51 | + // and the system property set for zone id |
| 52 | + System.setProperty("zone.id", "az0"); |
| 53 | + |
| 54 | + try (KafkaBenchmarkDriver driver = new KafkaBenchmarkDriver()) { |
| 55 | + // When initializing kafka driver |
| 56 | + Files.write(configPath, KafkaBenchmarkDriver.mapper.writeValueAsBytes(config)); |
| 57 | + driver.initialize(configPath.toFile(), null); |
| 58 | + |
| 59 | + // Then |
| 60 | + if (producerClientId != null) { |
| 61 | + assertThat(driver.producerProperties).containsEntry("client.id", producerClientId); |
| 62 | + } else { |
| 63 | + assertThat(driver.producerProperties).doesNotContainKey("client.id"); |
| 64 | + } |
| 65 | + if (consumerClientId != null) { |
| 66 | + assertThat(driver.consumerProperties).containsEntry("client.id", consumerClientId); |
| 67 | + } else { |
| 68 | + assertThat(driver.consumerProperties).doesNotContainKey("client.id"); |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments