class TestQuorum(StreamTest): def setUp(self): StreamTest.setUp(self) self.doc = handler_document("echo_chamber") self.ev = Event({'x':'y'}, identity("atlas"), self.doc.version) self.quorum = Quorum(self.ev, self.doc._qs) self.quorum.document = self.doc self.ident = identity() self.owner = Owner(self.ident, make_jack=False) self.owner.own_document(self.doc) self.owner.identities.update_ident(self.ev.author) def test_clear(self): self.quorum.sign(self.ident) self.assertEqual(self.quorum.completion, 1) self.quorum.clear() self.assertEqual(self.quorum.completion, 0) def test_completion(self): self.assertEqual(self.quorum.completion, 0) self.quorum.sign(self.ident) self.assertEqual(self.quorum.completion, 1) def test_outdated(self): self.assertEqual(self.doc.version, 'current') self.assertEqual(self.doc._qs.version, 'current') self.assertEqual(self.ev.version, 'current') self.assertEqual(self.quorum.version, 'current') self.assertFalse(self.quorum.outdated) self.quorum.sign(self.ident) self.assertFalse(self.quorum.outdated) self.owner.protocol.paxos.check_quorum(self.doc, self.ev) # Stupid Python 2 makes this the easiest way to put up with string crap output = self.getOutput() self.assertIn(output, [ "Event '{'x': 'y'}' achieved.\n", "Event '{u'x': u'y'}' achieved.\n", ]) self.assertEqual(self.doc.version, self.ev.hash()) self.assertEqual(self.quorum.version, 'current') self.assertTrue(self.quorum.outdated) def test_participants(self): self.assertEqual(self.quorum.participants, [self.ident]) def test_thresholds(self): self.assertEqual(self.quorum.thresholds, {'read':1, 'write':1}) def test_threshold(self): self.assertEqual(self.quorum.threshold, 1)
class TestQuorum(StreamTest): def setUp(self): StreamTest.setUp(self) self.doc = handler_document("echo_chamber") self.ev = Event({'x':'y'}, identity("atlas"), self.doc.version) self.quorum = Quorum(self.ev, self.doc._qs) self.quorum.document = self.doc self.ident = identity() self.owner = Owner(self.ident, make_jack=False) self.owner.own_document(self.doc) def test_clear(self): self.quorum.sign(self.ident) self.assertEqual(self.quorum.completion, 1) self.quorum.clear() self.assertEqual(self.quorum.completion, 0) def test_completion(self): self.assertEqual(self.quorum.completion, 0) self.quorum.sign(self.ident) self.assertEqual(self.quorum.completion, 1) def test_outdated(self): self.assertEqual(self.doc.version, 'current') self.assertEqual(self.doc._qs.version, 'current') self.assertEqual(self.ev.version, 'current') self.assertEqual(self.quorum.version, 'current') self.assertFalse(self.quorum.outdated) self.quorum.sign(self.ident) self.assertFalse(self.quorum.outdated) self.quorum.enact(self.doc) self.assertOutput( "Event '{'x': 'y'}' achieved.\n" + "No known address for String('[\"local\",null,\"atlas\"]'), skipping\n" ) self.assertEqual(self.doc.version, self.ev.hash()) self.assertEqual(self.quorum.version, 'current') self.assertTrue(self.quorum.outdated) def test_participants(self): self.assertEqual(self.quorum.participants, [self.ident]) def test_thresholds(self): self.assertEqual(self.quorum.thresholds, {'read':1, 'write':1}) def test_threshold(self): self.assertEqual(self.quorum.threshold, 1)