Skip to content

Commit 4ab8986

Browse files
authored
Merge pull request #524 from icraggs-sparkplug/3.x
Check NDEATH for matching bdseq - ignore otherwise #502
2 parents e56de52 + fc1f887 commit 4ab8986

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/PrimaryHostTest.java

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2022 Ian Craggs
2+
* Copyright (c) 2021, 2024 Ian Craggs
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v2.0
@@ -47,6 +47,7 @@
4747
import static org.eclipse.sparkplug.tck.test.common.Requirements.OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_RECONNECT;
4848
import static org.eclipse.sparkplug.tck.test.common.Requirements.OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_TIMESTAMP;
4949

50+
import java.nio.ByteBuffer;
5051
import java.util.ArrayList;
5152
import java.util.Arrays;
5253
import java.util.List;
@@ -62,6 +63,7 @@
6263
import org.eclipse.sparkplug.tck.test.TCKTest;
6364
import org.eclipse.sparkplug.tck.test.common.Constants;
6465
import org.eclipse.sparkplug.tck.test.common.Constants.TestStatus;
66+
import org.eclipse.sparkplug.tck.test.common.SparkplugBProto;
6567
import org.eclipse.sparkplug.tck.test.common.Utils;
6668
import org.jboss.test.audit.annotations.SpecAssertion;
6769
import org.jboss.test.audit.annotations.SpecVersion;
@@ -83,6 +85,7 @@ public class PrimaryHostTest extends TCKTest {
8385

8486
private static final @NotNull Logger logger = LoggerFactory.getLogger("Sparkplug");
8587
public static final String PROPERTY_KEY_QUALITY = "Quality";
88+
private static final String BD_SEQ = "bdSeq";
8689

8790
public static final @NotNull List<String> testIds = List.of(ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_WAIT,
8891
ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_WAIT_ID,
@@ -101,6 +104,7 @@ public class PrimaryHostTest extends TCKTest {
101104
private @NotNull String edgeNodeId;
102105
private @NotNull String hostApplicationId;
103106
private @NotNull long seqUnassigned = -1;
107+
private @NotNull long birthSeq = -1; // record the nbirth seq to check for matching ndeath
104108
private Utilities utilities = null;
105109

106110
private TestStatus state = TestStatus.NONE;
@@ -350,6 +354,18 @@ public void subscribe(final @NotNull String clientId, final @NotNull SubscribePa
350354
// TODO Auto-generated method stub
351355
}
352356

357+
private long getBdSeq(final ByteBuffer payload) {
358+
final SparkplugBProto.PayloadOrBuilder inboundPayload = Utils.decode(payload);
359+
if (inboundPayload != null) {
360+
for (SparkplugBProto.Payload.Metric m : inboundPayload.getMetricsList()) {
361+
if (m.getName().equals(BD_SEQ)) {
362+
return m.getLongValue();
363+
}
364+
}
365+
}
366+
return -1L;
367+
}
368+
353369
@SpecAssertion(
354370
section = Sections.OPERATIONAL_BEHAVIOR_EDGE_NODE_SESSION_ESTABLISHMENT,
355371
id = ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_WAIT)
@@ -387,6 +403,10 @@ public void publish(final @NotNull String clientId, final @NotNull PublishPacket
387403

388404
if (topic.equals(Constants.TOPIC_ROOT_SP_BV_1_0 + "/" + groupId + "/" + Constants.TOPIC_PATH_NBIRTH + "/"
389405
+ edgeNodeId)) {
406+
407+
ByteBuffer payload = packet.getPayload().orElseGet(null);
408+
birthSeq = getBdSeq(payload);
409+
390410
// found the edge NBIRTH
391411
if (state == TestStatus.WRONG_HOST_ONLINE) {
392412
// received NBIRTH for wrong host
@@ -466,20 +486,25 @@ public void publish(final @NotNull String clientId, final @NotNull PublishPacket
466486
}
467487
} else if (topic.equals(Constants.TOPIC_ROOT_SP_BV_1_0 + "/" + groupId + "/" + Constants.TOPIC_PATH_NDEATH + "/"
468488
+ edgeNodeId)) {
489+
ByteBuffer payload = packet.getPayload().orElseGet(null);
490+
long deathSeq = getBdSeq(payload);
469491

470-
logger.info("Received NDEATH in state " + state.name());
471-
Utils.setResultIfNotFail(testResults, state == TestStatus.EXPECT_DEATHS || state == TestStatus.HOST_OFFLINE,
472-
ID_OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE,
473-
OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE);
492+
logger.info("Received NDEATH in state " + state.name() + " with bdseq " + deathSeq + " (birthSeq " + birthSeq + ")");
474493

475-
Utils.setResultIfNotFail(testResults, state == TestStatus.EXPECT_DEATHS || state == TestStatus.HOST_OFFLINE,
476-
ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_OFFLINE,
477-
MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_OFFLINE);
494+
if (deathSeq == birthSeq) { // ignore ndeaths from different births
495+
Utils.setResultIfNotFail(testResults, state == TestStatus.EXPECT_DEATHS || state == TestStatus.HOST_OFFLINE,
496+
ID_OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE,
497+
OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE);
478498

479-
if (state == TestStatus.DONT_EXPECT_DEATHS) {
480-
Utils.setResult(testResults, false,
481-
ID_OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_TIMESTAMP,
482-
OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_TIMESTAMP);
499+
Utils.setResultIfNotFail(testResults, state == TestStatus.EXPECT_DEATHS || state == TestStatus.HOST_OFFLINE,
500+
ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_OFFLINE,
501+
MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_OFFLINE);
502+
503+
if (state == TestStatus.DONT_EXPECT_DEATHS) {
504+
Utils.setResult(testResults, false,
505+
ID_OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_TIMESTAMP,
506+
OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_TIMESTAMP);
507+
}
483508
}
484509

485510
} else if (topic.equals(Constants.TOPIC_ROOT_SP_BV_1_0 + "/" + groupId + "/" + Constants.TOPIC_PATH_DDEATH + "/"

0 commit comments

Comments
 (0)