Exemple #1
0
    def gen_full_db_op_set(self, test_label):
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)

        n_set = [n_0, n_1]
        l_set = [l_0]
        topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set)

        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)

        test_rzdoc = generate_random_RZDoc(test_label)

        op_set = [
            DBO_rzdoc__clone(),
            DBO_add_node_set(meta_attr_list_to_meta_attr_map(n_set)),
            DBO_add_link_set(
                meta_attr_list_to_meta_attr_map(l_set, meta_attr='__type')),
            DBO_diff_commit__attr(attr_diff),
            DBO_diff_commit__topo(topo_diff),
            DBO_rm_node_set(id_set=[n_0_id]),

            # block chain
            DBO_block_chain__init(test_rzdoc),
            DBO_block_chain__commit(commit_obj=topo_diff.to_json_dict()),

            # rzdoc
            DBO_rzdoc__create(test_rzdoc),
            DBO_rzdoc__delete(test_rzdoc),
            DBO_rzdoc__list(),
            DBO_rzdoc__lookup_by_name(test_rzdoc.name),
        ]
        return op_set
Exemple #2
0
    def gen_full_db_op_set(self, test_label):
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_1, n_1_id = generate_random_node_dict(test_label)
        l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id)

        n_set = [n_0, n_1]
        l_set = [l_0]
        topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set)

        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)

        test_rzdoc = generate_random_RZDoc(test_label)

        op_set = [
                  DBO_rzdoc__clone(),
                  DBO_add_node_set(meta_attr_list_to_meta_attr_map(n_set)),
                  DBO_add_link_set(meta_attr_list_to_meta_attr_map(l_set, meta_attr='__type')),
                  DBO_diff_commit__attr(attr_diff),
                  DBO_diff_commit__topo(topo_diff),
                  DBO_rm_node_set(id_set=[n_0_id]),

                  # block chain
                  DBO_block_chain__init(test_rzdoc),
                  DBO_block_chain__commit(commit_obj=topo_diff.to_json_dict()),

                  # rzdoc
                  DBO_rzdoc__create(test_rzdoc),
                  DBO_rzdoc__delete(test_rzdoc),
                  DBO_rzdoc__list(),
                  DBO_rzdoc__lookup_by_name(test_rzdoc.name),
                  ]
        return op_set
Exemple #3
0
    def sanitize_input(req):
        rzdoc_name = request.get_json().get('rzdoc_name')
        attr_diff_dict = request.get_json()['attr_diff']
        attr_diff = Attr_Diff.from_json_dict(attr_diff_dict)

        sanitize_input__attr_diff(attr_diff)

        return rzdoc_name, attr_diff;
Exemple #4
0
    def sanitize_input(req):
        rzdoc_name = request.get_json().get('rzdoc_name')
        attr_diff_dict = request.get_json()['attr_diff']
        attr_diff = Attr_Diff.from_json_dict(attr_diff_dict)

        sanitize_input__attr_diff(attr_diff)

        return rzdoc_name, attr_diff
Exemple #5
0
    def test_ws_event__attr_diff(self):
        class NS_test(BaseNamespace):
            def on_diff_commit__attr(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt(
                )  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n, n_id = test_util.generate_random_node_dict(test_label)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_id, 'attr_2')

        def c_0():
            with RZ_websocket(namespace=NS_test) as (_, ns_sock):
                c1_t.switch()  # allow peer to connect
                data = json.dumps(attr_diff)
                ns_sock.emit('diff_commit__attr', data)
                c1_t.switch()

        def c_1():
            with RZ_websocket(namespace=NS_test) as (sock, _):
                c0_t.switch()  # allow peer to emit
                sock.wait(8)  # allow self to receive

        c0_t = greenlet(c_0)
        c1_t = greenlet(c_1)
        c1_t.data = None
        c0_t.switch()

        self.assertTrue(None != c1_t.data)
        self.assertEqual(2, len(c1_t.data))

        diff_in = Attr_Diff.from_json_dict(c1_t.data[0])
        commit_ret = Attr_Diff.from_json_dict(c1_t.data[1])

        self.assertEqual(Attr_Diff, type(diff_in))
        self.assertEqual(Attr_Diff, type(commit_ret))
