def testFetchKeys(self): entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name", "prop1val", ns="blah") db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) 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()}}) zk_client = flexmock() zk_client.should_receive('add_listener') zookeeper = flexmock(handle=zk_client) zookeeper.should_receive("acquire_lock").and_return(True) zookeeper.should_receive("release_lock").and_return(True) transaction_manager = flexmock() dd = DatastoreDistributed(db_batch, transaction_manager, zookeeper) self.assertEquals(({'test\x00blah\x00test_kind:bob\x01': {'txnID': 1, 'entity': entity_proto1.Encode()} }, ['test\x00blah\x00test_kind:bob\x01']), dd.fetch_keys([entity_proto1.key()]))
def test_fetch_keys(self): entity_proto1 = self.get_new_entity_proto( "test", "test_kind", "bob", "prop1name", "prop1val", ns="blah") async_get_1 = gen.Future() async_get_1.set_result({ 'test\x00blah\x00test_kind:bob\x01': { APP_ENTITY_SCHEMA[0]: entity_proto1.Encode(), APP_ENTITY_SCHEMA[1]: 1 } }) async_get_2 = gen.Future() async_get_2.set_result({ 'test\x00blah\x00test_kind:bob\x01\x000000000002': { JOURNAL_SCHEMA[0]: entity_proto1.Encode() }}) db_batch = flexmock() db_batch.should_receive('valid_data_version_sync').and_return(True) db_batch.should_receive("batch_delete").and_return(ASYNC_NONE) db_batch.should_receive("batch_put_entity").and_return(ASYNC_NONE) db_batch.should_receive("batch_get_entity").\ and_return(async_get_1).\ and_return(async_get_2) zk_client = flexmock() zk_client.should_receive('add_listener') zookeeper = flexmock(handle=zk_client) zookeeper.should_receive("acquire_lock").and_return(True) zookeeper.should_receive("release_lock").and_return(True) transaction_manager = flexmock() dd = DatastoreDistributed(db_batch, transaction_manager, zookeeper) fetched = yield dd.fetch_keys([entity_proto1.key()]) self.assertEquals(fetched[0], { 'test\x00blah\x00test_kind:bob\x01': { 'txnID': 1, 'entity': entity_proto1.Encode() } }) self.assertEqual(fetched[1], ['test\x00blah\x00test_kind:bob\x01'])
def testFetchKeys(self): entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name", "prop1val", ns="blah") db_batch = flexmock() db_batch.should_receive('valid_data_version').and_return(True) 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) dd = DatastoreDistributed(db_batch, zookeeper) self.assertEquals(({'test\x00blah\x00test_kind:bob\x01': {'txnID': 1, 'entity': entity_proto1.Encode()} }, ['test\x00blah\x00test_kind:bob\x01']), dd.fetch_keys([entity_proto1.key()]))