Skip to content

Commit 2bbda73

Browse files
committed
Improving error message for when max value query fails
We were catching the error when the query succeeds but brings back an unexpected result. We now catch the error when the query fails. This is in response to the `pullDataUsingFromSearchDocs` test failing due to a change in the server where the "select" call fails when used with "fromSearchDocs".
1 parent 77a2c10 commit 2bbda73

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

Jenkinsfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pipeline{
1414
stages{
1515
stage('tests'){
1616
steps{
17-
copyRPM 'Latest','11.0'
17+
copyRPM 'Release','11.0.0'
1818
setUpML '$WORKSPACE/xdmp/src/Mark*.rpm'
1919
sh label:'setup', script: '''#!/bin/bash
2020
cd kafka-connector

src/main/java/com/marklogic/kafka/connect/source/QueryHandlerUtil.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ interface QueryHandlerUtil {
3737
static String executeMaxValuePlan(RowManager rowManager, PlanBuilder.Plan maxValuePlan, long serverTimestamp, String maxValueQuery) {
3838
JacksonHandle handle = new JacksonHandle();
3939
handle.setPointInTimeQueryTimestamp(serverTimestamp);
40-
JacksonHandle result = rowManager.resultDoc(maxValuePlan, handle);
40+
41+
JacksonHandle result;
42+
try {
43+
result = rowManager.resultDoc(maxValuePlan, handle);
44+
} catch (Exception e) {
45+
throw new MarkLogicConnectorException(String.format(
46+
"Unable to get max constraint value; query: %s; server timestamp: %d; cause: %s",
47+
maxValueQuery, serverTimestamp, e.getMessage()
48+
), e);
49+
}
50+
4151
JsonNode valueNode = result.get().at("/rows/0/constraint/value");
4252
if (valueNode == null) {
4353
String message = String.format(

src/test/java/com/marklogic/kafka/connect/source/AbstractIntegrationSourceTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4343
import static org.junit.jupiter.api.Assertions.assertEquals;
44+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4445
import static org.junit.jupiter.api.Assertions.assertNull;
4546
import static org.junit.jupiter.api.Assertions.assertTrue;
4647

@@ -156,6 +157,7 @@ protected void verifyQueryReturnsExpectedRows(String constraintValue, int expect
156157
task.setConstraintValueStore(new TestConstraintValueStore((String)parsedConfig.get(MarkLogicSourceConfig.CONSTRAINT_COLUMN_NAME), constraintValue));
157158
try {
158159
List<SourceRecord> newRecords = task.poll();
160+
assertNotNull(newRecords, "poll() unexpectedly returned null; params: " + params + "; constraintValue: " + constraintValue);
159161
assertEquals(expectedRowCount, newRecords.size());
160162
assertTrue(((String) newRecords.get(0).value()).contains(stringInFirstRecord),
161163
"Did not find " + stringInFirstRecord + " in " + ((String) newRecords.get(0).value()));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.marklogic.kafka.connect.source;
2+
3+
import com.marklogic.client.io.StringHandle;
4+
import com.marklogic.client.row.RawQueryDSLPlan;
5+
import com.marklogic.client.row.RowManager;
6+
import com.marklogic.kafka.connect.MarkLogicConnectorException;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
11+
12+
public class QueryHandlerUtilTest extends AbstractIntegrationSourceTest {
13+
14+
@Test
15+
void invalidMaxValueQuery() {
16+
RowManager rowManager = getDatabaseClient().newRowManager();
17+
final String invalidDsl = "This should fail";
18+
RawQueryDSLPlan invalidQuery = rowManager.newRawQueryDSLPlan(new StringHandle(invalidDsl));
19+
20+
MarkLogicConnectorException ex = assertThrows(MarkLogicConnectorException.class,
21+
() -> QueryHandlerUtil.executeMaxValuePlan(rowManager, invalidQuery, 0, invalidDsl));
22+
23+
assertTrue(ex.getMessage().startsWith("Unable to get max constraint value; query: This should fail"),
24+
"If either our max value query has a bug in it, or the server has a bug in it with processing our max " +
25+
"value query, an exception should be thrown that informs the user that the max value query failed " +
26+
"along with what the query was");
27+
}
28+
}

0 commit comments

Comments
 (0)