forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chunk SingleNodeShutdownStatus and ShutdownShardMigrationStatus (and …
…related action) response (elastic#99798) Moving SingleNodeShutdownStatus and ShutdownShardMigrationStatus to chunked response
- Loading branch information
Showing
7 changed files
with
207 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pr: 99798 | ||
summary: Chunk `SingleNodeShutdownStatus` and `ShutdownShardMigrationStatus` (and | ||
related action) response | ||
area: Infra/Node Lifecycle | ||
type: enhancement | ||
issues: | ||
- 99678 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
server/src/test/java/org/elasticsearch/common/xcontent/ChunkedToXContentHelperTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.common.xcontent; | ||
|
||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.collect.Iterators; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xcontent.ToXContent; | ||
|
||
import java.util.Iterator; | ||
import java.util.function.IntFunction; | ||
|
||
import static org.elasticsearch.xcontent.ToXContent.EMPTY_PARAMS; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class ChunkedToXContentHelperTests extends ESTestCase { | ||
|
||
public void testFieldWithInnerChunkedObject() { | ||
|
||
ToXContent innerXContent = (builder, p) -> { | ||
builder.startObject(); | ||
builder.field("field1", 10); | ||
builder.field("field2", "aaa"); | ||
builder.endObject(); | ||
return builder; | ||
}; | ||
|
||
ToXContent outerXContent = (builder, p) -> { | ||
builder.field("field3", 10); | ||
builder.field("field4", innerXContent); | ||
return builder; | ||
}; | ||
|
||
var expectedContent = Strings.toString(outerXContent); | ||
|
||
ChunkedToXContentObject innerChunkedContent = params -> Iterators.concat( | ||
ChunkedToXContentHelper.startObject(), | ||
ChunkedToXContentHelper.field("field1", 10), | ||
ChunkedToXContentHelper.field("field2", "aaa"), | ||
ChunkedToXContentHelper.endObject() | ||
); | ||
|
||
ChunkedToXContent outerChunkedContent = params -> Iterators.concat( | ||
ChunkedToXContentHelper.field("field3", 10), | ||
ChunkedToXContentHelper.field("field4", innerChunkedContent, EMPTY_PARAMS) | ||
); | ||
|
||
assertThat(Strings.toString(outerChunkedContent), equalTo(expectedContent)); | ||
} | ||
|
||
public void testFieldWithInnerChunkedArray() { | ||
|
||
ToXContent innerXContent = (builder, p) -> { | ||
builder.startArray(); | ||
builder.value(10); | ||
builder.value(20); | ||
builder.endArray(); | ||
return builder; | ||
}; | ||
|
||
ToXContent outerXContent = (builder, p) -> { | ||
builder.field("field3", 10); | ||
builder.field("field4", innerXContent); | ||
return builder; | ||
}; | ||
|
||
var expectedContent = Strings.toString(outerXContent); | ||
|
||
IntFunction<Iterator<ToXContent>> value = v -> Iterators.single(((builder, p) -> builder.value(v))); | ||
|
||
ChunkedToXContentObject innerChunkedContent = params -> Iterators.concat( | ||
ChunkedToXContentHelper.startArray(), | ||
value.apply(10), | ||
value.apply(20), | ||
ChunkedToXContentHelper.endArray() | ||
); | ||
|
||
ChunkedToXContent outerChunkedContent = params -> Iterators.concat( | ||
ChunkedToXContentHelper.field("field3", 10), | ||
ChunkedToXContentHelper.field("field4", innerChunkedContent, EMPTY_PARAMS) | ||
); | ||
|
||
assertThat(Strings.toString(outerChunkedContent), equalTo(expectedContent)); | ||
} | ||
|
||
public void testFieldWithInnerChunkedField() { | ||
|
||
ToXContent innerXContent = (builder, p) -> { | ||
builder.value(10); | ||
return builder; | ||
}; | ||
|
||
ToXContent outerXContent = (builder, p) -> { | ||
builder.field("field3", 10); | ||
builder.field("field4", innerXContent); | ||
return builder; | ||
}; | ||
|
||
var expectedContent = Strings.toString(outerXContent); | ||
|
||
IntFunction<Iterator<ToXContent>> value = v -> Iterators.single(((builder, p) -> builder.value(v))); | ||
|
||
ChunkedToXContentObject innerChunkedContent = params -> Iterators.single((builder, p) -> builder.value(10)); | ||
|
||
ChunkedToXContent outerChunkedContent = params -> Iterators.concat( | ||
ChunkedToXContentHelper.field("field3", 10), | ||
ChunkedToXContentHelper.field("field4", innerChunkedContent, EMPTY_PARAMS) | ||
); | ||
|
||
assertThat(Strings.toString(outerChunkedContent), equalTo(expectedContent)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters