def test_allocate_ids(self): PREFIX = "x" BATCH_SIZE = 1000 db_batch = flexmock() db_batch.should_receive("batch_get_entity").and_return( {PREFIX: { APP_ID_SCHEMA[0]: "1" }}) db_batch.should_receive("batch_put_entity").and_return(None) dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, BATCH_SIZE), (1, 1000)) db_batch.should_receive("batch_get_entity").and_return( {PREFIX: { APP_ID_SCHEMA[0]: "1" }}) db_batch.should_receive("batch_put_entity").and_return(None) dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, None, max_id=10), (1, 10)) db_batch.should_receive("batch_get_entity").and_return( {PREFIX: { APP_ID_SCHEMA[0]: "1" }}) db_batch.should_receive("batch_put_entity").and_return(None) try: # Unable to use self.assertRaises because of the optional argrument max_id ed = DatastoreDistributed(db_batch, self.get_zookeeper()) dd.allocate_ids(PREFIX, BATCH_SIZE, max_id=10) raise "Allocate IDs should not let you set max_id and size" except ValueError: pass
def test_allocate_ids(self): PREFIX = "x" BATCH_SIZE = 1000 db_batch = flexmock() db_batch.should_receive("batch_get_entity").and_return({PREFIX:{APP_ID_SCHEMA[0]:"1"}}) db_batch.should_receive("batch_put_entity").and_return(None) dd = DatastoreDistributed(db_batch) assert dd.allocate_ids(PREFIX, BATCH_SIZE) == (20000, 20999)
def test_allocate_ids(self): PREFIX = "x" BATCH_SIZE = 1000 db_batch = flexmock() dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, BATCH_SIZE), (1, 1000)) dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, None, max_id=1000), (1, 1000)) try: # Unable to use self.assertRaises because of the optional argrument max_id ed = DatastoreDistributed(db_batch, self.get_zookeeper()) dd.allocate_ids(PREFIX, BATCH_SIZE, max_id=10) raise "Allocate IDs should not let you set max_id and size" except ValueError: pass
def test_allocate_ids(self): PREFIX = "x" BATCH_SIZE = 1000 db_batch = flexmock() dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, BATCH_SIZE), (1, 1000)) dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, None, max_id=1000), (1, 1000)) try: # Unable to use self.assertRaises because of the optional argrument max_id ed = DatastoreDistributed(db_batch, self.get_zookeeper()) dd.allocate_ids(PREFIX, BATCH_SIZE, max_id=10) raise "Allocate IDs should not let you set max_id and size" except ValueError: pass
def test_allocate_ids(self): PREFIX = "x" BATCH_SIZE = 1000 db_batch = flexmock() db_batch.should_receive("batch_get_entity").and_return( {PREFIX: { APP_ID_SCHEMA[0]: "1" }}) db_batch.should_receive("batch_put_entity").and_return(None) dd = DatastoreDistributed(db_batch) assert dd.allocate_ids(PREFIX, BATCH_SIZE) == (20000, 20999)
def test_allocate_ids(self): PREFIX = "x" BATCH_SIZE = 1000 db_batch = flexmock() db_batch.should_receive("batch_get_entity").and_return({PREFIX:{APP_ID_SCHEMA[0]:"1"}}) db_batch.should_receive("batch_put_entity").and_return(None) dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, BATCH_SIZE), (1, 1000)) db_batch.should_receive("batch_get_entity").and_return({PREFIX:{APP_ID_SCHEMA[0]:"1"}}) db_batch.should_receive("batch_put_entity").and_return(None) dd = DatastoreDistributed(db_batch, self.get_zookeeper()) self.assertEquals(dd.allocate_ids(PREFIX, None, max_id=10), (1, 10)) db_batch.should_receive("batch_get_entity").and_return({PREFIX:{APP_ID_SCHEMA[0]:"1"}}) db_batch.should_receive("batch_put_entity").and_return(None) try: # Unable to use self.assertRaises because of the optional argrument max_id ed = DatastoreDistributed(db_batch, self.get_zookeeper()) dd.allocate_ids(PREFIX, BATCH_SIZE, max_id=10) raise "Allocate IDs should not let you set max_id and size" except ValueError: pass