Search in sources :

Example 1 with CommandError

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandError in project incubator-pulsar by apache.

the class Commands method newError.

public static ByteBuf newError(long requestId, ServerError error, String message) {
    CommandError.Builder cmdErrorBuilder = CommandError.newBuilder();
    cmdErrorBuilder.setRequestId(requestId);
    cmdErrorBuilder.setError(error);
    cmdErrorBuilder.setMessage(message);
    CommandError cmdError = cmdErrorBuilder.build();
    ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.ERROR).setError(cmdError));
    cmdError.recycle();
    cmdErrorBuilder.recycle();
    return res;
}
Also used : CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with CommandError

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandError in project incubator-pulsar by apache.

the class ServerCnxTest method testProducerCommand.

@Test(timeOut = 30000)
public void testProducerCommand() throws Exception {
    resetChannel();
    setChannelConnected();
    // test PRODUCER success case
    ByteBuf clientCommand = Commands.newProducer(successTopicName, 1, /* producer id */
    1, /* request id */
    "prod-name", Collections.emptyMap());
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandProducerSuccess);
    PersistentTopic topicRef = (PersistentTopic) brokerService.getTopicReference(successTopicName);
    assertNotNull(topicRef);
    assertEquals(topicRef.getProducers().size(), 1);
    // test PRODUCER error case
    clientCommand = Commands.newProducer(failTopicName, 2, 2, "prod-name-2", Collections.emptyMap());
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandError);
    assertNull(brokerService.getTopicReference(failTopicName));
    channel.finish();
    assertEquals(topicRef.getProducers().size(), 0);
}
Also used : PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) CommandProducerSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 3 with CommandError

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandError in project incubator-pulsar by apache.

the class ServerCnxTest method testSubscribeCommand.

@Test(timeOut = 30000)
public void testSubscribeCommand() throws Exception {
    final String failSubName = "failSub";
    resetChannel();
    setChannelConnected();
    doReturn(false).when(brokerService).isAuthenticationEnabled();
    doReturn(false).when(brokerService).isAuthorizationEnabled();
    // test SUBSCRIBE on topic and cursor creation success
    ByteBuf clientCommand = // 
    Commands.newSubscribe(// 
    successTopicName, successSubName, 1, /* consumer id */
    1, /* request id */
    SubType.Exclusive, 0, "test");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandSuccess);
    PersistentTopic topicRef = (PersistentTopic) brokerService.getTopicReference(successTopicName);
    assertNotNull(topicRef);
    assertTrue(topicRef.getSubscriptions().containsKey(successSubName));
    assertTrue(topicRef.getSubscription(successSubName).getDispatcher().isConsumerConnected());
    // test SUBSCRIBE on topic creation success and cursor failure
    clientCommand = Commands.newSubscribe(successTopicName, failSubName, 2, 2, SubType.Exclusive, 0, "test");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandError);
    // test SUBSCRIBE on topic creation failure
    clientCommand = Commands.newSubscribe(failTopicName, successSubName, 3, 3, SubType.Exclusive, 0, "test");
    channel.writeInbound(clientCommand);
    assertEquals(getResponse().getClass(), CommandError.class);
    // Server will not close the connection
    assertTrue(channel.isOpen());
    channel.finish();
}
Also used : CommandSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) ByteString(com.google.protobuf.ByteString) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with CommandError

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandError in project incubator-pulsar by apache.

the class ServerCnxTest method testProducerOnNotOwnedTopic.

@Test(timeOut = 30000)
public void testProducerOnNotOwnedTopic() throws Exception {
    resetChannel();
    setChannelConnected();
    // Force the case where the broker doesn't own any topic
    doReturn(false).when(namespaceService).isServiceUnitActive(any(TopicName.class));
    // test PRODUCER failure case
    ByteBuf clientCommand = Commands.newProducer(nonOwnedTopicName, 1, /* producer id */
    1, /* request id */
    "prod-name", Collections.emptyMap());
    channel.writeInbound(clientCommand);
    Object response = getResponse();
    assertEquals(response.getClass(), CommandError.class);
    CommandError errorResponse = (CommandError) response;
    assertEquals(errorResponse.getError(), ServerError.ServiceNotReady);
    assertNull(brokerService.getTopicReference(nonOwnedTopicName));
    channel.finish();
}
Also used : Matchers.anyObject(org.mockito.Matchers.anyObject) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test)

Example 5 with CommandError

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandError in project incubator-pulsar by apache.

the class ServerCnxTest method testUseSameProducerName.

@Test(timeOut = 30000)
public void testUseSameProducerName() throws Exception {
    resetChannel();
    setChannelConnected();
    String producerName = "my-producer";
    ByteBuf clientCommand1 = Commands.newProducer(successTopicName, 1, /* producer id */
    1, /* request id */
    producerName, Collections.emptyMap());
    channel.writeInbound(clientCommand1);
    assertTrue(getResponse() instanceof CommandProducerSuccess);
    ByteBuf clientCommand2 = Commands.newProducer(successTopicName, 2, /* producer id */
    2, /* request id */
    producerName, Collections.emptyMap());
    channel.writeInbound(clientCommand2);
    assertTrue(getResponse() instanceof CommandError);
    channel.finish();
}
Also used : CommandProducerSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) ByteString(com.google.protobuf.ByteString) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Aggregations

CommandError (org.apache.pulsar.common.api.proto.PulsarApi.CommandError)16 ByteBuf (io.netty.buffer.ByteBuf)15 Test (org.testng.annotations.Test)14 ByteString (com.google.protobuf.ByteString)7 Matchers.anyObject (org.mockito.Matchers.anyObject)7 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)6 AuthorizationService (org.apache.pulsar.broker.authorization.AuthorizationService)4 CommandProducerSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)3 Field (java.lang.reflect.Field)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 PulsarAuthorizationProvider (org.apache.pulsar.broker.authorization.PulsarAuthorizationProvider)2 CommandSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess)2 TopicName (org.apache.pulsar.common.naming.TopicName)2 Policies (org.apache.pulsar.common.policies.data.Policies)2 AuthenticationException (javax.naming.AuthenticationException)1 AuthenticationDataCommand (org.apache.pulsar.broker.authentication.AuthenticationDataCommand)1 AuthenticationService (org.apache.pulsar.broker.authentication.AuthenticationService)1 ConfigurationCacheService (org.apache.pulsar.broker.cache.ConfigurationCacheService)1 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)1