diff --git a/application/pom.xml b/application/pom.xml index d2cc11f069..805194c408 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -458,6 +458,7 @@ thingsboard + ${project.version} **/nosql/*Test.java diff --git a/application/src/test/java/org/thingsboard/server/edge/EdgeLatestVersionTest.java b/application/src/test/java/org/thingsboard/server/edge/EdgeLatestVersionTest.java new file mode 100644 index 0000000000..84c90f6b63 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/edge/EdgeLatestVersionTest.java @@ -0,0 +1,47 @@ +/** + * Copyright © 2016-2026 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.edge; + +import org.junit.Assert; +import org.junit.Test; +import org.thingsboard.server.gen.edge.v1.EdgeVersion; + +import java.util.Arrays; +import java.util.Comparator; + +public class EdgeLatestVersionTest { + + @Test + public void edgeLatestVersionIsSynchronizedTest() { + EdgeVersion currentHighestEdgeVersion = Arrays.stream(EdgeVersion.values()) + .filter(v -> v != EdgeVersion.UNRECOGNIZED) + .filter(v -> v != EdgeVersion.V_LATEST) + .max(Comparator.comparingInt(EdgeVersion::getNumber)) + .orElseThrow(); + + String projectVersion = EdgeLatestVersionTest.class.getPackage().getImplementationVersion(); + if (projectVersion == null || projectVersion.isBlank()) { + projectVersion = System.getProperty("project.version", "UNKNOWN"); + } + + String projectVersionDigits = projectVersion.replaceAll("\\D", ""); + String currentHighestEdgeVersionDigits = currentHighestEdgeVersion.name().replaceAll("\\D", ""); + + String msg = "EdgeVersion enum in edge.proto is out of sync. Please add respective " + projectVersionDigits + " to EdgeVersion"; + Assert.assertEquals(msg, projectVersionDigits, currentHighestEdgeVersionDigits); + } + +} diff --git a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java index 1b17fbe849..2b9aad0ff1 100644 --- a/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java +++ b/common/edge-api/src/main/java/org/thingsboard/edge/rpc/EdgeGrpcClient.java @@ -144,17 +144,45 @@ public class EdgeGrpcClient implements EdgeRpcClient { public static EdgeVersion getNewestEdgeVersion() { EdgeVersion newest = null; + int[] newestParts = null; for (EdgeVersion v : EdgeVersion.values()) { if (v == EdgeVersion.V_LATEST || v == EdgeVersion.UNRECOGNIZED) { continue; } - if (newest == null || v.getNumber() > newest.getNumber()) { + int[] parts = parseVersionParts(v); + if (newest == null || compareVersionParts(parts, newestParts) > 0) { newest = v; + newestParts = parts; } } return newest; } + private static int[] parseVersionParts(EdgeVersion version) { + String name = version.name(); + if (name.startsWith("V_")) { + name = name.substring(2); + } + String[] parts = name.split("_"); + int[] result = new int[parts.length]; + for (int i = 0; i < parts.length; i++) { + result[i] = Integer.parseInt(parts[i]); + } + return result; + } + + private static int compareVersionParts(int[] a, int[] b) { + int maxLen = Math.max(a.length, b.length); + for (int i = 0; i < maxLen; i++) { + int partA = i < a.length ? a[i] : 0; + int partB = i < b.length ? b[i] : 0; + if (partA != partB) { + return Integer.compare(partA, partB); + } + } + return 0; + } + private StreamObserver initOutputStream(String edgeKey, Consumer onUplinkResponse, Consumer onEdgeUpdate, diff --git a/common/edge-api/src/main/proto/edge.proto b/common/edge-api/src/main/proto/edge.proto index a01e0e561a..836a961b26 100644 --- a/common/edge-api/src/main/proto/edge.proto +++ b/common/edge-api/src/main/proto/edge.proto @@ -45,6 +45,7 @@ enum EdgeVersion { V_4_1_0 = 11; V_4_2_0 = 12; V_4_3_0 = 13; + V_4_2_1_2 = 14; V_LATEST = 999; }