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;
}
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);
}
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();
}
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();
}
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();
}
Aggregations