Skip to content

Commit

Permalink
[fix][broker] Ignore the exception of creating namespace (apache#18837)
Browse files Browse the repository at this point in the history
  • Loading branch information
nodece authored Dec 12, 2022
1 parent 1be5a69 commit bdbb118
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,11 @@ void createNameSpace(String cluster, String publicTenant, NamespaceName ns) thro
}

if (!nsr.namespaceExists(ns)) {
broker.getAdminClient().namespaces().createNamespace(ns.toString());
try {
broker.getAdminClient().namespaces().createNamespace(ns.toString());
} catch (Exception e) {
log.warn("Failed to create the default namespace {}: {}", ns, e.getMessage());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.commons.io.FileUtils.cleanDirectory;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand All @@ -33,6 +34,7 @@
import org.apache.bookkeeper.util.IOUtils;
import org.apache.pulsar.client.admin.Namespaces;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
Expand Down Expand Up @@ -61,7 +63,7 @@ public void testCreateNameSpace() throws Exception {
doNothing().when(tr).createTenant(eq(tenant), any());

NamespaceResources nsr = mock(NamespaceResources.class);
when(nsr.namespaceExists(ns)).thenReturn(false).thenReturn(true);
when(nsr.namespaceExists(ns)).thenReturn(false).thenReturn(true).thenReturn(false);
doNothing().when(nsr).createPolicies(eq(ns), any());

PulsarResources resources = mock(PulsarResources.class);
Expand Down Expand Up @@ -95,6 +97,9 @@ public void testCreateNameSpace() throws Exception {
verify(tr, times(1)).createTenant(eq(tenant), any());
verify(admin, times(1)).namespaces();
verify(admin.namespaces(), times(1)).createNamespace(eq(ns.toString()));

doThrow(new PulsarAdminException("No permission")).when(namespaces).createNamespace(any());
standalone.createNameSpace(cluster, tenant, ns);
}

@Test(groups = "broker")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
*/
package org.apache.pulsar.tests.integration.standalone;

import static org.testng.Assert.assertEquals;
import java.util.function.Supplier;
import lombok.Cleanup;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.tests.integration.suites.PulsarStandaloneTestSuite;
import org.testng.annotations.Test;

Expand All @@ -29,4 +34,13 @@ public void testPublishAndConsume(Supplier<String> serviceUrl, boolean isPersist
super.testPublishAndConsume(serviceUrl.get(), isPersistent);
}

@Test
public void testGetBundleRange() throws PulsarClientException, PulsarAdminException {
@Cleanup
PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(getHttpServiceUrl()).build();

String topic = "test-get-topic-bundle-range";
admin.topics().createNonPartitionedTopic(topic);
assertEquals(admin.lookups().getBundleRange(topic), "0xc0000000_0xffffffff");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@ protected void dumpFunctionLogs(String name) {
}
}

protected String getHttpServiceUrl() {
return container.getHttpServiceUrl();
}
}

0 comments on commit bdbb118

Please sign in to comment.