-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #2340: Ensure CompositeQueryLogic error codes are sent to metri…
…cs (#2399) The query metrics API expects QueryExceptions to be found in the cause of the original exception passed to BaseQueryMetric.setError(Throwable). In the case of CompositeQueryLogic, due to the additional wrapping of exceptions passed from its defined internal logics in a CompositeLogicException, query exceptions were not in the expected place in the stack hierarchy. Updateid the CompositeLogicException to identify any QueryExceptions present in the stacks of exception arguments, and ensure that they are either already a QueryException, or that if they contain a QueryException in the stack, that they are subsequently wrapped in a CompositeRaisedQueryException with a copy of the desired error code.
- Loading branch information
Showing
4 changed files
with
182 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...uery/src/main/java/datawave/core/query/logic/composite/CompositeRaisedQueryException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package datawave.core.query.logic.composite; | ||
|
||
import datawave.webservice.query.exception.QueryException; | ||
|
||
/** | ||
* This class exists to be used when a {@link CompositeLogicException} has a cause that is not a {@link QueryException}, but contains a {@link QueryException} | ||
* in its stack trace. In order for the error code to be properly passed to query metrics, the error code must be present as part of the | ||
* {@link CompositeLogicException}'s cause. This exception is intended to be a wrapper for the original cause, with the error code of the identified query | ||
* exception. | ||
*/ | ||
public class CompositeRaisedQueryException extends QueryException { | ||
|
||
public CompositeRaisedQueryException(Throwable cause, String errorCode) { | ||
super(cause, errorCode); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
.../query/src/test/java/datawave/core/query/logic/composite/CompositeLogicExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package datawave.core.query.logic.composite; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
|
||
import datawave.webservice.query.exception.DatawaveErrorCode; | ||
import datawave.webservice.query.exception.QueryException; | ||
|
||
public class CompositeLogicExceptionTest { | ||
|
||
@Test | ||
public void testSingleNonQueryExceptionCause() { | ||
IllegalArgumentException cause = new IllegalArgumentException("illegal argument"); | ||
CompositeLogicException exception = new CompositeLogicException("composite error occurred", "LogicName", cause); | ||
assertEquals("composite error occurred:\nLogicName: illegal argument", exception.getMessage()); | ||
assertEquals(cause, exception.getCause()); | ||
} | ||
|
||
@Test | ||
public void testSingleQueryExceptionCause() { | ||
QueryException cause = new QueryException(DatawaveErrorCode.MODEL_FETCH_ERROR, "connection failed"); | ||
CompositeLogicException exception = new CompositeLogicException("composite error occurred", "LogicName", cause); | ||
|
||
assertEquals("composite error occurred:\nLogicName: Could not get model. connection failed", exception.getMessage()); | ||
assertEquals(cause, exception.getCause()); | ||
assertEquals(DatawaveErrorCode.MODEL_FETCH_ERROR.getErrorCode(), ((QueryException) exception.getCause()).getErrorCode()); | ||
} | ||
|
||
@Test | ||
public void testNestedSingleQueryExceptionCause() { | ||
QueryException nestedCause = new QueryException(DatawaveErrorCode.MODEL_FETCH_ERROR, "connection failed"); | ||
IllegalArgumentException cause = new IllegalArgumentException("illegal argument", nestedCause); | ||
CompositeLogicException exception = new CompositeLogicException("composite error occurred", "LogicName", cause); | ||
assertEquals("composite error occurred:\nLogicName: illegal argument", exception.getMessage()); | ||
assertEquals(CompositeRaisedQueryException.class, exception.getCause().getClass()); | ||
assertEquals(DatawaveErrorCode.MODEL_FETCH_ERROR.getErrorCode(), ((CompositeRaisedQueryException) exception.getCause()).getErrorCode()); | ||
} | ||
|
||
@Test | ||
public void testMultipleNonQueryExceptionCauses() { | ||
IllegalArgumentException expectedCause = new IllegalArgumentException("illegal name"); | ||
Map<String,Exception> exceptions = new LinkedHashMap<>(); | ||
exceptions.put("logic1", expectedCause); | ||
exceptions.put("logic2", new NullPointerException("null value")); | ||
exceptions.put("logic3", new IllegalStateException("bad state")); | ||
|
||
CompositeLogicException exception = new CompositeLogicException("failed to complete", exceptions); | ||
assertEquals("failed to complete:\nlogic1: illegal name\nlogic2: null value\nlogic3: bad state", exception.getMessage()); | ||
assertEquals(expectedCause, exception.getCause()); | ||
} | ||
|
||
@Test | ||
public void testMultipleExceptionWithOneTopLevelQueryException() { | ||
QueryException expectedCause = new QueryException(DatawaveErrorCode.MODEL_FETCH_ERROR, "connection failed"); | ||
Map<String,Exception> exceptions = new LinkedHashMap<>(); | ||
exceptions.put("logic1", new IllegalArgumentException("illegal name")); | ||
exceptions.put("logic2", new NullPointerException("null value")); | ||
exceptions.put("logic3", expectedCause); | ||
exceptions.put("logic4", new IllegalStateException("bad state")); | ||
|
||
CompositeLogicException exception = new CompositeLogicException("failed to complete", exceptions); | ||
assertEquals("failed to complete:\nlogic1: illegal name\nlogic2: null value\nlogic3: Could not get model. connection failed\nlogic4: bad state", | ||
exception.getMessage()); | ||
assertEquals(expectedCause, exception.getCause()); | ||
} | ||
|
||
@Test | ||
public void testMultipleExceptionWithOneNestedQueryException() { | ||
QueryException nestedCause = new QueryException(DatawaveErrorCode.MODEL_FETCH_ERROR, "connection failed"); | ||
IllegalStateException topCause = new IllegalStateException("bad state", nestedCause); | ||
Map<String,Exception> exceptions = new LinkedHashMap<>(); | ||
exceptions.put("logic1", new IllegalArgumentException("illegal name")); | ||
exceptions.put("logic2", topCause); | ||
exceptions.put("logic3", new NullPointerException("null value")); | ||
|
||
CompositeLogicException exception = new CompositeLogicException("failed to complete", exceptions); | ||
assertEquals("failed to complete:\nlogic1: illegal name\nlogic2: bad state\nlogic3: null value", exception.getMessage()); | ||
assertEquals(CompositeRaisedQueryException.class, exception.getCause().getClass()); | ||
assertEquals(DatawaveErrorCode.MODEL_FETCH_ERROR.getErrorCode(), ((CompositeRaisedQueryException) exception.getCause()).getErrorCode()); | ||
} | ||
|
||
@Test | ||
public void testMultipleExceptionWithNestedQueryExceptionSeenFirst() { | ||
QueryException nestedCause = new QueryException(DatawaveErrorCode.MODEL_FETCH_ERROR, "connection failed"); | ||
IllegalStateException topCause = new IllegalStateException("bad state", nestedCause); | ||
Map<String,Exception> exceptions = new LinkedHashMap<>(); | ||
exceptions.put("logic1", topCause); | ||
exceptions.put("logic2", new IllegalArgumentException("illegal name")); | ||
exceptions.put("logic3", new NullPointerException("null value")); | ||
|
||
CompositeLogicException exception = new CompositeLogicException("failed to complete", exceptions); | ||
assertEquals("failed to complete:\nlogic1: bad state\nlogic2: illegal name\nlogic3: null value", exception.getMessage()); | ||
assertEquals(CompositeRaisedQueryException.class, exception.getCause().getClass()); | ||
assertEquals(DatawaveErrorCode.MODEL_FETCH_ERROR.getErrorCode(), ((CompositeRaisedQueryException) exception.getCause()).getErrorCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters