Search in sources :

Example 1 with CommandProducerSuccess

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess in project incubator-pulsar by apache.

the class Commands method newProducerSuccess.

public static ByteBuf newProducerSuccess(long requestId, String producerName, long lastSequenceId, SchemaVersion schemaVersion) {
    CommandProducerSuccess.Builder producerSuccessBuilder = CommandProducerSuccess.newBuilder();
    producerSuccessBuilder.setRequestId(requestId);
    producerSuccessBuilder.setProducerName(producerName);
    producerSuccessBuilder.setLastSequenceId(lastSequenceId);
    producerSuccessBuilder.setSchemaVersion(ByteString.copyFrom(schemaVersion.bytes()));
    CommandProducerSuccess producerSuccess = producerSuccessBuilder.build();
    ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.PRODUCER_SUCCESS).setProducerSuccess(producerSuccess));
    producerSuccess.recycle();
    producerSuccessBuilder.recycle();
    return res;
}
Also used : CommandProducerSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with CommandProducerSuccess

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess 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);
}
Also used : PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) CommandProducerSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 3 with CommandProducerSuccess

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess in project incubator-pulsar by apache.

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", Collections.emptyMap());
    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 = ByteBufPair.coalesce(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(org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata) CommandProducerSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) CommandSendReceipt(org.apache.pulsar.common.api.proto.PulsarApi.CommandSendReceipt) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with CommandProducerSuccess

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess 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();
}
Also used : CommandProducerSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) ByteString(com.google.protobuf.ByteString) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 5 with CommandProducerSuccess

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess in project incubator-pulsar by apache.

the class ServerCnxTest method testSendFailureOnEncryptionRequiredTopic.

@Test(timeOut = 30000)
public void testSendFailureOnEncryptionRequiredTopic() throws Exception {
    resetChannel();
    setChannelConnected();
    // Set encryption_required to true
    ZooKeeperDataCache<Policies> zkDataCache = mock(ZooKeeperDataCache.class);
    Policies policies = mock(Policies.class);
    policies.encryption_required = true;
    policies.clusterDispatchRate = Maps.newHashMap();
    doReturn(Optional.of(policies)).when(zkDataCache).get(AdminResource.path(POLICIES, TopicName.get(encryptionRequiredTopicName).getNamespace()));
    doReturn(CompletableFuture.completedFuture(Optional.of(policies))).when(zkDataCache).getAsync(AdminResource.path(POLICIES, TopicName.get(encryptionRequiredTopicName).getNamespace()));
    doReturn(zkDataCache).when(configCacheService).policiesCache();
    ByteBuf clientCommand = Commands.newProducer(encryptionRequiredTopicName, 1, /* producer id */
    1, /* request id */
    "prod-name", true, null);
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandProducerSuccess);
    // test failure case: unencrypted messages cannot be published
    MessageMetadata messageMetadata = MessageMetadata.newBuilder().setPublishTime(System.currentTimeMillis()).setProducerName("prod-name").setSequenceId(0).build();
    ByteBuf data = Unpooled.buffer(1024);
    clientCommand = ByteBufPair.coalesce(Commands.newSend(1, 0, 1, ChecksumType.None, messageMetadata, data));
    channel.writeInbound(Unpooled.copiedBuffer(clientCommand));
    clientCommand.release();
    assertTrue(getResponse() instanceof CommandSendError);
    channel.finish();
}
Also used : MessageMetadata(org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata) Policies(org.apache.pulsar.common.policies.data.Policies) CommandProducerSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess) ByteBuf(io.netty.buffer.ByteBuf) CommandSendError(org.apache.pulsar.common.api.proto.PulsarApi.CommandSendError) Test(org.testng.annotations.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)8 CommandProducerSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)8 Test (org.testng.annotations.Test)7 CommandError (org.apache.pulsar.common.api.proto.PulsarApi.CommandError)3 MessageMetadata (org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata)3 Field (java.lang.reflect.Field)2 AuthorizationService (org.apache.pulsar.broker.authorization.AuthorizationService)2 PulsarAuthorizationProvider (org.apache.pulsar.broker.authorization.PulsarAuthorizationProvider)2 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)2 CommandSendReceipt (org.apache.pulsar.common.api.proto.PulsarApi.CommandSendReceipt)2 Policies (org.apache.pulsar.common.policies.data.Policies)2 ByteString (com.google.protobuf.ByteString)1 CommandSendError (org.apache.pulsar.common.api.proto.PulsarApi.CommandSendError)1 CommandSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess)1 TopicName (org.apache.pulsar.common.naming.TopicName)1 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)1