diff --git a/common/message/src/main/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsg.java b/common/message/src/main/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsg.java index f5673c6dcb..72550a48cf 100644 --- a/common/message/src/main/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsg.java +++ b/common/message/src/main/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsg.java @@ -3,19 +3,37 @@ package org.thingsboard.server.common.msg.queue; import lombok.Data; -import lombok.Getter; +import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.msg.MsgType; import org.thingsboard.server.common.msg.TbActorMsg; +import java.util.Set; + /** * @author Andrew Shvayka */ @Data public final class PartitionChangeMsg implements TbActorMsg { - @Getter private final ServiceType serviceType; + /** + * Tenants whose partition ownership changed. Null means the shared + * (non-isolated) tenant pool itself changed, so every tenant actor must + * re-verify — shared-pool tenants aren't individually tracked as + * queueKeys, so they can't be enumerated here. + */ + private final Set affectedTenants; + + public PartitionChangeMsg(ServiceType serviceType) { + this(serviceType, null); + } + + public PartitionChangeMsg(ServiceType serviceType, Set affectedTenants) { + this.serviceType = serviceType; + this.affectedTenants = affectedTenants; + } + @Override public MsgType getMsgType() { return MsgType.PARTITION_CHANGE_MSG; diff --git a/common/message/src/test/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsgTest.java b/common/message/src/test/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsgTest.java new file mode 100644 index 0000000000..6e01879941 --- /dev/null +++ b/common/message/src/test/java/org/thingsboard/server/common/msg/queue/PartitionChangeMsgTest.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.common.msg.queue; + +import org.junit.jupiter.api.Test; +import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.common.msg.MsgType; + +import java.util.Set; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +public class PartitionChangeMsgTest { + + @Test + public void singleArgConstructor_defaultsAffectedTenantsToNull() { + PartitionChangeMsg msg = new PartitionChangeMsg(ServiceType.TB_RULE_ENGINE); + + assertEquals(ServiceType.TB_RULE_ENGINE, msg.getServiceType()); + assertNull(msg.getAffectedTenants()); + assertEquals(MsgType.PARTITION_CHANGE_MSG, msg.getMsgType()); + } + + @Test + public void twoArgConstructor_carriesAffectedTenants() { + TenantId tenant = new TenantId(UUID.randomUUID()); + PartitionChangeMsg msg = new PartitionChangeMsg(ServiceType.TB_RULE_ENGINE, Set.of(tenant)); + + assertEquals(ServiceType.TB_RULE_ENGINE, msg.getServiceType()); + assertEquals(Set.of(tenant), msg.getAffectedTenants()); + } +}