def test_put_entities(self): PREFIX = "x!" db_batch = flexmock() db_batch.should_receive("batch_put_entity").and_return(None) db_batch.should_receive("batch_get_entity").and_return({PREFIX: {}}) db_batch.should_receive("batch_delete").and_return(None) zookeeper = flexmock() zookeeper.should_receive("acquire_lock").and_return(True) entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name", "prop1val", ns="blah") entity_proto2 = self.get_new_entity_proto("test", "test_kind", "nancy", "prop1name", "prop2val", ns="blah") entity_list = [entity_proto1, entity_proto2] dd = DatastoreDistributed(db_batch, zookeeper) # Make sure it does not throw an exception dd.put_entities("hello", entity_list, { "test/blah/test_kind:bob!": 1, "test/blah/test_kind:nancy!": 1 })
def test_put_entities(self): item1 = Item(key_name="Bob", name="Bob", _app="hello") item2 = Item(key_name="Sally", name="Sally", _app="hello") key1 = db.model_to_protobuf(item1) key2 = db.model_to_protobuf(item2) db_batch = flexmock() db_batch.should_receive("batch_delete").and_return(None) db_batch.should_receive("batch_put_entity").and_return(None) db_batch.should_receive("batch_get_entity").and_return({ "key1": {}, "key2": {} }) zookeeper = flexmock() zookeeper.should_receive("acquire_lock").and_return(True) zookeeper.should_receive("release_lock").and_return(True) dd = DatastoreDistributed(db_batch, zookeeper) dd.put_entities("hello", [key1, key2], {}) db_batch = flexmock() db_batch.should_receive("batch_delete").and_return(None) db_batch.should_receive("batch_put_entity").and_return(None) db_batch.should_receive("batch_get_entity").and_return({ "key1": { "entity": key1.Encode() }, "key2": { "entity": key2.Encode() } }) dd = DatastoreDistributed(db_batch, zookeeper) dd.put_entities("hello", [key1, key2], {})
def test_put_entities(self): item1 = Item(key_name="Bob", name="Bob", _app="hello") item2 = Item(key_name="Sally", name="Sally", _app="hello") key1 = db.model_to_protobuf(item1) key2 = db.model_to_protobuf(item2) db_batch = flexmock() db_batch.should_receive("batch_delete").and_return(None) db_batch.should_receive("batch_put_entity").and_return(None) db_batch.should_receive("batch_get_entity").and_return({"key1":{},"key2":{}}) dd = DatastoreDistributed(db_batch) dd.put_entities([key1, key2]) db_batch = flexmock() db_batch.should_receive("batch_delete").and_return(None) db_batch.should_receive("batch_put_entity").and_return(None) db_batch.should_receive("batch_get_entity").and_return({"key1":{"entity":key1.Encode()},"key2":{"entity":key2.Encode()}}) dd = DatastoreDistributed(db_batch) dd.put_entities([key1, key2])
def test_put_entities(self): PREFIX = "x!" db_batch = flexmock() db_batch.should_receive("batch_put_entity").and_return(None) db_batch.should_receive("batch_get_entity").and_return({PREFIX:{}}) db_batch.should_receive("batch_delete").and_return(None) zookeeper = flexmock() zookeeper.should_receive("acquireLock").and_return(True) entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name", "prop1val", ns="blah") entity_proto2 = self.get_new_entity_proto("test", "test_kind", "nancy", "prop1name", "prop2val", ns="blah") entity_list = [entity_proto1, entity_proto2] dd = DatastoreDistributed(db_batch, zookeeper) # Make sure it does not throw an exception dd.put_entities("hello", entity_list, {"test/blah/test_kind:bob!":1, "test/blah/test_kind:nancy!":1})
def test_put_entities(self): db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) zookeeper = flexmock() zookeeper.should_receive("acquire_lock").and_return(True) entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name", "prop1val", ns="blah") entity_key1 = 'test\x00blah\x00test_kind:bob\x01' entity_proto2 = self.get_new_entity_proto("test", "test_kind", "nancy", "prop1name", "prop2val", ns="blah") entity_key2 = 'test\x00blah\x00test_kind:nancy\x01' entity_list = [entity_proto1, entity_proto2] db_batch.should_receive('batch_get_entity').and_return( {entity_key1: {}, entity_key2: {}}) db_batch.should_receive('batch_mutate') dd = DatastoreDistributed(db_batch, zookeeper) # Make sure it does not throw an exception dd.put_entities(entity_list, {"test\x00blah\x00test_kind:bob\x01":1, "test\x00blah\x00test_kind:nancy\x01":1})