Skip to content

Commit b7bae91

Browse files
CON-177: Added support for sample/view/instance state (#15)
* CON-177: Added support for sample/view/instance state * CON-177: PR feedback - Indicate possible values of the new fields in the docs - Use the naming conventions for strings in unit tests
1 parent 1d2cc6d commit b7bae91

3 files changed

Lines changed: 117 additions & 1 deletion

File tree

rticonnextdds-connector.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ class SampleIterator {
453453
* (see :meth:`Output.write`)
454454
* * ``'valid_data'`` returns a boolean (equivalent to
455455
* :attr:`SampleIterator.validData`)
456+
* * ``'view_state'``, returns a string (either "NEW" or "NOT_NEW")
457+
* * ``'instance_state'``, returns a string (one of "ALIVE", "NOT_ALIVE_DISPOSED" or "NOT_ALIVE_NO_WRITERS")
458+
* * ``'sample_state'``, returns a string (either "READ" or "NOT_READ")
456459
*
457460
* These fields are documented in `The SampleInfo Structure
458461
* <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>`__

test/nodejs/test_rticonnextdds_metadata.js

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,113 @@ describe('Test operations involving meta data', () => {
207207
expect(sample.get('my_string')).to.deep.equals(testJsonObject.my_string)
208208
}
209209
})
210-
})
210+
211+
it('test getting sample_state', async () => {
212+
testOutput.write()
213+
try {
214+
await testInput.wait(testExpectSuccessTimeout)
215+
} catch (err) {
216+
// Fail the test
217+
console.log('Error caught: ' + err)
218+
expect(false).to.deep.equals(true)
219+
}
220+
221+
// Since this is the first time that we are accessing the sample, it should
222+
// have a sample state of NOT_READ
223+
testInput.read()
224+
expect(testInput.samples.get(0).info.get('sample_state')).to.deep.equals('NOT_READ')
225+
// Now that we have already accessed the sample once time, accessing it
226+
// again should result in a sample state of READ
227+
testInput.read()
228+
expect(testInput.samples.get(0).info.get('sample_state')).to.deep.equals('READ')
229+
// Taking after a read should also have a sample state of READ
230+
testInput.take()
231+
expect(testInput.samples.get(0).info.get('sample_state')).to.deep.equals('READ')
232+
})
233+
234+
it('test getting instance state', async () => {
235+
testOutput.write()
236+
try {
237+
await testInput.wait(testExpectSuccessTimeout)
238+
} catch (err) {
239+
// Fail the test
240+
console.log('Error caught: ' + err)
241+
expect(false).to.deep.equals(true)
242+
}
243+
testInput.take()
244+
// Instance is currently alive
245+
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('ALIVE')
246+
// Disposing the sample should update the instance state
247+
testOutput.write({ action: 'dispose' })
248+
try {
249+
await testInput.wait(testExpectSuccessTimeout)
250+
} catch (err) {
251+
// Fail the test
252+
console.log('Error caught: ' + err)
253+
expect(false).to.deep.equals(true)
254+
}
255+
testInput.take()
256+
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('NOT_ALIVE_DISPOSED')
257+
// Writing the sample again should transition it back to alive
258+
testOutput.write()
259+
try {
260+
await testInput.wait(testExpectSuccessTimeout)
261+
} catch (err) {
262+
// Fail the test
263+
console.log('Error caught: ' + err)
264+
expect(false).to.deep.equals(true)
265+
}
266+
testInput.take()
267+
// Instance is currently alive
268+
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('ALIVE')
269+
// Unregister the instance to get NO_WRITERS
270+
testOutput.write({ action: 'unregister' })
271+
try {
272+
await testInput.wait(testExpectSuccessTimeout)
273+
} catch (err) {
274+
// Fail the test
275+
console.log('Error caught: ' + err)
276+
expect(false).to.deep.equals(true)
277+
}
278+
testInput.take()
279+
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('NOT_ALIVE_NO_WRITERS')
280+
})
281+
282+
it('test getting sample view state', async () => {
283+
// View state is per-instance
284+
testOutput.instance.setString('my_key_string', 'Brown')
285+
testOutput.write()
286+
try {
287+
await testInput.wait(testExpectSuccessTimeout)
288+
} catch (err) {
289+
// Fail the test
290+
console.log('Error caught: ' + err)
291+
expect(false).to.deep.equals(true)
292+
}
293+
testInput.take()
294+
expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NEW')
295+
// Updating that instance should update the view state
296+
testOutput.write()
297+
try {
298+
await testInput.wait(testExpectSuccessTimeout)
299+
} catch (err) {
300+
// Fail the test
301+
console.log('Error caught: ' + err)
302+
expect(false).to.deep.equals(true)
303+
}
304+
testInput.take()
305+
expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NOT_NEW')
306+
// Writing a new instance should have a NEW view state
307+
testOutput.instance.setString('my_key_string', 'Maroon')
308+
testOutput.write()
309+
try {
310+
await testInput.wait(testExpectSuccessTimeout)
311+
} catch (err) {
312+
// Fail the test
313+
console.log('Error caught: ' + err)
314+
expect(false).to.deep.equals(true)
315+
}
316+
testInput.take()
317+
expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NEW')
318+
})
319+
})

test/xml/TestConnector.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ This code contains trade secrets of Real-Time Innovations, Inc.
3939
<initial_instances>1</initial_instances>
4040
<max_instances>5</max_instances>
4141
</resource_limits>
42+
<writer_data_lifecycle>
43+
<autodispose_unregistered_instances>false</autodispose_unregistered_instances>
44+
</writer_data_lifecycle>
4245
</datawriter_qos>
4346
<datareader_qos>
4447
<reliability>
@@ -133,6 +136,7 @@ This code contains trade secrets of Real-Time Innovations, Inc.
133136
<member name="my_point_alias" type="nonBasic" nonBasicTypeName= "PointAlias" optional="true"/>
134137
<member name="my_int64" type="int64"/>
135138
<member name="my_uint64" type="uint64"/>
139+
<member name="my_key_string" stringMaxLength="128" type="string" key="true"/>
136140
</struct>
137141
</types>
138142

0 commit comments

Comments
 (0)