Search in sources :

Example 6 with CommandConnected

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

the class Commands method newConnected.

public static ByteBuf newConnected(int clientProtocolVersion) {
    CommandConnected.Builder connectedBuilder = CommandConnected.newBuilder();
    connectedBuilder.setServerVersion("Pulsar Server");
    // 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);
    connectedBuilder.setProtocolVersion(versionToAdvertise);
    CommandConnected connected = connectedBuilder.build();
    ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.CONNECTED).setConnected(connected));
    connected.recycle();
    connectedBuilder.recycle();
    return res;
}
Also used : CommandConnected(org.apache.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf)

Example 7 with CommandConnected

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandConnected in project incubator-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.getNumber(), 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.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(org.apache.pulsar.common.api.proto.PulsarApi.CommandConnected) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Aggregations

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