def test_delete_block(self): g = BlockGroup(block_group_id='g000640000000123', idcs=['a', 'b', 'c'], config=_ec_config) self.assertIsNone(g.get_block('0000')) g.add_block(self.foo_block) self.assertIsNotNone(g.get_block('0000')) g.delete_block('0000') self.assertIsNone(g.get_block('0000')) g.delete_block('0000') self.assertIsNone(g.get_block('0000'))
def test_mark_delete_block(self): g = BlockGroup(block_group_id='g000640000000123', idcs=['a', 'b', 'c'], config=_ec_config) g.add_block(self.foo_block) g.mark_delete_block('0000') block = g.get_block('0000') self.assertEqual(1, block['is_del']) self.assertRaises(BlockNotFoundError, g.mark_delete_block, '9999')
def test_delete_block(self): g = BlockGroup(block_group_id='g000640000000123', idcs=['a', 'b', 'c'], config=_ec_config) self.assertIsNone(g.get_block('0000', raise_error=False)) g.add_block(self.foo_block) self.assertIsNotNone(g.get_block('0000')) self.foo_block.add_ref() del_blk = g.delete_block('0000') self.assertIsNotNone(g.get_block('0000', raise_error=False)) del_blk = g.delete_block('0000') self.assertIsNone(g.get_block('0000', raise_error=False)) self.assertDictEqual(self.foo_block, del_blk) self.assertRaises(BlockNotFoundError, g.delete_block, '0000')
def test_replace_block(self): g = BlockGroup(block_group_id='g000640000000123', idcs=['a', 'b', 'c'], config=_ec_config) prev = g.add_block(self.foo_block) self.assertIsNone(prev) block = g.get_block('0000') self.assertEqual(0, block['is_del']) prev = g.add_block(self.foo_block, replace=True) self.assertEqual(self.foo_block, prev) self.assertRaises(BlockExists, g.add_block, self.foo_block) self.assertRaises(BlockExists, g.add_block, self.foo_block, replace=False)
def test_get_block(self): g = BlockGroup(block_group_id='g000640000000123', idcs=['a', 'b', 'c'], config=_ec_config) block = g.get_block('0000') self.assertIsNone(block) block = g.get_block('9999') self.assertIsNone(block) with self.assertRaises(BlockNotFoundError): g.get_block('9999', raise_error=True) g.add_block(self.foo_block) block = g.get_block(self.foo_block['block_id'].block_index) self.assertDictEqual(self.foo_block, block) with self.assertRaises(BlockNotFoundError): g.get_block('0002', raise_error=True) with self.assertRaises(ValueError): g.get_block('d0g0006400000001230000c62d2')
def test_mark_delete_block(self): g = BlockGroup(block_group_id='g000640000000123', idcs=['a', 'b', 'c'], config=_ec_config) g.add_block(self.foo_block) self.foo_block.add_ref() self.assertEqual(2, self.foo_block['ref_num']) self.assertEqual(0, self.foo_block['is_del']) del_blk = g.mark_delete_block('0000') self.assertIsNone(del_blk) self.assertEqual(1, self.foo_block['ref_num']) self.assertEqual(0, self.foo_block['is_del']) del_blk = g.mark_delete_block('0000') self.assertEqual(del_blk['ref_num'], 0) self.assertEqual(1, del_blk['is_del']) self.assertDictEqual(del_blk, g.get_block('0000')) self.assertTrue(int(time.time()) - del_blk["mtime"] < 3) self.assertRaises(BlockNotFoundError, g.mark_delete_block, '9999')