|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.datafusion; |
| 21 | + |
| 22 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertSame; |
| 25 | + |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +class DataFusionExceptionTest { |
| 29 | + |
| 30 | + @Test |
| 31 | + void parentExtendsRuntimeException() { |
| 32 | + DataFusionException e = new DataFusionException("x"); |
| 33 | + assertInstanceOf(RuntimeException.class, e); |
| 34 | + assertEquals("x", e.getMessage()); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + void parentCauseConstructorPropagatesCause() { |
| 39 | + Throwable cause = new IllegalStateException("inner"); |
| 40 | + DataFusionException e = new DataFusionException("outer", cause); |
| 41 | + assertEquals("outer", e.getMessage()); |
| 42 | + assertSame(cause, e.getCause()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void allSubclassesExtendDataFusionException() { |
| 47 | + // Each subclass must extend the parent so callers can `catch |
| 48 | + // (DataFusionException)` for "anything from DataFusion" and `catch |
| 49 | + // (RuntimeException)` keeps working unchanged. |
| 50 | + assertInstanceOf(DataFusionException.class, new PlanException("x")); |
| 51 | + assertInstanceOf(DataFusionException.class, new ExecutionException("x")); |
| 52 | + assertInstanceOf(DataFusionException.class, new ResourcesExhaustedException("x")); |
| 53 | + assertInstanceOf(DataFusionException.class, new IoException("x")); |
| 54 | + assertInstanceOf(DataFusionException.class, new NotImplementedException("x")); |
| 55 | + assertInstanceOf(DataFusionException.class, new ConfigurationException("x")); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void allSubclassesExtendRuntimeException() { |
| 60 | + // Existing callers use `catch (RuntimeException)`. A typed-exception PR |
| 61 | + // that breaks them is a regression even if the new types are correct. |
| 62 | + assertInstanceOf(RuntimeException.class, new PlanException("x")); |
| 63 | + assertInstanceOf(RuntimeException.class, new ExecutionException("x")); |
| 64 | + assertInstanceOf(RuntimeException.class, new ResourcesExhaustedException("x")); |
| 65 | + assertInstanceOf(RuntimeException.class, new IoException("x")); |
| 66 | + assertInstanceOf(RuntimeException.class, new NotImplementedException("x")); |
| 67 | + assertInstanceOf(RuntimeException.class, new ConfigurationException("x")); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + void allSubclassesAcceptCauseConstructor() { |
| 72 | + // The (String, Throwable) constructor is the seam upstream issue #55 |
| 73 | + // plugs into for Java-throwable propagation from JVM upcalls. v1 has no |
| 74 | + // production caller for it, but it must exist on every subclass so #55 |
| 75 | + // doesn't have to add it later. |
| 76 | + Throwable cause = new IllegalStateException("c"); |
| 77 | + assertSame(cause, new PlanException("m", cause).getCause()); |
| 78 | + assertSame(cause, new ExecutionException("m", cause).getCause()); |
| 79 | + assertSame(cause, new ResourcesExhaustedException("m", cause).getCause()); |
| 80 | + assertSame(cause, new IoException("m", cause).getCause()); |
| 81 | + assertSame(cause, new NotImplementedException("m", cause).getCause()); |
| 82 | + assertSame(cause, new ConfigurationException("m", cause).getCause()); |
| 83 | + } |
| 84 | +} |
0 commit comments