Skip to content

Commit

Permalink
Converted to v2 topic names test related to ProducerConsumerBase (apa…
Browse files Browse the repository at this point in the history
…che#1562)

* Converted to v2 topic names test related to ProducerConsumerBase

* Added comment around v2 lookup API marker

* Fixed proxy tests

* Fixed BatchMessageTest

* Fixed ProxyForwardAuthDataTest and ProxyRolesEnforcementTest
  • Loading branch information
merlimat authored Apr 13, 2018
1 parent 5d2c038 commit ac2721f
Show file tree
Hide file tree
Showing 57 changed files with 1,240 additions and 630 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void deleteNamespace(@PathParam("property") String property, @PathParam("
}

@DELETE
@Path("/{property}/{namespace}/bundle/{bundle}")
@Path("/{property}/{namespace}/{bundle}")
@ApiOperation(value = "Delete a namespace bundle and all the topics under it.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*/
package org.apache.pulsar.broker.lookup;

import static com.google.common.base.Preconditions.checkArgument;

import java.net.URI;

import org.apache.pulsar.broker.namespace.NamespaceEphemeralData;
import org.apache.pulsar.common.lookup.data.LookupData;

Expand Down Expand Up @@ -69,5 +65,5 @@ public LookupData getLookupData() {
public String toString() {
return "LookupResult [type=" + type + ", lookupData=" + lookupData + "]";
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.broker.lookup.v1;

import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.Encoded;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.MediaType;

import org.apache.pulsar.broker.lookup.TopicLookupBase;
import org.apache.pulsar.broker.web.NoSwaggerDocumentation;
import org.apache.pulsar.common.naming.TopicName;

/**
* The path for this handler is marked as "v2" even though it refers to Pulsar 1.x topic name format.
*
* The lookup API was already <code>/v2/</code> in Pulsar 1.x. This was internally versioned at Yahoo to not clash with
* an earlier API.
*
* Since we're adding now the "Pulsar v2" we cannot rename this topic lookup into <code>/v1</code>. Rather the
* difference here would be : <code>lookup/v2/destination/persistent/prop/cluster/ns/topic</code> vs
* <code>lookup/v2/topic/persistent/prop/ns/topic</code>.
*/
@Path("/v2/destination/")
@NoSwaggerDocumentation
public class TopicLookup extends TopicLookupBase {

@GET
@Path("{topic-domain}/{property}/{cluster}/{namespace}/{topic}")
@Produces(MediaType.APPLICATION_JSON)
public void lookupTopicAsync(@PathParam("topic-domain") String topicDomain, @PathParam("property") String property,
@PathParam("cluster") String cluster, @PathParam("namespace") String namespace,
@PathParam("topic") @Encoded String encodedTopic,
@QueryParam("authoritative") @DefaultValue("false") boolean authoritative,
@Suspended AsyncResponse asyncResponse) {
TopicName topicName = getTopicName(topicDomain, property, cluster, namespace, encodedTopic);
internalLookupTopicAsync(topicName, authoritative, asyncResponse);
}

@GET
@Path("{topic-domain}/{property}/{cluster}/{namespace}/{topic}/bundle")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 405, message = "Invalid topic domain type") })
public String getNamespaceBundle(@PathParam("topic-domain") String topicDomain,
@PathParam("property") String property, @PathParam("cluster") String cluster,
@PathParam("namespace") String namespace, @PathParam("topic") @Encoded String encodedTopic) {
TopicName topicName = getTopicName(topicDomain, property, cluster, namespace, encodedTopic);
return internalGetNamespaceBundle(topicName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.broker.lookup.v2;

import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.Encoded;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.MediaType;

import org.apache.pulsar.broker.lookup.TopicLookupBase;
import org.apache.pulsar.broker.web.NoSwaggerDocumentation;
import org.apache.pulsar.common.naming.TopicName;

@Path("/v2/topic")
@NoSwaggerDocumentation
public class TopicLookup extends TopicLookupBase {

@GET
@Path("{topic-domain}/{property}/{namespace}/{topic}")
@Produces(MediaType.APPLICATION_JSON)
public void lookupTopicAsync(@PathParam("topic-domain") String topicDomain, @PathParam("property") String property,
@PathParam("namespace") String namespace, @PathParam("topic") @Encoded String encodedTopic,
@QueryParam("authoritative") @DefaultValue("false") boolean authoritative,
@Suspended AsyncResponse asyncResponse) {
TopicName topicName = getTopicName(topicDomain, property, namespace, encodedTopic);
internalLookupTopicAsync(topicName, authoritative, asyncResponse);
}

@GET
@Path("{topic-domain}/{property}/{namespace}/{topic}/bundle")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 405, message = "Invalid topic domain type") })
public String getNamespaceBundle(@PathParam("topic-domain") String topicDomain,
@PathParam("property") String property, @PathParam("namespace") String namespace,
@PathParam("topic") @Encoded String encodedTopic) {
TopicName topicName = getTopicName(topicDomain, property, namespace, encodedTopic);
return internalGetNamespaceBundle(topicName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.pulsar.broker.admin.impl.PersistentTopicsBase.getPartitionedTopicMetadata;
import static org.apache.pulsar.broker.lookup.TopicLookup.lookupTopicAsync;
import static org.apache.pulsar.broker.lookup.v1.TopicLookup.lookupTopicAsync;
import static org.apache.pulsar.common.api.Commands.newLookupErrorResponse;
import static org.apache.pulsar.common.api.proto.PulsarApi.ProtocolVersion.v5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public static String getNamespaceFromPoliciesPath(String path) {
i.next();
i.next();
// prop, cluster, namespace
return Joiner.on("/").join(i.next(), i.next(), i.next());
return Joiner.on("/").join(i);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ public void testPersistentTopicExpireMessageOnParitionTopic() throws Exception {

/**
* This test-case verifies that broker should support both url/uri encoding for topic-name. It calls below api with
* url-encoded and also uri-encoded topic-name in http request: a. PartitionedMetadataLookup b. TopicLookup c. Topic
* url-encoded and also uri-encoded topic-name in http request: a. PartitionedMetadataLookup b. TopicLookupBase c. Topic
* Stats
*
* @param topicName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
import org.apache.pulsar.broker.admin.AdminResource;
import org.apache.pulsar.broker.authorization.AuthorizationService;
import org.apache.pulsar.broker.cache.ConfigurationCacheService;
import org.apache.pulsar.broker.lookup.TopicLookup;
import org.apache.pulsar.broker.lookup.NamespaceData;
import org.apache.pulsar.broker.lookup.RedirectData;
import org.apache.pulsar.broker.lookup.v1.TopicLookup;
import org.apache.pulsar.broker.namespace.NamespaceService;
import org.apache.pulsar.broker.service.BrokerService;
import org.apache.pulsar.broker.web.PulsarWebResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void cleanup() throws Exception {

@Test
public void testCreateNamespaceWithDefaultBundles() throws Exception {
String namespaceName = "prop/use/default-bundles";
String namespaceName = "prop/default-bundles";

admin.namespaces().createNamespace(namespaceName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import static org.testng.Assert.assertTrue;

import com.google.common.collect.Sets;

import org.apache.pulsar.broker.service.BrokerTestBase;
import org.apache.pulsar.client.api.Producer;
import org.testng.annotations.AfterMethod;
Expand All @@ -42,23 +44,25 @@ protected void cleanup() throws Exception {

@Test
public void testUnloadNotLoadedNamespace() throws Exception {
admin.namespaces().createNamespace("prop/use/ns-test-1");
admin.namespaces().createNamespace("prop/ns-test-1");
admin.namespaces().setNamespaceReplicationClusters("prop/ns-test-1", Sets.newHashSet("test"));

assertTrue(admin.namespaces().getNamespaces("prop", "use").contains("prop/use/ns-test-1"));
assertTrue(admin.namespaces().getNamespaces("prop").contains("prop/ns-test-1"));

admin.namespaces().unload("prop/use/ns-test-1");
admin.namespaces().unload("prop/ns-test-1");
}

@Test
public void testUnloadPartiallyLoadedNamespace() throws Exception {
admin.namespaces().createNamespace("prop/use/ns-test-2", 16);
admin.namespaces().createNamespace("prop/ns-test-2", 16);
admin.namespaces().setNamespaceReplicationClusters("prop/ns-test-2", Sets.newHashSet("test"));

Producer<byte[]> producer = pulsarClient.newProducer().topic("persistent://prop/use/ns-test-2/my-topic")
Producer<byte[]> producer = pulsarClient.newProducer().topic("persistent://prop/ns-test-2/my-topic")
.create();

assertTrue(admin.namespaces().getNamespaces("prop", "use").contains("prop/use/ns-test-2"));
assertTrue(admin.namespaces().getNamespaces("prop").contains("prop/ns-test-2"));

admin.namespaces().unload("prop/use/ns-test-2");
admin.namespaces().unload("prop/ns-test-2");

producer.close();
}
Expand Down
Loading

0 comments on commit ac2721f

Please sign in to comment.