-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses the expiry interval from connect properties (#764)
- Retrieve the session expiry interval from Connect property SESSION_EXPIRY_INTERVAL - Added unit test to verify that CONNECT's SESSION_EXPIRY_INTERVAL property is used to set session expiration timeout in seconds - Fallback to global expiry if one is not provided (if session is not clean) - cap the SESSION_EXPIRY_INTERVAL that client can configure with the setting 'persistent_client_expiration'
- Loading branch information
Showing
4 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
broker/src/test/java/io/moquette/broker/SessionRegistryMQTT5Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.moquette.broker; | ||
import io.netty.handler.codec.mqtt.MqttConnectMessage; | ||
import io.netty.handler.codec.mqtt.MqttMessageBuilders; | ||
import io.netty.handler.codec.mqtt.MqttProperties; | ||
import io.netty.handler.codec.mqtt.MqttVersion; | ||
import org.awaitility.Awaitility; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
public class SessionRegistryMQTT5Test extends SessionRegistryTest { | ||
private static final Logger LOG = LoggerFactory.getLogger(SessionRegistryMQTT5Test.class); | ||
@Test | ||
public void givenSessionWithConnectionExpireTimeWhenAfterExpirationIsPassedThenSessionIsRemoved() { | ||
LOG.info("givenSessionWithExpireTimeWhenAfterExpirationIsPassedThenSessionIsRemoved"); | ||
// insert a not clean session that should expire in connect selected expiry time | ||
final String clientId = "client_to_be_removed"; | ||
final MqttProperties connectProperties = new MqttProperties(); | ||
int customExpirySeconds = 60; | ||
connectProperties.add(new MqttProperties.IntegerProperty(MqttProperties.MqttPropertyType.SESSION_EXPIRY_INTERVAL.value(), customExpirySeconds)); | ||
final MqttConnectMessage connectMessage = MqttMessageBuilders.connect() | ||
.protocolVersion(MqttVersion.MQTT_5) | ||
.cleanSession(false) | ||
.properties(connectProperties) | ||
.build(); | ||
final SessionRegistry.SessionCreationResult res = sut.createOrReopenSession(connectMessage, clientId, "User"); | ||
assertEquals(SessionRegistry.CreationModeEnum.CREATED_CLEAN_NEW, res.mode, "Not clean session must be created"); | ||
// remove it, so that it's tracked in the inner delay queue | ||
sut.connectionClosed(res.session); | ||
assertEquals(1, sessionRepository.list().size(), "Not clean session must be persisted"); | ||
// move time forward | ||
Duration moreThenSessionExpiration = Duration.ofSeconds(customExpirySeconds).plusSeconds(10); | ||
slidingClock.forward(moreThenSessionExpiration); | ||
// check the session has been removed | ||
Awaitility | ||
.await() | ||
.atMost(3 * SessionRegistry.EXPIRED_SESSION_CLEANER_TASK_INTERVAL.toMillis(), TimeUnit.MILLISECONDS) | ||
.until(sessionsList(), Matchers.empty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters