You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/02/26 04:20:49 UTC

[GitHub] [accumulo] ctubbsii commented on a change in pull request #2530: checks for nested error in AUEH

ctubbsii commented on a change in pull request #2530:
URL: https://github.com/apache/accumulo/pull/2530#discussion_r815264874



##########
File path: core/src/test/java/org/apache/accumulo/core/util/threads/AccumuloUncaughtExceptionHandlerTest.java
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.accumulo.core.util.threads;
+
+import static org.apache.accumulo.core.util.threads.AccumuloUncaughtExceptionHandler.isError;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+
+import org.junit.Test;
+
+public class AccumuloUncaughtExceptionHandlerTest {
+
+  @Test
+  public void testIsError() {
+    assertFalse(isError(new IOException()));
+    assertFalse(isError(new UncheckedIOException(new IOException())));
+
+    Exception e = new UncheckedIOException(new IOException());
+    e.addSuppressed(new RuntimeException());
+    e.addSuppressed(new RuntimeException());
+    assertFalse(isError(e));
+
+    assertTrue(isError(new UnsatisfiedLinkError()));
+    assertTrue(isError(new RuntimeException(new UnsatisfiedLinkError())));
+    assertTrue(isError(new RuntimeException(new RuntimeException(new UnsatisfiedLinkError()))));
+
+    e.addSuppressed(new RuntimeException(new UnsatisfiedLinkError()));
+    assertTrue(isError(e));
+    assertTrue(isError(new RuntimeException(e)));

Review comment:
       `e` is used here, but defined earlier, with several tests in between that are unrelated. It might make more sense to split these into three test methods: `testIsError_self()`, `testIsError_cause()`, `testIsError_suppressed()` (for example) so similar tests are together, and the `e` variable is only declared alongside code that uses it.
   
   Minimally, you could use a new variable to make the two test scenarios independent, or you could reorder the test cases, so its declaration is closer to its use.
   
   Also, I noticed that all these test cases treat `Error` as the terminal `Throwable` in any given cause chain or suppressed list. The test coverage could overlook the case where an Error was caused by a non-Error, or where an Error was found in the middle of the suppressed list. Looking at the code, it seems the implementation should find the Error even in these situations... but if there were a bug where it was only found at the end, these tests wouldn't catch it.




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org