def test_write_sync_escaped(self):
        # Given
        envelope = _SyncRequest('bar/baz/', 'foo/bar')
        expected = '@sync(node:"bar/baz/",lane:"foo/bar")'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_sync(self):
        # Given
        envelope = _SyncRequest('foo', 'bar')
        expected = '@sync(node:foo,lane:bar)'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_sync_body_string(self):
        # Given
        envelope = _SyncRequest('bar/baz/',
                                'foo/bar',
                                body=Text.create_from('Hello, World!'))
        expected = '@sync(node:"bar/baz/",lane:"foo/bar")"Hello, World!"'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_sync_body_bool(self):
        # Given
        envelope = _SyncRequest('bar/baz/',
                                'foo/bar',
                                body=Bool.create_from(False))
        expected = '@sync(node:"bar/baz/",lane:"foo/bar")false'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_sync_body_float(self):
        # Given
        envelope = _SyncRequest('bar/baz/',
                                'foo/bar',
                                body=Num.create_from(33.22))
        expected = '@sync(node:"bar/baz/",lane:"foo/bar")33.22'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
    def test_write_sync_prio_rate(self):
        # Given
        envelope = _SyncRequest('bar/baz/',
                                'foo/bar',
                                prio=33.2,
                                rate=0.3,
                                body=Text.create_from('Hello, World!'))
        expected = '@sync(node:"bar/baz/",lane:"foo/bar",prio:33.2,rate:0.3)"Hello, World!"'

        # When
        actual = envelope._to_recon()

        # Then
        self.assertEqual(expected, actual)
Example #7
0
 def test_link_addressed_form_mold_prio_zero(self):
     # Given
     envelope = _SyncRequest('node_foo', 'lane_bar', prio=0, rate=2.5)
     form = _SyncRequestForm()
     # When
     actual = form._mold(envelope)
     # Then
     self.assertIsInstance(actual, RecordMap)
     self.assertEqual('node_foo',
                      actual.get_item(0).value.get_item(0).value.value)
     self.assertEqual('lane_bar',
                      actual.get_item(0).value.get_item(1).value.value)
     self.assertEqual('rate',
                      actual.get_item(0).value.get_item(2).key.value)
     self.assertEqual(2.5, actual.get_item(0).value.get_item(2).value.value)
Example #8
0
 def test_sync_request_empty_body(self):
     # Given
     node_uri = 'foo__sync_node'
     lane_uri = 'bar__sync_lane'
     # When
     actual = _SyncRequest(node_uri, lane_uri)
     # Then
     self.assertEqual('foo__sync_node', actual._node_uri)
     self.assertEqual('bar__sync_lane', actual._lane_uri)
     self.assertEqual(0.0, actual._prio)
     self.assertEqual(0.0, actual._rate)
     self.assertEqual('sync', actual._tag)
     self.assertEqual('foo__sync_node/bar__sync_lane', actual._route)
     self.assertEqual(_Absent._get_absent(), actual._body)
     self.assertIsInstance(actual._form, _SyncRequestForm)
Example #9
0
 def test_link_addressed_form_mold_prio_nan(self):
     # Given
     envelope = _SyncRequest('synced_node',
                             'synced_lane',
                             prio=math.nan,
                             rate=3.4)
     form = _SyncRequestForm()
     # When
     actual = form._mold(envelope)
     # Then
     self.assertIsInstance(actual, RecordMap)
     self.assertEqual('synced_node',
                      actual.get_item(0).value.get_item(0).value.value)
     self.assertEqual('synced_lane',
                      actual.get_item(0).value.get_item(1).value.value)
     self.assertEqual('rate',
                      actual.get_item(0).value.get_item(2).key.value)
     self.assertEqual(3.4, actual.get_item(0).value.get_item(2).value.value)
Example #10
0
 def test_sync_request_existing_body(self):
     # Given
     node_uri = 'foo_sync_node'
     lane_uri = 'bar_sync_lane'
     body = Text.create_from('Sync_Body')
     priority = 3.5
     rate = 2.0
     # When
     actual = _SyncRequest(node_uri, lane_uri, priority, rate, body=body)
     # Then
     self.assertEqual('foo_sync_node', actual._node_uri)
     self.assertEqual('bar_sync_lane', actual._lane_uri)
     self.assertEqual(3.5, actual._prio)
     self.assertEqual(2.0, actual._rate)
     self.assertEqual('sync', actual._tag)
     self.assertEqual('foo_sync_node/bar_sync_lane', actual._route)
     self.assertEqual(body, actual._body)
     self.assertIsInstance(actual._form, _SyncRequestForm)
Example #11
0
 def test_link_addressed_form_mold_rate_nan(self):
     # Given
     envelope = _SyncRequest('node_baz',
                             'lane_qux',
                             prio=13.4,
                             rate=math.nan)
     form = _SyncRequestForm()
     # When
     actual = form._mold(envelope)
     # Then
     self.assertIsInstance(actual, RecordMap)
     self.assertEqual('node_baz',
                      actual.get_item(0).value.get_item(0).value.value)
     self.assertEqual('lane_qux',
                      actual.get_item(0).value.get_item(1).value.value)
     self.assertEqual('prio',
                      actual.get_item(0).value.get_item(2).key.value)
     self.assertEqual(13.4,
                      actual.get_item(0).value.get_item(2).value.value)
Example #12
0
 def test_sync_form_mold(self):
     # Given
     form = _SyncRequestForm()
     envelope = _SyncRequest('sync_node',
                             'sync_lane',
                             prio=99.1,
                             rate=41.42,
                             body=Text.create_from('Moo'))
     # When
     actual = form._mold(envelope)
     # Then
     self.assertIsInstance(actual, RecordMap)
     self.assertEqual(2, actual.size)
     self.assertEqual('sync', actual._tag)
     self.assertEqual('sync_node',
                      actual.get_item(0).value.get_item(0).value.value)
     self.assertEqual('sync_lane',
                      actual.get_item(0).value.get_item(1).value.value)
     self.assertEqual(99.1,
                      actual.get_item(0).value.get_item(2).value.value)
     self.assertEqual(41.42,
                      actual.get_item(0).value.get_item(3).value.value)
     self.assertEqual('Moo', actual.get_item(1).value)
Example #13
0
 async def _establish_downlink(self) -> None:
     sync_request = _SyncRequest(self.node_uri, self.lane_uri)
     await self.connection._send_message(sync_request._to_recon())