Skip to content

Commit cb82610

Browse files
authored
Merge pull request #525 from icraggs-sparkplug/develop
3 Commits to bring develop in line with 3.x
2 parents c9c090b + 735009c commit cb82610

File tree

5 files changed

+115
-83
lines changed

5 files changed

+115
-83
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, 2023 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 + "/"

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/**
3-
* Copyright (c) 2022, 2023 Anja Helmbrecht-Schaar, Ian Craggs
3+
* Copyright (c) 2022, 2024 Anja Helmbrecht-Schaar, Ian Craggs
44
* <p>
55
* All rights reserved. This program and the accompanying materials
66
* are made available under the terms of the Eclipse Public License v2.0
@@ -341,9 +341,11 @@ public void checkSequenceNumberIncluded(final @NotNull PublishPacket packet, Str
341341
isValid = false;
342342
logger.error("Check req set for : {}", ID_PAYLOADS_SEQUENCE_NUM_ALWAYS_INCLUDED);
343343
} else {
344-
if (result.getSeq() >= 0) {
345-
isValid = true;
346-
} else if (result.getSeq() == seqUnassigned && topic.contains(TOPIC_PATH_NDEATH)) {
344+
if (result.hasSeq()) {
345+
if (result.getSeq() >= 0 && result.getSeq() <= 255) {
346+
isValid = true;
347+
}
348+
} else if (topic.contains(TOPIC_PATH_NDEATH)) {
347349
isValid = true;
348350
}
349351
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2023 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
@@ -511,7 +511,7 @@ private Boolean[] checkValidPayload(PayloadOrBuilder payload) {
511511
if (payload != null) {
512512
long seqNum = payload.getSeq();
513513
bValidPayload[0] = true;
514-
bValidPayload[1] = (seqNum >= 0 && seqNum <= 255);
514+
bValidPayload[1] = payload.hasSeq() && (seqNum >= 0 && seqNum <= 255);
515515
bValidPayload[2] = payload.hasTimestamp();
516516
bValidPayload[3] = payload.hasTimestamp();
517517
List<Metric> metrics = payload.getMetricsList();

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2023 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
@@ -611,14 +611,15 @@ public void checkNBirth(final @NotNull PublishPacket packet) {
611611
logger.debug("Check Req: NBIRTH message must have Qos set to 0.");
612612
logger.debug(
613613
"Check Req: Every NBIRTH message MUST include a sequence number and it MUST have a value of 0.");
614+
boolean hasSeq = sparkplugPayload.hasSeq();
614615
seq = sparkplugPayload.getSeq();
615-
testResults.put(ID_PAYLOADS_NBIRTH_SEQ, setResult((seq == 0), PAYLOADS_NBIRTH_SEQ));
616-
testResults.put(ID_TOPICS_NBIRTH_SEQ_NUM, setResult((seq == 0), TOPICS_NBIRTH_SEQ_NUM));
616+
testResults.put(ID_PAYLOADS_NBIRTH_SEQ, setResult((hasSeq && seq == 0), PAYLOADS_NBIRTH_SEQ));
617+
testResults.put(ID_TOPICS_NBIRTH_SEQ_NUM, setResult((hasSeq && seq == 0), TOPICS_NBIRTH_SEQ_NUM));
617618
testResults.put(ID_PAYLOADS_SEQUENCE_NUM_REQ_NBIRTH,
618-
setResult((seq >= 0 && seq <= 255), PAYLOADS_SEQUENCE_NUM_REQ_NBIRTH));
619+
setResult((hasSeq && (seq >= 0 && seq <= 255)), PAYLOADS_SEQUENCE_NUM_REQ_NBIRTH));
619620

620621
testResults.put(ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_NBIRTH_PAYLOAD_SEQ,
621-
setResult((seq >= 0 && seq <= 255), MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_NBIRTH_PAYLOAD_SEQ));
622+
setResult((hasSeq && (seq >= 0 && seq <= 255)), MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_NBIRTH_PAYLOAD_SEQ));
622623

623624
// receivedBirthTime::making sure that the payload timestamp is greater than (receivedBirthTime - 5 min) and
624625
// less than the
@@ -843,9 +844,8 @@ public void checkDBirth(final @NotNull PublishPacket packet) {
843844
logger.debug("Check Req: DBIRTH must include a sequence number");
844845
prevResult = testResults.getOrDefault(ID_PAYLOADS_DBIRTH_SEQ, NOT_EXECUTED);
845846
if (!prevResult.contains(FAIL)) {
846-
boolean bContains = (sparkplugPayload.getSeq() != -1);
847847
if (prevResult.equals(NOT_EXECUTED)) {
848-
testResults.put(ID_PAYLOADS_DBIRTH_SEQ, setResult(bContains, PAYLOADS_DBIRTH_SEQ));
848+
testResults.put(ID_PAYLOADS_DBIRTH_SEQ, setResult(sparkplugPayload.hasSeq(), PAYLOADS_DBIRTH_SEQ));
849849
}
850850
}
851851

@@ -856,12 +856,12 @@ public void checkDBirth(final @NotNull PublishPacket packet) {
856856
if (!prevResult.contains(FAIL)) {
857857
boolean bSeqValid = false;
858858
if (seq != 255) {
859-
if (sparkplugPayload.getSeq() == (seq + 1)) {
859+
if (sparkplugPayload.hasSeq() && (sparkplugPayload.getSeq() == (seq + 1))) {
860860
bSeqValid = true;
861861
seq = sparkplugPayload.getSeq();
862862
}
863863
} else {
864-
if (sparkplugPayload.getSeq() == 0) {
864+
if (sparkplugPayload.hasSeq() && (sparkplugPayload.getSeq() == 0)) {
865865
bSeqValid = true;
866866
seq = sparkplugPayload.getSeq();
867867
}

0 commit comments

Comments
 (0)