1
1
/*******************************************************************************
2
- * Copyright (c) 2021, 2022 Ian Craggs
2
+ * Copyright (c) 2021, 2024 Ian Craggs
3
3
*
4
4
* All rights reserved. This program and the accompanying materials
5
5
* are made available under the terms of the Eclipse Public License v2.0
47
47
import static org .eclipse .sparkplug .tck .test .common .Requirements .OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_RECONNECT ;
48
48
import static org .eclipse .sparkplug .tck .test .common .Requirements .OPERATIONAL_BEHAVIOR_EDGE_NODE_TERMINATION_HOST_OFFLINE_TIMESTAMP ;
49
49
50
+ import java .nio .ByteBuffer ;
50
51
import java .util .ArrayList ;
51
52
import java .util .Arrays ;
52
53
import java .util .List ;
62
63
import org .eclipse .sparkplug .tck .test .TCKTest ;
63
64
import org .eclipse .sparkplug .tck .test .common .Constants ;
64
65
import org .eclipse .sparkplug .tck .test .common .Constants .TestStatus ;
66
+ import org .eclipse .sparkplug .tck .test .common .SparkplugBProto ;
65
67
import org .eclipse .sparkplug .tck .test .common .Utils ;
66
68
import org .jboss .test .audit .annotations .SpecAssertion ;
67
69
import org .jboss .test .audit .annotations .SpecVersion ;
@@ -83,6 +85,7 @@ public class PrimaryHostTest extends TCKTest {
83
85
84
86
private static final @ NotNull Logger logger = LoggerFactory .getLogger ("Sparkplug" );
85
87
public static final String PROPERTY_KEY_QUALITY = "Quality" ;
88
+ private static final String BD_SEQ = "bdSeq" ;
86
89
87
90
public static final @ NotNull List <String > testIds = List .of (ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_WAIT ,
88
91
ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_WAIT_ID ,
@@ -101,6 +104,7 @@ public class PrimaryHostTest extends TCKTest {
101
104
private @ NotNull String edgeNodeId ;
102
105
private @ NotNull String hostApplicationId ;
103
106
private @ NotNull long seqUnassigned = -1 ;
107
+ private @ NotNull long birthSeq = -1 ; // record the nbirth seq to check for matching ndeath
104
108
private Utilities utilities = null ;
105
109
106
110
private TestStatus state = TestStatus .NONE ;
@@ -350,6 +354,18 @@ public void subscribe(final @NotNull String clientId, final @NotNull SubscribePa
350
354
// TODO Auto-generated method stub
351
355
}
352
356
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
+
353
369
@ SpecAssertion (
354
370
section = Sections .OPERATIONAL_BEHAVIOR_EDGE_NODE_SESSION_ESTABLISHMENT ,
355
371
id = ID_MESSAGE_FLOW_EDGE_NODE_BIRTH_PUBLISH_PHID_WAIT )
@@ -387,6 +403,10 @@ public void publish(final @NotNull String clientId, final @NotNull PublishPacket
387
403
388
404
if (topic .equals (Constants .TOPIC_ROOT_SP_BV_1_0 + "/" + groupId + "/" + Constants .TOPIC_PATH_NBIRTH + "/"
389
405
+ edgeNodeId )) {
406
+
407
+ ByteBuffer payload = packet .getPayload ().orElseGet (null );
408
+ birthSeq = getBdSeq (payload );
409
+
390
410
// found the edge NBIRTH
391
411
if (state == TestStatus .WRONG_HOST_ONLINE ) {
392
412
// received NBIRTH for wrong host
@@ -466,20 +486,25 @@ public void publish(final @NotNull String clientId, final @NotNull PublishPacket
466
486
}
467
487
} else if (topic .equals (Constants .TOPIC_ROOT_SP_BV_1_0 + "/" + groupId + "/" + Constants .TOPIC_PATH_NDEATH + "/"
468
488
+ edgeNodeId )) {
489
+ ByteBuffer payload = packet .getPayload ().orElseGet (null );
490
+ long deathSeq = getBdSeq (payload );
469
491
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 + ")" );
474
493
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 );
478
498
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
+ }
483
508
}
484
509
485
510
} else if (topic .equals (Constants .TOPIC_ROOT_SP_BV_1_0 + "/" + groupId + "/" + Constants .TOPIC_PATH_DDEATH + "/"
0 commit comments