示例#1
0
 def test__p_resolveConflict_nointersection(self):
     from repoze.session.linkedlist import ListNode
     from ZODB.POSException import ConflictError
     root = self._makeOne(30, 1)
     old = self._makeState(1, 1, ListNode((1, {}), None))
     committed = self._makeState(1, 1, ListNode((2, {}), None))
     new = self._makeState(1, 1, ListNode((3, {}), None))
     self.assertRaises(ConflictError, root._p_resolveConflict, old,
                       committed, new)
示例#2
0
    def new_head(self, old_head, when=None):
        if when is None:
            when = time.time()

        bucket = self._BUCKET_TYPE()
        head = ListNode((when, bucket), old_head)
        return head
示例#3
0
    def test_CR_both_adding_new_truncating(self):
        from repoze.session.linkedlist import ListNode

        old = self._makeOne(30, 1)
        oh = old.head = ListNode((1234, {}), ListNode((1000, {}), None))

        committed = self._makeOne(30, 1)
        committed.head = ListNode((2345, {}), oh)

        new = self._makeOne(30, 1)
        new.head = ListNode((3456, {}), ListNode((1234, {}), None))

        resolved = new._p_resolveConflict(*_statify(old, committed, new))

        nodes = _flatten(resolved['head'])
        self.assertEqual(len(nodes), 3)
        self.assertEqual([x[0] for x in nodes], [3456, 2345, 1234])
示例#4
0
    def test_CR_new_tail_newer_than_old_head_raises_ConflictError(self):
        from ZODB.POSException import ConflictError
        from repoze.session.linkedlist import ListNode

        old = self._makeOne(30, 1)
        o_h = old.head = ListNode((1234, {}), None)

        committed = self._makeOne(30, 1)
        committed.head = ListNode((2345, {}), o_h)

        # The tail of 'new' is more recent than the head of 'old',
        # which makes any attempt at conflict resolution pointless.
        new = self._makeOne(30, 1)
        new.head = ListNode((3456, {}), None)

        self.assertRaises(ConflictError, new._p_resolveConflict,
                          *_statify(old, committed, new))
示例#5
0
    def test__p_resolveConflict_differing_tails(self):
        from repoze.session.linkedlist import ListNode
        root = self._makeOne(30, 1)

        long_tail = ListNode((1, {}), None)
        long_between = ListNode((2, {}), long_tail)
        long_head = ListNode((3, {}), long_between)

        mid_tail = ListNode((2, {}), None)
        mid_head = ListNode((3, {}), mid_tail)

        short_head = ListNode((3, {}), None)

        old = self._makeState(1, 1, long_head)
        committed = self._makeState(1, 1, mid_head)
        new = self._makeState(1, 1, short_head)

        result = root._p_resolveConflict(old, committed, new)
        self.assertEqual(result['period'], 1)
        self.assertEqual(result['timeout'], 1)
        # we take the intersection of the three states, so we only get "3" back
        head = result['head']
        self.assertEqual(head.ob[0], 3)
        next = head.next
        self.assertEqual(next, None)
示例#6
0
    def test_search_newer_shadows_older(self):
        root = self._makeOne(30, 1)
        root.head.ob[1]['a'] = 1

        from repoze.session.linkedlist import ListNode
        import time

        newbucket = root._BUCKET_TYPE()
        newbucket['a'] = 2
        now = time.time()
        newhead = ListNode((now, newbucket), root.head)
        root.head = newhead
        self.assertEqual(root.search('a'), 2)
示例#7
0
 def test__p_resolveConflict_both_committed_and_new_have_new_head(self):
     from repoze.session.linkedlist import ListNode
     root = self._makeOne(30, 1)
     shared_node_tail = ListNode((1, {}), None)
     shared_node_head = ListNode((2, {}), shared_node_tail)
     old = self._makeState(1, 1, shared_node_head)
     committed = self._makeState(1, 1, ListNode((3, {}), shared_node_head))
     new = self._makeState(1, 1, ListNode((4, {}), shared_node_head))
     result = root._p_resolveConflict(old, committed, new)
     # note that we've composed the linked list out of both the
     # shared elements and the new head elements in committed and
     # new
     self.assertEqual(result['period'], 1)
     self.assertEqual(result['timeout'], 1)
     head = result['head']
     self.assertEqual(head.ob[0], 4)
     next = head.next
     self.assertEqual(next.ob[0], 3)
     next = next.next
     self.assertEqual(next.ob[0], 2)
     next = next.next
     self.assertEqual(next.ob[0], 1)
     next = next.next
     self.assertEqual(next, None)
示例#8
0
    def test_search_findintail(self):
        root = self._makeOne(30, 1)
        root.head.ob[1]['a'] = 1

        from repoze.session.linkedlist import ListNode
        import time

        newbucket = root._BUCKET_TYPE()
        now = time.time()
        newhead = ListNode((now, newbucket), root.head)
        root.head = newhead
        self.assertEqual(root.search('a'), 1)

        # value was moved forward
        self.assertEqual(newbucket.get('a'), 1)