diff --git a/CHANGELOG.md b/CHANGELOG.md index 387a9db..54536c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Fixed +- Fix failed message expiration check. + ## [1.1.0] - 2023-01-16 ## [1.1.0-alpha.0] - 2022-12-15 diff --git a/DeviceSDKAndroid/src/main/java/org/astarteplatform/devicesdk/android/AstarteAndroidFailedMessage.java b/DeviceSDKAndroid/src/main/java/org/astarteplatform/devicesdk/android/AstarteAndroidFailedMessage.java index 4429dbe..1019c4f 100644 --- a/DeviceSDKAndroid/src/main/java/org/astarteplatform/devicesdk/android/AstarteAndroidFailedMessage.java +++ b/DeviceSDKAndroid/src/main/java/org/astarteplatform/devicesdk/android/AstarteAndroidFailedMessage.java @@ -4,6 +4,7 @@ import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.PrimaryKey; +import java.util.concurrent.TimeUnit; import org.astarteplatform.devicesdk.transport.AstarteFailedMessage; @Entity(tableName = "failed_messages") @@ -30,7 +31,7 @@ public AstarteAndroidFailedMessage(String topic, byte[] payload, int qos) { } public AstarteAndroidFailedMessage(String topic, byte[] payload, int qos, int relativeExpiry) { - this.absoluteExpiry = System.currentTimeMillis() + relativeExpiry; + this.absoluteExpiry = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(relativeExpiry); this.topic = topic; this.payload = payload; this.qos = qos; @@ -61,7 +62,11 @@ public void setAbsoluteExpiry(long absoluteExpiry) { @Override public boolean isExpired() { - return absoluteExpiry > System.currentTimeMillis(); + if (absoluteExpiry <= 0) { + return false; + } + + return absoluteExpiry < System.currentTimeMillis(); } public long getStorageId() { diff --git a/DeviceSDKGeneric/src/main/java/org/astarteplatform/devicesdk/generic/AstarteGenericFailedMessage.java b/DeviceSDKGeneric/src/main/java/org/astarteplatform/devicesdk/generic/AstarteGenericFailedMessage.java index cbf78a2..e14643a 100644 --- a/DeviceSDKGeneric/src/main/java/org/astarteplatform/devicesdk/generic/AstarteGenericFailedMessage.java +++ b/DeviceSDKGeneric/src/main/java/org/astarteplatform/devicesdk/generic/AstarteGenericFailedMessage.java @@ -3,6 +3,7 @@ import com.j256.ormlite.field.DataType; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; +import java.util.concurrent.TimeUnit; import org.astarteplatform.devicesdk.transport.AstarteFailedMessage; @DatabaseTable(tableName = "failed_messages") @@ -34,7 +35,7 @@ public AstarteGenericFailedMessage(String topic, byte[] payload, int qos) { } public AstarteGenericFailedMessage(String topic, byte[] payload, int qos, int relativeExpiry) { - this.absoluteExpiry = System.currentTimeMillis() + relativeExpiry; + this.absoluteExpiry = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(relativeExpiry); this.topic = topic; this.payload = payload; this.qos = qos; @@ -57,7 +58,11 @@ public int getQos() { @Override public boolean isExpired() { - return absoluteExpiry > System.currentTimeMillis(); + if (absoluteExpiry <= 0) { + return false; + } + + return absoluteExpiry < System.currentTimeMillis(); } public long getStorageId() {