Search in sources :

Example 1 with CommandConnected

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

the class ServerCnxTest method testKeepAliveNotEnforcedWithOlderClients.

@Test(timeOut = 30000)
public void testKeepAliveNotEnforcedWithOlderClients() throws Exception {
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "", ProtocolVersion.v0.getNumber());
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    CommandConnected response = (CommandConnected) getResponse();
    // Server is responding with same version as client
    assertEquals(response.getProtocolVersion(), ProtocolVersion.v0.getNumber());
    // Connection will *not* be closed in 2 seconds
    for (int i = 0; i < 3; i++) {
        channel.runPendingTasks();
        Thread.sleep(1000);
    }
    assertTrue(channel.isActive());
    channel.finish();
}
Also used : CommandConnected(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 2 with CommandConnected

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

the class ServerCnxTest method testConnectCommandWithAuthenticationPositive.

@Test(timeOut = 30000)
public void testConnectCommandWithAuthenticationPositive() throws Exception {
    AuthenticationService authenticationService = mock(AuthenticationService.class);
    doReturn(authenticationService).when(brokerService).getAuthenticationService();
    doReturn("appid1").when(authenticationService).authenticate(new AuthenticationDataCommand(Mockito.anyString()), Mockito.anyString());
    doReturn(true).when(brokerService).isAuthenticationEnabled();
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "");
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    assertTrue(getResponse() instanceof CommandConnected);
    channel.finish();
}
Also used : AuthenticationDataCommand(com.yahoo.pulsar.broker.authentication.AuthenticationDataCommand) CommandConnected(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) AuthenticationService(com.yahoo.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Example 3 with CommandConnected

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

the class ServerCnxTest method testConnectCommandWithProtocolVersion.

@Test(timeOut = 30000)
public void testConnectCommandWithProtocolVersion() throws Exception {
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "");
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    CommandConnected response = (CommandConnected) getResponse();
    assertEquals(response.getProtocolVersion(), currentProtocolVersion);
    channel.finish();
}
Also used : CommandConnected(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with CommandConnected

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

the class ServerCnxTest method testConnectCommand.

@Test(timeOut = 30000)
public void testConnectCommand() throws Exception {
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "");
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    assertTrue(getResponse() instanceof CommandConnected);
    channel.finish();
}
Also used : CommandConnected(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 5 with CommandConnected

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

the class ServerCnxTest method testConnectCommandWithEnum.

@Test(timeOut = 30000)
public void testConnectCommandWithEnum() throws Exception {
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect(AuthMethod.AuthMethodNone, "");
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    assertTrue(getResponse() instanceof CommandConnected);
    channel.finish();
}
Also used : CommandConnected(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Aggregations

CommandConnected (com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected)7 ByteBuf (io.netty.buffer.ByteBuf)7 Test (org.testng.annotations.Test)6 AuthenticationDataCommand (com.yahoo.pulsar.broker.authentication.AuthenticationDataCommand)1 AuthenticationService (com.yahoo.pulsar.broker.authentication.AuthenticationService)1 RecyclableDuplicateByteBuf (io.netty.buffer.RecyclableDuplicateByteBuf)1 UnpooledHeapByteBuf (io.netty.buffer.UnpooledHeapByteBuf)1