Search in sources :

Example 1 with TopicLookup

use of org.apache.pulsar.broker.lookup.TopicLookup in project incubator-pulsar by apache.

the class HttpTopicLookupv2Test method testNotEnoughLookupPermits.

@Test
public void testNotEnoughLookupPermits() throws Exception {
    BrokerService brokerService = pulsar.getBrokerService();
    doReturn(new Semaphore(0)).when(brokerService).getLookupRequestSemaphore();
    TopicLookup destLookup = spy(new TopicLookup());
    doReturn(false).when(destLookup).isRequestHttps();
    destLookup.setPulsar(pulsar);
    doReturn("null").when(destLookup).clientAppId();
    Field uriField = PulsarWebResource.class.getDeclaredField("uri");
    uriField.setAccessible(true);
    UriInfo uriInfo = mock(UriInfo.class);
    uriField.set(destLookup, uriInfo);
    URI uri = URI.create("http://localhost:8080/lookup/v2/destination/topic/myprop/usc/ns2/topic1");
    doReturn(uri).when(uriInfo).getRequestUri();
    doReturn(true).when(config).isAuthorizationEnabled();
    AsyncResponse asyncResponse1 = mock(AsyncResponse.class);
    destLookup.lookupTopicAsync(TopicDomain.persistent.value(), "myprop", "usc", "ns2", "topic1", false, asyncResponse1);
    ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse1).resume(arg.capture());
    assertEquals(arg.getValue().getClass(), WebApplicationException.class);
    WebApplicationException wae = (WebApplicationException) arg.getValue();
    assertEquals(wae.getResponse().getStatus(), Status.SERVICE_UNAVAILABLE.getStatusCode());
}
Also used : TopicLookup(org.apache.pulsar.broker.lookup.TopicLookup) Field(java.lang.reflect.Field) WebApplicationException(javax.ws.rs.WebApplicationException) Semaphore(java.util.concurrent.Semaphore) AsyncResponse(javax.ws.rs.container.AsyncResponse) BrokerService(org.apache.pulsar.broker.service.BrokerService) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 2 with TopicLookup

use of org.apache.pulsar.broker.lookup.TopicLookup in project incubator-pulsar by apache.

the class HttpTopicLookupv2Test method crossColoLookup.

@Test
public void crossColoLookup() throws Exception {
    TopicLookup destLookup = spy(new TopicLookup());
    doReturn(false).when(destLookup).isRequestHttps();
    destLookup.setPulsar(pulsar);
    doReturn("null").when(destLookup).clientAppId();
    Field uriField = PulsarWebResource.class.getDeclaredField("uri");
    uriField.setAccessible(true);
    UriInfo uriInfo = mock(UriInfo.class);
    uriField.set(destLookup, uriInfo);
    URI uri = URI.create("http://localhost:8080/lookup/v2/destination/topic/myprop/usc/ns2/topic1");
    doReturn(uri).when(uriInfo).getRequestUri();
    doReturn(true).when(config).isAuthorizationEnabled();
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    destLookup.lookupTopicAsync(TopicDomain.persistent.value(), "myprop", "usc", "ns2", "topic1", false, asyncResponse);
    ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse).resume(arg.capture());
    assertEquals(arg.getValue().getClass(), WebApplicationException.class);
    WebApplicationException wae = (WebApplicationException) arg.getValue();
    assertEquals(wae.getResponse().getStatus(), Status.TEMPORARY_REDIRECT.getStatusCode());
}
Also used : TopicLookup(org.apache.pulsar.broker.lookup.TopicLookup) Field(java.lang.reflect.Field) WebApplicationException(javax.ws.rs.WebApplicationException) AsyncResponse(javax.ws.rs.container.AsyncResponse) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 3 with TopicLookup

use of org.apache.pulsar.broker.lookup.TopicLookup in project incubator-pulsar by apache.

the class HttpTopicLookupv2Test method testValidateReplicationSettingsOnNamespace.

@Test
public void testValidateReplicationSettingsOnNamespace() throws Exception {
    final String property = "my-prop";
    final String cluster = "global";
    final String ns1 = "ns1";
    final String ns2 = "ns2";
    Policies policies1 = new Policies();
    doReturn(Optional.of(policies1)).when(policiesCache).get(AdminResource.path(POLICIES, property, cluster, ns1));
    Policies policies2 = new Policies();
    policies2.replication_clusters = Lists.newArrayList("invalid-localCluster");
    doReturn(Optional.of(policies2)).when(policiesCache).get(AdminResource.path(POLICIES, property, cluster, ns2));
    TopicLookup destLookup = spy(new TopicLookup());
    doReturn(false).when(destLookup).isRequestHttps();
    destLookup.setPulsar(pulsar);
    doReturn("null").when(destLookup).clientAppId();
    Field uriField = PulsarWebResource.class.getDeclaredField("uri");
    uriField.setAccessible(true);
    UriInfo uriInfo = mock(UriInfo.class);
    uriField.set(destLookup, uriInfo);
    doReturn(false).when(config).isAuthorizationEnabled();
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    destLookup.lookupTopicAsync(TopicDomain.persistent.value(), property, cluster, ns1, "empty-cluster", false, asyncResponse);
    ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse).resume(arg.capture());
    assertEquals(arg.getValue().getClass(), RestException.class);
    AsyncResponse asyncResponse2 = mock(AsyncResponse.class);
    destLookup.lookupTopicAsync(TopicDomain.persistent.value(), property, cluster, ns2, "invalid-localCluster", false, asyncResponse2);
    ArgumentCaptor<Throwable> arg2 = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse2).resume(arg2.capture());
    // Should have raised exception for invalid cluster
    assertEquals(arg2.getValue().getClass(), RestException.class);
}
Also used : TopicLookup(org.apache.pulsar.broker.lookup.TopicLookup) Field(java.lang.reflect.Field) Policies(org.apache.pulsar.common.policies.data.Policies) AsyncResponse(javax.ws.rs.container.AsyncResponse) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Aggregations

Field (java.lang.reflect.Field)3 AsyncResponse (javax.ws.rs.container.AsyncResponse)3 UriInfo (javax.ws.rs.core.UriInfo)3 TopicLookup (org.apache.pulsar.broker.lookup.TopicLookup)3 Test (org.testng.annotations.Test)3 URI (java.net.URI)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Semaphore (java.util.concurrent.Semaphore)1 BrokerService (org.apache.pulsar.broker.service.BrokerService)1 Policies (org.apache.pulsar.common.policies.data.Policies)1