Skip to content

Commit 833906d

Browse files
committed
Made ExportListener a fast test
Moved the 3 fast DMSDK tests under fastfunctest.datamovement.
1 parent 9a1f2f6 commit 833906d

File tree

4 files changed

+28
-177
lines changed

4 files changed

+28
-177
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.marklogic.client.fastfunctest;
17+
package com.marklogic.client.fastfunctest.datamovement;
1818

1919
import com.fasterxml.jackson.databind.JsonNode;
2020
import com.fasterxml.jackson.databind.ObjectMapper;
Lines changed: 26 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.marklogic.client.datamovement.functionaltests;
17+
package com.marklogic.client.fastfunctest.datamovement;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.util.*;
2323

24+
import com.marklogic.client.fastfunctest.AbstractFunctionalTest;
2425
import org.junit.jupiter.api.AfterEach;
2526
import org.junit.jupiter.api.BeforeEach;
2627
import org.junit.jupiter.api.BeforeAll;
@@ -40,86 +41,37 @@
4041
import com.marklogic.client.query.QueryManager;
4142
import com.marklogic.client.query.StringQueryDefinition;
4243

43-
public class ExportListenerTest extends BasicJavaClientREST {
44+
public class ExportListenerTest extends AbstractFunctionalTest {
4445

45-
private static String dbName = "ExportListener";
4646
private static DataMovementManager dmManager = null;
4747
private static DatabaseClient dbClient;
48-
private static String user = "admin";
49-
private static int port = 8000;
50-
private static String password = "admin";
51-
private static String server = "App-Services";
5248

5349
private static final String query1 = "fn:count(fn:doc())";
54-
private static String[] hostNames;
55-
56-
@BeforeAll
57-
public static void setUpBeforeClass() throws Exception {
58-
loadGradleProperties();
59-
server = getRestAppServerName();
60-
port = getRestAppServerPort();
61-
62-
hostNames = getHosts();
63-
createDB(dbName);
64-
Thread.currentThread().sleep(500L);
65-
int count = 1;
66-
for (String forestHost : hostNames) {
67-
createForestonHost(dbName + "-" + count, dbName, forestHost);
68-
count++;
69-
Thread.currentThread().sleep(500L);
70-
}
71-
// Create App Server if needed.
72-
createRESTServerWithDB(server, port);
73-
assocRESTServer(server, dbName, port);
74-
if (IsSecurityEnabled()) {
75-
enableSecurityOnRESTServer(server, dbName);
76-
}
77-
78-
dbClient = getDatabaseClient(user, password, getConnType());
79-
dmManager = dbClient.newDataMovementManager();
80-
}
81-
82-
@AfterAll
83-
public static void tearDownAfterClass() throws Exception {
84-
associateRESTServerWithDB(server, "Documents");
85-
for (int i = 0; i < hostNames.length; i++) {
86-
System.out.println(dbName + "-" + (i + 1));
87-
detachForest(dbName, dbName + "-" + (i + 1));
88-
deleteForest(dbName + "-" + (i + 1));
89-
}
90-
deleteDB(dbName);
91-
}
9250

9351
@BeforeEach
9452
public void setUp() throws Exception {
53+
dbClient = client;
54+
dmManager = client.newDataMovementManager();
55+
deleteDocuments(client);
56+
9557
String jsonDoc = "{" +
9658
"\"employees\": [" +
9759
"{ \"firstName\":\"John\" , \"lastName\":\"Doe\" }," +
9860
"{ \"firstName\":\"Ann\" , \"lastName\":\"Smith\" }," +
9961
"{ \"firstName\":\"Bob\" , \"lastName\":\"Foo\" }]" +
10062
"}";
10163

102-
// Use WriteBatcher to write the files.
10364
WriteBatcher wbatcher = dmManager.newWriteBatcher();
104-
105-
wbatcher.withBatchSize(1000);
10665
StringHandle handle = new StringHandle();
10766
handle.set(jsonDoc);
10867
String uri = null;
109-
110-
// Insert 10K documents
11168
for (int i = 0; i < 100; i++) {
11269
uri = "firstName" + i + ".json";
11370
wbatcher.add(uri, handle);
11471
}
11572
wbatcher.flushAndWait();
11673
}
11774

118-
@AfterEach
119-
public void tearDown() throws Exception {
120-
clearDB(port);
121-
}
122-
12375
/*
12476
* This test verifies that DMSDK supports PointInTime query and export using
12577
* ExportListener. The result returned is deterministic, since we have a
@@ -128,13 +80,7 @@ public void tearDown() throws Exception {
12880
* 3) Second query batcher after delete listener should return 0 uris.
12981
*/
13082
@Test
131-
public void testPointInTimeQueryDeterministicSet() throws Exception {
132-
System.out.println("Running testPointInTimeQueryDeterministicSet");
133-
Map<String, String> props = new HashMap<String, String>();
134-
props.put("merge-timestamp", "-6000000000");
135-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
136-
Thread.currentThread().sleep(10000L);
137-
83+
public void testPointInTimeQueryDeterministicSet() {
13884
List<String> docExporterList = Collections.synchronizedList(new ArrayList<String>());
13985
List<String> batcherList2 = Collections.synchronizedList(new ArrayList<String>());
14086

@@ -146,7 +92,6 @@ public void testPointInTimeQueryDeterministicSet() throws Exception {
14692
querydef2.setCriteria("John AND Bob");
14793
StringBuffer batchResults = new StringBuffer();
14894

149-
try {
15095
// Listener IS setup with withConsistentSnapshot()
15196
ExportListener exportListener = new ExportListener();
15297
exportListener.withConsistentSnapshot()
@@ -191,14 +136,9 @@ public void testPointInTimeQueryDeterministicSet() throws Exception {
191136

192137
dmManager.startJob(batcher2);
193138
batcher2.awaitCompletion();
194-
} catch (Exception ex) {
195-
System.out.println("Exceptions from testPointInTimeQueryDeterministicSet method is" + ex.getMessage());
196-
} finally {
197-
}
198139

199-
System.out.println("Batch" + batchResults.toString());
200-
props.put("merge-timestamp", "0");
201-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
140+
System.out.println("Batch" + batchResults.toString());
141+
202142
assertEquals(0, dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue());
203143
System.out.println("List size from second QueryBatcher is " + batcherList2.size());
204144
System.out.println("List size from Export Listener is " + docExporterList.size());
@@ -214,13 +154,7 @@ public void testPointInTimeQueryDeterministicSet() throws Exception {
214154
* ConsistentSnapshot and 2) Listener is setup with ConsistentSnapshot.
215155
*/
216156
@Test
217-
public void testWithSnapshots() throws Exception {
218-
System.out.println("Running testWithSnapshots");
219-
Map<String, String> props = new HashMap<String, String>();
220-
props.put("merge-timestamp", "-6000000000");
221-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
222-
Thread.currentThread().sleep(5000L);
223-
157+
public void testWithSnapshots() {
224158
List<String> docExporterList = Collections.synchronizedList(new ArrayList<String>());
225159
List<String> batcherList = Collections.synchronizedList(new ArrayList<String>());
226160

@@ -271,11 +205,7 @@ public void testWithSnapshots() throws Exception {
271205
assertEquals("Ann", node.path("employees").get(1).path("firstName").asText());
272206
assertEquals("Bob", node.path("employees").get(2).path("firstName").asText());
273207
}
274-
try {
275-
Thread.sleep(5000);
276-
} catch (Exception e) {
277-
e.printStackTrace();
278-
}
208+
// This test used to sleep for 5 seconds for unknown reasons.
279209
})
280210
.onQueryFailure(exception -> {
281211
System.out.println("Exceptions thrown from testPointInTimeQueryDeterministicSet callback onQueryFailure");
@@ -301,12 +231,9 @@ public void testWithSnapshots() throws Exception {
301231
exportBatcher.awaitCompletion();
302232
} catch (Exception ex) {
303233
System.out.println("Exceptions from testPointInTimeQueryDeterministicSet method is" + ex.getMessage());
304-
} finally {
305234
}
306235

307236
System.out.println("Batch" + batchResults.toString());
308-
props.put("merge-timestamp", "0");
309-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
310237

311238
System.out.println("List size from QueryBatcher is " + batcherList.size());
312239
System.out.println("List size from Export Listener is " + docExporterList.size());
@@ -321,20 +248,13 @@ public void testWithSnapshots() throws Exception {
321248
// Verify getServerTimestamp on the batch with no ConsistentSnapshot - Git
322249
// Issue 629
323250
@Test
324-
public void testServerTimestampNoSnapshots() throws Exception {
325-
System.out.println("Running testServerTimestampNoSnapshots");
326-
Map<String, String> props = new HashMap<String, String>();
327-
props.put("merge-timestamp", "-6000000000");
328-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
329-
Thread.currentThread().sleep(5000L);
330-
251+
public void testServerTimestampNoSnapshots() {
331252
List<String> docExporterList = Collections.synchronizedList(new ArrayList<String>());
332253

333254
QueryManager queryMgr = dbClient.newQueryManager();
334255
StringQueryDefinition querydef = queryMgr.newStringDefinition();
335256
querydef.setCriteria("John AND Bob");
336257

337-
try {
338258
// Listener is setup with no withConsistentSnapshot()
339259
ExportListener exportListener = new ExportListener();
340260
exportListener
@@ -361,12 +281,6 @@ public void testServerTimestampNoSnapshots() throws Exception {
361281
});
362282
dmManager.startJob(exportBatcher);
363283
exportBatcher.awaitCompletion();
364-
} catch (Exception ex) {
365-
System.out.println("Exceptions from testPointInTimeQueryDeterministicSet method is" + ex.getMessage());
366-
} finally {
367-
props.put("merge-timestamp", "0");
368-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
369-
}
370284
}
371285

372286
/*
@@ -376,13 +290,7 @@ public void testServerTimestampNoSnapshots() throws Exception {
376290
* ConsistentSnapshot and 2) Listener is NOT setup with ConsistentSnapshot.
377291
*/
378292
@Test
379-
public void testNoSnapshotOnListener() throws Exception {
380-
System.out.println("Running testNoSnapshotOnListener");
381-
Map<String, String> props = new HashMap<String, String>();
382-
props.put("merge-timestamp", "-6000000000");
383-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
384-
Thread.currentThread().sleep(5000L);
385-
293+
public void testNoSnapshotOnListener() {
386294
List<String> docExporterList = new ArrayList<String>();
387295
List<String> batcherList = new ArrayList<String>();
388296

@@ -391,14 +299,12 @@ public void testNoSnapshotOnListener() throws Exception {
391299
querydef.setCriteria("John AND Bob");
392300
StringBuffer batchResults = new StringBuffer();
393301

394-
try {
395302
// Listener is NOT setup with withConsistentSnapshot()
396303
ExportListener exportListener = new ExportListener();
397304
exportListener.onDocumentReady(doc -> {
398305
String uriOfDoc = doc.getUri();
399306
docExporterList.add(uriOfDoc);
400-
}
401-
);
307+
});
402308

403309
QueryBatcher exportBatcher = dmManager.newQueryBatcher(querydef)
404310
.withConsistentSnapshot()
@@ -423,11 +329,8 @@ public void testNoSnapshotOnListener() throws Exception {
423329
assertEquals("Ann", node.path("employees").get(1).path("firstName").asText());
424330
assertEquals("Bob", node.path("employees").get(2).path("firstName").asText());
425331
}
426-
try {
427-
Thread.sleep(1000);
428-
} catch (Exception e) {
429-
e.printStackTrace();
430-
}
332+
// Not known why this is needed.
333+
waitFor(1000);
431334
})
432335
.onQueryFailure(exception -> {
433336
System.out.println("Exceptions thrown from exportBatcher callback onQueryFailure");
@@ -444,19 +347,13 @@ public void testNoSnapshotOnListener() throws Exception {
444347
deleteBatcher.awaitCompletion();
445348

446349
exportBatcher.awaitCompletion();
447-
} catch (Exception ex) {
448-
System.out.println("Exceptions from deleteBatcher method is" + ex.getMessage());
449-
} finally {
450-
}
451350

452351
System.out.println("Batch" + batchResults.toString());
453-
props.put("merge-timestamp", "0");
454-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
455352

456353
System.out.println("List size from QueryBatcher is " + batcherList.size());
457354
System.out.println("List size from Export Listener is " + docExporterList.size());
458355

459-
assertTrue(batcherList.size() == 100);
356+
assertEquals(100, batcherList.size());
460357
assertTrue(docExporterList.size() != 100);
461358

462359
// Doc count should be zero after both batchers are done.
@@ -472,13 +369,7 @@ public void testNoSnapshotOnListener() throws Exception {
472369
* delete listener Results should be non deterministic.
473370
*/
474371
@Test
475-
public void testPointInTimeQueryNonDeterministicSet() throws Exception {
476-
System.out.println("Running testPointInTimeQueryNonDeterministicSet");
477-
Map<String, String> props = new HashMap<String, String>();
478-
props.put("merge-timestamp", "-6000000000");
479-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
480-
Thread.currentThread().sleep(5000L);
481-
372+
public void testPointInTimeQueryNonDeterministicSet() {
482373
List<String> docExporterList = new ArrayList<String>();
483374
List<String> batcherList = new ArrayList<String>();
484375

@@ -487,7 +378,6 @@ public void testPointInTimeQueryNonDeterministicSet() throws Exception {
487378
querydef.setCriteria("John AND Bob");
488379
StringBuffer batchResults = new StringBuffer();
489380

490-
try {
491381
ExportListener exportListener = new ExportListener();
492382
exportListener.onDocumentReady(doc -> {
493383
String uriOfDoc = doc.getUri();
@@ -505,13 +395,9 @@ public void testPointInTimeQueryNonDeterministicSet() throws Exception {
505395
batcherList.add(u);
506396
}
507397
batchResults.append("|");
508-
System.out.println("Batch Numer is " + batch.getJobBatchNumber());
509-
510-
try {
511-
Thread.sleep(5000);
512-
} catch (Exception e) {
513-
e.printStackTrace();
514-
}
398+
System.out.println("Batch Number is " + batch.getJobBatchNumber());
399+
// Not known why this is needed.
400+
waitFor(1000);
515401
})
516402
.onQueryFailure(exception -> {
517403
System.out.println("Exceptions thrown from testPointInTimeQueryDeterministicSet callback onQueryFailure");
@@ -528,14 +414,8 @@ public void testPointInTimeQueryNonDeterministicSet() throws Exception {
528414
deleteBatcher.awaitCompletion();
529415

530416
exportBatcher.awaitCompletion();
531-
} catch (Exception ex) {
532-
System.out.println("Exceptions from testPointInTimeQueryDeterministicSet method is" + ex.getMessage());
533-
} finally {
534-
}
535417

536418
System.out.println("Batch" + batchResults.toString());
537-
props.put("merge-timestamp", "0");
538-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
539419

540420
assertTrue(batcherList.size() != 100);
541421
assertTrue(docExporterList.size() != 100);
@@ -549,13 +429,7 @@ public void testPointInTimeQueryNonDeterministicSet() throws Exception {
549429
*/
550430

551431
@Test
552-
public void testOnBatchFailure() throws Exception {
553-
System.out.println("Running testOnBatchFailure");
554-
Map<String, String> props = new HashMap<String, String>();
555-
props.put("merge-timestamp", "-6000000000");
556-
changeProperty(props, "/manage/v2/databases/" + dbName + "/properties");
557-
Thread.currentThread().sleep(5000L);
558-
432+
public void testOnBatchFailure() {
559433
String jsonDoc = "{" +
560434
"\"employees\": [" +
561435
"{ \"firstName\":\"Will\" , \"lastName\":\"Kirkham\" }," +
@@ -585,7 +459,6 @@ public void testOnBatchFailure() throws Exception {
585459
querydef.setCriteria("Will AND Hus");
586460
StringBuilder onBatchFailureStr = new StringBuilder();
587461

588-
try {
589462
QueryBatcher exportBatcher = dmManager.newQueryBatcher(querydef)
590463
.withBatchSize(50)
591464
.onUrisReady(
@@ -613,11 +486,8 @@ public void testOnBatchFailure() throws Exception {
613486
dmManager.startJob(exportBatcher);
614487

615488
exportBatcher.awaitCompletion();
616-
} catch (Exception ex) {
617-
System.out.println("Exceptions from testOnBatchFailure method is" + ex.getMessage());
618-
} finally {
619-
}
620-
System.out.println("On Batch Failure contents are " + onBatchFailureStr.toString());
621-
assertTrue(onBatchFailureStr.toString().contains("From onBatchFailure QA Exception"));
489+
490+
assertTrue(onBatchFailureStr.toString().contains("From onBatchFailure QA Exception"),
491+
"Unexpected exception: " + onBatchFailureStr);
622492
}
623493
}

0 commit comments

Comments
 (0)