private void initializeKeepAliveTimeout(Channel channel, MqttConnectMessage msg, String clientId) { int keepAlive = msg.variableHeader().keepAliveTimeSeconds(); NettyUtils.keepAlive(channel, keepAlive); NettyUtils.cleanSession(channel, msg.variableHeader().isCleanSession()); NettyUtils.clientID(channel, clientId); int idleTime = Math.round(keepAlive * 1.5f); setIdleTime(channel.pipeline(), idleTime); LOG.debug("Connection has been configured CId={}, keepAlive={}, removeTemporaryQoS2={}, idleTime={}", clientId, keepAlive, msg.variableHeader().isCleanSession(), idleTime); }
@Test public void testConnAckContainsSessionPresentFlag() { MqttConnectMessage msg = connMsg.clientId(FAKE_CLIENT_ID) .protocolVersion(MqttVersion.MQTT_3_1_1) .build(); NettyUtils.clientID(channel, FAKE_CLIENT_ID); NettyUtils.cleanSession(channel, false); // Connect a first time sut.bindToSession(connection, msg, FAKE_CLIENT_ID); // disconnect sut.disconnect(FAKE_CLIENT_ID); // Exercise, reconnect EmbeddedChannel anotherChannel = new EmbeddedChannel(); MQTTConnection anotherConnection = createMQTTConnection(ALLOW_ANONYMOUS_AND_ZEROBYTE_CLIENT_ID, anotherChannel); sut.bindToSession(anotherConnection, msg, FAKE_CLIENT_ID); // Verify assertEqualsConnAck(CONNECTION_ACCEPTED, anotherChannel.readOutbound()); assertTrue("Connection is accepted and therefore should remain open", anotherChannel.isOpen()); }