Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made sessionPresent flag settable in ModifiableConnackPacket. #479

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class ModifiableConnackPacketImpl implements ModifiableConnackPacket {

private @NotNull ConnackReasonCode reasonCode;
private final boolean sessionPresent;
private boolean sessionPresent;
private final long sessionExpiryInterval;
private final int serverKeepAlive;
private @Nullable String assignedClientId;
Expand Down Expand Up @@ -158,6 +158,16 @@ public void setAssignedClientIdentifier(final @Nullable String assignedClientIde
modified = true;
}

@Override
public void setSessionPresent(final boolean sessionPresent) {
if (Objects.equals(this.sessionPresent, sessionPresent)) {
return;
}

this.sessionPresent = sessionPresent;
modified = true;
}

@Override
public @NotNull Optional<String> getAuthenticationMethod() {
return Optional.ofNullable(authenticationMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,36 @@ public void copy_changes() {
UserPropertiesImpl.of(ImmutableList.of(new MqttUserProperty("testName", "testValue"))));
assertEquals(expectedPacket, copy);
}

@Test
public void setSessionPresent() {
final ConnackPacketImpl packet = new ConnackPacketImpl(ConnackReasonCode.UNSPECIFIED_ERROR,
true,
10,
60,
null,
null,
null,
3,
1000,
10,
Qos.AT_LEAST_ONCE,
true,
true,
true,
true,
null,
null,
null,
UserPropertiesImpl.of(ImmutableList.of()));
final ModifiableConnackPacketImpl modifiablePacket =
new ModifiableConnackPacketImpl(packet, configurationService, true);

assertFalse(modifiablePacket.isModified());

modifiablePacket.setSessionPresent(false);

assertTrue(modifiablePacket.isModified());
assertFalse(modifiablePacket.getSessionPresent());
}
}
Loading