Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default.extend-words]
# abbr
"vertx" = "vertx"
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<nexus-staging-maven-plugin.version>1.7.0</nexus-staging-maven-plugin.version>
<spotbugs-maven-plugin.version>4.8.6.2</spotbugs-maven-plugin.version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
<apache-http-client.version>5.3.1</apache-http-client.version>
<netty.version>4.1.112.Final</netty.version>
<okhttp.version>4.12.0</okhttp.version>
<vertx.version>4.5.10</vertx.version>
</properties>

<dependencyManagement>
Expand All @@ -62,6 +66,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
<version>${netty.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -92,6 +103,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion pulsar-admin-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
</parent>

<artifactId>pulsar-admin-api</artifactId>

<dependencies>
<dependency>
<groupId>io.github.openfacade</groupId>
<artifactId>http-facade</artifactId>
<version>${http-facade.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.protocol.pulsar.admin.api;

import io.github.openfacade.http.HttpClientEngine;

public class Configuration {
public String host = "localhost";

Expand All @@ -9,6 +11,8 @@ public class Configuration {

public TlsConfig tlsConfig;

public HttpClientEngine engine;

public Configuration() {
}

Expand All @@ -31,4 +35,9 @@ public Configuration tlsConfig(TlsConfig tlsConfig) {
this.tlsConfig = tlsConfig;
return this;
}

public Configuration engine(HttpClientEngine engine) {
this.engine = engine;
return this;
}
}
17 changes: 17 additions & 0 deletions pulsar-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@
<artifactId>http-facade</artifactId>
<version>${http-facade.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${apache-http-client.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>${vertx.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class InnerHttpClient {

public InnerHttpClient(Configuration conf) {
HttpClientConfig.Builder clientConfigBuilder = new HttpClientConfig.Builder();
clientConfigBuilder.engine(HttpClientEngine.Java);
clientConfigBuilder.engine(conf.engine == null ? HttpClientEngine.Java : conf.engine);
if (conf.tlsEnabled) {
TlsConfig.Builder tlsConfigBuilder = new TlsConfig.Builder();
io.github.protocol.pulsar.admin.api.TlsConfig tlsConfig = conf.tlsConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.protocol.pulsar.admin.jdk;

import io.github.embedded.pulsar.core.EmbeddedPulsarServer;
import io.github.openfacade.http.HttpClientEngine;
import io.github.protocol.pulsar.admin.api.Configuration;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.provider.Arguments;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class BaseTest {
protected EmbeddedPulsarServer server;
protected List<PulsarAdmin> pulsarAdmins;

@BeforeAll
public void setup() throws Exception {
server = new EmbeddedPulsarServer();
server.start();
pulsarAdmins = initPulsarAdmins();
}

@AfterAll
public void teardown() throws Exception {
server.close();
}

protected int getPort() {
return server.getWebPort();
}

protected List<PulsarAdmin> initPulsarAdmins() {
List<PulsarAdmin> pulsarAdmins = new ArrayList<>();
for (HttpClientEngine engine: HttpClientEngine.values()) {
// async and jetty client has dependency conflicts with embedded pulsar core, skip it.
if (engine.equals(HttpClientEngine.Async) || engine.equals(HttpClientEngine.Jetty)) {
continue;
}
Configuration conf = new Configuration();
conf.host("localhost");
conf.port(getPort());
conf.engine(engine);
PulsarAdminImpl pulsarAdmin = new PulsarAdminImpl(conf);
pulsarAdmins.add(pulsarAdmin);
}
return pulsarAdmins;
}

protected Stream<Arguments> providePulsarAdmins() {
return pulsarAdmins.stream().map(pulsarAdmin -> Arguments.arguments(pulsarAdmin));
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
package io.github.protocol.pulsar.admin.jdk;

import io.github.embedded.pulsar.core.EmbeddedPulsarServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class BrokersTest {
private static final EmbeddedPulsarServer SERVER = new EmbeddedPulsarServer();

@BeforeAll
public static void setup() throws Exception {
SERVER.start();
}

@AfterAll
public static void teardown() throws Exception {
SERVER.close();
}
public class BrokersTest extends BaseTest{

@Test
public void testHealthCheckV1() throws PulsarAdminException {
PulsarAdmin pulsarAdmin = PulsarAdmin.builder().port(SERVER.getWebPort()).build();
PulsarAdmin pulsarAdmin = PulsarAdmin.builder().port(getPort()).build();
pulsarAdmin.brokers().healthcheck(TopicVersion.V1);
}

@Test
public void testHealthCheckV2() throws PulsarAdminException {
PulsarAdmin pulsarAdmin = PulsarAdmin.builder().port(SERVER.getWebPort()).build();
PulsarAdmin pulsarAdmin = PulsarAdmin.builder().port(getPort()).build();
pulsarAdmin.brokers().healthcheck(TopicVersion.V2);
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
package io.github.protocol.pulsar.admin.jdk;

import io.github.embedded.pulsar.core.EmbeddedPulsarServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class ClustersTest {

private static final EmbeddedPulsarServer SERVER = new EmbeddedPulsarServer();

@BeforeAll
public static void setup() throws Exception {
SERVER.start();
}

@AfterAll
public static void teardown() throws Exception {
SERVER.close();
}

public class ClustersTest extends BaseTest{
@Test
public void getClustersTest() throws PulsarAdminException {
Assertions.assertEquals(Arrays.asList("standalone"),
PulsarAdmin.builder().port(SERVER.getWebPort()).build().clusters().getClusters());
PulsarAdmin.builder().port(getPort()).build().clusters().getClusters());
}

}
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
package io.github.protocol.pulsar.admin.jdk;

import com.google.common.collect.ImmutableMap;
import io.github.embedded.pulsar.core.EmbeddedPulsarServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.Arrays;
import java.util.HashSet;
import java.util.TreeMap;

public class NamespacesTest {

private static final EmbeddedPulsarServer SERVER = new EmbeddedPulsarServer();

public class NamespacesTest extends BaseTest {
private static final String CLUSTER_STANDALONE = "standalone";

private static final TenantInfo initialTenantInfo = (new TenantInfo.TenantInfoBuilder())
.adminRoles(new HashSet<>(0))
.allowedClusters(new HashSet<>(Arrays.asList(CLUSTER_STANDALONE))).build();

private static PulsarAdmin pulsarAdmin;

@BeforeAll
public static void setup() throws Exception {
SERVER.start();
pulsarAdmin = PulsarAdmin.builder().port(SERVER.getWebPort()).build();
}

@AfterAll
public static void teardown() throws Exception {
SERVER.close();
}

@Test
public void namespaceTest() throws PulsarAdminException {
@ParameterizedTest
@MethodSource("providePulsarAdmins")
public void namespaceTest(PulsarAdmin pulsarAdmin) throws PulsarAdminException {
String tenant = RandomUtil.randomString();
String namespace = RandomUtil.randomString();
pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo);
Expand All @@ -52,8 +35,9 @@ public void namespaceTest() throws PulsarAdminException {
Assertions.assertEquals(Arrays.asList(), pulsarAdmin.namespaces().getTenantNamespaces(tenant));
}

@Test
public void namespacesBacklogQuotaTest() throws PulsarAdminException, InterruptedException {
@ParameterizedTest
@MethodSource("providePulsarAdmins")
public void namespacesBacklogQuotaTest(PulsarAdmin pulsarAdmin) throws PulsarAdminException, InterruptedException {
String tenant = RandomUtil.randomString();
String namespace = RandomUtil.randomString();
pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo);
Expand Down Expand Up @@ -86,8 +70,9 @@ public void namespacesBacklogQuotaTest() throws PulsarAdminException, Interrupte
new TreeMap<>(pulsarAdmin.namespaces().getBacklogQuotaMap(tenant, namespace)));
}

@Test
public void namespacesClearBacklogTest() throws PulsarAdminException {
@ParameterizedTest
@MethodSource("providePulsarAdmins")
public void namespacesClearBacklogTest(PulsarAdmin pulsarAdmin) throws PulsarAdminException {
String tenant = RandomUtil.randomString();
String namespace = RandomUtil.randomString();
pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo);
Expand All @@ -97,8 +82,9 @@ public void namespacesClearBacklogTest() throws PulsarAdminException {
tenant, namespace, RandomUtil.randomString(), false);
}

@Test
public void namespacesRetentionTest() throws PulsarAdminException {
@ParameterizedTest
@MethodSource("providePulsarAdmins")
public void namespacesRetentionTest(PulsarAdmin pulsarAdmin) throws PulsarAdminException {
String tenant = RandomUtil.randomString();
String namespace = RandomUtil.randomString();
pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo);
Expand All @@ -113,8 +99,9 @@ public void namespacesRetentionTest() throws PulsarAdminException {
Assertions.assertNull(pulsarAdmin.namespaces().getRetention(tenant, namespace));
}

@Test
public void namespacesMessageTTLTest() throws PulsarAdminException {
@ParameterizedTest
@MethodSource("providePulsarAdmins")
public void namespacesMessageTTLTest(PulsarAdmin pulsarAdmin) throws PulsarAdminException {
String tenant = RandomUtil.randomString();
String namespace = RandomUtil.randomString();
pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo);
Expand All @@ -126,8 +113,9 @@ public void namespacesMessageTTLTest() throws PulsarAdminException {
Assertions.assertNull(pulsarAdmin.namespaces().getNamespaceMessageTTL(tenant, namespace));
}

@Test
public void namespacesCompactionThresholdTest() throws PulsarAdminException {
@ParameterizedTest
@MethodSource("providePulsarAdmins")
public void namespacesCompactionThresholdTest(PulsarAdmin pulsarAdmin) throws PulsarAdminException {
String tenant = RandomUtil.randomString();
String namespace = RandomUtil.randomString();
pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo);
Expand Down
Loading