|
| 1 | +package io.openmessaging.benchmark.e2e; |
| 2 | + |
| 3 | +import io.openmessaging.benchmark.TestResult; |
| 4 | +import io.openmessaging.benchmark.Workload; |
| 5 | +import io.openmessaging.benchmark.WorkloadGenerator; |
| 6 | +import io.openmessaging.benchmark.worker.LocalWorker; |
| 7 | +import io.pravega.client.ClientConfig; |
| 8 | +import io.pravega.client.admin.StreamManager; |
| 9 | +import org.junit.jupiter.api.AfterAll; |
| 10 | +import org.junit.jupiter.api.BeforeAll; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | +import org.slf4j.Logger; |
| 13 | +import org.slf4j.LoggerFactory; |
| 14 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 15 | +import org.testcontainers.junit.jupiter.Container; |
| 16 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | +import java.net.URI; |
| 20 | +import java.nio.file.Files; |
| 21 | +import java.nio.file.Path; |
| 22 | +import java.time.Duration; |
| 23 | + |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; |
| 25 | + |
| 26 | +/** |
| 27 | + * End-to-end tests for Pravega using a standalone container. |
| 28 | + */ |
| 29 | +@Testcontainers |
| 30 | +class PravegaE2eIT extends BaseE2eIT { |
| 31 | + |
| 32 | + private static final Logger log = LoggerFactory.getLogger(PravegaE2eIT.class); |
| 33 | + |
| 34 | + private static final String SCOPE = "ombscope"; |
| 35 | + |
| 36 | + @Container |
| 37 | + static PravegaContainer pravega = new PravegaContainer() |
| 38 | + .waitingFor( |
| 39 | + Wait.forLogMessage(".*Pravega Sandbox is running.*", 1) |
| 40 | + .withStartupTimeout(Duration.ofMinutes(5)) |
| 41 | + ); |
| 42 | + |
| 43 | + private static File driverConfigFile; |
| 44 | + |
| 45 | + @BeforeAll |
| 46 | + static void setupDriver() throws Exception { |
| 47 | + pravega.start(); |
| 48 | + var host = pravega.getHost(); |
| 49 | + |
| 50 | + log.info("Pravega controller URI: {}", pravega.getControllerURI()); |
| 51 | + log.info("Pravega segment store: {}:{}", host, pravega.getSegmentStoreEndpoint()); |
| 52 | + |
| 53 | + verifyPravegaConnection(); |
| 54 | + |
| 55 | + // Fixed config with proper structure from reference file |
| 56 | + String driverConfig = """ |
| 57 | + name: Pravega |
| 58 | + driverClass: io.openmessaging.benchmark.driver.pravega.PravegaBenchmarkDriver |
| 59 | +
|
| 60 | + client: |
| 61 | + controllerURI: %s |
| 62 | + scopeName: %s |
| 63 | +
|
| 64 | + writer: |
| 65 | + enableConnectionPooling: true |
| 66 | +
|
| 67 | + includeTimestampInEvent: false |
| 68 | + """.formatted(pravega.getControllerURI(), SCOPE); |
| 69 | + |
| 70 | + Path configPath = Files.createTempFile("pravega-driver-", ".yaml"); |
| 71 | + Files.writeString(configPath, driverConfig); |
| 72 | + driverConfigFile = configPath.toFile(); |
| 73 | + driverConfigFile.deleteOnExit(); |
| 74 | + |
| 75 | + log.info("Created Pravega driver config at: {}", driverConfigFile.getAbsolutePath()); |
| 76 | + log.info("Config content:\n{}", driverConfig); |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + private static void verifyPravegaConnection() { |
| 81 | + var clientConfig = ClientConfig.builder() |
| 82 | + .controllerURI(URI.create(pravega.getControllerURI())) |
| 83 | + .build(); |
| 84 | + try (StreamManager streamManager = StreamManager.create(clientConfig)) { |
| 85 | + boolean created = streamManager.createScope(SCOPE); |
| 86 | + log.info("Scope '{}' ensure/create result: {}", SCOPE, created); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + @AfterAll |
| 91 | + static void tearDownDriver() { |
| 92 | + if (driverConfigFile != null && driverConfigFile.exists()) { |
| 93 | + driverConfigFile.delete(); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + void testSimpleProduceConsume() throws Exception { |
| 99 | + Workload workload = createSimpleWorkload(); |
| 100 | + workload.topics = 1; |
| 101 | + workload.partitionsPerTopic = 2; |
| 102 | + workload.producersPerTopic = 2; |
| 103 | + workload.consumerPerSubscription = 2; |
| 104 | + workload.producerRate = 500; |
| 105 | + workload.useRandomizedPayloads = true; |
| 106 | + workload.randomizedPayloadPoolSize = 10; |
| 107 | + workload.randomBytesRatio = 0.5; |
| 108 | + workload.testDurationMinutes = 1; |
| 109 | + |
| 110 | + TestResult result = runBenchmark(workload); |
| 111 | + |
| 112 | + // Debug logging before validation |
| 113 | + log.info("Test result - Topics: {}", result.topics); |
| 114 | + log.info("Publish rate size: {}, values: {}", result.publishRate.size(), result.publishRate); |
| 115 | + log.info("Consume rate size: {}, values: {}", result.consumeRate.size(), result.consumeRate); |
| 116 | + log.info("Aggregate publish: {} msg/s", result.publishRate.stream().reduce(0.0, Double::sum)); |
| 117 | + |
| 118 | + validateResults(result, workload); |
| 119 | + |
| 120 | + var total = result.publishRate.stream().reduce(0.0, Double::sum); |
| 121 | + assertThat(total) |
| 122 | + .as("Should publish expected volume") |
| 123 | + .isGreaterThan(workload.producerRate * workload.testDurationMinutes * 0.7); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + void testMultipleStreams() throws Exception { |
| 128 | + Workload workload = createSimpleWorkload(); |
| 129 | + workload.topics = 3; |
| 130 | + workload.partitionsPerTopic = 2; |
| 131 | + workload.producerRate = 300; |
| 132 | + workload.useRandomizedPayloads = true; |
| 133 | + workload.randomizedPayloadPoolSize = 10; |
| 134 | + workload.randomBytesRatio = 0.5; |
| 135 | + workload.testDurationMinutes = 1; |
| 136 | + |
| 137 | + TestResult result = runBenchmark(workload); |
| 138 | + validateResults(result, workload); |
| 139 | + assertThat(result.topics).isEqualTo(workload.topics); |
| 140 | + } |
| 141 | + |
| 142 | + @Test |
| 143 | + void testHighThroughput() throws Exception { |
| 144 | + Workload workload = createSimpleWorkload(); |
| 145 | + workload.topics = 1; |
| 146 | + workload.partitionsPerTopic = 4; |
| 147 | + workload.messageSize = 200; |
| 148 | + workload.producersPerTopic = 4; |
| 149 | + workload.consumerPerSubscription = 4; |
| 150 | + workload.producerRate = 800; |
| 151 | + workload.useRandomizedPayloads = true; |
| 152 | + workload.randomizedPayloadPoolSize = 10; |
| 153 | + workload.randomBytesRatio = 0.5; |
| 154 | + workload.testDurationMinutes = 1; |
| 155 | + |
| 156 | + TestResult result = runBenchmark(workload); |
| 157 | + validateResults(result, workload); |
| 158 | + |
| 159 | + double total = result.publishRate.stream().reduce(0.0, Double::sum); |
| 160 | + double actualRate = total / workload.testDurationMinutes; |
| 161 | + log.info("Actual Pravega publish rate: {} msg/s", actualRate); |
| 162 | + assertThat(actualRate).isGreaterThan(workload.producerRate * 0.5); |
| 163 | + } |
| 164 | + |
| 165 | + private TestResult runBenchmark(Workload workload) throws Exception { |
| 166 | + var worker = new LocalWorker(statsLogger); |
| 167 | + try { |
| 168 | + worker.initializeDriver(driverConfigFile); |
| 169 | + WorkloadGenerator generator = new WorkloadGenerator("Pravega", workload, worker); |
| 170 | + TestResult result = generator.run(); |
| 171 | + generator.close(); |
| 172 | + return result; |
| 173 | + } finally { |
| 174 | + worker.stopAll(); |
| 175 | + worker.close(); |
| 176 | + } |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | + |
0 commit comments