Search in sources :

Example 1 with CommandProducerSuccess

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

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");
    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");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandError);
    assertNull(brokerService.getTopicReference(failTopicName));
    channel.finish();
    assertEquals(topicRef.getProducers().size(), 0);
}
Also used : PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) 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 2 with CommandProducerSuccess

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

the class ServerCnxTest method testSendCommand.

@Test(timeOut = 30000)
public void testSendCommand() throws Exception {
    resetChannel();
    setChannelConnected();
    ByteBuf clientCommand = Commands.newProducer(successTopicName, 1, /* producer id */
    1, /* request id */
    "prod-name");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandProducerSuccess);
    // test SEND success
    MessageMetadata messageMetadata = MessageMetadata.newBuilder().setPublishTime(System.currentTimeMillis()).setProducerName("prod-name").setSequenceId(0).build();
    ByteBuf data = Unpooled.buffer(1024);
    clientCommand = Commands.newSend(1, 0, 1, ChecksumType.None, messageMetadata, data);
    channel.writeInbound(Unpooled.copiedBuffer(clientCommand));
    clientCommand.release();
    assertTrue(getResponse() instanceof CommandSendReceipt);
    channel.finish();
}
Also used : MessageMetadata(com.yahoo.pulsar.common.api.proto.PulsarApi.MessageMetadata) CommandProducerSuccess(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) CommandSendReceipt(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSendReceipt) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 3 with CommandProducerSuccess

use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess 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 4 with CommandProducerSuccess

use of com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess 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 5 with CommandProducerSuccess

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

the class ServerCnxTest method testNonExistentTopicSuperUserAccess.

@Test(timeOut = 30000)
public void testNonExistentTopicSuperUserAccess() throws Exception {
    AuthorizationManager authorizationManager = spy(new AuthorizationManager(svcConfig, configCacheService));
    doReturn(authorizationManager).when(brokerService).getAuthorizationManager();
    doReturn(true).when(brokerService).isAuthorizationEnabled();
    doReturn(true).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 CommandProducerSuccess);
    PersistentTopic topicRef = (PersistentTopic) brokerService.getTopicReference(nonExistentTopicName);
    assertNotNull(topicRef);
    assertEquals(topicRef.getProducers().size(), 1);
    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);
    topicRef = (PersistentTopic) brokerService.getTopicReference(nonExistentTopicName);
    assertNotNull(topicRef);
    assertTrue(topicRef.getSubscriptions().containsKey(successSubName));
    assertTrue(topicRef.getPersistentSubscription(successSubName).getDispatcher().isConsumerConnected());
    assertTrue(getResponse() instanceof CommandSuccess);
}
Also used : CommandSuccess(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) CommandProducerSuccess(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Aggregations

CommandProducerSuccess (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)6 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.testng.annotations.Test)5 CommandError (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError)3 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)2 PersistentTopic (com.yahoo.pulsar.broker.service.persistent.PersistentTopic)2 CommandSendReceipt (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSendReceipt)1 CommandSuccess (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess)1 MessageMetadata (com.yahoo.pulsar.common.api.proto.PulsarApi.MessageMetadata)1 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)1 AuthAction (com.yahoo.pulsar.common.policies.data.AuthAction)1 RecyclableDuplicateByteBuf (io.netty.buffer.RecyclableDuplicateByteBuf)1 UnpooledHeapByteBuf (io.netty.buffer.UnpooledHeapByteBuf)1