예제 #1
0
    def test_query_endpoints_reverse(self):
        st = minemeld.ft.st.ST(TABLENAME, 8, truncate=True)

        sid1 = uuid.uuid4().bytes
        sid2 = uuid.uuid4().bytes

        st.put(sid1, 1, 70, 1)
        st.put(sid2, 50, 100, 1)

        eps = [
            ep[0] for ep in st.query_endpoints(start=0,
                                               stop=st.max_endpoint,
                                               reverse=True,
                                               include_start=False,
                                               include_stop=False)
        ]

        self.assertEqual(eps, [100, 70, 50, 1])

        st.close()
예제 #2
0
    def test_query_endpoints_reverse(self):
        st = minemeld.ft.st.ST(TABLENAME, 8, truncate=True)

        sid1 = uuid.uuid4().bytes
        sid2 = uuid.uuid4().bytes

        st.put(sid1, 1, 70, 1)
        st.put(sid2, 50, 100, 1)

        eps = [ep[0] for ep in st.query_endpoints(
            start=0,
            stop=st.max_endpoint,
            reverse=True,
            include_start=False,
            include_stop=False
        )]

        self.assertEqual(eps, [100, 70, 50, 1])

        st.close()
예제 #3
0
    def _random_map(self, nbits=10, nintervals=1000):
        epmax = (1 << nbits)-1

        rmap = [set() for i in xrange(epmax+1)]

        st = minemeld.ft.st.ST(TABLENAME, nbits, truncate=True)

        for j in xrange(nintervals):
            sid = uuid.uuid4().bytes
            end = random.randint(0, epmax)
            start = random.randint(0, epmax)
            if end < start:
                start, end = end, start
            st.put(sid, start, end, level=1)

            for k in xrange(start, end+1):
                rmap[k].add(sid)

        eps = []
        for ep, lvl, t, id_ in st.query_endpoints():
            if ep == 0 or ep == epmax:
                self.assertTrue(len(rmap[ep]) > 0)
            else:
                c = len(rmap[ep] ^ rmap[ep-1]) + len(rmap[ep] ^ rmap[ep+1])
                self.assertTrue(
                    c > 0,
                    msg="no change detected @ep %d: "
                        "%r %r %r" % (ep, rmap[ep-1], rmap[ep], rmap[ep+1])
                )
            eps.append(ep)

        for e in eps:
            intervals = [x[0] for x in st.cover(e)]
            intervals.sort()
            self.assertListEqual(intervals, sorted(rmap[e]))

        st.close()
예제 #4
0
    def _random_map(self, nbits=10, nintervals=1000):
        epmax = (1 << nbits) - 1

        rmap = [set() for i in xrange(epmax + 1)]

        st = minemeld.ft.st.ST(TABLENAME, nbits, truncate=True)

        for j in xrange(nintervals):
            sid = uuid.uuid4().bytes
            end = random.randint(0, epmax)
            start = random.randint(0, epmax)
            if end < start:
                start, end = end, start
            st.put(sid, start, end, level=1)

            for k in xrange(start, end + 1):
                rmap[k].add(sid)

        eps = []
        for ep, lvl, t, id_ in st.query_endpoints():
            if ep == 0 or ep == epmax:
                self.assertTrue(len(rmap[ep]) > 0)
            else:
                c = len(rmap[ep] ^ rmap[ep - 1]) + len(rmap[ep] ^ rmap[ep + 1])
                self.assertTrue(c > 0,
                                msg="no change detected @ep %d: "
                                "%r %r %r" %
                                (ep, rmap[ep - 1], rmap[ep], rmap[ep + 1]))
            eps.append(ep)

        for e in eps:
            intervals = [x[0] for x in st.cover(e)]
            intervals.sort()
            self.assertListEqual(intervals, sorted(rmap[e]))

        st.close()