StephanEwen commented on a change in pull request #8282: [FLINK-12338] Update
Apache Avro test to use try-with-resources
URL: https://github.com/apache/flink/pull/8282#discussion_r280777846
##########
File path:
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/AvroOutputFormatTest.java
##########
@@ -107,23 +107,23 @@ private void serializeAndDeserialize(final
AvroOutputFormat.Codec codec, final S
outputFormat.setSchema(schema);
}
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- // when
- try (final ObjectOutputStream oos = new
ObjectOutputStream(bos)) {
- oos.writeObject(outputFormat);
- }
- try (final ObjectInputStream ois = new ObjectInputStream(new
ByteArrayInputStream(bos.toByteArray()))) {
- // then
- Object o = ois.readObject();
- assertTrue(o instanceof AvroOutputFormat);
- @SuppressWarnings("unchecked")
- final AvroOutputFormat<User> restored =
(AvroOutputFormat<User>) o;
- final AvroOutputFormat.Codec restoredCodec =
(AvroOutputFormat.Codec) Whitebox.getInternalState(restored, "codec");
- final Schema restoredSchema = (Schema)
Whitebox.getInternalState(restored, "userDefinedSchema");
-
- assertTrue(codec != null ? restoredCodec == codec :
restoredCodec == null);
- assertTrue(schema != null ?
restoredSchema.equals(schema) : restoredSchema == null);
+ try (final ByteArrayOutputStream bos = new
ByteArrayOutputStream()) {
+ // when
+ try (final ObjectOutputStream oos = new
ObjectOutputStream(bos)) {
+ oos.writeObject(outputFormat);
+ }
+ try (final ByteArrayInputStream bais = new
ByteArrayInputStream(bos.toByteArray());
+ final ObjectInputStream ois = new
ObjectInputStream(bais)) {
Review comment:
same as above, would not separate the nested streams/readers
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services