Skip to content

Commit

Permalink
Verify HTTP service URL
Browse files Browse the repository at this point in the history
  • Loading branch information
BewareMyPower committed Oct 30, 2024
1 parent dc04cf1 commit 76032c9
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,20 @@ public void testTokenProducerAndConsumer() throws Exception {
log.info("-- Exiting {} test --", methodName);
}

@Test
public void testTopicNotFoundWithNoAuth() throws Exception {
@DataProvider
public static Object[][] useTcpServiceUrl() {
return new Object[][] {
{ true },
{ false }
};
}

@Test(dataProvider = "useTcpServiceUrl")
public void testTopicNotFoundWithWrongAuth(boolean useTcpServiceUrl) throws Exception {
final var token = generateToken("role");
final var operationTimeoutMs = 10000;
@Cleanup final var client = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl())
final var url = useTcpServiceUrl ? pulsar.getBrokerServiceUrl() : pulsar.getWebServiceAddress();
@Cleanup final var client = PulsarClient.builder().serviceUrl(url)
.operationTimeout(operationTimeoutMs, TimeUnit.MILLISECONDS)
.authentication(AuthenticationFactory.token(token)).build();
final var topic = "my-property/not-exist/tp"; // the namespace does not exist
Expand All @@ -192,7 +201,11 @@ public void testTopicNotFoundWithNoAuth() throws Exception {
final var elapsedMs = System.currentTimeMillis() - start;
log.info("Failed to create producer after {} ms: {} {}", elapsedMs, e.getClass().getName(), e.getMessage());
Assert.assertTrue(elapsedMs < operationTimeoutMs);
Assert.assertTrue(e instanceof PulsarClientException.TopicDoesNotExistException);
if (useTcpServiceUrl) {
Assert.assertTrue(e instanceof PulsarClientException.TopicDoesNotExistException);
} else {
Assert.assertTrue(e instanceof PulsarClientException.NotFoundException);
}
}
start = System.currentTimeMillis();
try {
Expand All @@ -201,7 +214,11 @@ public void testTopicNotFoundWithNoAuth() throws Exception {
final var elapsedMs = System.currentTimeMillis() - start;
log.info("Failed to subscribe after {} ms: {} {}", elapsedMs, e.getClass().getName(), e.getMessage());
Assert.assertTrue(elapsedMs < operationTimeoutMs);
Assert.assertTrue(e instanceof PulsarClientException.TopicDoesNotExistException);
if (useTcpServiceUrl) {
Assert.assertTrue(e instanceof PulsarClientException.TopicDoesNotExistException);
} else {
Assert.assertTrue(e instanceof PulsarClientException.NotFoundException);
}
}
}
}

0 comments on commit 76032c9

Please sign in to comment.