Remove unnecessary originator locality check

This commit is contained in:
Dmytro Skarzhynets 2024-01-24 17:58:24 +02:00 committed by Dmytro Skarzhynets
parent 5e846116a8
commit c65a9c2e0d
2 changed files with 1 additions and 26 deletions

View File

@ -81,14 +81,7 @@ public class TbDeviceStateNode implements TbNode {
@Override @Override
public void onMsg(TbContext ctx, TbMsg msg) { public void onMsg(TbContext ctx, TbMsg msg) {
var originator = msg.getOriginator(); if (!EntityType.DEVICE.equals(msg.getOriginator().getEntityType())) {
if (!ctx.isLocalEntity(originator)) {
log.warn("[{}][{}] Received message from non-local entity [{}]!",
ctx.getTenantId().getId(), ctx.getSelfId().getId(), originator.getId());
ctx.ack(msg);
return;
}
if (!EntityType.DEVICE.equals(originator.getEntityType())) {
ctx.tellSuccess(msg); ctx.tellSuccess(msg);
return; return;
} }

View File

@ -132,32 +132,15 @@ public class TbDeviceStateNodeTest {
// GIVEN // GIVEN
var asset = new AssetId(UUID.randomUUID()); var asset = new AssetId(UUID.randomUUID());
var msg = TbMsg.newMsg(TbMsgType.ENTITY_CREATED, asset, TbMsgMetaData.EMPTY, TbMsg.EMPTY_JSON_OBJECT); var msg = TbMsg.newMsg(TbMsgType.ENTITY_CREATED, asset, TbMsgMetaData.EMPTY, TbMsg.EMPTY_JSON_OBJECT);
given(ctxMock.isLocalEntity(asset)).willReturn(true);
// WHEN // WHEN
node.onMsg(ctxMock, msg); node.onMsg(ctxMock, msg);
// THEN // THEN
then(ctxMock).should().isLocalEntity(asset);
then(ctxMock).should().tellSuccess(msg); then(ctxMock).should().tellSuccess(msg);
then(ctxMock).shouldHaveNoMoreInteractions(); then(ctxMock).shouldHaveNoMoreInteractions();
} }
@Test
public void givenNonLocalOriginator_whenOnMsg_thenTellsSuccessAndNoActivityActionsTriggered() {
// GIVEN
given(ctxMock.isLocalEntity(msg.getOriginator())).willReturn(false);
given(ctxMock.getSelfId()).willReturn(new RuleNodeId(UUID.randomUUID()));
given(ctxMock.getTenantId()).willReturn(TENANT_ID);
// WHEN
node.onMsg(ctxMock, msg);
// THEN
then(ctxMock).should().ack(msg);
then(ctxMock).shouldHaveNoMoreInteractions();
}
@ParameterizedTest @ParameterizedTest
@MethodSource("provideSupportedEventsAndExpectedMessages") @MethodSource("provideSupportedEventsAndExpectedMessages")
public void givenSupportedEvent_whenOnMsg_thenCorrectMsgIsSent(TbMsgType event, TransportProtos.ToCoreMsg expectedToCoreMsg) { public void givenSupportedEvent_whenOnMsg_thenCorrectMsgIsSent(TbMsgType event, TransportProtos.ToCoreMsg expectedToCoreMsg) {
@ -171,7 +154,6 @@ public class TbDeviceStateNodeTest {
} }
given(ctxMock.getTenantId()).willReturn(TENANT_ID); given(ctxMock.getTenantId()).willReturn(TENANT_ID);
given(ctxMock.getClusterService()).willReturn(tbClusterServiceMock); given(ctxMock.getClusterService()).willReturn(tbClusterServiceMock);
given(ctxMock.isLocalEntity(msg.getOriginator())).willReturn(true);
// WHEN // WHEN
node.onMsg(ctxMock, msg); node.onMsg(ctxMock, msg);