Search in sources :

Example 6 with CommandConnected

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

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

Example 7 with CommandConnected

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

the class Commands method newConnected.

public static ByteBuf newConnected(CommandConnect cmdConnect) {
    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, cmdConnect.getProtocolVersion());
    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(com.yahoo.pulsar.common.api.proto.PulsarApi.CommandConnected) UnpooledHeapByteBuf(io.netty.buffer.UnpooledHeapByteBuf) RecyclableDuplicateByteBuf(io.netty.buffer.RecyclableDuplicateByteBuf) ByteBuf(io.netty.buffer.ByteBuf)

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