Small oversight in #56078 that only showed up during backporting where a stream copy was turned from a non-closing to a closing one. Enhanced part of a test in this PR to make it show up in master also even though we practically never use this method with stream targets that actually close.
This commit is contained in:
parent
222665a48e
commit
859ad761bb
|
@ -75,6 +75,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
|
@ -947,11 +948,18 @@ public abstract class BaseXContentTestCase extends ESTestCase {
|
||||||
assertNull(parser.nextToken());
|
assertNull(parser.nextToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
os = new ByteArrayOutputStream();
|
final AtomicBoolean closed = new AtomicBoolean(false);
|
||||||
|
os = new ByteArrayOutputStream() {
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
closed.set(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) {
|
try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) {
|
||||||
generator.writeStartObject();
|
generator.writeStartObject();
|
||||||
generator.writeFieldName("test");
|
generator.writeFieldName("test");
|
||||||
generator.writeRawValue(new BytesArray(rawData).streamInput(), source.type());
|
generator.writeRawValue(new BytesArray(rawData).streamInput(), source.type());
|
||||||
|
assertFalse("Generator should not have closed the output stream", closed.get());
|
||||||
generator.writeEndObject();
|
generator.writeEndObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue