def testSliceAndShardRetries(self):
    self.init(__name__ + ".test_handler_raise_exception")
    TestEntity().put()

    # First time, the task gets retried.
    self._handle_request(expect_finalize=False)
    self.assertEqual(httplib.SERVICE_UNAVAILABLE, self.handler.response.status)
    self.verify_shard_state(
        model.ShardState.get_by_shard_id(self.shard_id),
        active=True,
        processed=0,
        slice_retries=1)

    # After the Nth attempt on slice, we retry the shard.
    shard_state = model.ShardState.get_by_shard_id(self.shard_id)
    shard_state.slice_retries = (
        parameters.config.TASK_MAX_DATA_PROCESSING_ATTEMPTS)
    shard_state.put()
    # TODO(user): fix
    self.handler.post()
    self.verify_shard_state(
        model.ShardState.get_by_shard_id(self.shard_id),
        active=True,
        result_status=None,
        processed=0,
        slice_retries=0,
        retries=1)

  # TODO(user): test MR jobs that only allow slice or shard retry when
  # it is configurable per job.
Test when a handler throws a non fatal exception.
dataset/ETHPy150Open GoogleCloudPlatform/appengine-mapreduce/python/test/mapreduce/handlers_test.py/MapperWorkerCallbackHandlerTest.testSliceAndShardRetries