21
21
import org .apache .flink .runtime .executiongraph .IndexRange ;
22
22
import org .apache .flink .runtime .jobgraph .IntermediateDataSetID ;
23
23
import org .apache .flink .runtime .jobgraph .IntermediateResultPartitionID ;
24
+ import org .apache .flink .runtime .scheduler .strategy .ConsumedPartitionGroup ;
24
25
25
26
import org .junit .jupiter .api .Test ;
26
27
29
30
import java .util .List ;
30
31
import java .util .Map ;
31
32
33
+ import static org .apache .flink .runtime .io .network .partition .ResultPartitionType .BLOCKING ;
32
34
import static org .assertj .core .api .Assertions .assertThat ;
33
35
34
36
/** Tests for {@link ConsumedSubpartitionContext}. */
@@ -40,17 +42,13 @@ void testBuildConsumedSubpartitionContextWithGroups() {
40
42
new IndexRange (0 , 1 ), new IndexRange (0 , 2 ),
41
43
new IndexRange (2 , 3 ), new IndexRange (3 , 5 ));
42
44
43
- List <IntermediateResultPartitionID > consumedPartitionIds = new ArrayList <>();
44
-
45
- IntermediateResultPartitionID [] partitions = new IntermediateResultPartitionID [4 ];
46
- for (int i = 0 ; i < partitions .length ; i ++) {
47
- partitions [i ] = new IntermediateResultPartitionID (new IntermediateDataSetID (), i );
48
- consumedPartitionIds .add (partitions [i ]);
49
- }
45
+ List <IntermediateResultPartitionID > partitions = createPartitions ();
46
+ ConsumedPartitionGroup consumedPartitionGroup =
47
+ ConsumedPartitionGroup .fromMultiplePartitions (4 , partitions , BLOCKING );
50
48
51
49
ConsumedSubpartitionContext context =
52
50
ConsumedSubpartitionContext .buildConsumedSubpartitionContext (
53
- consumedSubpartitionGroups , consumedPartitionIds . iterator () , partitions );
51
+ consumedSubpartitionGroups , consumedPartitionGroup , partitions :: get );
54
52
55
53
assertThat (context .getNumConsumedShuffleDescriptors ()).isEqualTo (4 );
56
54
@@ -71,17 +69,13 @@ void testBuildConsumedSubpartitionContextWithUnorderedGroups() {
71
69
new IndexRange (3 , 3 ), new IndexRange (1 , 1 ),
72
70
new IndexRange (0 , 0 ), new IndexRange (0 , 1 ));
73
71
74
- List <IntermediateResultPartitionID > consumedPartitionIds = new ArrayList <>();
75
-
76
- IntermediateResultPartitionID [] partitions = new IntermediateResultPartitionID [4 ];
77
- for (int i = 0 ; i < partitions .length ; i ++) {
78
- partitions [i ] = new IntermediateResultPartitionID (new IntermediateDataSetID (), i );
79
- consumedPartitionIds .add (partitions [i ]);
80
- }
72
+ List <IntermediateResultPartitionID > partitions = createPartitions ();
73
+ ConsumedPartitionGroup consumedPartitionGroup =
74
+ ConsumedPartitionGroup .fromMultiplePartitions (4 , partitions , BLOCKING );
81
75
82
76
ConsumedSubpartitionContext context =
83
77
ConsumedSubpartitionContext .buildConsumedSubpartitionContext (
84
- consumedSubpartitionGroups , consumedPartitionIds . iterator () , partitions );
78
+ consumedSubpartitionGroups , consumedPartitionGroup , partitions :: get );
85
79
86
80
assertThat (context .getNumConsumedShuffleDescriptors ()).isEqualTo (2 );
87
81
@@ -100,17 +94,13 @@ void testBuildConsumedSubpartitionContextWithOverlapGroups() {
100
94
new IndexRange (0 , 3 ), new IndexRange (1 , 1 ),
101
95
new IndexRange (0 , 1 ), new IndexRange (2 , 2 ));
102
96
103
- List <IntermediateResultPartitionID > consumedPartitionIds = new ArrayList <>();
104
-
105
- IntermediateResultPartitionID [] partitions = new IntermediateResultPartitionID [4 ];
106
- for (int i = 0 ; i < partitions .length ; i ++) {
107
- partitions [i ] = new IntermediateResultPartitionID (new IntermediateDataSetID (), i );
108
- consumedPartitionIds .add (partitions [i ]);
109
- }
97
+ List <IntermediateResultPartitionID > partitions = createPartitions ();
98
+ ConsumedPartitionGroup consumedPartitionGroup =
99
+ ConsumedPartitionGroup .fromMultiplePartitions (4 , partitions , BLOCKING );
110
100
111
101
ConsumedSubpartitionContext context =
112
102
ConsumedSubpartitionContext .buildConsumedSubpartitionContext (
113
- consumedSubpartitionGroups , consumedPartitionIds . iterator () , partitions );
103
+ consumedSubpartitionGroups , consumedPartitionGroup , partitions :: get );
114
104
115
105
assertThat (context .getNumConsumedShuffleDescriptors ()).isEqualTo (4 );
116
106
@@ -144,4 +134,13 @@ void testBuildConsumedSubpartitionContextWithRange() {
144
134
IndexRange subpartitionRange = context .getConsumedSubpartitionRange (2 );
145
135
assertThat (subpartitionRange ).isEqualTo (consumedSubpartitionRange );
146
136
}
137
+
138
+ private static List <IntermediateResultPartitionID > createPartitions () {
139
+ List <IntermediateResultPartitionID > partitions = new ArrayList <>();
140
+ IntermediateDataSetID intermediateDataSetID = new IntermediateDataSetID ();
141
+ for (int i = 0 ; i < 4 ; i ++) {
142
+ partitions .add (new IntermediateResultPartitionID (intermediateDataSetID , i ));
143
+ }
144
+ return partitions ;
145
+ }
147
146
}
0 commit comments