Skip to content

Commit 85f5222

Browse files
committed
Revert "WIP (#121463)"
This reverts commit fd1bd79. PR was merged by a mistake, still needs to get reviewed.
1 parent c8b6d2f commit 85f5222

File tree

2 files changed

+2
-57
lines changed

2 files changed

+2
-57
lines changed

test/framework/src/main/java/org/elasticsearch/test/AbstractXContentTestCase.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,8 @@ private XContentTester(
145145
public void test() throws IOException {
146146
for (int runs = 0; runs < numberOfTestRuns; runs++) {
147147
XContentType xContentType = randomFrom(XContentType.values()).canonical();
148-
T testInstance = null;
148+
T testInstance = instanceSupplier.apply(xContentType);
149149
try {
150-
if (xContentType.equals(XContentType.YAML)) {
151-
testInstance = randomValueOtherThanMany(instance -> {
152-
// unicode character U+0085 (NEXT LINE (NEL)) doesn't survive YAML round trip tests (see #97716)
153-
// get a new random instance if we detect this character in the xContent output
154-
try {
155-
return toXContent.apply(instance, xContentType).utf8ToString().contains("\u0085");
156-
} catch (IOException e) {
157-
throw new RuntimeException(e);
158-
}
159-
}, () -> instanceSupplier.apply(xContentType));
160-
} else {
161-
testInstance = instanceSupplier.apply(xContentType);
162-
}
163150
BytesReference originalXContent = toXContent.apply(testInstance, xContentType);
164151
BytesReference shuffledContent = insertRandomFieldsAndShuffle(
165152
originalXContent,
@@ -186,9 +173,7 @@ public void test() throws IOException {
186173
dispose.accept(parsed);
187174
}
188175
} finally {
189-
if (testInstance != null) {
190-
dispose.accept(testInstance);
191-
}
176+
dispose.accept(testInstance);
192177
}
193178
}
194179
}

test/framework/src/test/java/org/elasticsearch/test/AbstractXContentTestCaseTests.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
import com.carrotsearch.randomizedtesting.RandomizedContext;
1313

1414
import org.elasticsearch.common.bytes.BytesReference;
15-
import org.elasticsearch.xcontent.ToXContentFragment;
1615
import org.elasticsearch.xcontent.XContentBuilder;
1716
import org.elasticsearch.xcontent.XContentFactory;
1817
import org.elasticsearch.xcontent.XContentParser;
1918
import org.elasticsearch.xcontent.XContentType;
2019

21-
import java.io.IOException;
2220
import java.util.Map;
2321

2422
import static org.hamcrest.Matchers.equalTo;
@@ -51,42 +49,4 @@ public void testInsertRandomFieldsAndShuffle() throws Exception {
5149
assertThat(mapOrdered.keySet().iterator().next(), not(equalTo("field")));
5250
}
5351
}
54-
55-
private record TestToXContent(String field, String value) implements ToXContentFragment {
56-
57-
@Override
58-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
59-
return builder.field(field, value);
60-
}
61-
}
62-
63-
public void testYamlXContentRoundtripSanitization() throws Exception {
64-
var test = new AbstractXContentTestCase<TestToXContent>() {
65-
66-
@Override
67-
protected TestToXContent createTestInstance() {
68-
// we need to randomly create both a "problematic" and an okay version in order to ensure that the sanitization code
69-
// can draw at least one okay version if polled often enough
70-
return randomBoolean() ? new TestToXContent("a\u0085b", "def") : new TestToXContent("a b", "def");
71-
}
72-
73-
@Override
74-
protected TestToXContent doParseInstance(XContentParser parser) throws IOException {
75-
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
76-
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
77-
String name = parser.currentName();
78-
assertEquals(XContentParser.Token.VALUE_STRING, parser.nextToken());
79-
String value = parser.text();
80-
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
81-
return new TestToXContent(name, value);
82-
};
83-
84-
@Override
85-
protected boolean supportsUnknownFields() {
86-
return false;
87-
}
88-
};
89-
// testFromXContent runs 20 repetitions, enough to hit a YAML xcontent version very likely
90-
test.testFromXContent();
91-
}
9252
}

0 commit comments

Comments
 (0)