use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.
the class ServerCnxTest method testSubscribeCommandWithAuthorizationNegative.
@Test(timeOut = 30000)
public void testSubscribeCommandWithAuthorizationNegative() throws Exception {
AuthorizationManager authorizationManager = mock(AuthorizationManager.class);
doReturn(CompletableFuture.completedFuture(false)).when(authorizationManager).canConsumeAsync(Mockito.any(), Mockito.any());
doReturn(authorizationManager).when(brokerService).getAuthorizationManager();
doReturn(true).when(brokerService).isAuthenticationEnabled();
doReturn(true).when(brokerService).isAuthorizationEnabled();
resetChannel();
setChannelConnected();
// 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 CommandError);
channel.finish();
}
use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.
the class ServerCnxTest method testDuplicateConcurrentProducerCommand.
@Test(timeOut = 5000)
public void testDuplicateConcurrentProducerCommand() throws Exception {
resetChannel();
setChannelConnected();
CompletableFuture<Topic> delayFuture = new CompletableFuture<>();
doReturn(delayFuture).when(brokerService).getTopic(any(String.class));
// Create producer first time
ByteBuf clientCommand = Commands.newProducer(successTopicName, 1, /* producer id */
1, /* request id */
"prod-name");
channel.writeInbound(clientCommand);
// Create producer second time
clientCommand = Commands.newProducer(successTopicName, 1, /* producer id */
1, /* request id */
"prod-name");
channel.writeInbound(clientCommand);
Object response = getResponse();
assertTrue(response instanceof CommandError);
CommandError error = (CommandError) response;
assertEquals(error.getError(), ServerError.ServiceNotReady);
}
use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.
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;
}
Aggregations