Search in sources :

Example 1 with CommandSendReceipt

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

the class Commands method newSendReceipt.

public static ByteBuf newSendReceipt(long producerId, long sequenceId, long ledgerId, long entryId) {
    CommandSendReceipt.Builder sendReceiptBuilder = CommandSendReceipt.newBuilder();
    sendReceiptBuilder.setProducerId(producerId);
    sendReceiptBuilder.setSequenceId(sequenceId);
    MessageIdData.Builder messageIdBuilder = MessageIdData.newBuilder();
    messageIdBuilder.setLedgerId(ledgerId);
    messageIdBuilder.setEntryId(entryId);
    MessageIdData messageId = messageIdBuilder.build();
    sendReceiptBuilder.setMessageId(messageId);
    CommandSendReceipt sendReceipt = sendReceiptBuilder.build();
    ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.SEND_RECEIPT).setSendReceipt(sendReceipt));
    messageIdBuilder.recycle();
    messageId.recycle();
    sendReceiptBuilder.recycle();
    sendReceipt.recycle();
    return res;
}
Also used : MessageIdData(org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData) CommandSendReceipt(org.apache.pulsar.common.api.proto.PulsarApi.CommandSendReceipt) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with CommandSendReceipt

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandSendReceipt 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 3 with CommandSendReceipt

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

the class ServerCnxTest method testSendSuccessOnEncryptionRequiredTopic.

@Test(timeOut = 30000)
public void testSendSuccessOnEncryptionRequiredTopic() 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 success case: encrypted messages can be published
    MessageMetadata messageMetadata = MessageMetadata.newBuilder().setPublishTime(System.currentTimeMillis()).setProducerName("prod-name").setSequenceId(0).addEncryptionKeys(EncryptionKeys.newBuilder().setKey("testKey").setValue(ByteString.copyFrom("testVal".getBytes()))).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) Policies(org.apache.pulsar.common.policies.data.Policies) 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)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)3 CommandSendReceipt (org.apache.pulsar.common.api.proto.PulsarApi.CommandSendReceipt)3 CommandProducerSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)2 MessageMetadata (org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata)2 Test (org.testng.annotations.Test)2 MessageIdData (org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData)1 Policies (org.apache.pulsar.common.policies.data.Policies)1