Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import static org.apache.commons.lang3.StringUtils.isBlank;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.broker.ServiceConfigurationUtils;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.admin.PulsarAdmin;
import java.nio.file.Files;
import java.nio.file.Path;

public final class PulsarStandaloneBuilder {

Expand Down Expand Up @@ -96,6 +100,31 @@ public PulsarStandaloneBuilder withAdvertisedAddress(String advertisedAddress) {
return this;
}

public PulsarClient buildClient () throws Exception {
return PulsarClient.builder()
.serviceUrl(pulsarStandalone.getConfig().getBrokerServiceUrl())
.build();
}

public PulsarAdmin buildAdmin() throws Exception {
return PulsarAdmin.builder()
.serviceHttpUrl(pulsarStandalone.getConfig().getWebServiceAddress())
.build();
}

private PulsarStandaloneBuilder() throws IOException {
pulsarStandalone = new PulsarStandalone();
pulsarStandalone.setWipeData(true);
pulsarStandalone.setNoFunctionsWorker(true);

Path tempZkDir = Files.createTempDirectory("zk");
Path tempBkDir = Files.createTempDirectory("bk");
Comment on lines +120 to +121
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files would be left around in the temp directories. wipeData currently wipes data only at startup time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These directories would also be created when it's not desired.


pulsarStandalone.setZkDir(tempZkDir.toString());
pulsarStandalone.setBkDir(tempBkDir.toString());
}


public PulsarStandalone build() {
ServiceConfiguration config = new ServiceConfiguration();
config.setClusterName("standalone");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.apache.pulsar;

import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.junit.jupiter.api.Test;

public class PulsarStandaloneBuilderTest {

@Test
public void testStandaloneBuilder() throws Exception {

PulsarStandaloneBuilder builder = PulsarStandaloneBuilder.instance();

PulsarStandalone standalone = builder.build();
standalone.start();

PulsarClient client = builder.buildClient();
PulsarAdmin admin = builder.buildAdmin();

assertNotNull(client);
assertNotNull(admin);

client.close();
admin.close();
standalone.stop();
}

}