code: def test_external_sort(self):
      class CustomizedSorter(ExternalSorter):
          def _next_limit(self):
              return self.memory_limit
  
      lst = list(range(1024))
      random.shuffle(lst)
      sorter = CustomizedSorter(1)
      self.assertEqual(sorted(lst), list(sorter.sorted(lst)))
      self.assertGreater(shuffle.DiskBytesSpilled, 0)
      last = shuffle.DiskBytesSpilled
      self.assertEqual(
          sorted(lst, reverse=True),
          list(sorter.sorted(lst, reverse=True)),
      )
      self.assertGreater(shuffle.DiskBytesSpilled, last)
      last = shuffle.DiskBytesSpilled
      self.assertEqual(
          sorted(lst, key=lambda x: -x),
          list(sorter.sorted(lst, key=lambda x: -x)),
      )
      self.assertGreater(shuffle.DiskBytesSpilled, last)
      last = shuffle.DiskBytesSpilled
      self.assertEqual(
          sorted(lst, key=lambda x: -x, reverse=True),
          list(sorter.sorted(lst, key=lambda x: -x, reverse=True)),
      )
      self.assertGreater(shuffle.DiskBytesSpilled, last)
  
imports: import random
  import unittest
  import tempfile
  import os
  from py4j.protocol import Py4JJavaError
  from pyspark import shuffle, CPickleSerializer, SparkConf, SparkContext
  from pyspark.shuffle import Aggregator, ExternalMerger, ExternalSorter, SimpleAggregator, Merger, ExternalGroupBy
label_desc: Use image node_id 2 for calling the SorterTests obj's underlying member method code with example usage: obj.test_external_sort() and returns: self