Search in sources :

Example 11 with CommandError

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();
}
Also used : AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 12 with CommandError

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Matchers.anyObject(org.mockito.Matchers.anyObject) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 13 with CommandError

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;
}
Also used : CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) UnpooledHeapByteBuf(io.netty.buffer.UnpooledHeapByteBuf) RecyclableDuplicateByteBuf(io.netty.buffer.RecyclableDuplicateByteBuf) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

CommandError (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError)13 ByteBuf (io.netty.buffer.ByteBuf)13 Test (org.testng.annotations.Test)11 PersistentTopic (com.yahoo.pulsar.broker.service.persistent.PersistentTopic)5 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)4 Matchers.anyObject (org.mockito.Matchers.anyObject)4 CommandProducerSuccess (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)3 CommandSuccess (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess)2 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AuthenticationDataCommand (com.yahoo.pulsar.broker.authentication.AuthenticationDataCommand)1 AuthenticationService (com.yahoo.pulsar.broker.authentication.AuthenticationService)1 ConfigurationCacheService (com.yahoo.pulsar.broker.cache.ConfigurationCacheService)1 AuthAction (com.yahoo.pulsar.common.policies.data.AuthAction)1 Policies (com.yahoo.pulsar.common.policies.data.Policies)1 RecyclableDuplicateByteBuf (io.netty.buffer.RecyclableDuplicateByteBuf)1 UnpooledHeapByteBuf (io.netty.buffer.UnpooledHeapByteBuf)1 AuthenticationException (javax.naming.AuthenticationException)1