def test_id_batch_exhaustion_with_non_positive_batch_size(self): id_batch = _IdBatch(1, 2, 0) iterator = iter(id_batch) id_batch2 = _IdBatch(3, 4, -1) iterator2 = iter(id_batch2) with self.assertRaises(StopIteration): next(iterator) with self.assertRaises(StopIteration): next(iterator2)
def test_block_after_validity_period(self): id_batch = _IdBatch(-1, -2, 2) block = _Block(id_batch, 1) time.sleep(0.5) self.assertTrueEventually(lambda: block.next_id() is None)
def test_block_after_validity_period(self): id_batch = _IdBatch(-1, -2, 2) block = _Block(id_batch, 0.1) time.sleep(0.5) self.assertIsNone(block.next_id())
def test_id_batch_stop_iteration_raised(self): batch_size = 10 count = 0 for _ in _IdBatch(0, 1, batch_size): count += 1 # For loop ends when the iterator raises StopIteration self.assertEqual(batch_size, count)
def test_id_batch_as_iterator(self): base = 3 increment = 4 batch_size = 100 # number of elements * (first element + last element) / 2 expected_value = batch_size * (base + (base + (batch_size - 1) * increment)) / 2 self.assertEqual(expected_value, sum(_IdBatch(base, increment, batch_size)))
def _id_batch_supplier(self, batch_size): return ImmediateFuture( _IdBatch(AUTO_BATCHER_BASE, FLAKE_ID_STEP, batch_size))
def test_block_with_batch_exhaustion(self): id_batch = _IdBatch(100, 10000, 0) block = _Block(id_batch, 1000) self.assertIsNone(block.next_id())
def test_block(self): id_batch = _IdBatch(1, 2, 3) block = _Block(id_batch, 0) self.assertIsNotNone(block.next_id())