Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rticonnextdds-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ class SampleIterator {
* (see :meth:`Output.write`)
* * ``'valid_data'`` returns a boolean (equivalent to
* :attr:`SampleIterator.validData`)
* * ``'view_state'``, returns a string (either "NEW" or "NOT_NEW")
* * ``'instance_state'``, returns a string (one of "ALIVE", "NOT_ALIVE_DISPOSED" or "NOT_ALIVE_NO_WRITERS")
* * ``'sample_state'``, returns a string (either "READ" or "NOT_READ")
*
* These fields are documented in `The SampleInfo Structure
* <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>`__
Expand Down
111 changes: 110 additions & 1 deletion test/nodejs/test_rticonnextdds_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,113 @@ describe('Test operations involving meta data', () => {
expect(sample.get('my_string')).to.deep.equals(testJsonObject.my_string)
}
})
})

it('test getting sample_state', async () => {
testOutput.write()
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}

// Since this is the first time that we are accessing the sample, it should
// have a sample state of NOT_READ
testInput.read()
expect(testInput.samples.get(0).info.get('sample_state')).to.deep.equals('NOT_READ')
// Now that we have already accessed the sample once time, accessing it
// again should result in a sample state of READ
testInput.read()
expect(testInput.samples.get(0).info.get('sample_state')).to.deep.equals('READ')
// Taking after a read should also have a sample state of READ
testInput.take()
expect(testInput.samples.get(0).info.get('sample_state')).to.deep.equals('READ')
})

it('test getting instance state', async () => {
testOutput.write()
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}
testInput.take()
// Instance is currently alive
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('ALIVE')
// Disposing the sample should update the instance state
testOutput.write({ action: 'dispose' })
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}
testInput.take()
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('NOT_ALIVE_DISPOSED')
// Writing the sample again should transition it back to alive
testOutput.write()
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}
testInput.take()
// Instance is currently alive
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('ALIVE')
// Unregister the instance to get NO_WRITERS
testOutput.write({ action: 'unregister' })
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}
testInput.take()
expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('NOT_ALIVE_NO_WRITERS')
})

it('test getting sample view state', async () => {
// View state is per-instance
testOutput.instance.setString('my_key_string', 'Brown')
testOutput.write()
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}
testInput.take()
expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NEW')
// Updating that instance should update the view state
testOutput.write()
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}
testInput.take()
expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NOT_NEW')
// Writing a new instance should have a NEW view state
testOutput.instance.setString('my_key_string', 'Maroon')
testOutput.write()
try {
await testInput.wait(testExpectSuccessTimeout)
} catch (err) {
// Fail the test
console.log('Error caught: ' + err)
expect(false).to.deep.equals(true)
}
testInput.take()
expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NEW')
})
})
4 changes: 4 additions & 0 deletions test/xml/TestConnector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ This code contains trade secrets of Real-Time Innovations, Inc.
<initial_instances>1</initial_instances>
<max_instances>5</max_instances>
</resource_limits>
<writer_data_lifecycle>
<autodispose_unregistered_instances>false</autodispose_unregistered_instances>
</writer_data_lifecycle>
</datawriter_qos>
<datareader_qos>
<reliability>
Expand Down Expand Up @@ -133,6 +136,7 @@ This code contains trade secrets of Real-Time Innovations, Inc.
<member name="my_point_alias" type="nonBasic" nonBasicTypeName= "PointAlias" optional="true"/>
<member name="my_int64" type="int64"/>
<member name="my_uint64" type="uint64"/>
<member name="my_key_string" stringMaxLength="128" type="string" key="true"/>
</struct>
</types>

Expand Down