Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -729,123 +729,6 @@ public void testRawCtsQuery() throws IOException, InterruptedException {
}
}

/*
* To test query by example with WriteBatcher and QueryBatcher with Query
* Failure (incorrect query syntax).
*
* @throws IOException
*
* @throws InterruptedException
*/
// EA 3 Modify the test for batch failure results. Remove the fail.
@Disabled
public void testQueryBatcherQueryFailures() throws IOException, InterruptedException
{
System.out.println("Running testQueryBatcherQueryFailures");

try {
String[] filenames = { "constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml" };
WriteBatcher batcher = dmManager.newWriteBatcher();

batcher.withBatchSize(2);
// Move to individual data sub folders.
String dataFileDir = dataConfigDirPath + "/data/";

InputStreamHandle contentHandle1 = new InputStreamHandle();
contentHandle1.set(new FileInputStream(dataFileDir + filenames[0]));
InputStreamHandle contentHandle2 = new InputStreamHandle();
contentHandle2.set(new FileInputStream(dataFileDir + filenames[1]));
InputStreamHandle contentHandle3 = new InputStreamHandle();
contentHandle3.set(new FileInputStream(dataFileDir + filenames[2]));
InputStreamHandle contentHandle4 = new InputStreamHandle();
contentHandle4.set(new FileInputStream(dataFileDir + filenames[3]));
InputStreamHandle contentHandle5 = new InputStreamHandle();
contentHandle5.set(new FileInputStream(dataFileDir + filenames[4]));

batcher.add("/fail-contraints1.xml", contentHandle1);
batcher.add("/fail-contraints2.xml", contentHandle2);
batcher.add("/fail-contraints3.xml", contentHandle3);
batcher.add("/fail-contraints4.xml", contentHandle4);
batcher.add("/fail-contraints5.xml", contentHandle5);

// Flush
batcher.flushAndWait();
StringBuilder batchResults = new StringBuilder();
StringBuilder batchFailResults = new StringBuilder();
// create query def
String combinedQuery = "{\"search\":" +
"{\"query\":{\"value-constraint-query\":{\"constraint-name\":\"id\", \"text\":\"0026\"}}," +
"\"options\":{\"return-metrcs\":false, \"return-qtext\":false, \"debug\":true, \"transorm-results\":{\"apply\":\"raw\"}," +
"\"constraint\":{\"name\":\"id\", \"value\":{\"element\":{\"ns\":\"\", \"name\":\"id\"}}}}}}";

System.out.println("QUERY IS : " + combinedQuery);
// create a handle for the search criteria
StringHandle rawHandle = new StringHandle(combinedQuery);

rawHandle.setFormat(Format.JSON);

QueryManager queryMgr = client.newQueryManager();

// create a search definition based on the handle
RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(rawHandle);

// Run a QueryBatcher.
QueryBatcher queryBatcher1 = dmManager.newQueryBatcher(querydef);
queryBatcher1.onUrisReady(batch -> {

for (String str : batch.getItems()) {
batchResults.append(str).append('|');
}

batchResults.append(batch.getJobResultsSoFar())
.append('|')
.append(batch.getForest().getForestName())
.append('|')
.append(batch.getJobBatchNumber())
.append('|');

});
queryBatcher1.onQueryFailure(throwable -> {
System.out.println("Exceptions thrown from callback onQueryFailure");
Forest forest = throwable.getForest();
batchFailResults.append("Test has Exceptions")
.append('|')
.append(throwable.getForestResultsSoFar())
.append('|')
.append(forest.getForestName())
.append('|')
.append(forest.getHost())
.append('|')
.append(forest.getDatabaseName())
.append('|')
.append(forest.isUpdateable());
});
dmManager.startJob(queryBatcher1);
boolean isStopped = queryBatcher1.awaitCompletion(3, TimeUnit.MINUTES);

if (isStopped) {
if (!batchFailResults.toString().isEmpty() && batchFailResults.toString().contains("Exceptions")) {
// Write out and assert on query failures.
System.out.println("Exception Buffer contents on Query Exceptions received from callback onQueryFailure");
System.out.println(batchFailResults);
// Remove this failure once there are no NPEs and doa asserts on various
// counters in failure scenario.
fail("Test failed due to exceptions");
}
}
} catch (Exception e) {
e.printStackTrace();
fail("testQueryBatcherQueryFailures method failed");
}
finally {
try {
clearDB();
} catch (Exception e) {
e.printStackTrace();
}
}
}

/*
* To test QueryBatcher's callback support by invoking the client object to do
* a lookup Insert only one document to validate the functionality
Expand Down Expand Up @@ -1565,106 +1448,6 @@ public void testBatchClientLookupTimeout() throws InterruptedException{
}
}

/*
* To test QueryBatcher when WriteBatcher writes same document. Simulate a
* deadlock / resource contention.
*
* @throws IOException
*
* @throws InterruptedException
*/

