Skip to content

Commit 4f3e0cd

Browse files
MMirellinodece
authored andcommitted
[improve][bk] Add integration test with bookie http server enabled (apache#20149)
Signed-off-by: tison <wander4096@gmail.com> Co-authored-by: tison <wander4096@gmail.com> (cherry picked from commit 3f2978d) Signed-off-by: Zixuan Liu <nodeces@gmail.com>
1 parent 730a5ea commit 4f3e0cd

4 files changed

Lines changed: 113 additions & 14 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.tests.integration.bookkeeper;
20+
21+
import lombok.extern.slf4j.Slf4j;
22+
import org.apache.pulsar.tests.integration.docker.ContainerExecResult;
23+
import org.apache.pulsar.tests.integration.topologies.PulsarCluster;
24+
import org.apache.pulsar.tests.integration.topologies.PulsarClusterSpec;
25+
import org.apache.pulsar.tests.integration.topologies.PulsarClusterTestBase;
26+
import org.testng.annotations.AfterClass;
27+
import org.testng.annotations.BeforeClass;
28+
import org.testng.annotations.Test;
29+
30+
import java.util.stream.Stream;
31+
32+
import static java.util.stream.Collectors.joining;
33+
import static org.testng.Assert.assertEquals;
34+
35+
/**
36+
* Test bookkeeper setup with http server enabled.
37+
*/
38+
@Slf4j
39+
public class BookkeeperInstallWithHttpServerEnabledTest extends PulsarClusterTestBase {
40+
41+
@BeforeClass(alwaysRun = true)
42+
@Override
43+
public final void setupCluster() throws Exception {
44+
incrementSetupNumber();
45+
46+
final String clusterName = Stream.of(this.getClass().getSimpleName(), randomName(5))
47+
.filter(s -> !s.isEmpty())
48+
.collect(joining("-"));
49+
bookkeeperEnvs.put("httpServerEnabled", "true");
50+
bookieAdditionalPorts.add(8000);
51+
PulsarClusterSpec spec = PulsarClusterSpec.builder()
52+
.numBookies(2)
53+
.numBrokers(1)
54+
.bookkeeperEnvs(bookkeeperEnvs)
55+
.bookieAdditionalPorts(bookieAdditionalPorts)
56+
.clusterName(clusterName)
57+
.build();
58+
59+
log.info("Setting up cluster {} with {} bookies, {} brokers",
60+
spec.clusterName(), spec.numBookies(), spec.numBrokers());
61+
62+
pulsarCluster = PulsarCluster.forSpec(spec);
63+
pulsarCluster.start();
64+
65+
log.info("Cluster {} is setup", spec.clusterName());
66+
}
67+
68+
@AfterClass(alwaysRun = true)
69+
@Override
70+
public final void tearDownCluster() throws Exception {
71+
super.tearDownCluster();
72+
}
73+
74+
@Test
75+
public void testBookieHttpServerIsRunning() throws Exception {
76+
ContainerExecResult result = pulsarCluster.getAnyBookie().execCmd(
77+
PulsarCluster.CURL,
78+
"-X",
79+
"GET",
80+
"http://localhost:8000/heartbeat");
81+
assertEquals(result.getExitCode(), 0);
82+
assertEquals(result.getStdout(), "OK\n");
83+
}
84+
}

tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarCluster.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,25 @@ private PulsarCluster(PulsarClusterSpec spec, CSContainer csContainer, boolean s
149149

150150
// create bookies
151151
bookieContainers.putAll(
152-
runNumContainers("bookie", spec.numBookies(), (name) -> new BKContainer(clusterName, name)
153-
.withNetwork(network)
154-
.withNetworkAliases(appendClusterName(name))
155-
.withEnv("zkServers", appendClusterName(ZKContainer.NAME))
156-
.withEnv("useHostNameAsBookieID", "true")
157-
// Disable fsyncs for tests since they're slow within the containers
158-
.withEnv("journalSyncData", "false")
159-
.withEnv("journalMaxGroupWaitMSec", "0")
160-
.withEnv("clusterName", clusterName)
161-
.withEnv("PULSAR_PREFIX_diskUsageWarnThreshold", "0.95")
162-
.withEnv("diskUsageThreshold", "0.99")
163-
.withEnv("PULSAR_PREFIX_diskUsageLwmThreshold", "0.97")
164-
.withEnv("nettyMaxFrameSizeBytes", "" + spec.maxMessageSize)
165-
)
152+
runNumContainers("bookie", spec.numBookies(), (name) -> {
153+
BKContainer bookieContainer = new BKContainer(clusterName, name)
154+
.withNetwork(network)
155+
.withNetworkAliases(appendClusterName(name))
156+
.withEnv("zkServers", appendClusterName(ZKContainer.NAME))
157+
.withEnv("useHostNameAsBookieID", "true")
158+
// Disable fsyncs for tests since they're slow within the containers
159+
.withEnv("journalSyncData", "false")
160+
.withEnv("journalMaxGroupWaitMSec", "0")
161+
.withEnv("clusterName", clusterName)
162+
.withEnv("PULSAR_PREFIX_diskUsageWarnThreshold", "0.95")
163+
.withEnv("diskUsageThreshold", "0.99")
164+
.withEnv("PULSAR_PREFIX_diskUsageLwmThreshold", "0.97")
165+
.withEnv("nettyMaxFrameSizeBytes", "" + spec.maxMessageSize);
166+
if (spec.bookkeeperEnvs != null) {
167+
bookieContainer.withEnv(spec.bookkeeperEnvs);
168+
}
169+
return bookieContainer;
170+
})
166171
);
167172

168173
// create brokers
@@ -699,4 +704,8 @@ public void dumpFunctionLogs(String name) {
699704
private String appendClusterName(String name) {
700705
return sharedCsContainer ? clusterName + "-" + name : name;
701706
}
707+
708+
public BKContainer getAnyBookie() {
709+
return getAnyContainer(bookieContainers, "bookie");
710+
}
702711
}

tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarClusterSpec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public class PulsarClusterSpec {
144144
*/
145145
Map<String, String> brokerEnvs;
146146

147+
/**
148+
* Specify envs for bookkeeper.
149+
*/
150+
Map<String, String> bookkeeperEnvs;
151+
147152
/**
148153
* Specify mount files.
149154
*/

tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarClusterTestBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
@Slf4j
3333
public abstract class PulsarClusterTestBase extends PulsarTestBase {
3434
protected final Map<String, String> brokerEnvs = new HashMap<>();
35+
protected final Map<String, String> bookkeeperEnvs = new HashMap<>();
3536

3637
@Override
3738
protected final void setup() throws Exception {

0 commit comments

Comments
 (0)