Search in sources :

Example 1 with CommandSuccess

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

the class ServerCnxTest method testSubscribeCommandWithAuthorizationPositive.

@Test(timeOut = 30000)
public void testSubscribeCommandWithAuthorizationPositive() throws Exception {
    AuthorizationManager authorizationManager = mock(AuthorizationManager.class);
    doReturn(CompletableFuture.completedFuture(true)).when(authorizationManager).canConsumeAsync(Mockito.any(), Mockito.any());
    doReturn(authorizationManager).when(brokerService).getAuthorizationManager();
    doReturn(true).when(brokerService).isAuthenticationEnabled();
    doReturn(true).when(brokerService).isAuthorizationEnabled();
    resetChannel();
    setChannelConnected();
    // 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);
    channel.finish();
}
Also used : CommandSuccess(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess) AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 2 with CommandSuccess

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

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(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) Matchers.anyObject(org.mockito.Matchers.anyObject) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 3 with CommandSuccess

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

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(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with CommandSuccess

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

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.getPersistentSubscription(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(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) CommandError(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 5 with CommandSuccess

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

CommandSuccess (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandSuccess)7 ByteBuf (io.netty.buffer.ByteBuf)7 Test (org.testng.annotations.Test)6 PersistentTopic (com.yahoo.pulsar.broker.service.persistent.PersistentTopic)3 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)2 CommandError (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandError)2 CommandProducerSuccess (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)1 RecyclableDuplicateByteBuf (io.netty.buffer.RecyclableDuplicateByteBuf)1 UnpooledHeapByteBuf (io.netty.buffer.UnpooledHeapByteBuf)1 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1