diff --git a/application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java b/application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java index 95160f1b21..4908c19fad 100644 --- a/application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java +++ b/application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java @@ -64,6 +64,10 @@ public class DefaultCacheCleanupService implements CacheCleanupService { log.info("Clear cache to upgrade from version 3.3.2 to 3.3.3 ..."); clearAll(); break; + case "3.3.3": + log.info("Clear cache to upgrade from version 3.3.3 to 3.4 ..."); + clearAll(); + break; default: //Do nothing, since cache cleanup is optional. } diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDes.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDes.java index 1d8fc1071c..1002c81cac 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDes.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDes.java @@ -57,7 +57,6 @@ public class LwM2MClientSerDes { resourceValue.add("lwM2mResource", serialize(v.getLwM2mResource())); resourceValue.add("resourceModel", serialize(v.getResourceModel())); resources.add(k, resourceValue); - }); o.add("resources", resources); JsonObject sharedAttributes = Json.object(); @@ -300,21 +299,21 @@ public class LwM2MClientSerDes { if (edrxCycle != null) { Field edrxCycleField = lwM2mClientClass.getDeclaredField("edrxCycle"); edrxCycleField.setAccessible(true); - edrxCycleField.setLong(lwM2mClient, edrxCycle.asLong()); + edrxCycleField.set(lwM2mClient, edrxCycle.asLong()); } JsonValue psmActivityTimer = o.get("psmActivityTimer"); if (psmActivityTimer != null) { Field psmActivityTimerField = lwM2mClientClass.getDeclaredField("psmActivityTimer"); psmActivityTimerField.setAccessible(true); - psmActivityTimerField.setLong(lwM2mClient, psmActivityTimer.asLong()); + psmActivityTimerField.set(lwM2mClient, psmActivityTimer.asLong()); } JsonValue pagingTransmissionWindow = o.get("pagingTransmissionWindow"); if (pagingTransmissionWindow != null) { Field pagingTransmissionWindowField = lwM2mClientClass.getDeclaredField("pagingTransmissionWindow"); pagingTransmissionWindowField.setAccessible(true); - pagingTransmissionWindowField.setLong(lwM2mClient, pagingTransmissionWindow.asLong()); + pagingTransmissionWindowField.set(lwM2mClient, pagingTransmissionWindow.asLong()); } JsonValue registration = o.get("registration"); diff --git a/common/transport/lwm2m/src/test/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDesTest.java b/common/transport/lwm2m/src/test/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDesTest.java new file mode 100644 index 0000000000..f53e7888f6 --- /dev/null +++ b/common/transport/lwm2m/src/test/org/thingsboard/server/transport/lwm2m/server/store/util/LwM2MClientSerDesTest.java @@ -0,0 +1,95 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.thingsboard.server.transport.lwm2m.server.store.util; + +import org.eclipse.leshan.core.link.Link; +import org.eclipse.leshan.core.request.Identity; +import org.eclipse.leshan.server.registration.Registration; +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.thingsboard.server.common.data.device.data.PowerMode; +import org.thingsboard.server.common.data.id.CustomerId; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.common.data.id.DeviceProfileId; +import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.common.transport.auth.TransportDeviceInfo; +import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; +import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; + +import java.net.InetSocketAddress; +import java.util.UUID; + +class LwM2MClientSerDesTest { + + @Test + void serializeDeserialize() { + LwM2mClient client = new LwM2mClient("nodeId", "testEndpoint"); + + TransportDeviceInfo tdi = new TransportDeviceInfo(); + tdi.setPowerMode(PowerMode.PSM); + tdi.setPsmActivityTimer(10000L); + tdi.setPagingTransmissionWindow(2000L); + tdi.setEdrxCycle(3000L); + tdi.setTenantId(TenantId.fromUUID(UUID.randomUUID())); + tdi.setCustomerId(new CustomerId(UUID.randomUUID())); + tdi.setDeviceId(new DeviceId(UUID.randomUUID())); + tdi.setDeviceProfileId(new DeviceProfileId(UUID.randomUUID())); + tdi.setDeviceName("testDevice"); + tdi.setDeviceType("testType"); + ValidateDeviceCredentialsResponse credentialsResponse = ValidateDeviceCredentialsResponse.builder() + .deviceInfo(tdi) + .build(); + + client.init(credentialsResponse, UUID.randomUUID()); + + Registration registration = + new Registration.Builder("test", "testEndpoint", Identity + .unsecure(new InetSocketAddress(1000))) + .supportedContentFormats() + .objectLinks(new Link[]{new Link("/")}) + .build(); + + client.setRegistration(registration); + + byte[] bytes = LwM2MClientSerDes.serialize(client); + Assert.assertNotNull(bytes); + + LwM2mClient desClient = LwM2MClientSerDes.deserialize(bytes); + + Assert.assertEquals(client.getNodeId(), desClient.getNodeId()); + Assert.assertEquals(client.getEndpoint(), desClient.getEndpoint()); + Assert.assertEquals(client.getResources(), desClient.getResources()); + Assert.assertEquals(client.getSharedAttributes(), desClient.getSharedAttributes()); + Assert.assertEquals(client.getKeyTsLatestMap(), desClient.getKeyTsLatestMap()); + Assert.assertEquals(client.getTenantId(), desClient.getTenantId()); + Assert.assertEquals(client.getProfileId(), desClient.getProfileId()); + Assert.assertEquals(client.getDeviceId(), desClient.getDeviceId()); + Assert.assertEquals(client.getState(), desClient.getState()); + Assert.assertEquals(client.getSession(), desClient.getSession()); + Assert.assertEquals(client.getPowerMode(), desClient.getPowerMode()); + Assert.assertEquals(client.getPsmActivityTimer(), desClient.getPsmActivityTimer()); + Assert.assertEquals(client.getPagingTransmissionWindow(), desClient.getPagingTransmissionWindow()); + Assert.assertEquals(client.getEdrxCycle(), desClient.getEdrxCycle()); + Assert.assertEquals(client.getRegistration(), desClient.getRegistration()); + Assert.assertEquals(client.isAsleep(), desClient.isAsleep()); + Assert.assertEquals(client.getLastUplinkTime(), desClient.getLastUplinkTime()); + Assert.assertEquals(client.getSleepTask(), desClient.getSleepTask()); + Assert.assertEquals(client.getClientSupportContentFormats(), desClient.getClientSupportContentFormats()); + Assert.assertEquals(client.getDefaultContentFormat(), desClient.getDefaultContentFormat()); + Assert.assertEquals(client.getRetryAttempts().get(), desClient.getRetryAttempts().get()); + Assert.assertEquals(client.getLastSentRpcId(), desClient.getLastSentRpcId()); + } +} \ No newline at end of file