@@ -0,0 +1,3157 @@
+/*%0A * Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.hazelcast.jet.pipeline;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.stream.IntStream;%0Aimport org.junit.Test;%0A%0Aimport static com.hazelcast.jet.pipeline.test.AssertionSinks.assertOrdered;%0Aimport static java.util.stream.Collectors.toList;%0Aimport static org.assertj.core.api.Assertions.assertThatThrownBy;%0A%0Apublic class SortBatchStageTest extends PipelineTestSupport %7B%0A%0A    @Test%0A    public void sort_withRepeatingItems() %7B%0A        // Given%0A        List%3CInteger%3E input = IntStream.range(0, itemCount).map(t -%3E t / 10).boxed().collect(toList());%0A        List%3CInteger%3E expected = new ArrayList%3C%3E(input);%0A        Collections.shuffle(input);%0A%0A        // When%0A        BatchStage%3CInteger%3E sorted = batchStageFromList(input).rebalance().sort();%0A%0A        // Then%0A        sorted.writeTo(assertOrdered(expected));%0A        execute();%0A    %7D%0A%0A    @Test%0A    public void sort_withComparator() %7B%0A        // Given%0A        List%3CInteger%3E input = IntStream.range(0, itemCount).boxed().sorted(Collections.reverseOrder()).collect(toList());%0A        List%3CInteger%3E expected = new ArrayList%3C%3E(input);%0A        Collections.shuffle(input);%0A%0A        // When%0A        BatchStage%3CInteger%3E sorted = batchStageFromList(input).rebalance()%0A                .sort((a, b) -%3E b - a);%0A%0A        // Then%0A        sorted.writeTo(assertOrdered(expected));%0A        execute();%0A    %7D%0A%0A    @Test%0A    public void sort_exceptionDuringComparing() %7B%0A        // Given%0A        List%3CInteger%3E input = IntStream.range(0, 20).boxed().collect(toList());%0A%0A        // When%0A        BatchStage%3CInteger%3E sorted = batchStageFromList(input).rebalance()%0A                .sort((a, b) -%3E %7B%0A                    if (a == 5 %7C%7C b == 5) %7B%0A                        throw new RuntimeException(%22expectedFailure%22);%0A                    %7D%0A                    return a - b;%0A                %7D);%0A        sorted.writeTo(Sinks.logger());%0A%0A        // Then%0A        assertThatThrownBy(this::execute)%0A                .hasRootCauseInstanceOf(RuntimeException.class)%0A                .hasMessageContaining(%22expectedFailure%22);%0A    %7D%0A%0A    @Test%0A    public void sort_lessItemsThanProcessors() %7B%0A        // Given%0A        List%3CInteger%3E input = IntStream.range(0, 3).boxed().collect(toList());%0A        List%3CInteger%3E expected = new ArrayList%3C%3E(input);%0A        Collections.shuffle(input);%0A%0A        // When%0A        BatchStage%3CInteger%3E sorted = batchStageFromList(input).sort();%0A%0A        // Then%0A        sorted.writeTo(assertOrdered(expected));%0A        execute();%0A    %7D%0A%7D%0A

Add test for sort batch stage