flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [2/5] flink git commit: [FLINK-3782] [tests] Properly close streams in CollectionInputFormatTest
Date Tue, 17 May 2016 21:44:23 GMT
[FLINK-3782] [tests] Properly close streams in CollectionInputFormatTest

This closes #1995


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/6c0c0a54
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/6c0c0a54
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/6c0c0a54

Branch: refs/heads/master
Commit: 6c0c0a54a2f47780b338c79023acd0566007e709
Parents: bd1c245
Author: Joshi <rekhajoshm@gmail.com>
Authored: Mon May 16 15:18:42 2016 -0700
Committer: Stephan Ewen <sewen@apache.org>
Committed: Tue May 17 20:18:24 2016 +0200

----------------------------------------------------------------------
 .../api/java/io/CollectionInputFormatTest.java  | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/6c0c0a54/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
b/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
index ebaa44d..53523b0 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/io/CollectionInputFormatTest.java
@@ -80,7 +80,8 @@ public class CollectionInputFormatTest {
 
 	@Test
 	public void testSerializability() {
-		try {
+		try (ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+			 ObjectOutputStream out = new ObjectOutputStream(buffer)) {
 			Collection<ElementType> inputCollection = new ArrayList<ElementType>();
 			ElementType element1 = new ElementType(1);
 			ElementType element2 = new ElementType(2);
@@ -95,9 +96,6 @@ public class CollectionInputFormatTest {
 			CollectionInputFormat<ElementType> inputFormat = new CollectionInputFormat<ElementType>(inputCollection,
 					info.createSerializer(new ExecutionConfig()));
 
-			ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-			ObjectOutputStream out = new ObjectOutputStream(buffer);
-
 			out.writeObject(inputFormat);
 
 			ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
@@ -125,6 +123,7 @@ public class CollectionInputFormatTest {
 			e.printStackTrace();
 			fail(e.toString());
 		}
+
 	}
 	
 	@Test
@@ -204,14 +203,12 @@ public class CollectionInputFormatTest {
 	
 	@Test
 	public void testSerializationFailure() {
-		try {
+		try (ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+			ObjectOutputStream out = new ObjectOutputStream(buffer)) {
 			// a mock serializer that fails when writing
 			CollectionInputFormat<ElementType> inFormat = new CollectionInputFormat<ElementType>(
 					Collections.singleton(new ElementType()), new TestSerializer(false, true));
 			
-			ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-			ObjectOutputStream out = new ObjectOutputStream(buffer);
-			
 			try {
 				out.writeObject(inFormat);
 				fail("should throw an exception");
@@ -231,13 +228,12 @@ public class CollectionInputFormatTest {
 	
 	@Test
 	public void testDeserializationFailure() {
-		try {
+		try (ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+			 ObjectOutputStream out = new ObjectOutputStream(buffer)) {
 			// a mock serializer that fails when writing
 			CollectionInputFormat<ElementType> inFormat = new CollectionInputFormat<ElementType>(
 					Collections.singleton(new ElementType()), new TestSerializer(true, false));
-			
-			ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-			ObjectOutputStream out = new ObjectOutputStream(buffer);
+
 			out.writeObject(inFormat);
 			out.close();
 			


Mime
View raw message