Skip to content

Commit b6517df

Browse files
assert chunk count
1 parent e115afd commit b6517df

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import java.util.HashMap;
1919
import java.util.Map;
2020
import java.util.Objects;
21+
import java.util.function.Function;
22+
import java.util.stream.Collectors;
23+
import java.util.stream.IntStream;
2124

2225
public class GetMappingsResponseTests extends AbstractWireSerializingTestCase<GetMappingsResponse> {
2326

@@ -63,6 +66,22 @@ protected GetMappingsResponse createTestInstance() {
6366
return resp;
6467
}
6568

69+
public void testChunkedXContentUsesChunkPerIndex() {
70+
final int indexCount = randomIntBetween(1, 10);
71+
final var response = new GetMappingsResponse(
72+
IntStream.range(0, indexCount)
73+
.mapToObj(i -> "index-" + i)
74+
.collect(Collectors.toUnmodifiableMap(Function.identity(), k -> createMappingsForIndex()))
75+
);
76+
final var chunks = response.toXContentChunked();
77+
int chunkCount = 0;
78+
while (chunks.hasNext()) {
79+
chunks.next();
80+
chunkCount++;
81+
}
82+
assertEquals(indexCount, chunkCount);
83+
}
84+
6685
// Not meant to be exhaustive
6786
private static Map<String, Object> randomFieldMapping() {
6887
Map<String, Object> mappings = new HashMap<>();

0 commit comments

Comments
 (0)