コード例 #1
0
    def checkRSResolve(self):
        # ZODB.tests.ConflictResolution.ConflictResolvingStorage has a checkResolve
        # with a different signature (as of 4.4.0) that we were unintentionally(?)
        # shadowing, hence the weird name.
        obj = PCounter()
        obj.inc()

        oid = self._storage.new_oid()

        revid1 = self._dostoreNP(oid, data=zodb_pickle(obj))

        obj.inc()
        obj.inc()

        # The effect of committing two transactions with the same
        # pickle is to commit two different transactions relative to
        # revid1 that add two to _value.

        # open s1
        s1 = self._storage.new_instance()
        # start a load transaction in s1
        s1.poll_invalidations()

        # commit a change
        _revid2 = self._dostoreNP(oid, revid=revid1, data=zodb_pickle(obj))

        # commit a conflicting change using s1
        main_storage = self._storage
        self._storage = s1
        try:
            # we can resolve this conflict because s1 has an open
            # transaction that can read the old state of the object.
            _revid3 = self._dostoreNP(oid, revid=revid1, data=zodb_pickle(obj))
            s1.release()
        finally:
            self._storage = main_storage

        data, _serialno = self._storage.load(oid, '')
        inst = zodb_unpickle(data)
        self.assertEqual(inst._value, 5)
コード例 #2
0
ファイル: hftestbase.py プロジェクト: NouryG/pychronia
    def checkResolve(self):
        obj = PCounter()
        obj.inc()

        oid = self._storage.new_oid()

        revid1 = self._dostoreNP(oid, data=zodb_pickle(obj))

        obj.inc()
        obj.inc()

        # The effect of committing two transactions with the same
        # pickle is to commit two different transactions relative to
        # revid1 that add two to _value.

        # open s1
        s1 = self._storage.new_instance()
        # start a load transaction in s1
        s1.poll_invalidations()

        # commit a change
        revid2 = self._dostoreNP(oid, revid=revid1, data=zodb_pickle(obj))

        # commit a conflicting change using s1
        main_storage = self._storage
        self._storage = s1
        try:
            # we can resolve this conflict because s1 has an open
            # transaction that can read the old state of the object.
            revid3 = self._dostoreNP(oid, revid=revid1, data=zodb_pickle(obj))
            s1.release()
        finally:
            self._storage = main_storage

        data, serialno = self._storage.load(oid, '')
        inst = zodb_unpickle(data)
        self.assertEqual(inst._value, 5)