Skip to content

Commit

Permalink
Made sessionPresent flag settable in ModifiableConnackPacket. (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian-Limpoeck authored Apr 24, 2024
1 parent 9dd10fe commit d4dc1b7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: |
git clone https://github.com/hivemq/hivemq-extension-sdk.git ../hivemq-extension-sdk
cd ../hivemq-extension-sdk
git checkout ${GITHUB_REF##*/} || true
git checkout ${GITHUB_REF#refs/heads/} || true
cd ../hivemq-community-edition
- name: Setup Java
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4
Expand Down
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());
}
}

0 comments on commit d4dc1b7

Please sign in to comment.