steveloughran commented on a change in pull request #3076:
URL: https://github.com/apache/hadoop/pull/3076#discussion_r647799533
##########
File path:
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java
##########
@@ -482,6 +482,12 @@ public static IOException wrapException(final String path,
if (exception instanceof InterruptedIOException
|| exception instanceof PathIOException) {
return exception;
+ } else if (exception.getCause() != null
+ && exception.getCause() instanceof InterruptedException) {
Review comment:
you can get rid of the !=null check, as L486 does that implicitly
##########
File path:
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtilsWrapExceptionSuite.java
##########
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.io;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestIOUtilsWrapExceptionSuite extends Assert {
Review comment:
extends AbstractHadoopTestBase ; this sets up a timeout and names the
test thread
##########
File path:
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtilsWrapExceptionSuite.java
##########
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.io;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestIOUtilsWrapExceptionSuite extends Assert {
+ @Test
+ public void testWrapExceptionWithInterruptedException() throws Exception {
+ InterruptedIOException inputException = new
InterruptedIOException("message");
+ NullPointerException causeException = new
NullPointerException("cause");
+ inputException.initCause(causeException);
+ Exception outputException = IOUtils.wrapException("path",
"methodName", inputException);
+
+ // The new exception should retain the input message, cause, and type
+ assertTrue(outputException instanceof InterruptedIOException);
+ assertTrue(outputException.getCause() instanceof NullPointerException);
+ assertEquals(outputException.getMessage(),
inputException.getMessage());
+ assertEquals(outputException.getCause(), inputException.getCause());
+ }
+
+ @Test
+ public void testWrapExceptionWithInterruptedCauseException() throws
Exception {
+ IOException inputException = new IOException("message");
+ InterruptedException causeException = new
InterruptedException("cause");
+ inputException.initCause(causeException);
+ Exception outputException = IOUtils.wrapException("path",
"methodName", inputException);
+
+ // The new exception should retain the input message and cause
+ // but be an InterruptedIOException because the cause was an
InterruptedException
+ assertTrue(outputException instanceof InterruptedIOException);
Review comment:
same here, embrace AssertJ. It's better, mostly.
##########
File path:
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtilsWrapExceptionSuite.java
##########
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.io;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestIOUtilsWrapExceptionSuite extends Assert {
+ @Test
+ public void testWrapExceptionWithInterruptedException() throws Exception {
+ InterruptedIOException inputException = new
InterruptedIOException("message");
+ NullPointerException causeException = new
NullPointerException("cause");
+ inputException.initCause(causeException);
+ Exception outputException = IOUtils.wrapException("path",
"methodName", inputException);
+
+ // The new exception should retain the input message, cause, and type
+ assertTrue(outputException instanceof InterruptedIOException);
Review comment:
Can you use AssertJ assertions here? They'll fail with useful error messages
rather than just an "assert failed" which isn't any use debugging why something
failed.
```java
Assertions.assertThat(outputException)
.isInstanceOf(IOException.class);
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]