Search in sources :

Example 6 with CommandError

use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.

the class ServerCnxTest method testClusterAccess.

@Test(timeOut = 30000)
public void testClusterAccess() throws Exception {
    AuthorizationManager authorizationManager = spy(new AuthorizationManager(svcConfig, configCacheService));
    doReturn(authorizationManager).when(brokerService).getAuthorizationManager();
    doReturn(true).when(brokerService).isAuthorizationEnabled();
    doReturn(false).when(authorizationManager).isSuperUser(Mockito.anyString());
    doReturn(CompletableFuture.completedFuture(true)).when(authorizationManager).checkPermission(any(DestinationName.class), Mockito.anyString(), any(AuthAction.class));
    resetChannel();
    setChannelConnected();
    ByteBuf clientCommand = Commands.newProducer(successTopicName, 1, /* producer id */
    1, /* request id */
    "prod-name");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandProducerSuccess);
    resetChannel();
    setChannelConnected();
    clientCommand = Commands.newProducer(topicWithNonLocalCluster, 1, /* producer id */
    1, /* request id */
    "prod-name");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandError);
}
Also used : DestinationName(com.yahoo.pulsar.common.naming.DestinationName) CommandProducerSuccess(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) AuthAction(com.yahoo.pulsar.common.policies.data.AuthAction) Test(org.testng.annotations.Test)

Example 7 with CommandError

use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.

the class ServerCnxTest method testNonExistentTopic.

@SuppressWarnings("unchecked")
@Test(timeOut = 30000)
public void testNonExistentTopic() throws Exception {
    ZooKeeperDataCache<Policies> zkDataCache = mock(ZooKeeperDataCache.class);
    ConfigurationCacheService configCacheService = mock(ConfigurationCacheService.class);
    doReturn(configCacheService).when(pulsar).getConfigurationCache();
    doReturn(zkDataCache).when(configCacheService).policiesCache();
    doReturn(CompletableFuture.completedFuture(Optional.empty())).when(zkDataCache).getAsync(matches(".*nonexistent.*"));
    AuthorizationManager authorizationManager = spy(new AuthorizationManager(svcConfig, configCacheService));
    doReturn(authorizationManager).when(brokerService).getAuthorizationManager();
    doReturn(true).when(brokerService).isAuthorizationEnabled();
    doReturn(false).when(authorizationManager).isSuperUser(Mockito.anyString());
    // Test producer creation
    resetChannel();
    setChannelConnected();
    ByteBuf newProducerCmd = Commands.newProducer(nonExistentTopicName, 1, /* producer id */
    1, /* request id */
    "prod-name");
    channel.writeInbound(newProducerCmd);
    assertTrue(getResponse() instanceof CommandError);
    channel.finish();
    // Test consumer creation
    resetChannel();
    setChannelConnected();
    ByteBuf newSubscribeCmd = //
    Commands.newSubscribe(//
    nonExistentTopicName, successSubName, 1, /* consumer id */
    1, /* request id */
    SubType.Exclusive, 0, "test");
    channel.writeInbound(newSubscribeCmd);
    assertTrue(getResponse() instanceof CommandError);
}
Also used : Policies(com.yahoo.pulsar.common.policies.data.Policies) ConfigurationCacheService(com.yahoo.pulsar.broker.cache.ConfigurationCacheService) 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 8 with CommandError

use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.

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(DestinationName.class));
    // test PRODUCER failure case
    ByteBuf clientCommand = Commands.newProducer(nonOwnedTopicName, 1, /* producer id */
    1, /* request id */
    "prod-name");
    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 : DestinationName(com.yahoo.pulsar.common.naming.DestinationName) Matchers.anyObject(org.mockito.Matchers.anyObject) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 9 with CommandError

use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.

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);
    channel.writeInbound(clientCommand1);
    assertTrue(getResponse() instanceof CommandProducerSuccess);
    ByteBuf clientCommand2 = Commands.newProducer(successTopicName, 2, /* producer id */
    2, /* request id */
    producerName);
    channel.writeInbound(clientCommand2);
    assertTrue(getResponse() instanceof CommandError);
    channel.finish();
}
Also used : CommandProducerSuccess(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 10 with CommandError

use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError in project pulsar by yahoo.

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.getPersistentSubscription(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(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

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