|
16 | 16 | package com.marklogic.client.test.rows; |
17 | 17 |
|
18 | 18 | import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; |
19 | | -import static org.junit.Assert.assertArrayEquals; |
20 | | -import static org.junit.Assert.assertEquals; |
21 | | -import static org.junit.Assert.assertFalse; |
22 | | -import static org.junit.Assert.assertNotNull; |
23 | | -import static org.junit.Assert.assertTrue; |
| 19 | +import static org.junit.Assert.*; |
24 | 20 |
|
25 | 21 | import java.io.IOException; |
26 | 22 | import java.io.LineNumberReader; |
|
40 | 36 | import javax.xml.xpath.XPathExpressionException; |
41 | 37 |
|
42 | 38 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 39 | +import com.marklogic.client.FailedRequestException; |
43 | 40 | import com.marklogic.client.datamovement.DataMovementManager; |
44 | 41 | import com.marklogic.client.datamovement.WriteBatcher; |
45 | 42 | import com.marklogic.client.io.*; |
@@ -527,27 +524,33 @@ public void testSQL0Result() { |
527 | 524 | assertEquals("", exception); |
528 | 525 | } |
529 | 526 |
|
| 527 | + /** |
| 528 | + * This test was added to take advantage of MarkLogic 11's support for HTTP chunking. It is expected that when calls |
| 529 | + * are made to /v1/rows, the TE and ML-Check-ML11-Headers headers will be added, thus triggering HTTP chunking in the |
| 530 | + * server. The SQL query in this test is designed to produce an error for the "last" musician of the 4 in the test |
| 531 | + * database. OkHttpServices is then expected to check for the special MarkLogic trailers in the HTTP response - |
| 532 | + * ml-error-code and ml-error-message. And then the end result is that a FailedRequestException is expected. |
| 533 | + * |
| 534 | + * You can verify this test works by commenting out the sections in OkHttpServices that check for the special |
| 535 | + * MarkLogic trailers in the HTTP response, and/or commenting out the two places where the TE/ML-Check-ML11-Headers |
| 536 | + * headers are sent. |
| 537 | + */ |
530 | 538 | @Test |
531 | | - public void testSQLException() { |
| 539 | + public void testMarklogicHeadersProduceExpectedError() { |
532 | 540 | if (!Common.markLogicIsVersion11OrHigher()) { |
533 | 541 | return; |
534 | 542 | } |
535 | 543 |
|
536 | 544 | RowManager rowMgr = Common.client.newRowManager(); |
537 | | - PlanBuilder p = rowMgr.newPlanBuilder(); |
538 | | - PlanBuilder.ExportablePlan builtPlan = |
539 | | - p.fromSql("select case when lastName = 'Davis' then fn_error(fn_qname('', 'SQL-TABLENOTFOUND'), 'Internal Server Error') end, opticUnitTest.musician.* from (select * from opticUnitTest.musician order by lastName)"); |
540 | | - String exception = ""; |
541 | | - int rowNum = 0; |
542 | | - try { |
543 | | - for (RowRecord row: rowMgr.resultRows(builtPlan)) { |
544 | | - rowNum++; |
545 | | - } |
546 | | - } catch (Exception e) { |
547 | | - exception = e.toString(); |
548 | | - } |
549 | | - assertEquals(0, rowNum); |
550 | | - assertEquals("com.marklogic.client.FailedRequestException: failed to apply resource at rows: SQL-TABLENOTFOUND, Internal Server Error", exception); |
| 545 | + PlanBuilder.ExportablePlan builtPlan = rowMgr.newPlanBuilder() |
| 546 | + .fromSql("select case when lastName = 'Davis' then fn_error(fn_qname('', 'SQL-TABLENOTFOUND'), 'Internal Server Error') end, " + |
| 547 | + "opticUnitTest.musician.* from (select * from opticUnitTest.musician order by lastName)"); |
| 548 | + |
| 549 | + FailedRequestException ex = assertThrows(FailedRequestException.class, () -> rowMgr.resultRows(builtPlan)); |
| 550 | + assertEquals(500, ex.getServerStatusCode()); |
| 551 | + assertEquals("SQL-TABLENOTFOUND", ex.getServerMessage()); |
| 552 | + assertEquals("Local message: failed to apply resource at rows: SQL-TABLENOTFOUND, Internal Server Error. Server Message: SQL-TABLENOTFOUND", |
| 553 | + ex.getMessage()); |
551 | 554 | } |
552 | 555 |
|
553 | 556 | @Test |
|
0 commit comments