def test_handle_init1(self): self.service.access_mode = 'r' memcache.set(self.memcache_prefix + 'update_' + '1', {'path': ['a'], 'new_value': '["v1"]'}) memcache.set(self.memcache_prefix + 'state', { 'token': 'state_token_1', 'version': 1, 'last_transaction': [ {'path': ['b'], 'new_value': '["v2"]', 'version': 2}, ], 'clients': set(['1']) }) yield self.service._DatasourceService__handle_init({'init': [None, 'abc']}) self.assertEquals({'1': {'service1': [{'init_success': [ 'abc', 'state_token_1', 0, {}, [ ['a', ["v1"], 1], ['b', ["v2"], 2], ] ]}]}}, mcchannel._outgoing_messages) mcchannel._outgoing_messages = defaultdict(lambda: defaultdict(list)) datasource._Version(parent=self.datasource_key, id=1, version=1).put() datasource._Value(parent=self.datasource_key, id='a', value='["v3"]').put() yield self.service._DatasourceService__handle_init({'init': [None, 'abc']}) self.assertEquals({'1': {'service1': [{'init_success': [ 'abc', 'state_token_1', 1, {'a': {'.': ["v3"]}}, [ ['b', ["v2"], 2], ] ]}]}}, mcchannel._outgoing_messages) mcchannel._outgoing_messages = defaultdict(lambda: defaultdict(list)) datasource._Version(parent=self.datasource_key, id=1, version=2).put() datasource._Value(parent=self.datasource_key, id='b', value='["v4"]').put() yield self.service._DatasourceService__handle_init({'init': [None, 'abc']}) self.assertEquals({'1': {'service1': [{'init_success': [ 'abc', 'state_token_1', 2, { 'a': {'.': ["v3"]}, 'b': {'.': ["v4"]} }, [] ]}]}}, mcchannel._outgoing_messages)
def test_get_disk_state(self): disk_state = yield self.service._DatasourceService__get_disk_state() self.assertEquals((0, {}), disk_state) datasource._Version(parent=self.datasource_key, id=1, version=3).put() datasource._Value(parent=self.datasource_key, id='/', value='["v1"]').put() datasource._Value(parent=self.datasource_key, id='a0/a1', value='["v2"]').put() disk_state = yield self.service._DatasourceService__get_disk_state() self.assertEquals((3, { '.': ["v1"], 'a0': {'a1': {'.': ["v2"]}} }), disk_state)
def test_get_disk_version(self): version = yield self.service._DatasourceService__get_disk_version() self.assertEquals(0, version) datasource._Version(parent=self.datasource_key, id=1, version=3).put() version = yield self.service._DatasourceService__get_disk_version() self.assertEquals(3, version)