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();
}
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;
}
Aggregations