def get_metadata_to_write(self, metadata): """ Override VirtualConnection.get_metadata_to_write() """ if self.cluster_peer_id == RESERVED_CLUSTER_PEER_ID: self.close_with_error( "PeerShardConnection: remote is using reserved cluster peer id which is prohibited" ) return ClusterMetadata(self.shard_state.branch, self.cluster_peer_id)
def test_forward(self): meta = ClusterMetadata(FORWARD_BRANCH, CLUSTER_PEER_ID) metaBytes = meta.serialize() request = DummyPackage(999) requestsBytes = request.serialize() requestSizeBytes = len(requestsBytes).to_bytes(4, byteorder="big") rawData = bytearray() rawData += bytes([OP]) rawData += RPC_ID.to_bytes(8, byteorder="big") rawData += requestsBytes reader = AsyncMock() writer = MagicMock() reader.read.side_effect = [requestSizeBytes, metaBytes, rawData] conn = DummyClusterConnection(DEFAULT_ENV, reader, writer) asyncio.get_event_loop().run_until_complete(conn.loop_once()) conn.mockP2PConnection.write_raw_data.assert_called_once_with( P2PMetadata(FORWARD_BRANCH), rawData)
def get_metadata_to_write(self, metadata): """ Override VirtualConnection.get_metadata_to_write() """ return ClusterMetadata(self.shard_state.branch, self.cluster_peer_id)