/*
* public void testSimultaneousBothBatcherAccess() throws IOException,
* InterruptedException {
* System.out.println("Running testSimultaneousBothBatcherAccess");
* clearDB(restServerPort);
*
* String[] filenames = {"constraint1.json", "constraint2.json",
* "constraint3.json", "constraint4.json", "constraint5.json"}; WriteBatcher
* batcher = dmManager.newWriteBatcher();
*
* batcher.withBatchSize(2);
*
* InputStreamHandle contentHandle1 = new InputStreamHandle();
* contentHandle1.set(new FileInputStream(dataFileDir + filenames[0]));
* InputStreamHandle contentHandle2 = new InputStreamHandle();
* contentHandle2.set(new FileInputStream(dataFileDir + filenames[1]));
* InputStreamHandle contentHandle3 = new InputStreamHandle();
* contentHandle3.set(new FileInputStream(dataFileDir + filenames[2]));
* InputStreamHandle contentHandle4 = new InputStreamHandle();
* contentHandle4.set(new FileInputStream(dataFileDir + filenames[3]));
* InputStreamHandle contentHandle5 = new InputStreamHandle();
* contentHandle5.set(new FileInputStream(dataFileDir + filenames[4]));
*
* StringBuilder writebatchResults = new StringBuilder();
* batcher.add("/batcher-contraints1.json", contentHandle1);
* batcher.add("/batcher-contraints2.json", contentHandle2);
* batcher.add("/batcher-contraints3.json", contentHandle3);
* batcher.add("/batcher-contraints4.json", contentHandle4);
* batcher.add("/batcher-contraints5.json", contentHandle5);
*
* // Flush batcher.flushAndWait();
*
* StringBuffer querybatchResults = new StringBuffer(); StringBuilder
* querybatchFailResults = new StringBuilder();
*
* // get the query File file = new File(dataConfigDirPath + "qbe1.json");
* FileHandle fileHandle = new FileHandle(file);
*
* QueryManager queryMgr = client.newQueryManager();
* RawQueryByExampleDefinition qbyexDef =
* queryMgr.newRawQueryByExampleDefinition
* (fileHandle.withFormat(Format.JSON));
*
* // Run a QueryBatcher. QueryBatcher queryBatcher1 =
* dmManager.newQueryBatcher(qbyexDef); queryBatcher1.onUrisReady(batch-> {
*
* for (String str : batch.getItems()) { querybatchResults.append(str)
* .append('|'); }
*
* querybatchResults.append(batch.getForestResultsSoFar()) .append('|')
* .append(batch.getForest().getForestName()) .append('|')
* .append(batch.getJobBatchNumber()) .append('|');
*
* }); queryBatcher1.onQueryFailure(throwable-> {
* System.out.println("Exceptions thrown from callback onQueryFailure");
* throwable.printStackTrace();
* querybatchFailResults.append("Test has Exceptions");
* querybatchFailResults.append(throwable.getMessage()); } );
*
* // Trying to use a WriteBatcher on the same docId. WriteBatcher batcherTwo
* = dmManager.newWriteBatcher(); String jsonDoc = "{" + "\"employees\": [" +
* "{ \"firstName\":\"John\" , \"lastName\":\"Doe\" }," +
* "{ \"firstName\":\"Ann\" , \"lastName\":\"Smith\" }," +
* "{ \"firstName\":\"Bob\" , \"lastName\":\"Foo\" }]" + "}"; StringHandle
* handle = new StringHandle(); handle.set(jsonDoc);
*
* // Update contents to same doc uri. batcherTwo.withBatchSize(1);
* batcherTwo.add("/batcher-contraints11.json", handle);
* batcherTwo.flushAndWait();
*
* JobTicket jobTicketWriteTwo = dmManager.startJob(batcherTwo);
*
* JobTicket jobTicket = dmManager.startJob(queryBatcher1);
* queryBatcher1.awaitTermination(1, TimeUnit.MINUTES);
*
* if (queryBatcher1.isStopped()) {
*
* if( !querybatchFailResults.toString().isEmpty() &&
* querybatchFailResults.toString().contains("Exceptions")) {
* System.out.println("Query Batch Failed - Buffer Contents are:" +
* querybatchFailResults.toString()); fail("Test failed due to exceptions"); }
* if( querybatchResults != null && !querybatchResults.toString().isEmpty()) {
* // Verify the batch results now. String[] res =
* querybatchResults.toString().split("\\|");
*
* assertTrue(
* res[0].contains("/batcher-contraints1.json"));
* assertEquals("Bytes Moved","0", res[1]); assertEquals("Batch Number","0",
* res[3]); } } }
*/

@Test
public void testQueryBatcherJobDetails() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/

package com.marklogic.client.datamovement.functionaltests;
Expand Down Expand Up @@ -2164,71 +2164,6 @@ public void run() {

}

