From a6b3ac5d3291fdb4233cf2d25bddd5e8f10e5e5f Mon Sep 17 00:00:00 2001 From: Ferran Llamas Date: Tue, 6 Feb 2024 13:23:10 +0100 Subject: [PATCH] fix (#1805) --- .../cluster/standalone/grpc_node_binding.py | 2 + .../common/cluster/standalone/test_service.py | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/nucliadb/nucliadb/common/cluster/standalone/grpc_node_binding.py b/nucliadb/nucliadb/common/cluster/standalone/grpc_node_binding.py index b1b4532acc..1bc5e9ea75 100644 --- a/nucliadb/nucliadb/common/cluster/standalone/grpc_node_binding.py +++ b/nucliadb/nucliadb/common/cluster/standalone/grpc_node_binding.py @@ -409,6 +409,8 @@ async def GC(self, request: ShardId) -> EmptyResponse: "RelationSearch": (RelationSearchRequest, RelationSearchResponse), "GetShard": (GetShardRequest, NodeResourcesShard), "Suggest": (SuggestRequest, SuggestResponse), + "RelationEdges": (ShardId, EdgeList), + "RelationTypes": (ShardId, TypeList), } WRITER_METHODS = { "NewShard": (ShardMetadata, ShardCreated), diff --git a/nucliadb/nucliadb/tests/unit/common/cluster/standalone/test_service.py b/nucliadb/nucliadb/tests/unit/common/cluster/standalone/test_service.py index f26f6277cf..b85ba5304d 100644 --- a/nucliadb/nucliadb/tests/unit/common/cluster/standalone/test_service.py +++ b/nucliadb/nucliadb/tests/unit/common/cluster/standalone/test_service.py @@ -22,6 +22,8 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest +from nucliadb_protos.noderesources_pb2 import ShardId +from nucliadb_protos.utils_pb2 import RelationNode from nucliadb.common.cluster.settings import Settings from nucliadb.common.cluster.standalone import service @@ -48,6 +50,20 @@ def self_node(cluster_settings): self_node.writer = AsyncMock() self_node.reader.Search.return_value = nodereader_pb2.SearchResponse() + relation_types = nodereader_pb2.TypeList() + member = nodereader_pb2.RelationTypeListMember( + with_type=RelationNode.NodeType.ENTITY, with_subtype="foo" + ) + relation_types.list.append(member) + self_node.reader.RelationTypes.return_value = relation_types + + relation_edges = nodereader_pb2.EdgeList() + edge = nodereader_pb2.RelationEdge( + edge_type=RelationNode.NodeType.ENTITY, property="foo" + ) + relation_edges.list.append(edge) + self_node.reader.RelationEdges.return_value = relation_edges + with patch("nucliadb.common.cluster.standalone.service.get_self") as mock_get_self: mock_get_self.return_value = self_node yield self_node @@ -76,6 +92,36 @@ async def test_node_action( ) +async def test_reader_node_action_relations( + servicer: service.StandaloneClusterServiceServicer, + self_node, + cluster_settings, +): + resp = await servicer.NodeAction( + standalone_pb2.NodeActionRequest( + service="reader", + action="RelationTypes", + payload=ShardId(id="test").SerializeToString(), + ), + None, + ) + assert resp == standalone_pb2.NodeActionResponse( + payload=self_node.reader.RelationTypes.return_value.SerializeToString() + ) + + resp = await servicer.NodeAction( + standalone_pb2.NodeActionRequest( + service="reader", + action="RelationEdges", + payload=ShardId(id="test").SerializeToString(), + ), + None, + ) + assert resp == standalone_pb2.NodeActionResponse( + payload=self_node.reader.RelationEdges.return_value.SerializeToString() + ) + + async def test_node_info( servicer: service.StandaloneClusterServiceServicer, self_node, cluster_settings ):