Search in sources :

Example 1 with CommandConnected

use of org.apache.pulsar.common.api.proto.CommandConnected in project pulsar by apache.

the class ServerCnxTest method testKeepAlive.

@Test(timeOut = 30000)
public void testKeepAlive() throws Exception {
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "", null);
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    CommandConnected response = (CommandConnected) getResponse();
    assertEquals(response.getProtocolVersion(), currentProtocolVersion);
    // Connection will be closed in 2 seconds, in the meantime give chance to run the cleanup logic
    for (int i = 0; i < 3; i++) {
        channel.runPendingTasks();
        Thread.sleep(1000);
    }
    assertFalse(channel.isActive());
    channel.finish();
}
Also used : CommandConnected(org.apache.pulsar.common.api.proto.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 2 with CommandConnected

use of org.apache.pulsar.common.api.proto.CommandConnected in project pulsar by apache.

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", "", null);
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    CommandConnected response = (CommandConnected) getResponse();
    assertEquals(response.getProtocolVersion(), currentProtocolVersion);
    channel.finish();
}
Also used : CommandConnected(org.apache.pulsar.common.api.proto.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 3 with CommandConnected

use of org.apache.pulsar.common.api.proto.CommandConnected in project pulsar by apache.

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.getValue(), null, null, null, null, null);
    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.getValue());
    // 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(org.apache.pulsar.common.api.proto.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with CommandConnected

use of org.apache.pulsar.common.api.proto.CommandConnected in project pulsar by apache.

the class ServerCnxTest method testConnectCommandWithAuthenticationPositive.

@Test(timeOut = 30000)
public void testConnectCommandWithAuthenticationPositive() throws Exception {
    AuthenticationService authenticationService = mock(AuthenticationService.class);
    AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
    AuthenticationState authenticationState = mock(AuthenticationState.class);
    AuthenticationDataSource authenticationDataSource = mock(AuthenticationDataSource.class);
    AuthData authData = AuthData.of(null);
    doReturn(authenticationService).when(brokerService).getAuthenticationService();
    doReturn(authenticationProvider).when(authenticationService).getAuthenticationProvider(Mockito.anyString());
    doReturn(authenticationState).when(authenticationProvider).newAuthState(Mockito.any(), Mockito.any(), Mockito.any());
    doReturn(authData).when(authenticationState).authenticate(authData);
    doReturn(true).when(authenticationState).isComplete();
    doReturn("appid1").when(authenticationState).getAuthRole();
    doReturn(true).when(brokerService).isAuthenticationEnabled();
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "", null);
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Connected);
    assertTrue(getResponse() instanceof CommandConnected);
    channel.finish();
}
Also used : AuthData(org.apache.pulsar.common.api.AuthData) CommandConnected(org.apache.pulsar.common.api.proto.CommandConnected) AuthenticationProvider(org.apache.pulsar.broker.authentication.AuthenticationProvider) AuthenticationDataSource(org.apache.pulsar.broker.authentication.AuthenticationDataSource) ByteBuf(io.netty.buffer.ByteBuf) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService) AuthenticationState(org.apache.pulsar.broker.authentication.AuthenticationState) Test(org.testng.annotations.Test)

Example 5 with CommandConnected

use of org.apache.pulsar.common.api.proto.CommandConnected in project pulsar by yahoo.

the class Commands method newConnectedCommand.

public static BaseCommand newConnectedCommand(int clientProtocolVersion, int maxMessageSize) {
    BaseCommand cmd = localCmd(Type.CONNECTED);
    CommandConnected connected = cmd.setConnected().setServerVersion("Pulsar Server" + PulsarVersion.getVersion());
    if (INVALID_MAX_MESSAGE_SIZE != maxMessageSize) {
        connected.setMaxMessageSize(maxMessageSize);
    }
    // If the broker supports a newer version of the protocol, it will anyway advertise the max version that the
    // client supports, to avoid confusing the client.
    int currentProtocolVersion = getCurrentProtocolVersion();
    int versionToAdvertise = Math.min(currentProtocolVersion, clientProtocolVersion);
    connected.setProtocolVersion(versionToAdvertise);
    return cmd;
}
Also used : BaseCommand(org.apache.pulsar.common.api.proto.BaseCommand) CommandConnected(org.apache.pulsar.common.api.proto.CommandConnected)

Aggregations

CommandConnected (org.apache.pulsar.common.api.proto.CommandConnected)23 ByteBuf (io.netty.buffer.ByteBuf)18 Test (org.testng.annotations.Test)18 AuthenticationDataSource (org.apache.pulsar.broker.authentication.AuthenticationDataSource)3 AuthenticationProvider (org.apache.pulsar.broker.authentication.AuthenticationProvider)3 AuthenticationService (org.apache.pulsar.broker.authentication.AuthenticationService)3 AuthenticationState (org.apache.pulsar.broker.authentication.AuthenticationState)3 AuthData (org.apache.pulsar.common.api.AuthData)3 BaseCommand (org.apache.pulsar.common.api.proto.BaseCommand)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2