Exemplo n.º 1
0
	def test_suspend_multi(self):
		(doc, rev1, rev_s1) = self.createSuspendDoc()

		with Connector().update(self.store1, doc, rev1) as w:
			w.writeAll('FILE', 'forward')
			w.commit()
			rev2 = w.getRev()

		with Connector().update(self.store1, doc, rev2) as w:
			w.writeAll('FILE', 'Hail to the king, baby!')
			w.suspend()
			rev_s2 = w.getRev()

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev2])
		self.assertEqual(len(l.preRevs()), 2)
		self.assertTrue(rev_s1 in l.preRevs())
		self.assertTrue(rev_s2 in l.preRevs())

		s = Connector().stat(rev_s1)
		self.assertEqual(s.parents(), [rev1])
		s = Connector().stat(rev_s2)
		self.assertEqual(s.parents(), [rev2])

		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev_s1, {'FILE' : 'update'})
		self.assertRevContent(self.store1, rev2, {'FILE' : 'forward'})
		self.assertRevContent(self.store1, rev_s2, {'FILE' : 'Hail to the king, baby!'})
Exemplo n.º 2
0
	def test_suspend_multi(self):
		(doc, rev1, rev_s1) = self.createSuspendDoc()

		with Connector().update(self.store1, doc, rev1) as w:
			w.writeAll('FILE', 'forward')
			w.commit()
			rev2 = w.getRev()

		with Connector().update(self.store1, doc, rev2) as w:
			w.writeAll('FILE', 'Hail to the king, baby!')
			w.suspend()
			rev_s2 = w.getRev()

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev2])
		self.assertEqual(len(l.preRevs()), 2)
		self.assertTrue(rev_s1 in l.preRevs())
		self.assertTrue(rev_s2 in l.preRevs())

		s = Connector().stat(rev_s1)
		self.assertEqual(s.parents(), [rev1])
		s = Connector().stat(rev_s2)
		self.assertEqual(s.parents(), [rev2])

		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev_s1, {'FILE' : 'update'})
		self.assertRevContent(self.store1, rev2, {'FILE' : 'forward'})
		self.assertRevContent(self.store1, rev_s2, {'FILE' : 'Hail to the king, baby!'})
Exemplo n.º 3
0
    def test_sync_merge(self):
        (doc, rev1, rev2) = self.createMerge(
            "org.peerdrive.folder",
            {"META": struct.dumps({"a": 1}), "PDSD": struct.dumps([{"": 1}, {"": 2}])},
            {"META": struct.dumps({"a": 4, "b": 2}), "PDSD": struct.dumps([{"": 1}, {"": 2}, {"": 3}])},
            {"META": struct.dumps({"a": 1, "c": 3}), "PDSD": struct.dumps([{"": 2}])},
        )
        l = self.performSync(doc, "merge")

        rev = l.revs()[0]
        s = Connector().stat(rev)
        self.assertEqual(len(s.parents()), 2)
        self.assertTrue(rev1 in s.parents())
        self.assertTrue(rev2 in s.parents())

        # all revs on all stores?
        l = Connector().lookupRev(rev1)
        self.assertTrue(self.store1 in l)
        self.assertTrue(self.store2 in l)
        l = Connector().lookupRev(rev2)
        self.assertTrue(self.store1 in l)
        self.assertTrue(self.store2 in l)

        # see if merge was ok
        with Connector().peek(self.store1, rev) as r:
            meta = struct.loads(self.store1, r.readAll("META"))
            if "org.peerdrive.annotation" in meta:
                del meta["org.peerdrive.annotation"]
            self.assertEqual(meta, {"a": 4, "b": 2, "c": 3})
            pdsd = sorted(struct.loads(self.store1, r.readAll("PDSD")))
            self.assertEqual(pdsd, [{"": 2}, {"": 3}])
Exemplo n.º 4
0
    def test_sync_merge_fallback(self):
        (doc, rev1, rev2) = self.createMerge("public.data", {}, {"FILE": "left3"}, {"FILE": "right3"})
        l = self.performSync(doc, "merge")

        rev = l.revs()[0]
        s = Connector().stat(rev)
        self.assertEqual(len(s.parents()), 2)
        self.assertTrue(rev1 in s.parents())
        self.assertTrue(rev2 in s.parents())
        self.assertRevContent(self.store1, rev, {"FILE": "left3"})
Exemplo n.º 5
0
	def test_sync_latest(self):
		(doc, rev1, rev2) = self.createMerge("public.data", {}, {'FILE' : "left2"},
			{'FILE' : "right2"})
		l = self.performSync(doc, 'latest')

		rev = l.revs()[0]
		s = Connector().stat(rev)
		self.assertEqual(len(s.parents()), 2)
		self.assertTrue(rev1 in s.parents())
		self.assertTrue(rev2 in s.parents())
		self.assertRevContent(self.store1, rev, {'FILE' : 'left2'})
Exemplo n.º 6
0
	def test_sync_merge_fallback(self):
		(doc, rev1, rev2) = self.createMerge("public.data", {}, {'FILE' : "left3"},
			{'FILE' : "right3"})
		l = self.performSync(doc, 'merge')

		rev = l.revs()[0]
		s = Connector().stat(rev)
		self.assertEqual(len(s.parents()), 2)
		self.assertTrue(rev1 in s.parents())
		self.assertTrue(rev2 in s.parents())
		self.assertRevContent(self.store1, rev, {'FILE' : 'left3'})
