From 56cc3697ab25db788a9148d17deb32049133ff4a Mon Sep 17 00:00:00 2001 From: Sam Raeburn Date: Wed, 29 Jan 2020 14:27:37 -0800 Subject: [PATCH 1/2] CON-177: Added support for sample/view/instance state --- rticonnextdds-connector.js | 3 + test/nodejs/test_rticonnextdds_metadata.js | 109 +++++++++++++++++++++ test/xml/TestConnector.xml | 4 + 3 files changed, 116 insertions(+) diff --git a/rticonnextdds-connector.js b/rticonnextdds-connector.js index 643bf2b3..506da437 100644 --- a/rticonnextdds-connector.js +++ b/rticonnextdds-connector.js @@ -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 + * * ``'sample_state'`` returns a string + * * ``'instance_state'`` returns a string * * These fields are documented in `The SampleInfo Structure * `__ diff --git a/test/nodejs/test_rticonnextdds_metadata.js b/test/nodejs/test_rticonnextdds_metadata.js index 73e6da3f..6992efc8 100644 --- a/test/nodejs/test_rticonnextdds_metadata.js +++ b/test/nodejs/test_rticonnextdds_metadata.js @@ -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('DDS_NOT_READ_SAMPLE_STATE') + // 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('DDS_READ_SAMPLE_STATE') + // 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('DDS_READ_SAMPLE_STATE') + }) + + 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('DDS_ALIVE_INSTANCE_STATE') + // 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('DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE') + // 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('DDS_ALIVE_INSTANCE_STATE') + // 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('DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE') + }) + + 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('DDS_NEW_VIEW_STATE') + // 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('DDS_NOT_NEW_VIEW_STATE') + // 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('DDS_NEW_VIEW_STATE') + }) }) \ No newline at end of file diff --git a/test/xml/TestConnector.xml b/test/xml/TestConnector.xml index 6b0fc121..d486caac 100644 --- a/test/xml/TestConnector.xml +++ b/test/xml/TestConnector.xml @@ -39,6 +39,9 @@ This code contains trade secrets of Real-Time Innovations, Inc. 1 5 + + false + @@ -133,6 +136,7 @@ This code contains trade secrets of Real-Time Innovations, Inc. + From d243deccfc64594448e25a06aa6714ebea26b117 Mon Sep 17 00:00:00 2001 From: Sam Raeburn Date: Mon, 10 Feb 2020 13:10:23 +0100 Subject: [PATCH 2/2] CON-177: PR feedback - Indicate possible values of the new fields in the docs - Use the naming conventions for strings in unit tests --- rticonnextdds-connector.js | 6 +++--- test/nodejs/test_rticonnextdds_metadata.js | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rticonnextdds-connector.js b/rticonnextdds-connector.js index 506da437..a01c2120 100644 --- a/rticonnextdds-connector.js +++ b/rticonnextdds-connector.js @@ -453,9 +453,9 @@ class SampleIterator { * (see :meth:`Output.write`) * * ``'valid_data'`` returns a boolean (equivalent to * :attr:`SampleIterator.validData`) - * * ``'view_state'`` returns a string - * * ``'sample_state'`` returns a string - * * ``'instance_state'`` returns a string + * * ``'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 * `__ diff --git a/test/nodejs/test_rticonnextdds_metadata.js b/test/nodejs/test_rticonnextdds_metadata.js index 6992efc8..ffad0734 100644 --- a/test/nodejs/test_rticonnextdds_metadata.js +++ b/test/nodejs/test_rticonnextdds_metadata.js @@ -221,14 +221,14 @@ describe('Test operations involving meta data', () => { // 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('DDS_NOT_READ_SAMPLE_STATE') + 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('DDS_READ_SAMPLE_STATE') + 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('DDS_READ_SAMPLE_STATE') + expect(testInput.samples.get(0).info.get('sample_state')).to.deep.equals('READ') }) it('test getting instance state', async () => { @@ -242,7 +242,7 @@ describe('Test operations involving meta data', () => { } testInput.take() // Instance is currently alive - expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('DDS_ALIVE_INSTANCE_STATE') + 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 { @@ -253,7 +253,7 @@ describe('Test operations involving meta data', () => { expect(false).to.deep.equals(true) } testInput.take() - expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('DDS_NOT_ALIVE_DISPOSED_INSTANCE_STATE') + 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 { @@ -265,7 +265,7 @@ describe('Test operations involving meta data', () => { } testInput.take() // Instance is currently alive - expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('DDS_ALIVE_INSTANCE_STATE') + 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 { @@ -276,7 +276,7 @@ describe('Test operations involving meta data', () => { expect(false).to.deep.equals(true) } testInput.take() - expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('DDS_NOT_ALIVE_NO_WRITERS_INSTANCE_STATE') + expect(testInput.samples.get(0).info.get('instance_state')).to.deep.equals('NOT_ALIVE_NO_WRITERS') }) it('test getting sample view state', async () => { @@ -291,7 +291,7 @@ describe('Test operations involving meta data', () => { expect(false).to.deep.equals(true) } testInput.take() - expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('DDS_NEW_VIEW_STATE') + expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NEW') // Updating that instance should update the view state testOutput.write() try { @@ -302,7 +302,7 @@ describe('Test operations involving meta data', () => { expect(false).to.deep.equals(true) } testInput.take() - expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('DDS_NOT_NEW_VIEW_STATE') + 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() @@ -314,6 +314,6 @@ describe('Test operations involving meta data', () => { expect(false).to.deep.equals(true) } testInput.take() - expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('DDS_NEW_VIEW_STATE') + expect(testInput.samples.get(0).info.get('view_state')).to.deep.equals('NEW') }) -}) \ No newline at end of file +})