Skip to content

Commit 56291ce

Browse files
committed
Ignoring test that intermittently fails and hangs the entire suite
1 parent 71eec7b commit 56291ce

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

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

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@
4040

4141
import com.marklogic.client.fastfunctest.AbstractFunctionalTest;
4242
import org.apache.commons.io.FileUtils;
43-
import org.junit.AfterClass;
44-
import org.junit.Assert;
45-
import org.junit.BeforeClass;
46-
import org.junit.Test;
43+
import org.junit.*;
4744

4845
import com.fasterxml.jackson.databind.JsonNode;
4946
import com.marklogic.client.DatabaseClient;
@@ -248,70 +245,69 @@ public void testNullQdef() throws IOException, InterruptedException {
248245
}
249246

250247
@Test
248+
@Ignore("Ignoring this test for now, as it fails intermittently, and when it does, the test hangs indefinitely, causing " +
249+
"the test suite to never finish. Needs further investigation to make it more robust.")
251250
public void queryFailures() throws Exception {
252-
System.out.println("In queryFailures method");
253-
Thread t1 = new Thread(new DisabledDBRunnable());
254-
t1.setName("Status Check -1");
255-
256-
QueryManager queryMgr = dbClient.newQueryManager();
257-
StringQueryDefinition querydef = queryMgr.newStringDefinition();
258-
querydef.setCriteria("John AND Bob");
259-
AtomicInteger batches = new AtomicInteger(0);
260-
251+
// Insert documents to query
261252
String jsonDoc = "{" + "\"employees\": [" + "{ \"firstName\":\"John\" , \"lastName\":\"Doe\" },"
262253
+ "{ \"firstName\":\"Ann\" , \"lastName\":\"Smith\" },"
263254
+ "{ \"firstName\":\"Bob\" , \"lastName\":\"Foo\" }]" + "}";
264-
WriteBatcher wbatcher = dmManager.newWriteBatcher();
265-
wbatcher.withBatchSize(6000);
266-
wbatcher.onBatchFailure((batch, throwable) -> throwable.printStackTrace());
255+
WriteBatcher writeBatcher = dmManager.newWriteBatcher();
256+
writeBatcher.withBatchSize(6000);
267257
StringHandle handle = new StringHandle();
268258
handle.set(jsonDoc);
269-
String uri = null;
270-
271-
// Insert 10 K documents
272259
for (int i = 0; i < 6000; i++) {
273-
uri = "/firstName" + i + ".json";
274-
wbatcher.add(uri, handle);
260+
String uri = "/firstName" + i + ".json";
261+
writeBatcher.add(uri, handle);
275262
}
263+
writeBatcher.flushAndWait();
276264

277-
wbatcher.flushAndWait();
265+
// Construct a query to return all of the docs inserted above
266+
QueryManager queryMgr = dbClient.newQueryManager();
267+
StringQueryDefinition querydef = queryMgr.newStringDefinition();
268+
querydef.setCriteria("John AND Bob");
278269

279-
AtomicInteger failureCnts = new AtomicInteger(0);
270+
// Construct a QueryBatcher that will keep track of
271+
AtomicInteger successfulBatchCount = new AtomicInteger(0);
272+
AtomicInteger queryFailureCount = new AtomicInteger(0);
280273
QueryBatcher batcher = dmManager.newQueryBatcher(querydef).withBatchSize(10).withThreadCount(3);
281-
batcher.onUrisReady(batch -> {
282-
batches.incrementAndGet();
283-
});
284-
batcher.onQueryFailure((throwable) -> {
285-
System.out.println("queryFailures: ");
286-
failureCnts.incrementAndGet();
274+
batcher.onUrisReady(batch -> successfulBatchCount.incrementAndGet());
275+
batcher.onQueryFailure(throwable -> {
276+
System.out.println("QueryBatcher failure: " + throwable.getMessage());
277+
queryFailureCount.incrementAndGet();
287278
System.out.println("DB disabled for Forest " + throwable.getForest().getForestName());
279+
// TODO Figure out why 7s was chosen here
288280
try {
289281
Thread.currentThread().sleep(7000L);
290282
} catch (Exception e) {
291283
e.printStackTrace();
292284
}
293285
throwable.getBatcher().retry(throwable);
286+
// TODO Why does this need to throw an exception???
294287
// We need an NullPointerException. Hence these statements.
295288
String s = null;
296289
s.length();
297-
298290
});
299291

300292
queryTicket = dmManager.startJob(batcher);
301-
t1.start();
302293

294+
// Run a thread to disable the database, and then sleep, and then enable the database
295+
Thread t1 = new Thread(new DisabledDBRunnable());
296+
t1.setName("Status Check -1");
297+
t1.start();
303298
t1.join();
304299

305300
batcher.awaitCompletion();
306301

302+
// Verify that the QueryBatcher was able to recover after the database was re-enabled
307303
Assert.assertEquals(6000, dmManager.getJobReport(queryTicket).getSuccessEventsCount());
308-
Assert.assertEquals(batches.intValue(), dmManager.getJobReport(queryTicket).getSuccessBatchesCount());
304+
Assert.assertEquals(successfulBatchCount.intValue(), dmManager.getJobReport(queryTicket).getSuccessBatchesCount());
309305
if(!isLBHost()) {
310306
System.out.println("Method queryFailure hostNames.length " + hostNames.length);
311307
System.out.println("Method queryFailure getFailureEventsCount() " + dmManager.getJobReport(queryTicket).getFailureEventsCount());
312308

313-
Assert.assertEquals(failureCnts.get(), dmManager.getJobReport(queryTicket).getFailureEventsCount());
314-
Assert.assertEquals(failureCnts.get(), dmManager.getJobReport(queryTicket).getFailureBatchesCount());
309+
Assert.assertEquals(queryFailureCount.get(), dmManager.getJobReport(queryTicket).getFailureEventsCount());
310+
Assert.assertEquals(queryFailureCount.get(), dmManager.getJobReport(queryTicket).getFailureBatchesCount());
315311
}
316312
}
317313

@@ -324,22 +320,28 @@ public void run() {
324320
boolean state = true;
325321
while (state) {
326322
System.out.println(dmManager.getJobReport(queryTicket).getSuccessEventsCount());
323+
// Wait for at least one successful event before disabling
327324
if (dmManager.getJobReport(queryTicket).getSuccessEventsCount() >= 0) {
328-
325+
System.out.println("Disabling the java-functest database");
329326
changeProperty(properties, "/manage/v2/databases/java-functest/properties");
330327
System.out.println("DB disabled");
331328
state = false;
332329
}
333330

334331
}
332+
333+
// TODO Figure out why 5s was chosen here
334+
System.out.println("Sleeping before re-enabling the java-functest database");
335335
try {
336336
Thread.currentThread().sleep(5000L);
337337
} catch (InterruptedException e) {
338338
e.printStackTrace();
339339
}
340340

341+
System.out.println("Re-enabling the java-functest database");
341342
properties.put("enabled", "true");
342343
changeProperty(properties, "/manage/v2/databases/java-functest/properties");
344+
System.out.println("Re-enabled the java-functest database");
343345
}
344346
}
345347

0 commit comments

Comments
 (0)