Ejemplo n.º 1
0
    def testGlobalIndex(self):
        time.sleep(2)
        lindex = {}
        lindex['Harald'] = [calvinuuid.uuid("NODE") for i in range(1,5)]
        lindex['Per'] = [calvinuuid.uuid("NODE") for i in range(1,5)]
        common = calvinuuid.uuid("NODE")

        for n, node_ids in lindex.items():
            for id_ in node_ids:
                #print "ADD", n, id_
                utils.add_index(self.rt1, "node/affiliation/owner/com.ericsson/" + n, id_)

        h = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson")

        assert(set(h['result']) == set(lindex["Harald"]))
        assert(set(p['result']) == set(lindex["Per"]))
        assert(set(e['result']) == set(lindex["Per"] + lindex["Harald"]))

        for n, node_ids in lindex.items():
            utils.remove_index(self.rt1, "node/affiliation/owner/com.ericsson/" + n, node_ids[0])

        h = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson")

        assert(set(h['result']) == set(lindex["Harald"][1:]))
        assert(set(p['result']) == set(lindex["Per"][1:]))
        assert(set(e['result']) == set(lindex["Per"][1:] + lindex["Harald"][1:]))

        utils.add_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald", common)
        utils.add_index(self.rt1, "node/affiliation/owner/com.ericsson/Per", common)

        h = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson")

        assert(set(h['result']) == set(lindex["Harald"][1:] + [common]))
        assert(set(p['result']) == set(lindex["Per"][1:] + [common]))
        assert(set(e['result']) == set(lindex["Per"][1:] + lindex["Harald"][1:] + [common]))

        for node_id in lindex['Harald']:
            utils.remove_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald", node_id)

        h = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson")

        assert(set(h['result']) == set([common]))
        assert(set(p['result']) == set(lindex["Per"][1:] + [common]))
        assert(set(e['result']) == set(lindex["Per"][1:] + [common]))
Ejemplo n.º 2
0
    def testLocalIndex(self):
        # We don't have a way of preventing DHT storage from starting,
        # but if this test is run first the storage is not yet up and running
        lindex = {}
        lindex['Harald'] = [calvinuuid.uuid("NODE") for i in range(1,5)]
        lindex['Per'] = [calvinuuid.uuid("NODE") for i in range(1,5)]
        common = calvinuuid.uuid("NODE")

        for n, node_ids in lindex.items():
            for id_ in node_ids:
                #print "ADD", n, id_
                utils.add_index(self.rt1, "node/affiliation/owner/com.ericsson/" + n, id_)

        h_ = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Harald")
        h = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson")

        assert(h_['result'] is None)  # Test that the storage is local
        assert(set(h['result']) == set(lindex["Harald"]))
        assert(set(p['result']) == set(lindex["Per"]))
        assert(set(e['result']) == set(lindex["Per"] + lindex["Harald"]))

        for n, node_ids in lindex.items():
            utils.remove_index(self.rt1, "node/affiliation/owner/com.ericsson/" + n, node_ids[0])

        h = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson")

        assert(set(h['result']) == set(lindex["Harald"][1:]))
        assert(set(p['result']) == set(lindex["Per"][1:]))
        assert(set(e['result']) == set(lindex["Per"][1:] + lindex["Harald"][1:]))

        utils.add_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald", common)
        utils.add_index(self.rt1, "node/affiliation/owner/com.ericsson/Per", common)

        h = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson")

        assert(set(h['result']) == set(lindex["Harald"][1:] + [common]))
        assert(set(p['result']) == set(lindex["Per"][1:] + [common]))
        assert(set(e['result']) == set(lindex["Per"][1:] + lindex["Harald"][1:] + [common]))

        for node_id in lindex['Harald']:
            utils.remove_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald", node_id)

        h = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt1, "node/affiliation/owner/com.ericsson")
        h_ = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Harald")

        if h_['result'] is not None:
            # Test that the storage is local
            warn("Storage is no longer only local, it had time to start %s" % h_['result'])
        assert(set(h['result']) == set([common]))
        assert(set(p['result']) == set(lindex["Per"][1:] + [common]))
        assert(set(e['result']) == set(lindex["Per"][1:] + [common]))

        time.sleep(2)
        h = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Harald")
        p = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson/Per")
        e = utils.get_index(self.rt2, "node/affiliation/owner/com.ericsson")

        assert(set(h['result']) == set([common]))
        assert(set(p['result']) == set(lindex["Per"][1:] + [common]))
        assert(set(e['result']) == set(lindex["Per"][1:] + [common]))