Search in sources :

Example 1 with CommandSendError

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

the class Commands method newSendError.

public static ByteBuf newSendError(long producerId, long sequenceId, ServerError error, String errorMsg) {
    CommandSendError.Builder sendErrorBuilder = CommandSendError.newBuilder();
    sendErrorBuilder.setProducerId(producerId);
    sendErrorBuilder.setSequenceId(sequenceId);
    sendErrorBuilder.setError(error);
    sendErrorBuilder.setMessage(errorMsg);
    CommandSendError sendError = sendErrorBuilder.build();
    ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.SEND_ERROR).setSendError(sendError));
    sendErrorBuilder.recycle();
    sendError.recycle();
    return res;
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CommandSendError(org.apache.pulsar.common.api.proto.PulsarApi.CommandSendError)

Example 2 with CommandSendError

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandSendError 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)2 CommandSendError (org.apache.pulsar.common.api.proto.PulsarApi.CommandSendError)2 CommandProducerSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)1 MessageMetadata (org.apache.pulsar.common.api.proto.PulsarApi.MessageMetadata)1 Policies (org.apache.pulsar.common.policies.data.Policies)1 Test (org.testng.annotations.Test)1