InMemorySorter implements Sorter { public static InMemorySorter create(Options options) { return new InMemorySorter(options); } private  InMemorySorter(Options options); static InMemorySorter create(Options options); @Override void add(KV<byte[], byte[]> record); boolean addIfRoom(KV<byte[], byte[]> record); @Override Iterable<KV<byte[], byte[]>> sort();  }
@Test public void testEmpty() throws Exception { SorterTestUtils.testEmpty(InMemorySorter.create(new InMemorySorter.Options())); }
@Test public void testSingleElement() throws Exception { SorterTestUtils.testSingleElement(InMemorySorter.create(new InMemorySorter.Options())); }
@Test public void testEmptyKeyValueElement() throws Exception { SorterTestUtils.testEmptyKeyValueElement(InMemorySorter.create(new InMemorySorter.Options())); }
@Test public void testMultipleIterations() throws Exception { SorterTestUtils.testMultipleIterations(InMemorySorter.create(new InMemorySorter.Options())); }
@Test public void testManySorters() throws Exception { SorterTestUtils.testRandom( () -> InMemorySorter.create(new InMemorySorter.Options()), 1000000, 10); }
@Test public void testAddAfterSort() throws Exception { SorterTestUtils.testAddAfterSort(InMemorySorter.create(new InMemorySorter.Options()), thrown); fail(); }
@Test public void testSortTwice() throws Exception { SorterTestUtils.testSortTwice(InMemorySorter.create(new InMemorySorter.Options()), thrown); fail(); }
@Test public void testOutOfSpace() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage(is("No space remaining for in memory sorting")); SorterTestUtils.testRandom( () -> { InMemorySorter.Options options = new InMemorySorter.Options(); options.setMemoryMB(1); return InMemorySorter.create(options); }, 1, 10000000); }