Exemple #6
0
    def on_diff_commit__attr(self, json_data):

        # FIXME: sanitize input
        json_dict = json.loads(json_data)
        attr_diff = Attr_Diff.from_json_dict(json_dict['attr_diff'])
        log.info('ws: rx: attr diff: ' + str(attr_diff))

        ctx = self.__context__common(json_dict)
        kernel = self.request.kernel
        attr_diff, commit_ret = kernel.diff_commit__attr(attr_diff, ctx)

        # [!] note: here we actually send the attr_diff twice, but in the future
        # commit_ret may not be the same
        return self.multicast_msg('diff_commit__attr', attr_diff, commit_ret)
Exemple #7
0
    def test_ws_event__attr_diff(self):

        class NS_test(BaseNamespace):

            def on_diff_commit__attr(self, *data):
                greenlet.getcurrent().data = data
                raise KeyboardInterrupt()  # TODO: cleanup: properly close socket

        test_label = neo4j_test_util.rand_label()
        n, n_id = test_util.generate_random_node_dict(test_label)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_id, 'attr_2')

        def c_0():
            with RZ_websocket(namespace=NS_test) as (_, ns_sock):
                c1_t.switch()  # allow peer to connect
                data = json.dumps(attr_diff)
                ns_sock.emit('diff_commit__attr', data)
                c1_t.switch()

        def c_1():
            with RZ_websocket(namespace=NS_test) as (sock, _):
                c0_t.switch()  # allow peer to emit
                sock.wait(8)  # allow self to receive

        c0_t = greenlet(c_0)
        c1_t = greenlet(c_1)
        c1_t.data = None
        c0_t.switch()

        self.assertTrue(None != c1_t.data)
        self.assertEqual(2, len(c1_t.data))

        diff_in = Attr_Diff.from_json_dict(c1_t.data[0])
        commit_ret = Attr_Diff.from_json_dict(c1_t.data[1])

        self.assertEqual(Attr_Diff, type(diff_in))
        self.assertEqual(Attr_Diff, type(commit_ret))
Exemple #8
0
    def test_diff_commit__attr(self):
        # create test node
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_0['attr_0'] = 0
        topo_diff = Topo_Diff(node_set_add=[n_0])
        op = DBO_diff_commit__topo(topo_diff)
        self.db_ctl.exec_op(op)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_0_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)

        self.assertEqual(len(ret_diff.type__node), 1)
        self.assertTrue(None != ret_diff.type__node[n_0_id])

        # attr-set only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_2', 0)

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue(None != ret_diff.type__node[n_0_id]['__attr_write'].get('attr_2'))

        # attr-remove only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue('attr_2' in ret_diff.type__node[n_0_id]['__attr_remove'])
Exemple #9
0
    def test_diff_commit__attr(self):
        # create test node
        test_label = neo4j_test_util.rand_label()
        n_0, n_0_id = generate_random_node_dict(test_label)
        n_0['attr_0'] = 0
        topo_diff = Topo_Diff(node_set_add=[n_0])
        op = DBO_diff_commit__topo(topo_diff)
        self.db_ctl.exec_op(op)

        # apply attr_diff
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_0', 0)
        attr_diff.add_node_attr_write(n_0_id, 'attr_1', 'a')
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)

        self.assertEqual(len(ret_diff.type__node), 1)
        self.assertTrue(None != ret_diff.type__node[n_0_id])

        # attr-set only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_write(n_0_id, 'attr_2', 0)

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue(
            None != ret_diff.type__node[n_0_id]['__attr_write'].get('attr_2'))

        # attr-remove only
        attr_diff = Attr_Diff()
        attr_diff.add_node_attr_rm(n_0_id, 'attr_2')

        op = DBO_diff_commit__attr(attr_diff)
        ret_diff = self.db_ctl.exec_op(op)
        self.assertTrue(
            'attr_2' in ret_diff.type__node[n_0_id]['__attr_remove'])