// EA 3 - We need a better way of getting to know that DB is disabled and
// how
// to assert on counts.
@Disabled
public void testDisableDBDuringInsert() throws Exception {
System.out.println("In testDisableDBDuringInsert method");

Thread t1 = new Thread(new DisabledDBRunnable());
AtomicBoolean failCheck = new AtomicBoolean(false);
AtomicInteger successCount = new AtomicInteger(0);
AtomicInteger failureCount = new AtomicInteger(0);

t1.setName("Status Check");
Map<String, String> properties = new HashMap<>();
WriteBatcher ihb2 = dmManager.newWriteBatcher();
ihb2.withBatchSize(5);

ihb2.onBatchSuccess(batch -> {
successCount.getAndAdd(batch.getItems().length);
}).onBatchFailure((batch, throwable) -> {
failCheck.set(true);
failureCount.getAndAdd(batch.getItems().length);
throwable.printStackTrace();
});
dmManager.startJob(ihb2);
t1.start();

for (int j = 0; j < 1000; j++) {
String uri = "/local/json-" + j;
ihb2.add(uri, fileHandle);
}

ihb2.flushAndWait();
t1.join();
properties.put("enabled", "true");
changeProperty(properties, "/manage/v2/databases/" + dbName + "/properties");
assertTrue(failCheck.get());
assertTrue(successCount.intValue() >= 100);
assertTrue(successCount.intValue() < 1000);
assertTrue(failureCount.intValue() <= 900);
}

class DisabledDBRunnable implements Runnable {
final String query1 = "fn:count(fn:doc())";
Map<String, String> properties = new HashMap<>();

@Override
public void run() {

properties.put("enabled", "false");
boolean state = true;
while (state) {
int count = dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue();
System.out.println("Count is " + count);
if (count >= 100) {
changeProperty(properties, "/manage/v2/databases/" + dbName + "/properties");

state = false;
}

}
}

}

@Test
public void testNoHost() throws Exception {
Assumptions.assumeTrue(!isLBHost());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/

package com.marklogic.client.fastfunctest;
Expand Down Expand Up @@ -152,63 +152,6 @@ public void testWithNoFacet() throws KeyManagementException, NoSuchAlgorithmExce
assertXpathEvaluatesTo(expectedSearchReport, "string(//*[local-name()='report'])", resultDoc);
}

// @Test
public void testWithWordConstraintAndGoogleGrammar() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException,
XpathException
{
System.out.println("Running testWithWordConstraintAndGoogleGrammar");

String filename1 = "constraint1.xml";
String filename2 = "constraint2.xml";
String filename3 = "constraint3.xml";
String filename4 = "constraint4.xml";
String filename5 = "constraint5.xml";
String queryOptionName = "collectionConstraintWithWordConstraintAndGoogleGrammarOpt.xml";

// create and initialize a handle on the metadata
DocumentMetadataHandle metadataHandle1 = new DocumentMetadataHandle();
DocumentMetadataHandle metadataHandle2 = new DocumentMetadataHandle();
DocumentMetadataHandle metadataHandle3 = new DocumentMetadataHandle();
DocumentMetadataHandle metadataHandle4 = new DocumentMetadataHandle();
DocumentMetadataHandle metadataHandle5 = new DocumentMetadataHandle();

// set the metadata
metadataHandle1.getCollections().addAll("http://test.com/set1");
metadataHandle1.getCollections().addAll("http://test.com/set5");
metadataHandle2.getCollections().addAll("http://test.com/set1");
metadataHandle3.getCollections().addAll("http://test.com/set3");
metadataHandle4.getCollections().addAll("http://test.com/set3/set3-1");
metadataHandle5.getCollections().addAll("http://test.com/set1");
metadataHandle5.getCollections().addAll("http://test.com/set5");

// write docs
writeDocumentUsingInputStreamHandle(client, filename1, "/collection-constraint/", metadataHandle1, "XML");
writeDocumentUsingInputStreamHandle(client, filename2, "/collection-constraint/", metadataHandle2, "XML");
writeDocumentUsingInputStreamHandle(client, filename3, "/collection-constraint/", metadataHandle3, "XML");
writeDocumentUsingInputStreamHandle(client, filename4, "/collection-constraint/", metadataHandle4, "XML");
writeDocumentUsingInputStreamHandle(client, filename5, "/collection-constraint/", metadataHandle5, "XML");

setQueryOption(client, queryOptionName);
QueryManager queryMgr = client.newQueryManager();

// create query def
StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName);
querydef.setCriteria("(coll:set1 AND coll:set5) AND -intitle:memex");

// create handle
DOMHandle resultsHandle = new DOMHandle();
queryMgr.search(querydef, resultsHandle);

// get the result
Document resultDoc = resultsHandle.get();

assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc);
assertXpathEvaluatesTo("Vannevar Bush", "string(//*[local-name()='result'][1]//*[local-name()='title'])", resultDoc);

String expectedSearchReport = "(cts:search(fn:collection(), cts:and-query((cts:collection-query(\"http://test.com/set1\"), cts:collection-query(\"http://test.com/set5\"), cts:not-query(cts:element-word-query(fn:QName(\"\", \"title\"), \"memex\", (\"lang=en\"), 1), 1)), ()), (\"score-logtfidf\"), 1))[1 to 10]";

assertXpathEvaluatesTo(expectedSearchReport, "string(//*[local-name()='report'])", resultDoc);
}
// End of TestAppServicesCollectionConstraint

// Begin TestAppServicesConstraintCombination
Expand Down
Loading
Loading