Skip to content

Commit dc5c43f

Browse files
committed
Fixing testErrorWhileStreamingRows again
1 parent d2edcb4 commit dc5c43f

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

marklogic-client-api/src/test/java/com/marklogic/client/test/rows/RowManagerTest.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.databind.JsonNode;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020
import com.marklogic.client.FailedRequestException;
21+
import com.marklogic.client.MarkLogicIOException;
2122
import com.marklogic.client.datamovement.DataMovementManager;
2223
import com.marklogic.client.datamovement.WriteBatcher;
2324
import com.marklogic.client.document.DocumentManager;
@@ -531,16 +532,17 @@ public void testErrorWhileStreamingRows() {
531532
RowManager rowManager = Common.client.newRowManager();
532533
PlanBuilder.ModifyPlan plan = rowManager.newPlanBuilder().fromSql(validQueryThatEventuallyThrowsAnError);
533534

534-
FailedRequestException ex = assertThrows(FailedRequestException.class, () -> rowManager.resultRows(plan),
535-
"The SQL query is designed to not immediately fail - it will immediately return a 200 status code to the " +
536-
"Java Client because the query itself can be executed - but will fail later as it streams rows; " +
537-
"specifically, it will fail on the second row, which is the 'Byron' row. " +
538-
"If chunking is configured correctly for the /v1/rows requests - i.e. if the " +
539-
"'TE' header is present - then ML should return trailers in the HTTP response named 'ml-error-code' and " +
540-
"'ml-error-message'. Those are intended to indicate that while a 200 was returned, an error occurred later " +
541-
"while streaming data back. The Java Client is then expected to detect those trailers and throw a " +
542-
"FailedRequestException. If the Java Client does not do that, then no exception will be thrown and this " +
543-
"assertion will fail.");
535+
if (Common.getMarkLogicVersion().getMajor() >= 12) {
536+
FailedRequestException ex = assertThrows(FailedRequestException.class, () -> rowManager.resultRows(plan),
537+
"The SQL query is designed to not immediately fail - it will immediately return a 200 status code to the " +
538+
"Java Client because the query itself can be executed - but will fail later as it streams rows; " +
539+
"specifically, it will fail on the second row, which is the 'Byron' row. " +
540+
"If chunking is configured correctly for the /v1/rows requests - i.e. if the " +
541+
"'TE' header is present - then ML should return trailers in the HTTP response named 'ml-error-code' and " +
542+
"'ml-error-message'. Those are intended to indicate that while a 200 was returned, an error occurred later " +
543+
"while streaming data back. The Java Client is then expected to detect those trailers and throw a " +
544+
"FailedRequestException. If the Java Client does not do that, then no exception will be thrown and this " +
545+
"assertion will fail.");
544546

545547
assertEquals(500, ex.getServerStatusCode(),
546548
"A 500 is expected, even though ML immediately returned a 200 before it started streaming any data " +
@@ -556,6 +558,13 @@ public void testErrorWhileStreamingRows() {
556558
ex.getMessage().contains("SQL-TABLENOTFOUND"),
557559
"The exception message is expected to be a formatted message containing the values of the 'ml-error-code' and " +
558560
"'ml-error-message' trailers");
561+
562+
} else {
563+
// For unknown reasons in MarkLogic 11, the invalid query immediately causes an IO error, while on MarkLogic 12,
564+
// the expected exception is thrown.
565+
MarkLogicIOException ex = assertThrows(MarkLogicIOException.class, () -> rowManager.resultRows(plan));
566+
assertTrue(ex.getMessage().contains("unexpected end of stream"), "Unexpected error: " + ex.getMessage());
567+
}
559568
}
560569

561570
@Test

0 commit comments

Comments
 (0)