def test_broadcast_service_rpc(self): part = helper.get_new_partition() nodes = [] services = [] for i in range(3): nid = 'svc_rpc_node%s' % i node = helper.make_dsenode_same_partition( part, nid, self.messaging_config) service = _PingRpcService('tbsr_svc', nid) node.register_service(service) nodes.append(node) services.append(service) # Send from each node to all services for i, source in enumerate(nodes): scounts = [] for j, target in enumerate(nodes): ep = nodes[j]._services[-1].endpoints[0] scounts.append(ep.ping_receive_count) source.broadcast_service_rpc('tbsr_svc', 'ping', arg1=1, arg2='a') eventlet.sleep(0.5) # wait for async delivery for j, target in enumerate(nodes): ep = nodes[j]._services[-1].endpoints[0] ecount = ep.ping_receive_count self.assertEqual(ecount - scounts[j], 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, source.node_id)) self.assertEqual( ep.ping_received_from[-1]['node_id'], source.node_id, "Last ping received on %s was from %s" % ( nodes[j].node_id, source.node_id))
def test_node_broadcast_rpc(self): """Validate calling RPCs on DseNode""" part = helper.get_new_partition() nodes = [] endpoints = [] for i in range(3): nid = 'rpcnode%s' % i endpoints.append(_PingRpcEndpoint(nid)) nodes.append( helper.make_dsenode_same_partition( part, nid, self.messaging_config, [endpoints[-1]])) # Send from each node to all other nodes for i, source in enumerate(nodes): scounts = [] for j, target in enumerate(nodes): scounts.append(endpoints[j].ping_receive_count) source.broadcast_node_rpc('ping', arg1=1, arg2='a') eventlet.sleep(0.5) # wait for async delivery for j, target in enumerate(nodes): ecount = endpoints[j].ping_receive_count self.assertEqual(ecount - scounts[j], 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, source.node_id)) self.assertEqual( endpoints[j].ping_received_from[-1]['node_id'], source.node_id, "Last ping received on %s was from %s" % ( nodes[j].node_id, source.node_id))
def test_service_rpc(self): part = helper.get_new_partition() nodes = [] services = [] for i in range(3): nid = 'svc_rpc_node%s' % i node = helper.make_dsenode_same_partition( part, nid, self.messaging_config) service = _PingRpcService('srpc_node_svc%s' % i, nid) node.register_service(service) nodes.append(node) services.append(service) # Send from each node to each other node for i, source in enumerate(nodes): # intentionally including self in RPC target for j, service in enumerate(services): ep = nodes[j]._services[-1].endpoints[0] scount = ep.ping_receive_count args = {'arg1': 1, 'arg2': 'a'} ret = source.invoke_service_rpc(service.service_id, 'ping', **args) self.assertEqual(ret, args, "Ping echoed arguments") ecount = ep.ping_receive_count self.assertEqual(ecount - scount, 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, nodes[i].node_id)) self.assertEqual( ep.ping_received_from[-1]['node_id'], nodes[i].node_id, "Last ping received on %s was from %s" % ( nodes[j].node_id, nodes[i].node_id))
def test_broadcast_service_rpc(self): part = helper.get_new_partition() nodes = [] services = [] for i in range(3): nid = 'svc_rpc_node%s' % i node = helper.make_dsenode_same_partition(part, nid, self.messaging_config) service = _PingRpcService('tbsr_svc', nid) node.register_service(service) nodes.append(node) services.append(service) # Send from each node to all services for i, source in enumerate(nodes): scounts = [] for j, target in enumerate(nodes): ep = nodes[j]._services[-1].endpoints[0] scounts.append(ep.ping_receive_count) source.broadcast_service_rpc('tbsr_svc', 'ping_test', { 'arg1': 1, 'arg2': 'a' }) eventlet.sleep(0.5) # wait for async delivery for j, target in enumerate(nodes): ep = nodes[j]._services[-1].endpoints[0] ecount = ep.ping_receive_count self.assertEqual( ecount - scounts[j], 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, source.node_id)) self.assertEqual( ep.ping_received_from[-1]['node_id'], source.node_id, "Last ping received on %s was from %s" % (nodes[j].node_id, source.node_id))
def test_node_rpc(self): """Validate calling RPCs on DseNode""" part = helper.get_new_partition() nodes = [] endpoints = [] for i in range(3): nid = 'rpcnode%s' % i endpoints.append(_PingRpcEndpoint(nid)) nodes.append( helper.make_dsenode_same_partition( part, nid, self.messaging_config, [endpoints[-1]])) # Send from each node to each other node for i, source in enumerate(nodes): # intentionally including self in RPC target for j, target in enumerate(nodes): scount = endpoints[j].ping_receive_count args = {'arg1': 1, 'arg2': 'a'} ret = source.invoke_node_rpc(target.node_id, 'ping', **args) self.assertEqual(ret, args, "Ping echoed arguments") ecount = endpoints[j].ping_receive_count self.assertEqual(ecount - scount, 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, nodes[i].node_id)) self.assertEqual( endpoints[j].ping_received_from[-1]['node_id'], nodes[i].node_id, "Last ping received on %s was from %s" % ( nodes[j].node_id, nodes[i].node_id))
def test_service_rpc(self): part = helper.get_new_partition() nodes = [] services = [] for i in range(3): nid = 'svc_rpc_node%s' % i node = helper.make_dsenode_same_partition(part, nid, self.messaging_config) service = _PingRpcService('srpc_node_svc%s' % i, nid) node.register_service(service) nodes.append(node) services.append(service) # Send from each node to each other node for i, source in enumerate(nodes): # intentionally including self in RPC target for j, service in enumerate(services): ep = nodes[j]._services[-1].endpoints[0] scount = ep.ping_receive_count args = {'arg1': 1, 'arg2': 'a'} ret = source.invoke_service_rpc(service.service_id, 'ping_test', args) self.assertEqual(ret, args, "Ping echoed arguments") ecount = ep.ping_receive_count self.assertEqual( ecount - scount, 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, nodes[i].node_id)) self.assertEqual( ep.ping_received_from[-1]['node_id'], nodes[i].node_id, "Last ping received on %s was from %s" % (nodes[j].node_id, nodes[i].node_id))
def test_node_broadcast_rpc(self): """Validate calling RPCs on DseNode""" part = helper.get_new_partition() nodes = [] endpoints = [] for i in range(3): nid = 'rpcnode%s' % i endpoints.append(_PingRpcEndpoint(nid)) nodes.append( helper.make_dsenode_same_partition(part, nid, self.messaging_config, [endpoints[-1]])) # Send from each node to all other nodes for i, source in enumerate(nodes): scounts = [] for j, target in enumerate(nodes): scounts.append(endpoints[j].ping_receive_count) source.broadcast_node_rpc('ping_test', {'arg1': 1, 'arg2': 'a'}) eventlet.sleep(0.5) # wait for async delivery for j, target in enumerate(nodes): ecount = endpoints[j].ping_receive_count self.assertEqual( ecount - scounts[j], 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, source.node_id)) self.assertEqual( endpoints[j].ping_received_from[-1]['node_id'], source.node_id, "Last ping received on %s was from %s" % (nodes[j].node_id, source.node_id))
def test_node_rpc(self): """Validate calling RPCs on DseNode""" part = helper.get_new_partition() nodes = [] endpoints = [] for i in range(3): nid = 'rpcnode%s' % i endpoints.append(_PingRpcEndpoint(nid)) nodes.append( helper.make_dsenode_same_partition(part, nid, self.messaging_config, [endpoints[-1]])) # Send from each node to each other node for i, source in enumerate(nodes): # intentionally including self in RPC target for j, target in enumerate(nodes): scount = endpoints[j].ping_receive_count args = {'arg1': 1, 'arg2': 'a'} ret = source.invoke_node_rpc(target.node_id, 'ping_test', args) self.assertEqual(ret, args, "Ping echoed arguments") ecount = endpoints[j].ping_receive_count self.assertEqual( ecount - scount, 1, "Node %s received ping (%s was sending)" % (nodes[j].node_id, nodes[i].node_id)) self.assertEqual( endpoints[j].ping_received_from[-1]['node_id'], nodes[i].node_id, "Last ping received on %s was from %s" % (nodes[j].node_id, nodes[i].node_id))
def test_context(self): # Context must not only rely on node_id to prohibit multiple instances # of a node_id on the DSE part = helper.get_new_partition() n1 = helper.make_dsenode_same_partition(part, 'node_id', self.messaging_config, []) n2 = helper.make_dsenode_same_partition(part, 'node_id', self.messaging_config, []) self.assertEqual(n1._message_context, n1._message_context, "Comparison of context from the same node is equal") self.assertNotEqual(n1._message_context, n2._message_context, "Comparison of context from the different nodes " "is not equal")
def test_subs_list_update_aggregated_by_service(self): part = helper.get_new_partition() nodes = [] services = [] num_nodes = 3 for i in range(num_nodes): n = self._create_node_with_services(nodes, services, i, part) n.start() # add subscriptions for i in range(2, num_nodes): for s2 in services[i]: for s1 in services[i - 1]: s1.subscribe(s2.service_id, 'table-A') s2.subscribe(s1.service_id, 'table-B') services[1][0].subscribe(services[2][0].service_id, 'table-C') services[2][1].subscribe(services[2][0].service_id, 'table-D') # constructed expected results expected_subbed_tables = {} expected_subbed_tables[nodes[1].node_id] = {} expected_subbed_tables[nodes[2].node_id] = {} expected_subbed_tables[nodes[1].node_id][ services[1][0].service_id] = set(['table-B']) expected_subbed_tables[nodes[2].node_id][ services[2][0].service_id] = set(['table-A', 'table-C', 'table-D']) expected_subbed_tables[nodes[2].node_id][ services[2][1].service_id] = set(['table-A']) # validate def _validate_subbed_tables(node): for s in node.get_services(): sid = s.service_id subscribed_tables = node.service_object( sid)._published_tables_with_subscriber self.assertEqual( subscribed_tables, expected_subbed_tables[node.node_id][sid], '%s has incorrect subscribed tables list' % sid) return True for n in nodes: helper.retry_check_function_return_value( lambda: _validate_subbed_tables(n), True) # selectively unsubscribe services[1][0].unsubscribe(services[2][0].service_id, 'table-A') # note that services[2][1] still subscribes to 'table-B' services[2][0].unsubscribe(services[1][0].service_id, 'table-B') # extraneous unsubscribe services[2][0].unsubscribe(services[1][0].service_id, 'table-None') # update expected results expected_subbed_tables[nodes[2].node_id][ services[2][0].service_id] = set(['table-C', 'table-D']) for n in nodes: helper.retry_check_function_return_value( lambda: _validate_subbed_tables(n), True) # resubscribe services[1][0].subscribe(services[2][0].service_id, 'table-A') services[2][0].subscribe(services[1][0].service_id, 'table-B') # update expected results expected_subbed_tables[nodes[2].node_id][ services[2][0].service_id] = set(['table-A', 'table-C', 'table-D']) for n in nodes: helper.retry_check_function_return_value( lambda: _validate_subbed_tables(n), True)
def test_subs_list_update_aggregated_by_service(self): part = helper.get_new_partition() nodes = [] services = [] num_nodes = 3 for i in range(num_nodes): n = self._create_node_with_services(nodes, services, i, part) n.start() # add subscriptions for i in range(2, num_nodes): for s2 in services[i]: for s1 in services[i-1]: s1.subscribe(s2.service_id, 'table-A') s2.subscribe(s1.service_id, 'table-B') services[1][0].subscribe(services[2][0].service_id, 'table-C') services[2][1].subscribe(services[2][0].service_id, 'table-D') # constructed expected results expected_subbed_tables = {} expected_subbed_tables[nodes[1].node_id] = {} expected_subbed_tables[nodes[2].node_id] = {} expected_subbed_tables[nodes[1].node_id][ services[1][0].service_id] = set(['table-B']) expected_subbed_tables[nodes[2].node_id][ services[2][0].service_id] = set(['table-A', 'table-C', 'table-D']) expected_subbed_tables[nodes[2].node_id][ services[2][1].service_id] = set(['table-A']) # validate def _validate_subbed_tables(node): for s in node.get_services(): sid = s.service_id subscribed_tables = node.service_object( sid)._published_tables_with_subscriber self.assertEqual( subscribed_tables, expected_subbed_tables[node.node_id][sid], '%s has incorrect subscribed tables list' % sid) return True for n in nodes: helper.retry_check_function_return_value( lambda: _validate_subbed_tables(n), True) # selectively unsubscribe services[1][0].unsubscribe(services[2][0].service_id, 'table-A') # note that services[2][1] still subscribes to 'table-B' services[2][0].unsubscribe(services[1][0].service_id, 'table-B') # extraneous unsubscribe services[2][0].unsubscribe(services[1][0].service_id, 'table-None') # update expected results expected_subbed_tables[nodes[2].node_id][ services[2][0].service_id] = set(['table-C', 'table-D']) for n in nodes: helper.retry_check_function_return_value( lambda: _validate_subbed_tables(n), True) # resubscribe services[1][0].subscribe(services[2][0].service_id, 'table-A') services[2][0].subscribe(services[1][0].service_id, 'table-B') # update expected results expected_subbed_tables[nodes[2].node_id][ services[2][0].service_id] = set(['table-A', 'table-C', 'table-D']) for n in nodes: helper.retry_check_function_return_value( lambda: _validate_subbed_tables(n), True)