code: def test_flaky_write_row_to_file(ray_start_regular_shared, tmp_path):
      class FlakyTextDatasink(RowBasedFileDatasink):
          def __init__(self, path: str):
              super().__init__(path)
              self._num_attempts = 0
  
          def write_row_to_file(
              self, row: Dict[str, Any], file: "pyarrow.NativeFile"
          ):
              if self._num_attempts < 2:
                  self._num_attempts += 1
                  raise RuntimeError("AWS Error INTERNAL_FAILURE")
  
              file.write(f"{row['id']}".encode())
  
      ds = ray.data.range(100)
  
      ds.write_datasink(FlakyTextDatasink(tmp_path))
  
      expected_values = [str(i) for i in range(100)]
      written_values = [
          row["text"] for row in ray.data.read_text(tmp_path).take_all()
      ]
      assert sorted(written_values) == sorted(expected_values)
  
imports: import os
  from typing import Any, Dict
  import pyarrow
  import pytest
  from pyarrow.fs import LocalFileSystem
  import ray
  from ray.data.block import BlockAccessor
  from ray.data.datasource import BlockBasedFileDatasink, RowBasedFileDatasink
label_desc: Use image node_id 4 for calling a global function with example usage: test_flaky_write_row_to_file(ray_start_regular_shared, tmp_path) without return types