def test_next_object(self): """Test that L{oidres.OIDRes.next} works in the common case.""" with Counter(self, 4) as counter: class xMockRAMCloud(self.MockRAMCloud): def real_read(self): i = counter.bump([0, 2]) if i == 0: return (70, 54321) elif i == 2: return (900, 123450) def real_update(self, next_avail, want_version): i = counter.bump([1, 3]) if i == 1: self.tc.assertEqual(next_avail, 70 + 737) self.tc.assertEqual(want_version, 54321) elif i == 3: self.tc.assertEqual(next_avail, 900 + 737) self.tc.assertEqual(want_version, 123450) rc = xMockRAMCloud(self) res = oidres.OIDRes(rc, self.table, self.oid, delta=737) for i in range(737): retry_strategy = MockRetry(self) self.assertEqual(res.next(retry_strategy), i + 70) retry_strategy.done() self.assertEqual(counter.count, 1) self.assertEqual(res.next(), 900)
def test_next_no_object(self): """Test that L{oidres.OIDRes.next} works when there is no object.""" with Counter(self, 2) as counter: class xMockRAMCloud(self.MockRAMCloud): def real_read(self): counter.bump(0) raise ramcloud.NoObjectError() def real_create(self, next_avail): counter.bump(1) self.tc.assertEqual(next_avail, 737) rc = xMockRAMCloud(self) res = oidres.OIDRes(rc, self.table, self.oid, delta=737) for i in range(737): retry_strategy = MockRetry(self) self.assertEqual(res.next(retry_strategy), i) retry_strategy.done()
def test_mismatched_version(self): """Test that L{oidres.OIDRes.next} works under contention.""" with Counter(self, 2) as counter: class xMockRAMCloud(self.MockRAMCloud): def real_read(self): counter.bump(0) return (70, 54321) def real_update(self, next_avail, want_version): counter.bump(1) self.tc.assertEqual(next_avail, 70 + 737) self.tc.assertEqual(want_version, 54321) raise ramcloud.VersionError(54321, 54322) rc = xMockRAMCloud(self) res = oidres.OIDRes(rc, self.table, self.oid, delta=737) retry_strategy = MockRetry(self, expect_later=True) self.assertRaises(BreakException, lambda: res.next(retry_strategy)) retry_strategy.done()
def f(): with MockRetry(self, expect_later=True) as retries: raise E
def test_with(self): with MockRetry(self) as retries: for i, retry in enumerate(retries): pass
def test_immediate_bad(self): retries = MockRetry(self) retries.next() self.assertRaises(self.failureException, retries.immediate)
def test_immediate(self): retries = MockRetry(self, expect_immediate=True) retries.next() retries.immediate() self.assertRaises(BreakException, retries.next) retries.done()
def test_later_bad(self): retries = MockRetry(self) retries.next() self.assertRaises(self.failureException, retries.later)
def test_later(self): retries = MockRetry(self, expect_later=True) retries.next() retries.later() self.assertRaises(BreakException, retries.next) retries.done()
def test_next(self): retries = MockRetry(self) self.assertEquals(retries.next(), retries) self.assertRaises(StopIteration, retries.next) retries.done()