def _create_node_with_services(num):
     nid = 'cbd_node%s' % num
     nodes.append(dse_node.DseNode(self.messaging_config, nid, []))
     ns = []
     for s in range(num):
         # intentionally starting different number services
         ns.append(data_service.DataService('cbd-%d_svc-%d' % (num, s)))
         nodes[-1].register_service(ns[-1])
     services.append(ns)
     return nodes[-1]
Esempio n. 2
0
 def test_info(self):
     ds = data_service.DataService("svc1")
     node = mock.MagicMock()
     node.node_id = 'testnode'
     ds.node = node
     info = ds.info
     self.assertEqual(info.service_id, 'svc1')
     self.assertEqual(info.node_id, 'testnode')
     self.assertEqual(info.published_tables, [])
     self.assertEqual(info.subscribed_tables, [])
     self.assertEqual(info.rpc_endpoints_info, [])
Esempio n. 3
0
 def test_start_stop(self):
     ds = data_service.DataService("svc1")
     ds.node = mock.MagicMock()
     ds._rpc_server = mock.MagicMock()
     self.assertEqual(ds._running, False,
                      "Newly created service is marked as not running")
     ds.start()
     self.assertEqual(ds._running, True,
                      "Started service is marked as running")
     ds.stop()
     self.assertEqual(ds._running, False,
                      "Stopped service is marked as not running")
Esempio n. 4
0
    def test_service_info(self):
        ds = data_service.DataService("svc1")
        ds.node = mock.MagicMock()
        ds.node.node_id = 'node-id'
        ds._published_tables_with_subscriber = set(['table1'])

        expected_result = {
            'service_id': 'svc1',
            'node_id': 'node-id',
            'published_tables': [],
            'subscribed_tables': set(['table1']),
            'rpc_endpoints_info': []
        }

        self.assertEqual(expected_result, ds.info.to_dict())
Esempio n. 5
0
    def test_start_stop(self):
        # create node and register services
        node = helper.make_dsenode_new_partition('test_node',
                                                 self.messaging_config, [])
        services = []
        for i in range(2):
            service = data_service.DataService('test-service-%s' % i)
            node.register_service(service)
            services.append(service)
        for s in node.get_services(True):
            self.assertTrue(s._running,
                            "Service '%s' started" % str(s))
        self.assertEqual(set(services), set(node.get_services()),
                         "All services accounted for on node.")
        self.assertTrue(node._rpc_server._started,
                        "RPC server is started")
        self.assertTrue(node._control_bus._running,
                        "Control Bus is started")

        # stop node
        node.stop()
        node.wait()
        self.assertFalse(node._running,
                         "Node is stopped after node start")
        for idx, s in enumerate(node.get_services(True)):
            self.assertFalse(s._running,
                             "Service '%s' stopped after node stop" % str(s))
        # TODO(pballand): fix bug
        # self.assertFalse(node._rpc_server._started,
        #                  "RPC server is stopped after node stop")
        self.assertFalse(node._control_bus._running,
                         "Control Bus is stopped after node stop")

        # restart node
        node.start()
        for s in node.get_services(True):
            self.assertTrue(s._running,
                            "Service '%s' started" % str(s))
        self.assertEqual(set(services), set(node.get_services()),
                         "All services accounted for on node.")
        self.assertTrue(node._rpc_server._started,
                        "RPC server is started")
        self.assertTrue(node._control_bus._running,
                        "Control Bus is started")