def testFetchKeys(self): 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") 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({'test\x00blah\x00test_kind:bob\x01': {APP_ENTITY_SCHEMA[0]: entity_proto1.Encode(), APP_ENTITY_SCHEMA[1]: 1}}).and_return({'test\x00blah\x00test_kind:bob\x01\x000000000002': {JOURNAL_SCHEMA[0]: entity_proto1.Encode()}}) zookeeper = flexmock() zookeeper.should_receive("acquire_lock").and_return(True) zookeeper.should_receive("release_lock").and_return(True) zookeeper.should_receive("get_valid_transaction_id").and_return(2) dd = DatastoreDistributed(db_batch, zookeeper) self.assertEquals(({'test\x00blah\x00test_kind:bob\x01': {'txnID': "2", 'entity': entity_proto1.Encode()} }, ['test\x00blah\x00test_kind:bob\x01']), dd.fetch_keys([entity_proto1.key()]))
def testFetchKeys(self): 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") 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({'test\x00blah\x00test_kind:bob!': {APP_ENTITY_SCHEMA[0]: entity_proto1.Encode(), APP_ENTITY_SCHEMA[1]: 1}}).and_return({'test\x00blah\x00test_kind:bob!\x000000000002': {JOURNAL_SCHEMA[0]: entity_proto1.Encode()}}) zookeeper = flexmock() zookeeper.should_receive("acquire_lock").and_return(True) zookeeper.should_receive("release_lock").and_return(True) zookeeper.should_receive("get_valid_transaction_id").and_return(2) dd = DatastoreDistributed(db_batch, zookeeper) self.assertEquals(({'test\x00blah\x00test_kind:bob!': {'txnID': "2", 'entity': entity_proto1.Encode()} }, ['test\x00blah\x00test_kind:bob!']), dd.fetch_keys([entity_proto1.key()]))
def testFetchKeys(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(['aaa']) dd = DatastoreDistributed(db_batch) assert dd.fetch_keys([key1.key(), key2.key()]) == (['aaa'], ['hello//Item:Bob!', 'hello//Item:Sally!'])
def testFetchKeys(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(['aaa']) dd = DatastoreDistributed(db_batch) assert dd.fetch_keys([key1.key(), key2.key()]) == (['aaa'], [ 'hello//Item:Bob!', 'hello//Item:Sally!' ])