Skip to content

Commit 062e435

Browse files
Feature/con 188 (#18)
* CON-188: Added docs + tests * CON-188: Revert changes to package.json * CON-188: Change of functionality Previously, any non-key fields would be returned as null when obtain via DD_GET operations. This is no longer the case. * CON-188: Remove debug * CON-188: PR feedback - doc related * CON-188: PR Feedback - Do not access non-key fields in the unit tests - Fix docs Co-authored-by: Sam Raeburn <sam@rti.com>
1 parent 60c4275 commit 062e435

9 files changed

Lines changed: 564 additions & 35 deletions

docs/data.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,54 @@ In an :class:`Input`, you can obtain the selected member as a string::
452452
if (input.samples.get(0).getString('my_union#') == 'point') {
453453
value = input.samples.get(0).getNumber('my_union.point.x')
454454
}
455+
456+
Accessing key values of disposed samples
457+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
458+
459+
Using :meth:`Output.write`, an :class:`Output` can write data, or dispose or
460+
unregister an instance.
461+
Depending on which of these operations is performed, the ``instance_state`` of the
462+
received sample will be ``'ALIVE'``, ``'NOT_ALIVE_NO_WRITERS'`` or ``'NOT_ALIVE_DISPOSED'``.
463+
If the instance was disposed, this ``instance_state`` will be ``'NOT_ALIVE_DISPOSED'``.
464+
In this state, it is possible to access the key fields of the instance that was disposed.
465+
466+
.. note::
467+
:attr:`SampleInfo.valid_data` will be false when the :attr:`SampleInfo.instance_state`
468+
is ``'NOT_ALIVE_DISPOSED'``. In this situation it's possible to access the
469+
key fields in the received sample.
470+
471+
The key fields can be accessed as follows:
472+
473+
.. code-block::
474+
475+
// The output and input are using the following type:
476+
// struct ShapeType {
477+
// @key string<128> color;
478+
// long x;
479+
// long y;
480+
// long shapesize;
481+
// }
482+
483+
output.instance.set('x', 4)
484+
output.instance.set('color', 'Green')
485+
// Assume that some data associated with this instance has already been sent
486+
output.write({ action: 'dispose' })
487+
await input.wait()
488+
input.take()
489+
let sample = input.samples.get(0)
490+
491+
if (sample.info.get('instance_state') === 'NOT_ALIVE_DISPOSED') {
492+
// sample.info.get('valid_data') will be false in this situation
493+
// Only the key-fields should be accessed
494+
let color = sample.get('color') // 'Green'
495+
// The fields 'x','y' and 'shapesize' cannot be retrieved because they're
496+
// not part of the key
497+
// You can also call getJson() to get all of the key fields in a JSON object.
498+
// Again, only the key fields returned within the JSON object should
499+
// be used.
500+
let keyValues = sample.getJson() // { color: 'Green', x: 0, y: 0, shapesize: 0 }
501+
}
502+
503+
.. warning::
504+
When the sample has an instance state of ``'NOT_ALIVE_DISPOSED'`` only the
505+
key fields should be accessed.

docs/input.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ After calling :meth:`Input.read()` or :meth:`Input.take()`,
121121
122122
:meth:`SampleIterator.getJson()` retrieves all the fields of a sample.
123123

124-
If you don't need to access the meta-data (see :ref:`Accessing the SampleInfo`),
124+
If you don't need to access the meta-data (see :ref:`Accessing sample meta-data`),
125125
the simplest way to access the data is to use :attr:`Samples.validDataIter`
126126
to skip samples with invalid data:
127127

@@ -177,15 +177,11 @@ for example:
177177
178178
See more information and examples in :ref:`Accessing the data`.
179179

180-
Accessing the SampleInfo
181-
~~~~~~~~~~~~~~~~~~~~~~~~
182-
183-
*Connext DDS* can produce samples with invalid data, which contain meta-data only.
184-
For more information about this, see `Valid Data Flag
185-
<https://community.rti.com/static/documentation/connext-dds/current/doc/manuals/connext_dds/html_files/RTI_ConnextDDS_CoreLibraries_UsersManual/index.htm#UsersManual/The_SampleInfo_Structure.htm#receiving_2076951295_727613>`__
186-
in the *RTI Connext DDS Core Libraries User's Manual*.
180+
Accessing sample meta-data
181+
~~~~~~~~~~~~~~~~~~~~~~~~~~
187182

188-
You can access a field of the sample meta-data, the *SampleInfo*, as follows:
183+
Every sample contains an associated *SampleInfo* with meta-information about the
184+
sample:
189185

190186
.. code-block::
191187
@@ -195,6 +191,19 @@ You can access a field of the sample meta-data, the *SampleInfo*, as follows:
195191
196192
See :attr:`SampleIterator.info` for the list of available meta-data fields.
197193

194+
*Connext DDS* can produce samples with invalid data, which contain meta-data only.
195+
For more information about this, see `Valid Data Flag
196+
<https://community.rti.com/static/documentation/connext-dds/current/doc/manuals/connext_dds/html_files/RTI_ConnextDDS_CoreLibraries_UsersManual/index.htm#UsersManual/The_SampleInfo_Structure.htm#receiving_2076951295_727613>`__
197+
in the *RTI Connext DDS Core Libraries User's Manual*.
198+
These samples indicate a change in the instance state. Samples with invalid data
199+
still provide the following information:
200+
201+
* The :class:`SampleInfo`
202+
* When an instance is disposed (``sample.info.get('instance_state')`` is
203+
``'NOT_ALIVE_DISPOSED'``), the sample data contains the value of the key that
204+
has been disposed. You can access the key fields only. See
205+
:ref:`Accessing key values of disposed samples`.
206+
198207
Matching with a Publication
199208
~~~~~~~~~~~~~~~~~~~~~~~~~~~
200209

test/nodejs/test_rticonnextdds_data_access.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Data access tests with a pre-populated input', function () {
7070
} catch (err) {
7171
console.log('Caught err: ' + err)
7272
// Fail the test
73-
expect(true).to.deep.equals(false)
73+
throw(err)
7474
}
7575
// Write data on the the output
7676
output.instance.setFromJson(testJsonObject)
@@ -81,7 +81,7 @@ describe('Data access tests with a pre-populated input', function () {
8181
} catch (err) {
8282
console.log('Caught err: ' + err)
8383
// Fail the test
84-
expect(true).to.deep.equals(false)
84+
throw(err)
8585
}
8686
// Take the data on the input so that we can access it from the test
8787
prepopulatedInput.take()
@@ -388,7 +388,7 @@ describe('Tests with a testOutput and testInput', () => {
388388
expect(newMatches).to.deep.equals(1)
389389
} catch (err) {
390390
console.log('Caught err ' + err)
391-
expect(true).to.deep.equals(false)
391+
throw(err)
392392
}
393393
})
394394

