Skip to content

Commit 71d50ff

Browse files
authored
Merge pull request #1811 from marklogic/feature/test-fix
MLE-23146 Trying another approach with clearDB
2 parents 14128e4 + e33267a commit 71d50ff

File tree

2 files changed

+36
-53
lines changed

2 files changed

+36
-53
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/datamovement/functionaltests/StringQueryHostBatcherTest.java

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ public void testQueryBatcherFailures() throws IOException, InterruptedException
12201220
}
12211221

12221222
@Test
1223-
public void testServerXQueryTransform() throws IOException, ParserConfigurationException, SAXException, TransformerException, InterruptedException, XPathExpressionException
1223+
public void testServerXQueryTransform() throws InterruptedException, XPathExpressionException
12241224
{
12251225
System.out.println("Running testServerXQueryTransform");
12261226
try {
@@ -1272,8 +1272,7 @@ public void testServerXQueryTransform() throws IOException, ParserConfigurationE
12721272
batcher.flushAndWait();
12731273
dmManager.stopJob(batcher);
12741274

1275-
StringBuffer batchResults = new StringBuffer();
1276-
StringBuffer batchFailResults = new StringBuffer();
1275+
List<String> uris = new ArrayList<>();
12771276

12781277
// create query def
12791278
QueryManager queryMgr = client.newQueryManager();
@@ -1285,56 +1284,34 @@ public void testServerXQueryTransform() throws IOException, ParserConfigurationE
12851284
queryBatcher1.withBatchSize(5);
12861285

12871286
queryBatcher1.onUrisReady(batch -> {
1288-
for (String str : batch.getItems()) {
1289-
batchResults.append(str);
1290-
batchResults.append("|");
1287+
for (String item : batch.getItems()) {
1288+
uris.add(item);
12911289
}
12921290
});
1293-
queryBatcher1.onQueryFailure(throwable -> {
1294-
System.out.println("Exceptions thrown from callback onQueryFailure");
1295-
throwable.printStackTrace();
1296-
batchFailResults.append("Test has Exceptions");
1297-
});
12981291
dmManager.startJob(queryBatcher1);
1299-
queryBatcher1.awaitCompletion(3, TimeUnit.MINUTES);
1300-
while (!queryBatcher1.isStopped()) {
1301-
// Do nothing. Wait for batcher to complete.
1302-
}
1303-
1304-
if (queryBatcher1.isStopped()) {
1305-
// Verify the batch results now.
1306-
String[] res = batchResults.toString().split("\\|");
1307-
assertEquals(res.length, 20);
1308-
1309-
// Get a random URI, since the URIs returned are not ordered. Get the 3rd
1310-
// URI.
1311-
assertTrue( res[2].contains("foo") || res[2].contains("bar"));
1312-
1313-
// do a lookup with the first URI using the client to verify transforms
1314-
// are done.
1315-
DOMHandle readHandle = readDocumentUsingDOMHandle(client, res[0], "XML");
1316-
String contents = readHandle.evaluateXPath("/foo/text()", String.class);
1317-
String attribute = readHandle.evaluateXPath("/foo/@Lang", String.class);
1318-
// Verify that the contents are of xmlStr1 or xmlStr2.
1319-
1320-
System.out.println("Contents are : " + contents);
1321-
System.out.println("Contents are : " + attribute);
1322-
assertTrue( xmlStr1.contains(contents) || xmlStr2.contains(contents));
1323-
assertTrue( attribute.equalsIgnoreCase("English"));
1324-
}
1325-
else {
1326-
fail("testServerXQueryTransform method failed");
1327-
}
1328-
} catch (Exception e) {
1329-
e.printStackTrace();
1330-
fail("testServerXQueryTransform method failed");
1292+
queryBatcher1.awaitCompletion();
1293+
1294+
// Verify the batch results now.
1295+
assertEquals(20, uris.size());
1296+
1297+
// Get a random URI, since the URIs returned are not ordered. Get the 3rd
1298+
// URI.
1299+
String thirdUri = uris.get(2);
1300+
assertTrue( thirdUri.contains("foo") || thirdUri.contains("bar"), "Unexpected URI: " + thirdUri);
1301+
1302+
// do a lookup with the first URI using the client to verify transforms
1303+
// are done.
1304+
DOMHandle readHandle = readDocumentUsingDOMHandle(client, uris.get(0), "XML");
1305+
String contents = readHandle.evaluateXPath("/foo/text()", String.class);
1306+
String attribute = readHandle.evaluateXPath("/foo/@Lang", String.class);
1307+
// Verify that the contents are of xmlStr1 or xmlStr2.
1308+
System.out.println("Contents are : " + contents);
1309+
System.out.println("Contents are : " + attribute);
1310+
assertTrue( xmlStr1.contains(contents) || xmlStr2.contains(contents));
1311+
assertTrue( attribute.equalsIgnoreCase("English"));
13311312
}
13321313
finally {
1333-
try {
1334-
clearDB();
1335-
} catch (Exception e) {
1336-
e.printStackTrace();
1337-
}
1314+
clearDB();
13381315
}
13391316
}
13401317

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/ConnectedRESTQA.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.marklogic.client.DatabaseClient.ConnectionType;
1414
import com.marklogic.client.DatabaseClientBuilder;
1515
import com.marklogic.client.DatabaseClientFactory;
16+
import com.marklogic.client.FailedRequestException;
1617
import com.marklogic.client.admin.ServerConfigurationManager;
1718
import com.marklogic.client.impl.SSLUtil;
1819
import com.marklogic.client.io.DocumentMetadataHandle;
@@ -317,10 +318,15 @@ public static void clearDB(int port) {
317318
try (DatabaseClient client = newDatabaseClientBuilder().withPort(port).build()) {
318319
QueryManager mgr = client.newQueryManager();
319320
mgr.delete(mgr.newDeleteDefinition());
320-
// Clearing the database occasionally causes a forest to not be available for a moment or two when the tests
321-
// are running on Jenkins. This leads to intermittent failures. Waiting is not guaranteed to avoid the
322-
// error but simply hopes to minimize the chance of an intermittent failure.
323-
waitFor(2000);
321+
} catch (FailedRequestException ex) {
322+
LoggerFactory.getLogger(ConnectedRESTQA.class).warn("Unable to clear database. This intermittently " +
323+
"happens while running tests on Jenkins, typically with a server error message such as: " +
324+
"XDMP-FORESTNOT: Forest StringQueryHostBatcherDB-1 not available: XDMP-FORESTERR: " +
325+
"Error in clear of forest StringQueryHostBatcherDB-1: SVC-FILREN: File rename error: " +
326+
"rename '/var/opt/MarkLogic/TmpForests/StringQueryHostBatcherDB-1/Journals to " +
327+
"/var/opt/MarkLogic/Forests/StringQueryHostBatcherDB-1/Journals': No such file or directory. " +
328+
"This error is caught and logged in the hopes that proceeding tests will succeed even though " +
329+
"this clearDB call failed.", ex);
324330
}
325331
}
326332

@@ -814,7 +820,7 @@ public X509Certificate[] getAcceptedIssuers() {
814820
* Server.
815821
* @throws Exception
816822
*/
817-
public static void clearDB() throws Exception {
823+
public static void clearDB() {
818824
clearDB(getRestServerPort());
819825
}
820826

0 commit comments

Comments
 (0)