Example #1
0
    def test_gcounter(self):
        counter1 = GCounter(name="counter1")
        counter1.increment(10)
        
        self.assertEqual(10, counter1.value())

        counter2 = GCounter(name="counter2")
        counter2.increment(5)
        counter3 = counter1.merge(counter2)
        counter4 = GCounter.merge(counter1, counter2)

        self.assertEqual(5, counter2.value())
        self.assertFalse(counter1.compare(counter2))
        self.assertEqual(15, counter3.value())
        self.assertTrue(counter1.compare(counter3))
        self.assertEqual(counter3.value(), counter4.value())
        CRDTLaws.test(counter1, counter2, counter3)
Example #2
0
    def test_lwwregister(self):
        register1 = LWWRegister()
        register1.set(10)
        
        self.assertEqual(10, register1.value())

        register2 = LWWRegister()
        register2.set(15)
        register3 = register1.merge(register2)
        register4 = LWWRegister.merge(register1, register2)

        self.assertEqual(15, register2.value())
        self.assertFalse(register2.compare(register1))
        self.assertEqual(15, register3.value())
        self.assertTrue(register1.compare(register3))
        self.assertEqual(register4.value(), register4.value())
        CRDTLaws.test(register1, register2, register3)
Example #3
0
    def test_gset(self):
        set1 = GSet()
        set1.add("a")

        self.assertEqual({"a"}, set1.value())

        set2 = GSet()
        set2.add("b")
        set3 = set1.merge(set2)
        set4 = GSet.merge(set1, set2)

        self.assertEqual({"b"}, set2.value())
        self.assertTrue("a" in set1)
        self.assertFalse(set1.compare(set2))
        self.assertEqual({"a", "b"}, set3.value())
        self.assertTrue(set1.compare(set3))
        self.assertEqual(set3.value(), set4.value())
        CRDTLaws.test(set1, set2, set3)
Example #4
0
    def test_pncounter(self):
        counter1 = PNCounter(name="counter1")
        counter1.increment(10)
        counter1.decrement(5)
        
        self.assertEqual(5, counter1.value())

        counter2 = PNCounter(name="counter2")
        counter2.increment(5)
        counter2.decrement(7)
        counter3 = counter1.merge(counter2)
        counter4 = PNCounter.merge(counter1, counter2)

        self.assertEqual(-2, counter2.value())
        self.assertFalse(counter1.compare(counter2))
        self.assertEqual(3, counter3.value())
        self.assertTrue(counter1.compare(counter3))
        self.assertEqual(counter3.value(), counter4.value())
        CRDTLaws.test(counter1, counter2, counter3)
Example #5
0
    def assert_set_operations(self, klass):
        set1 = klass()
        for x in "abc":
            set1.add(x)
        set1.remove("b")

        self.assertEqual({"a", "c"}, set1.value())

        set2 = klass()
        set2 += "a"
        set2 -= "a"
        set3 = set1.merge(set2)
        set4 = klass.merge(set1, set2)

        self.assertEqual(set(), set2.value())
        self.assertFalse(set1.compare(set2))
        self.assertEqual({"c"}, set3.value())
        self.assertEqual(set3.value(), set4.value())
        CRDTLaws.test(set1, set2, set3)