@@ -512,7 +512,7 @@ describe('Tests with a testOutput and testInput', () => {
512512
await testInput.wait(testExpectSuccessTimeout)
513513
} catch (err) {
514514
console.log('Caught err: ' + err)
515-
expect(true).to.deep.equals(false)
515+
throw(err)
516516
}
517517
testInput.take()
518518
const received = testInput.samples.get(0).get('my_int_sequence')
@@ -531,7 +531,7 @@ describe('Tests with a testOutput and testInput', () => {
531531
await testInput.wait(testExpectSuccessTimeout)
532532
} catch (err) {
533533
console.log('Caught error: ' + err)
534-
expect(true).to.deep.equals(false)
534+
throw(err)
535535
}
536536
testInput.take()
537537
const received = testInput.samples.get(0).get('my_point_sequence')
@@ -545,7 +545,7 @@ describe('Tests with a testOutput and testInput', () => {
545545
await testInput.wait(testExpectSuccessTimeout)
546546
} catch (err) {
547547
console.log('Caught error: ' + err)
548-
expect(true).to.deep.equals(false)
548+
throw(err)
549549
}
550550
testInput.take()
551551
const sample = testInput.samples.get(0)
@@ -1017,14 +1017,14 @@ describe('Tests with two readers and two writers', () => {
10171017
expect(newMatches).to.deep.equals(1)
10181018
} catch (err) {
10191019
console.log('Caught err: ' + err)
1020-
expect(true).to.deep.equals(false)
1020+
throw(err)
10211021
}
10221022
try {
10231023
const newMatches = await testOutput2.waitForSubscriptions(testExpectSuccessTimeout)
10241024
expect(newMatches).to.deep.equals(1)
10251025
} catch (err) {
10261026
console.log('Caught err: ' + err)
1027-
expect(true).to.deep.equals(false)
1027+
throw(err)
10281028
}
10291029
})
10301030

@@ -1041,7 +1041,7 @@ describe('Tests with two readers and two writers', () => {
10411041
try {
10421042
await connector.wait(testExpectFailureTimeout)
10431043
console.log('Expected connector.wait to timeout but it did not')
1044-
expect(true).to.deep.equals(false)
1044+
throw(err)
10451045
} catch (err) {
10461046
expect(err).to.be.an.instanceof(rti.TimeoutError)
10471047
}
@@ -1051,7 +1051,7 @@ describe('Tests with two readers and two writers', () => {
10511051
try {
10521052
await testInput1.wait(testExpectFailureTimeout)
10531053
console.log('Expected testInput1.wait to timeout but it did not')
1054-
expect(true).to.deep.equals(false)
1054+
throw(err)
10551055
} catch (err) {
10561056
expect(err).to.be.an.instanceof(rti.TimeoutError)
10571057
}
@@ -1061,7 +1061,7 @@ describe('Tests with two readers and two writers', () => {
10611061
try {
10621062
await testInput2.wait(testExpectFailureTimeout)
10631063
console.log('Expected testInput2.wait to timeout but it did not')
1064-
expect(true).to.deep.equals(false)
1064+
throw(err)
10651065
} catch (err) {
10661066
expect(err).to.be.an.instanceof(rti.TimeoutError)
10671067
}
@@ -1073,7 +1073,7 @@ describe('Tests with two readers and two writers', () => {
10731073
await connector.wait(testExpectSuccessTimeout)
10741074
} catch (err) {
10751075
console.log('Caught err: ' + err)
1076-
expect(true).to.deep.equals(false)
1076+
throw(err)
10771077
}
10781078
})
10791079

@@ -1083,7 +1083,7 @@ describe('Tests with two readers and two writers', () => {
10831083
await testInput1.wait(testExpectSuccessTimeout)
10841084
} catch (err) {
10851085
console.log('Caught err: ' + err)
1086-
expect(true).to.deep.equals(false)
1086+
throw(err)
10871087
}
10881088
})
10891089

@@ -1092,7 +1092,7 @@ describe('Tests with two readers and two writers', () => {
10921092
try {
10931093
await testInput2.wait(testExpectFailureTimeout)
10941094
console.log('Expected testInput2.wait to timeout but it did not')
1095-
expect(true).to.deep.equals(false)
1095+
throw(err)
10961096
} catch (err) {
10971097
expect(err).to.be.an.instanceof(rti.TimeoutError)
10981098
}
@@ -1104,7 +1104,7 @@ describe('Tests with two readers and two writers', () => {
11041104
await connector.wait(testExpectSuccessTimeout)
11051105
} catch (err) {
11061106
console.log('Caught err: ' + err)
1107-
expect(true).to.deep.equals(false)
1107+
throw(err)
11081108
}
11091109
})
11101110

@@ -1114,7 +1114,7 @@ describe('Tests with two readers and two writers', () => {
11141114
await testInput2.wait(testExpectSuccessTimeout)
11151115
} catch (err) {
11161116
console.log('Caught err: ' + err)
1117-
expect(true).to.deep.equals(false)
1117+
throw(err)
11181118
}
11191119
})
11201120

@@ -1123,7 +1123,7 @@ describe('Tests with two readers and two writers', () => {
11231123
try {
11241124
await testInput1.wait(testExpectFailureTimeout)
11251125
console.log('Expected testInput2.wait to timeout but it did not')
1126-
expect(true).to.deep.equals(false)
1126+
throw(err)
11271127
} catch (err) {
11281128
expect(err).to.be.an.instanceof(rti.TimeoutError)
11291129
}

test/nodejs/test_rticonnextdds_dataflow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ params.forEach((retrievalMethod) => {
3939
expect(matches).to.be.at.least(1)
4040
} catch (err) {
4141
console.log('Caught err: ' + err)
42-
expect(true).to.deep.equals(false)
42+
throw(err)
4343
}
4444
})
4545

@@ -57,7 +57,7 @@ params.forEach((retrievalMethod) => {
5757
await input.wait(testExpectSuccessTimeout)
5858
} catch (err) {
5959
console.log('Caught err: ' + err)
60-
expect(true).to.deep.equals(false)
60+
throw(err)
6161
}
6262
input[retrievalMethod]()
6363
expect(input.samples.length).to.be.at.least(1)

test/nodejs/test_rticonnextdds_discovery.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ describe('Discovery tests', function () {
188188
} catch (err) {
189189
console.log('Caught error: ' + err)
190190
// Fail the test
191-
expect(true).to.deep.equals(false)
191+
throw(err)
192192
}
193193
}
194194
expect(totalMatches).to.be.at.least(2)
@@ -223,7 +223,7 @@ describe('Discovery tests', function () {
223223
} catch (err) {
224224
console.log('Caught error: ' + err)
225225
// Fail the test
226-
expect(true).to.deep.equals(false)
226+
throw(err)
227227
}
228228
}
229229
expect(totalMatches).to.be.at.least(2)
@@ -369,7 +369,7 @@ describe('Discovery tests', function () {
369369
} catch (err) {
370370
console.log('Caught error: ' + err)
371371
// Fail the test
372-
expect(true).to.deep.equals(false)
372+
throw(err)
373373
}
374374

375375
// Get the entity names of the matched subs
@@ -395,7 +395,7 @@ describe('Discovery tests', function () {
395395
} catch (err) {
396396
console.log('Caught error: ' + err)
397397
// Fail the test
398-
expect(true).to.deep.equals(false)
398+
throw(err)
399399
}
400400
const matches = output.matchedSubscriptions
401401
expect(matches.length).to.deep.equals(1)

test/nodejs/test_rticonnextdds_events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('Connector EventEmitter tests', function () {
7878
.then(() => {
7979
// This should not have been possible
8080
console.log('Error occurred. Expected wait to fail due to waitSetBusy')
81-
expect(true).to.deep.equals(false)
81+
throw(err)
8282
})
8383
.catch((err) => {
8484
expect(err.message).to.deep.equals('Can not concurrently wait on the same Connector object')

test/nodejs/test_rticonnextdds_input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('Subscriber not automatically enabled tests', () => {
9797
expect(newMatches).to.deep.equals(1)
9898
} catch (err) {
9999
console.log('Caught err: ' + err)
100-
expect(true).to.deep.equals(false)
100+
throw(err)
101101
}
102102
})
103103
})

0 commit comments

Comments
 (0)