Exemplo n.º 7
0
	def test_sync_merge(self):
		(doc, rev1, rev2) = self.createMerge("org.peerdrive.folder",
			{
				'META':struct.dumps({"a":1}),
				'PDSD':struct.dumps([{'':1}, {'':2}])
			},
			{
				'META':struct.dumps({"a":4, "b":2}),
				'PDSD':struct.dumps([{'':1}, {'':2}, {'':3}])
			},
			{
				'META':struct.dumps({"a":1, "c":3}),
				'PDSD':struct.dumps([{'':2}])
			})
		l = self.performSync(doc, 'merge')

		rev = l.revs()[0]
		s = Connector().stat(rev)
		self.assertEqual(len(s.parents()), 2)
		self.assertTrue(rev1 in s.parents())
		self.assertTrue(rev2 in s.parents())

		# all revs on all stores?
		l = Connector().lookupRev(rev1)
		self.assertTrue(self.store1 in l)
		self.assertTrue(self.store2 in l)
		l = Connector().lookupRev(rev2)
		self.assertTrue(self.store1 in l)
		self.assertTrue(self.store2 in l)

		# see if merge was ok
		with Connector().peek(self.store1, rev) as r:
			meta = struct.loads(self.store1, r.readAll('META'))
			if 'org.peerdrive.annotation' in meta:
				del meta['org.peerdrive.annotation']
			self.assertEqual(meta, {"a":4, "b":2, "c":3})
			pdsd = sorted(struct.loads(self.store1, r.readAll('PDSD')))
			self.assertEqual(pdsd, [{'':2},{'':3}])
Exemplo n.º 8
0
	def test_resume_suspend_orig(self):
		(doc, rev1, rev2) = self.createSuspendDoc()

		with Connector().resume(self.store1, doc, rev2) as w:
			w.suspend()
			rev3 = w.getRev()

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev1])
		self.assertEqual(l.preRevs(), [rev3])

		s = Connector().stat(rev3)
		self.assertEqual(s.parents(), [rev1])

		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev3, {'FILE' : 'update'})
Exemplo n.º 9
0
	def test_resume_commit(self):
		(doc, rev1, rev2) = self.createSuspendDoc()

		with Connector().resume(self.store1, doc, rev2) as w:
			w.writeAll('FILE', 'What are you waiting for, christmas?')
			w.commit()
			rev3 = w.getRev()

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev3])
		self.assertEqual(len(l.preRevs()), 0)

		s = Connector().stat(rev3)
		self.assertEqual(s.parents(), [rev1])
		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev3, {'FILE' : 'What are you waiting for, christmas?'})
Exemplo n.º 10
0
	def __update(self):
		if self.__seen:
			self.__unwatch()
			self.__available = len(Connector().lookupRev(self.__rev)) > 0
		else:
			self.__available = False
			try:
				stat = Connector().stat(self.__rev)
				self.__mtime = stat.mtime()
				self.__seen = True
				self.__available = True
				self.__view._addParents(stat.parents())
				self.__unwatch()
			except IOError:
				self.__watch()
				return
Exemplo n.º 11
0
 def __update(self):
     if self.__seen:
         self.__unwatch()
         self.__available = len(Connector().lookupRev(self.__rev)) > 0
     else:
         self.__available = False
         try:
             stat = Connector().stat(self.__rev)
             self.__mtime = stat.mtime()
             self.__seen = True
             self.__available = True
             self.__view._addParents(stat.parents())
             self.__unwatch()
         except IOError:
             self.__watch()
             return
Exemplo n.º 12
0
	def test_resume_suspend_orig(self):
		(doc, rev1, rev2) = self.createSuspendDoc()

		with Connector().resume(self.store1, doc, rev2) as w:
			w.suspend()
			rev3 = w.getRev()

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev1])
		self.assertEqual(l.preRevs(), [rev3])

		s = Connector().stat(rev3)
		self.assertEqual(s.parents(), [rev1])

		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev3, {'FILE' : 'update'})
Exemplo n.º 13
0
	def test_resume_commit(self):
		(doc, rev1, rev2) = self.createSuspendDoc()

		with Connector().resume(self.store1, doc, rev2) as w:
			w.writeAll('FILE', 'What are you waiting for, christmas?')
			w.commit()
			rev3 = w.getRev()

		l = Connector().lookupDoc(doc)
		self.assertEqual(l.revs(), [rev3])
		self.assertEqual(len(l.preRevs()), 0)

		s = Connector().stat(rev3)
		self.assertEqual(s.parents(), [rev1])
		self.assertRevContent(self.store1, rev1, {'FILE' : 'ok'})
		self.assertRevContent(self.store1, rev3, {'FILE' : 'What are you waiting for, christmas?'})
Exemplo n.º 14
0
    def test_resume_suspend_mod(self):
        (doc, rev1, rev2) = self.createSuspendDoc()

        with Connector().resume(self.store1, doc, rev2) as w:
            w.writeAll("FILE", "What are you waiting for, christmas?")
            w.suspend()
            rev3 = w.getRev()

        l = Connector().lookupDoc(doc)
        self.assertEqual(l.revs(), [rev1])
        self.assertEqual(l.preRevs(), [rev3])

        s = Connector().stat(rev3)
        self.assertEqual(s.parents(), [rev1])

        self.assertRevContent(self.store1, rev1, {"FILE": "ok"})
        self.assertRevContent(self.store1, rev3, {"FILE": "What are you waiting for, christmas?"})