async def test_write_sync_body_int(self): # Given envelope = SyncRequest('bar/baz/', 'foo/bar', body=Num.create_from(42)) expected = '@sync(node:"bar/baz/",lane:"foo/bar")42' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
async def test_write_sync(self): # Given envelope = SyncRequest('foo', 'bar') expected = '@sync(node:foo,lane:bar)' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
async def test_write_sync_escaped(self): # Given envelope = SyncRequest('bar/baz/', 'foo/bar') expected = '@sync(node:"bar/baz/",lane:"foo/bar")' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
async 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 = await envelope.to_recon() # Then self.assertEqual(expected, actual)
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)
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)
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)
async 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 = await envelope.to_recon() # Then self.assertEqual(expected, actual)
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)
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)
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)
async def establish_downlink(self) -> None: """ Send a `sync` request in order to initiate a connection to a lane from the remote agent. """ sync_request = SyncRequest(self.node_uri, self.lane_uri) await self.connection.send_message(await sync_request.to_recon())