diff --git a/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceReconnectTest.java b/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceReconnectTest.java index 8b90004e25..8b471d0548 100644 --- a/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceReconnectTest.java +++ b/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceReconnectTest.java @@ -1,18 +1,5 @@ -/** - * 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. - */ +// SPDX-FileCopyrightText: Copyright The Thingsboard Authors +// SPDX-License-Identifier: Apache-2.0 package org.thingsboard.server.service.edge.rpc; import com.google.common.util.concurrent.Futures; diff --git a/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceTest.java b/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceTest.java index ea6166d8f7..0b8f99e0dc 100644 --- a/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceTest.java +++ b/application/src/test/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcServiceTest.java @@ -199,17 +199,14 @@ public class EdgeGrpcServiceTest { @Test public void givenSessionReplacedDuringDisconnect_whenStaleCallbackRuns_thenLiveSessionKept() { - // Reproduces the get()/remove() interleaving on a single node: onEdgeConnect swaps in a new session - // right after the stale callback's id check passes. The stale callback must not evict or tear down - // the live session, nor clear the activity state. + // onEdgeConnect has already swapped in a new session on this node when the stale callback runs. + // The check-and-remove is a single atomic step against the same map that onEdgeConnect writes + // through, so the swap can only land before or after it. The stale callback must not evict or + // tear down the live session, nor clear the activity state. UUID staleSessionId = UUID.randomUUID(); EdgeGrpcSession live = mock(EdgeGrpcSession.class); - EdgeGrpcSession stale = mock(EdgeGrpcSession.class); - when(stale.getSessionId()).thenAnswer(invocation -> { - sessions().put(edgeId, live); - return staleSessionId; - }); - sessions().put(edgeId, stale); + when(live.getSessionId()).thenReturn(UUID.randomUUID()); + sessions().put(edgeId, live); onEdgeDisconnect(staleSessionId);