Search in sources :

Example 1 with CommandSuccess

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

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.getSubscription(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(org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) 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 2 with CommandSuccess

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

the class ServerCnxTest method testUnsupportedBatchMsgSubscribeCommand.

@Test(timeOut = 30000)
public void testUnsupportedBatchMsgSubscribeCommand() throws Exception {
    final String failSubName = "failSub";
    resetChannel();
    setChannelConnected();
    setConnectionVersion(ProtocolVersion.v3.getNumber());
    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, /* priority */
    "test");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandSuccess);
    PersistentTopic topicRef = (PersistentTopic) brokerService.getTopicReference(successTopicName);
    topicRef.markBatchMessagePublished();
    // test SUBSCRIBE on topic and cursor creation success
    clientCommand = Commands.newSubscribe(successTopicName, failSubName, 2, 2, SubType.Exclusive, 0, /* priority */
    "test");
    channel.writeInbound(clientCommand);
    Object response = getResponse();
    assertTrue(response instanceof CommandError);
    assertTrue(((CommandError) response).getError().equals(ServerError.UnsupportedVersionError));
    // Server will not close the connection
    assertTrue(channel.isOpen());
    channel.finish();
}
Also used : CommandSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) Matchers.anyObject(org.mockito.Matchers.anyObject) 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 3 with CommandSuccess

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

the class ServerCnxTest method testFlowCommand.

@Test(timeOut = 30000)
public void testFlowCommand() throws Exception {
    resetChannel();
    setChannelConnected();
    ByteBuf clientCommand = // 
    Commands.newSubscribe(// 
    successTopicName, // 
    successSubName, 1, /* consumer id */
    1, /* request id */
    SubType.Exclusive, 0, "test");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandSuccess);
    clientCommand = Commands.newFlow(1, /* consumer id */
    1);
    channel.writeInbound(clientCommand);
    // cursor is mocked
    // verify nothing is sent out on the wire after ack
    assertNull(channel.outboundMessages().peek());
    channel.finish();
}
Also used : CommandSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with CommandSuccess

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

the class Commands method newSuccess.

public static ByteBuf newSuccess(long requestId) {
    CommandSuccess.Builder successBuilder = CommandSuccess.newBuilder();
    successBuilder.setRequestId(requestId);
    CommandSuccess success = successBuilder.build();
    ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.SUCCESS).setSuccess(success));
    successBuilder.recycle();
    success.recycle();
    return res;
}
Also used : CommandSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with CommandSuccess

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

the class ServerCnxTest method testAckCommand.

@Test(timeOut = 30000)
public void testAckCommand() throws Exception {
    resetChannel();
    setChannelConnected();
    ByteBuf clientCommand = Commands.newSubscribe(successTopicName, successSubName, 1, /* consumer id */
    1, /*
                   * request id
                   */
    SubType.Exclusive, 0, "test");
    channel.writeInbound(clientCommand);
    assertTrue(getResponse() instanceof CommandSuccess);
    PositionImpl pos = new PositionImpl(0, 0);
    clientCommand = Commands.newAck(1, /* consumer id */
    pos.getLedgerId(), pos.getEntryId(), AckType.Individual, null, Collections.emptyMap());
    channel.writeInbound(clientCommand);
    // verify nothing is sent out on the wire after ack
    assertNull(channel.outboundMessages().peek());
    channel.finish();
}
Also used : CommandSuccess(org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)7 CommandSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess)7 Test (org.testng.annotations.Test)6 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)3 ByteString (com.google.protobuf.ByteString)2 AuthorizationService (org.apache.pulsar.broker.authorization.AuthorizationService)2 CommandError (org.apache.pulsar.common.api.proto.PulsarApi.CommandError)2 Field (java.lang.reflect.Field)1 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)1 PulsarAuthorizationProvider (org.apache.pulsar.broker.authorization.PulsarAuthorizationProvider)1 CommandProducerSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1