From 7d7ab18951b2094c5591e2f449dc9895801b3288 Mon Sep 17 00:00:00 2001 From: moxiaoying <1159230165@qq.com> Date: Sun, 5 Jan 2025 18:20:03 +0800 Subject: [PATCH] refactor: support jdk8 Signed-off-by: moxiaoying <1159230165@qq.com> --- README.md | 4 +- pom.xml | 4 +- .../pulsar/admin/common/JacksonService.java | 3 +- .../pulsar/admin/jdk/BaseTopicsImpl.java | 4 +- .../protocol/pulsar/admin/jdk/Brokers.java | 2 +- .../protocol/pulsar/admin/jdk/Clusters.java | 2 +- .../pulsar/admin/jdk/InnerHttpClient.java | 5 +- .../protocol/pulsar/admin/jdk/Namespaces.java | 6 +-- .../protocol/pulsar/admin/jdk/Tenants.java | 2 +- .../pulsar/admin/jdk/ClustersTest.java | 4 +- .../pulsar/admin/jdk/NamespacesTest.java | 25 +++++---- .../admin/jdk/NonPersistentTopicsTest.java | 19 ++++--- .../admin/jdk/PersistentTopicsTest.java | 52 +++++++++---------- .../protocol/pulsar/admin/jdk/RandomUtil.java | 12 ++--- .../pulsar/admin/jdk/TenantsTest.java | 15 +++--- .../protocol/pulsar/spring/NewNamespace.java | 13 ++++- .../protocol/pulsar/spring/NewTenant.java | 10 +++- 17 files changed, 100 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 478f2d2..450c628 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ ![License](https://img.shields.io/badge/license-Apache2.0-green) ![Language](https://img.shields.io/badge/language-Java-blue.svg) [![version](https://img.shields.io/github/v/tag/protocol-laboratory/pulsar-admin-java?label=release&color=blue)](https://github.com/protocol-laboratory/pulsar-admin-java/releases) [![codecov](https://codecov.io/gh/protocol-laboratory/pulsar-admin-java/branch/main/graph/badge.svg)](https://codecov.io/gh/protocol-laboratory/pulsar-admin-java) -This is a simple alternative to pulsar-admin built using the built-in HTTP client of the JDK. It minimizes project dependencies and requires a minimum of JDK 17. +This is a simple alternative to pulsar-admin built using the built-in HTTP client of the JDK. It minimizes project dependencies and requires a minimum of JDK 8. Features: - Basic functionality for managing Pulsar clusters - Built on top of the built-in HTTP client of the JDK - Minimizes project dependencies to provide a lightweight solution -- Requires a minimum of JDK 17 +- Requires a minimum of JDK 8 Notices: - currently disable hostname verification is not available. if you want to disable it ,please set property like : **System.setProperty("jdk.internal.httpclient.disableHostnameVerification", "true")**, but it's better to provide valid certificates. diff --git a/pom.xml b/pom.xml index 759d590..8cd4756 100644 --- a/pom.xml +++ b/pom.xml @@ -18,8 +18,8 @@ - 17 - 17 + 8 + 8 UTF-8 src/main/java diff --git a/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java b/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java index 5344af3..71af0e1 100644 --- a/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java +++ b/pulsar-admin-common/src/main/java/io/github/protocol/pulsar/admin/common/JacksonService.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; +import java.util.ArrayList; import java.util.List; public class JacksonService { @@ -41,7 +42,7 @@ public static T toRefer(byte[] json, TypeReference ref) throws IOExceptio public static List toList(byte[] json, TypeReference> typeRef) throws IOException { if (json == null || json.length == 0) { - return List.of(); + return new ArrayList<>(); } return MAPPER.readValue(json, typeRef); } diff --git a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java index 534d1e8..f5e600a 100644 --- a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java +++ b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/BaseTopicsImpl.java @@ -164,7 +164,7 @@ public List getList(String tenant, String namespace, String bundle, boolean incl + "under namespace %s/%s, status code %s, body : %s", tenant, namespace, response.statusCode(), response.bodyAsString())); } - return JacksonService.toRefer(response.body(), new TypeReference<>() { + return JacksonService.toRefer(response.body(), new TypeReference>() { }); } catch (IOException | InterruptedException | ExecutionException e) { throw new PulsarAdminException(e); @@ -183,7 +183,7 @@ public List getPartitionedTopicList(String tenant, String namespace, boolean inc + "status code %s, body : %s", tenant, namespace, response.statusCode(), response.bodyAsString())); } - return JacksonService.toRefer(response.body(), new TypeReference<>() { + return JacksonService.toRefer(response.body(), new TypeReference>() { }); } catch (IOException | InterruptedException | ExecutionException e) { throw new PulsarAdminException(e); diff --git a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Brokers.java b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Brokers.java index 2f27612..3d3ea4a 100644 --- a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Brokers.java +++ b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Brokers.java @@ -21,7 +21,7 @@ public void healthcheck(TopicVersion topicVersion) throws PulsarAdminException { httpResponse.statusCode()); } if (!httpResponse.bodyAsString().equals("ok")) { - throw new PulsarAdminException("healthcheck failed, body: " + httpResponse.body()); + throw new PulsarAdminException("healthcheck failed, body: " + httpResponse.bodyAsString()); } } catch (Exception e) { throw new PulsarAdminException(e); diff --git a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Clusters.java b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Clusters.java index e96cc15..91f751b 100644 --- a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Clusters.java +++ b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Clusters.java @@ -24,7 +24,7 @@ public List getClusters() throws PulsarAdminException { String.format("failed to get list of clusters, " + "status code %s, body : %s", response.statusCode(), response.body())); } - return JacksonService.toRefer(response.body(), new TypeReference<>() {}); + return JacksonService.toRefer(response.body(), new TypeReference>() {}); } catch (IOException | InterruptedException | ExecutionException e) { throw new PulsarAdminException(e); } diff --git a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/InnerHttpClient.java b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/InnerHttpClient.java index fc16c77..93ad64e 100644 --- a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/InnerHttpClient.java +++ b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/InnerHttpClient.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -61,7 +62,7 @@ public HttpResponse post(String url, Object body, String... params) private HttpResponse innerPost(String url, byte[] body, String... params) throws InterruptedException, ExecutionException { Map> headers = new HashMap<>(); - headers.put("Content-Type", List.of("application/json")); + headers.put("Content-Type", Arrays.asList("application/json")); HttpRequest request = new HttpRequest(concatUrlWithParams(url, params), HttpMethod.POST, headers, body); return client.send(request).get(); } @@ -82,7 +83,7 @@ public HttpResponse put(String url, Object body, String... params) private HttpResponse innerPut(String url, byte[] body, String... params) throws InterruptedException, ExecutionException { Map> headers = new HashMap<>(); - headers.put("Content-Type", List.of("application/json")); + headers.put("Content-Type", Arrays.asList("application/json")); HttpRequest request = new HttpRequest(concatUrlWithParams(url, params), HttpMethod.PUT, headers, body); return client.send(request).get(); } diff --git a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Namespaces.java b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Namespaces.java index 9e8af00..04d752d 100644 --- a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Namespaces.java +++ b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Namespaces.java @@ -25,7 +25,7 @@ public List getTenantNamespaces(String tenant) throws PulsarAdminExcepti String.format("failed to get namespaces of tenant %s, status code %s, body : %s", tenant, response.statusCode(), response.bodyAsString())); } - return JacksonService.toList(response.body(), new TypeReference<>() { + return JacksonService.toList(response.body(), new TypeReference>() { }); } catch (IOException | InterruptedException | ExecutionException e) { throw new PulsarAdminException(e); @@ -43,7 +43,7 @@ public List getTopics(String tenant, String namespace, Mode mode, boolea String.format("failed to get topics of namespace %s/%s, status code %s, body : %s", tenant, namespace, response.statusCode(), response.bodyAsString())); } - return JacksonService.toList(response.body(), new TypeReference<>() { + return JacksonService.toList(response.body(), new TypeReference>() { }); } catch (IOException | InterruptedException | ExecutionException e) { throw new PulsarAdminException(e); @@ -90,7 +90,7 @@ public Map getBacklogQuotaMap(String tenant, Str "failed to get backlog quota map of namespace %s/%s, status code %s, body : %s", tenant, namespace, response.statusCode(), response.bodyAsString())); } - return JacksonService.toRefer(response.body(), new TypeReference<>() { + return JacksonService.toRefer(response.body(), new TypeReference>() { }); } catch (IOException | InterruptedException | ExecutionException e) { throw new PulsarAdminException(e); diff --git a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Tenants.java b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Tenants.java index 1a9870d..4320794 100644 --- a/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Tenants.java +++ b/pulsar-admin/src/main/java/io/github/protocol/pulsar/admin/jdk/Tenants.java @@ -76,7 +76,7 @@ public List getTenants() throws PulsarAdminException { throw new PulsarAdminException(String.format("failed to get list of tenant, status code %s, body : %s", response.statusCode(), response.bodyAsString())); } - return JacksonService.toList(response.body(), new TypeReference<>() {}); + return JacksonService.toList(response.body(), new TypeReference>() {}); } catch (IOException | InterruptedException | ExecutionException e) { throw new PulsarAdminException(e); } diff --git a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/ClustersTest.java b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/ClustersTest.java index 0079a7a..5053bc9 100644 --- a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/ClustersTest.java +++ b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/ClustersTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.List; +import java.util.Arrays; public class ClustersTest { @@ -24,7 +24,7 @@ public static void teardown() throws Exception { @Test public void getClustersTest() throws PulsarAdminException { - Assertions.assertEquals(List.of("standalone"), + Assertions.assertEquals(Arrays.asList("standalone"), PulsarAdmin.builder().port(SERVER.getWebPort()).build().clusters().getClusters()); } diff --git a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NamespacesTest.java b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NamespacesTest.java index 749e905..4904b3a 100644 --- a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NamespacesTest.java +++ b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NamespacesTest.java @@ -1,15 +1,14 @@ 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 java.util.Arrays; import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.TreeMap; public class NamespacesTest { @@ -20,7 +19,7 @@ public class NamespacesTest { private static final TenantInfo initialTenantInfo = (new TenantInfo.TenantInfoBuilder()) .adminRoles(new HashSet<>(0)) - .allowedClusters(Set.of(CLUSTER_STANDALONE)).build(); + .allowedClusters(new HashSet<>(Arrays.asList(CLUSTER_STANDALONE))).build(); private static PulsarAdmin pulsarAdmin; @@ -41,16 +40,16 @@ public void namespaceTest() throws PulsarAdminException { String namespace = RandomUtil.randomString(); pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo); pulsarAdmin.namespaces().createNamespace(tenant, namespace); - Assertions.assertEquals(List.of(), pulsarAdmin.namespaces() - .getTopics(tenant, namespace, Mode.PERSISTENT, true)); - Assertions.assertEquals(List.of(), pulsarAdmin.namespaces() + Assertions.assertEquals(Arrays.asList(), pulsarAdmin.namespaces() + .getTopics(tenant, namespace, Mode.PERSISTENT, true)); + Assertions.assertEquals(Arrays.asList(), pulsarAdmin.namespaces() .getTopics(tenant, namespace, Mode.NON_PERSISTENT, true)); - Assertions.assertEquals(List.of(), pulsarAdmin.namespaces() + Assertions.assertEquals(Arrays.asList(), pulsarAdmin.namespaces() .getTopics(tenant, namespace, Mode.ALL, false)); Assertions.assertEquals( - List.of(tenant + "/" + namespace), pulsarAdmin.namespaces().getTenantNamespaces(tenant)); + Arrays.asList(tenant + "/" + namespace), pulsarAdmin.namespaces().getTenantNamespaces(tenant)); pulsarAdmin.namespaces().deleteNamespace(tenant, namespace, false, false); - Assertions.assertEquals(List.of(), pulsarAdmin.namespaces().getTenantNamespaces(tenant)); + Assertions.assertEquals(Arrays.asList(), pulsarAdmin.namespaces().getTenantNamespaces(tenant)); } @Test @@ -72,18 +71,18 @@ public void namespacesBacklogQuotaTest() throws PulsarAdminException, Interrupte pulsarAdmin.namespaces().setBacklogQuota(tenant, namespace, BacklogQuotaType.message_age, backlogQuota1); pulsarAdmin.namespaces().setBacklogQuota(tenant, namespace, BacklogQuotaType.destination_storage, backlogQuota2); - Assertions.assertEquals(Map.of( + Assertions.assertEquals(ImmutableMap.of( BacklogQuotaType.destination_storage, backlogQuota2, BacklogQuotaType.message_age, backlogQuota1), new TreeMap<>(pulsarAdmin.namespaces().getBacklogQuotaMap(tenant, namespace))); backlogQuota1.setPolicy(RetentionPolicy.producer_exception); pulsarAdmin.namespaces().setBacklogQuota(tenant, namespace, BacklogQuotaType.message_age, backlogQuota1); - Assertions.assertEquals(Map.of( + Assertions.assertEquals(ImmutableMap.of( BacklogQuotaType.destination_storage, backlogQuota2, BacklogQuotaType.message_age, backlogQuota1), new TreeMap<>(pulsarAdmin.namespaces().getBacklogQuotaMap(tenant, namespace))); pulsarAdmin.namespaces().removeBacklogQuota(tenant, namespace, BacklogQuotaType.message_age); - Assertions.assertEquals(Map.of(BacklogQuotaType.destination_storage, backlogQuota2), + Assertions.assertEquals(ImmutableMap.of(BacklogQuotaType.destination_storage, backlogQuota2), new TreeMap<>(pulsarAdmin.namespaces().getBacklogQuotaMap(tenant, namespace))); } diff --git a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NonPersistentTopicsTest.java b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NonPersistentTopicsTest.java index 4cedfcc..2f691d2 100644 --- a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NonPersistentTopicsTest.java +++ b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/NonPersistentTopicsTest.java @@ -6,9 +6,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Arrays; import java.util.HashSet; -import java.util.List; -import java.util.Set; public class NonPersistentTopicsTest { @@ -25,8 +24,8 @@ public static void setup() throws Exception { SERVER.start(); pulsarAdmin = PulsarAdmin.builder().port(SERVER.getWebPort()).build(); TenantInfo initialTenantInfo = (new TenantInfo.TenantInfoBuilder()) - .adminRoles(new HashSet<>(0)) - .allowedClusters(Set.of(CLUSTER_STANDALONE)).build(); + .adminRoles(new HashSet<>(0)) + .allowedClusters(new HashSet<>(Arrays.asList(CLUSTER_STANDALONE))).build(); pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo); } @@ -41,20 +40,20 @@ public void partitionedTopicsTest() throws PulsarAdminException { String topic = RandomUtil.randomString(); pulsarAdmin.namespaces().createNamespace(tenant, namespace); pulsarAdmin.nonPersistentTopics().createPartitionedTopic(tenant, namespace, topic, 2, false); - Assertions.assertEquals(List.of(String.format("non-persistent://%s/%s/%s", tenant, namespace, topic)), + Assertions.assertEquals(Arrays.asList(String.format("non-persistent://%s/%s/%s", tenant, namespace, topic)), pulsarAdmin.nonPersistentTopics().getPartitionedTopicList(tenant, namespace, false)); Assertions.assertEquals(2, pulsarAdmin.nonPersistentTopics().getPartitionedMetadata(tenant, namespace, topic, false, false).getPartitions()); pulsarAdmin.nonPersistentTopics().updatePartitionedTopic(tenant, namespace, topic, false, false, false, 3); - Assertions.assertEquals(List.of(String.format("non-persistent://%s/%s/%s", tenant, namespace, topic)), + Assertions.assertEquals(Arrays.asList(String.format("non-persistent://%s/%s/%s", tenant, namespace, topic)), pulsarAdmin.nonPersistentTopics().getPartitionedTopicList(tenant, namespace, false)); Assertions.assertEquals(3, pulsarAdmin.nonPersistentTopics().getPartitionedMetadata(tenant, namespace, topic, false, false).getPartitions()); pulsarAdmin.nonPersistentTopics().deletePartitionedTopic(tenant, namespace, topic, false, false); - Assertions.assertEquals(List.of(), + Assertions.assertEquals(Arrays.asList(), pulsarAdmin.nonPersistentTopics().getPartitionedTopicList(tenant, namespace, false)); Assertions.assertEquals( - List.of(), + Arrays.asList(), pulsarAdmin.nonPersistentTopics().getList(tenant, namespace, null, false)); } @@ -75,11 +74,11 @@ public void nonPartitionedTopicsTest() throws PulsarAdminException { pulsarAdmin.namespaces().createNamespace(tenant, namespace); pulsarAdmin.nonPersistentTopics().createNonPartitionedTopic(tenant, namespace, topic, false, null); Assertions.assertEquals( - List.of(String.format("non-persistent://%s/%s/%s", tenant, namespace, topic)), + Arrays.asList(String.format("non-persistent://%s/%s/%s", tenant, namespace, topic)), pulsarAdmin.nonPersistentTopics().getList(tenant, namespace, null, false)); pulsarAdmin.nonPersistentTopics().deleteTopic(tenant, namespace, topic, false, false); Assertions.assertEquals( - List.of(), + Arrays.asList(), pulsarAdmin.nonPersistentTopics().getList(tenant, namespace, null, false)); } diff --git a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/PersistentTopicsTest.java b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/PersistentTopicsTest.java index 1a82837..6ab88cb 100644 --- a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/PersistentTopicsTest.java +++ b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/PersistentTopicsTest.java @@ -1,5 +1,6 @@ package io.github.protocol.pulsar.admin.jdk; +import com.google.common.collect.ImmutableMap; import io.github.embedded.pulsar.core.EmbeddedPulsarServer; import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterAll; @@ -7,10 +8,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Arrays; import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.TreeMap; public class PersistentTopicsTest { @@ -28,8 +27,8 @@ public static void setup() throws Exception { SERVER.start(); pulsarAdmin = PulsarAdmin.builder().port(SERVER.getWebPort()).build(); TenantInfo initialTenantInfo = (new TenantInfo.TenantInfoBuilder()) - .adminRoles(new HashSet<>(0)) - .allowedClusters(Set.of(CLUSTER_STANDALONE)).build(); + .adminRoles(new HashSet<>(0)) + .allowedClusters(new HashSet<>(Arrays.asList(CLUSTER_STANDALONE))).build(); pulsarAdmin.tenants().createTenant(tenant, initialTenantInfo); } @@ -44,29 +43,29 @@ public void partitionedTopicsTest() throws PulsarAdminException { String topic = RandomUtil.randomString(); pulsarAdmin.namespaces().createNamespace(tenant, namespace); pulsarAdmin.persistentTopics().createPartitionedTopic(tenant, namespace, topic, 2, false); - Assertions.assertEquals(List.of(String.format("persistent://%s/%s/%s", tenant, namespace, topic)), + Assertions.assertEquals(Arrays.asList(String.format("persistent://%s/%s/%s", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getPartitionedTopicList(tenant, namespace, false)); Assertions.assertEquals(2, pulsarAdmin.persistentTopics().getPartitionedMetadata(tenant, namespace, topic, false, false).getPartitions()); Assertions.assertEquals( - List.of(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), + Arrays.asList(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), String.format("persistent://%s/%s/%s-partition-1", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); pulsarAdmin.persistentTopics().updatePartitionedTopic(tenant, namespace, topic, false, false, false, 3); - Assertions.assertEquals(List.of(String.format("persistent://%s/%s/%s", tenant, namespace, topic)), + Assertions.assertEquals(Arrays.asList(String.format("persistent://%s/%s/%s", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getPartitionedTopicList(tenant, namespace, false)); Assertions.assertEquals(3, pulsarAdmin.persistentTopics().getPartitionedMetadata(tenant, namespace, topic, false, false).getPartitions()); Assertions.assertEquals( - List.of(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), + Arrays.asList(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), String.format("persistent://%s/%s/%s-partition-1", tenant, namespace, topic), String.format("persistent://%s/%s/%s-partition-2", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); pulsarAdmin.persistentTopics().deletePartitionedTopic(tenant, namespace, topic, false, false); - Assertions.assertEquals(List.of(), + Assertions.assertEquals(Arrays.asList(), pulsarAdmin.persistentTopics().getPartitionedTopicList(tenant, namespace, false)); Assertions.assertEquals( - List.of(), + Arrays.asList(), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); } @@ -78,11 +77,11 @@ public void nonPartitionedTopicsTest() throws PulsarAdminException { pulsarAdmin.namespaces().createNamespace(tenant, namespace); pulsarAdmin.persistentTopics().createNonPartitionedTopic(tenant, namespace, topic, false, null); Assertions.assertEquals( - List.of(String.format("persistent://%s/%s/%s", tenant, namespace, topic)), + Arrays.asList(String.format("persistent://%s/%s/%s", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); pulsarAdmin.persistentTopics().deleteTopic(tenant, namespace, topic, false, false); Assertions.assertEquals( - List.of(), + Arrays.asList(), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); } @@ -93,16 +92,16 @@ public void createMissedPartitionsTest() throws PulsarAdminException { pulsarAdmin.namespaces().createNamespace(tenant, namespace); pulsarAdmin.persistentTopics().createPartitionedTopic(tenant, namespace, topic, 2, false); Assertions.assertEquals( - List.of(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), + Arrays.asList(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), String.format("persistent://%s/%s/%s-partition-1", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); pulsarAdmin.persistentTopics().deleteTopic(tenant, namespace, topic + "-partition-1", false, false); Assertions.assertEquals( - List.of(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic)), + Arrays.asList(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); pulsarAdmin.persistentTopics().createMissedPartitions(tenant, namespace, topic); Assertions.assertEquals( - List.of(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), + Arrays.asList(String.format("persistent://%s/%s/%s-partition-0", tenant, namespace, topic), String.format("persistent://%s/%s/%s-partition-1", tenant, namespace, topic)), pulsarAdmin.persistentTopics().getList(tenant, namespace, null, false)); } @@ -140,21 +139,22 @@ public void backLogQuotaTest() throws PulsarAdminException { //wait for metadata refresh - Awaitility.await().until(() -> Map.of(BacklogQuotaType.destination_storage, backlogQuota1) - .equals(new TreeMap<>(pulsarAdmin.persistentTopics().getBacklogQuotaMap(tenant, namespace, topic, false, - false, false)))); - pulsarAdmin.persistentTopics().setBacklogQuota(tenant, namespace, topic, false, false, - BacklogQuotaType.message_age, backlogQuota2); + Awaitility.await().until(() -> ImmutableMap.of(BacklogQuotaType.destination_storage, backlogQuota1).equals( + new TreeMap<>( + pulsarAdmin.persistentTopics().getBacklogQuotaMap(tenant, namespace, topic, false, false, false)))); + pulsarAdmin.persistentTopics() + .setBacklogQuota(tenant, namespace, topic, false, false, BacklogQuotaType.message_age, + backlogQuota2); //wait for metadata refresh - Awaitility.await().until(() -> Map.of(BacklogQuotaType.message_age, backlogQuota2, - BacklogQuotaType.destination_storage, backlogQuota1) - .equals(new TreeMap<>(pulsarAdmin.persistentTopics().getBacklogQuotaMap(tenant, namespace, topic, false, - false, false)))); + Awaitility.await().until( + () -> ImmutableMap.of(BacklogQuotaType.message_age, backlogQuota2, BacklogQuotaType.destination_storage, + backlogQuota1).equals(new TreeMap<>( + pulsarAdmin.persistentTopics().getBacklogQuotaMap(tenant, namespace, topic, false, false, false)))); pulsarAdmin.persistentTopics().removeBacklogQuota(tenant, namespace, topic, BacklogQuotaType.destination_storage, false, false); - Assertions.assertEquals(Map.of(BacklogQuotaType.message_age, backlogQuota2), + Assertions.assertEquals(ImmutableMap.of(BacklogQuotaType.message_age, backlogQuota2), pulsarAdmin.persistentTopics().getBacklogQuotaMap(tenant, namespace, topic, false, false, false)); Assertions.assertEquals(0L, pulsarAdmin.persistentTopics().getBacklogSizeByMessageId(tenant, namespace, diff --git a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/RandomUtil.java b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/RandomUtil.java index e64f0df..6e631bc 100644 --- a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/RandomUtil.java +++ b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/RandomUtil.java @@ -19,16 +19,16 @@ public static long randomLong() { return random.nextLong(); } - public static long randomPositiveLong(){ - return random.nextLong(0, Long.MAX_VALUE); + public static long randomPositiveLong() { + return Math.abs(random.nextLong()); } - public static int randomPositiveInt(){ - return random.nextInt(0, Integer.MAX_VALUE); + public static int randomPositiveInt() { + return random.nextInt(Integer.MAX_VALUE); } - public static int randomNegativeInt(){ - return random.nextInt(Integer.MIN_VALUE, -1); + public static int randomNegativeInt() { + return -random.nextInt(Integer.MAX_VALUE); } } diff --git a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/TenantsTest.java b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/TenantsTest.java index 2a3affc..8f168aa 100644 --- a/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/TenantsTest.java +++ b/pulsar-admin/src/test/java/io/github/protocol/pulsar/admin/jdk/TenantsTest.java @@ -6,9 +6,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.util.Arrays; import java.util.HashSet; -import java.util.List; -import java.util.Set; public class TenantsTest { @@ -33,19 +32,19 @@ public static void teardown() throws Exception { public void tenantsTest() throws PulsarAdminException { String tenantName = RandomUtil.randomString(); TenantInfo initialTenantInfo = (new TenantInfo.TenantInfoBuilder()) - .adminRoles(new HashSet<>(0)) - .allowedClusters(Set.of(CLUSTER_STANDALONE)).build(); + .adminRoles(new HashSet<>(0)) + .allowedClusters(new HashSet<>(Arrays.asList(CLUSTER_STANDALONE))).build(); TenantInfo updatedTenantInfo = (new TenantInfo.TenantInfoBuilder()) - .adminRoles(Set.of("test")) - .allowedClusters(Set.of("global")) + .adminRoles(new HashSet<>(Arrays.asList("test"))) + .allowedClusters(new HashSet<>(Arrays.asList(("global")))) .build(); pulsarAdmin.tenants().createTenant(tenantName, initialTenantInfo); - Assertions.assertEquals(List.of(tenantName, "public", "pulsar"), pulsarAdmin.tenants().getTenants()); + Assertions.assertEquals(Arrays.asList(tenantName, "public", "pulsar"), pulsarAdmin.tenants().getTenants()); Assertions.assertEquals(initialTenantInfo, pulsarAdmin.tenants().getTenantAdmin(tenantName)); pulsarAdmin.tenants().updateTenant(tenantName, updatedTenantInfo); Assertions.assertEquals(updatedTenantInfo, pulsarAdmin.tenants().getTenantAdmin(tenantName)); pulsarAdmin.tenants().deleteTenant(tenantName, false); - Assertions.assertEquals(List.of("public", "pulsar"), pulsarAdmin.tenants().getTenants()); + Assertions.assertEquals(Arrays.asList("public", "pulsar"), pulsarAdmin.tenants().getTenants()); } } diff --git a/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewNamespace.java b/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewNamespace.java index a93e3b5..faf0c0d 100644 --- a/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewNamespace.java +++ b/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewNamespace.java @@ -1,4 +1,15 @@ package io.github.protocol.pulsar.spring; -public record NewNamespace(String tenant, String namespace) { +import lombok.Getter; + +@Getter +public class NewNamespace { + String tenant; + + String namespace; + + public NewNamespace(String tenant, String namespace) { + this.tenant = tenant; + this.namespace = namespace; + } } diff --git a/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewTenant.java b/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewTenant.java index 301fe33..087bd80 100644 --- a/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewTenant.java +++ b/spring/pulsar-spring/src/main/java/io/github/protocol/pulsar/spring/NewTenant.java @@ -1,4 +1,12 @@ package io.github.protocol.pulsar.spring; -public record NewTenant(String tenant) { +import lombok.Getter; + +@Getter +public class NewTenant { + String tenant; + + public NewTenant(String tenant) { + this.tenant = tenant; + } }