def test_reserve_tx_succeeds(self): l = [(1, "a = b"), (2, "b = c")] n = TXManager(l) n.txn.sock.transport.stopConnecting() n.txn = FakeNetwork() d = n._reserve_tx(3) d.addCallback(self.gen_cb(3)) return d
def test_reserve_tx_recieved(self): # assert we fail if we've already recieved the TX we try to reserve l = [(1, "a = b"), (2, "b = c")] n = TXManager(l) n.txn.sock.transport.stopConnecting() n.txn = FakeNetwork() d = n._reserve_tx(2) d.addBoth(self.gen_cbs()) return d
def test_get_tx(self): c = Clock() m = TXManager(txs=[(1, "a = b")], clock=c) self.addCleanup(m.txn.sock.transport.stopConnecting) m.txn = FakeNetwork() results = [] def f(r): results.append(r) d = m.get_tx() d.addCallback(f) c.advance(1) self.assertEqual(results, [2])
def test_wait_on_tx_received(self): c = Clock() m = TXManager(txs=[(1, "a = b")], clock=c) self.addCleanup(m.txn.sock.transport.stopConnecting) m.txn = FakeNetwork() run_count = [0] def f(r): run_count[0] += 1 d = m.wait_on_tx(1) d.addCallback(f) c.advance(1) self.assertEqual(run_count[0], 1)
def __init__(self, port=None, bootstrap=None): self.db = DB() self.manager = TXManager(self, port, bootstrap) self.uid = self.manager.node.uid self.tx_version = 0 self.lock_holder = None self.history = [] self.waiters = defaultdict(list)
def test_execute2(self): p = DBP() c = Clock() self.addCleanup(p.manager.txn.sock.transport.stopConnecting) p.manager = TXManager(txs=[(1, "a = b"), (2, "b = c"), (3, "a = c")], clock=c) self.addCleanup(p.manager.txn.sock.transport.stopConnecting) p.manager.txn = FakeNetwork() p.execute("b = a") c.advance(1) p.execute("b = c") c.advance(1) p.sync_db() self.assertEqual(p.db._db, {"a": "c", "b": "c"})
def test_execute(self): c = Clock() p = DBP() self.addCleanup(p.manager.txn.sock.transport.stopConnecting) p.manager = TXManager(txs=[(1, "a = b"), (2, "b = c"), (3, "a = c")], clock=c) self.addCleanup(p.manager.txn.sock.transport.stopConnecting) p.manager.txn = FakeNetwork() results = [] def f(r): results.append(r) p.execute("b = a").addCallback(f) c.advance(1) self.assertEqual(results, [None]) self.assertEqual(p.db._db, {"a": "c", "b": "a"})
def test_get_tx_retry(self): raise SkipTest("this doesn't work with the current code mockup") c = Clock() m = TXManager(txs=[(1, "a = b")], clock=c) self.addCleanup(m.txn.sock.transport.stopConnecting) m.txn = FakeNetwork() results = [] def f(r): results.append(r) d = m.get_tx() d.addCallback(f) m.distribute(2, "b = c") c.advance(1) self.assertEqual(results, [3])