Skip to content

Commit 8ebddc5

Browse files
authored
Merge pull request #1771 from marklogic/feature/test-fixes
Fixing WriteHostBatcherTest
2 parents 4de6994 + ef92681 commit 8ebddc5

14 files changed

+84
-191
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ public static void setUpBeforeClass() throws Exception {
137137
@AfterAll
138138
public static void tearDownAfterClass() throws Exception {
139139
associateRESTServerWithDB(server, "Documents");
140-
for (int i = 0; i < hostNames.length; i++) {
141-
System.out.println(dbName + "-" + (i + 1));
142-
detachForest(dbName, dbName + "-" + (i + 1));
143-
deleteForest(dbName + "-" + (i + 1));
144-
}
145140
deleteDB(dbName);
146141

147142
// Delete the output file

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,6 @@ public static void tearDownAfterClass() throws Exception {
210210
// Perform the setup on multiple nodes only.
211211
if (hostNames.length > 1) {
212212
associateRESTServerWithDB(server, "Documents");
213-
for (int i = 0; i < hostNames.length; i++) {
214-
System.out.println(dbName + "-" + (i + 1));
215-
detachForest(dbName, dbName + "-" + (i + 1));
216-
if (i != 0) {
217-
removeReplica(dbName + "-" + (i + 1));
218-
deleteForest(dbName + "-" + (i + 1) + "-replica");
219-
}
220-
deleteForest(dbName + "-" + (i + 1));
221-
}
222213
deleteDB(dbName);
223214
} else {
224215
System.out.println("Test skipped - tearDownAfterClass");

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

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,39 @@
33
*/
44
package com.marklogic.client.datamovement.functionaltests;
55

6-
import static org.junit.jupiter.api.Assertions.assertEquals;
7-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
8-
import static org.junit.jupiter.api.Assertions.assertTrue;
9-
import static org.junit.jupiter.api.Assertions.fail;
10-
11-
import java.io.File;
12-
import java.io.FileInputStream;
13-
import java.io.IOException;
14-
import java.time.Duration;
15-
import java.util.*;
16-
import java.util.concurrent.TimeUnit;
17-
import java.util.concurrent.atomic.AtomicInteger;
18-
19-
import javax.xml.namespace.QName;
20-
import javax.xml.parsers.ParserConfigurationException;
21-
import javax.xml.transform.TransformerException;
22-
import javax.xml.xpath.XPathExpressionException;
23-
24-
import com.marklogic.client.expression.CtsQueryBuilder;
25-
import com.marklogic.client.query.*;
26-
import com.marklogic.client.type.CtsQueryExpr;
27-
import com.marklogic.client.util.EditableNamespaceContext;
28-
import org.junit.jupiter.api.*;
29-
import org.w3c.dom.DOMException;
30-
import org.w3c.dom.Document;
31-
import org.xml.sax.SAXException;
32-
336
import com.fasterxml.jackson.databind.JsonNode;
347
import com.marklogic.client.DatabaseClient;
358
import com.marklogic.client.admin.ExtensionMetadata;
369
import com.marklogic.client.admin.ServerConfigurationManager;
3710
import com.marklogic.client.admin.TransformExtensionsManager;
38-
import com.marklogic.client.datamovement.DataMovementManager;
39-
import com.marklogic.client.datamovement.Forest;
40-
import com.marklogic.client.datamovement.HostAvailabilityListener;
41-
import com.marklogic.client.datamovement.JobTicket;
42-
import com.marklogic.client.datamovement.ProgressListener;
43-
import com.marklogic.client.datamovement.QueryBatcher;
44-
import com.marklogic.client.datamovement.WriteBatcher;
11+
import com.marklogic.client.datamovement.*;
4512
import com.marklogic.client.document.JSONDocumentManager;
4613
import com.marklogic.client.document.ServerTransform;
14+
import com.marklogic.client.expression.CtsQueryBuilder;
4715
import com.marklogic.client.functionaltest.BasicJavaClientREST;
48-
import com.marklogic.client.io.DOMHandle;
49-
import com.marklogic.client.io.FileHandle;
50-
import com.marklogic.client.io.Format;
51-
import com.marklogic.client.io.InputStreamHandle;
52-
import com.marklogic.client.io.JacksonHandle;
53-
import com.marklogic.client.io.StringHandle;
16+
import com.marklogic.client.io.*;
17+
import com.marklogic.client.query.*;
5418
import com.marklogic.client.query.StructuredQueryBuilder.Operator;
19+
import com.marklogic.client.type.CtsQueryExpr;
20+
import com.marklogic.client.util.EditableNamespaceContext;
21+
import org.junit.jupiter.api.*;
22+
import org.w3c.dom.DOMException;
23+
import org.w3c.dom.Document;
24+
import org.xml.sax.SAXException;
25+
26+
import javax.xml.namespace.QName;
27+
import javax.xml.parsers.ParserConfigurationException;
28+
import javax.xml.transform.TransformerException;
29+
import javax.xml.xpath.XPathExpressionException;
30+
import java.io.File;
31+
import java.io.FileInputStream;
32+
import java.io.IOException;
33+
import java.time.Duration;
34+
import java.util.*;
35+
import java.util.concurrent.TimeUnit;
36+
import java.util.concurrent.atomic.AtomicInteger;
37+
38+
import static org.junit.jupiter.api.Assertions.*;
5539

5640
/**
5741
* @author ageorge Purpose : Test String Queries - On multiple documents using
@@ -123,10 +107,7 @@ public static void tearDownAfterClass() throws Exception {
123107
associateRESTServerWithDB(restServerName, "Documents");
124108
deleteRESTUser("eval-user");
125109
deleteUserRole("test-eval");
126-
detachForest(dbName, fNames[0]);
127-
128110
deleteDB(dbName);
129-
deleteForest(fNames[0]);
130111
}
131112

132113
@BeforeEach
@@ -1516,7 +1497,6 @@ public void testQueryBatcherWithForestRemoveAndAdd() throws IOException, Interru
15161497
deleteForest(testMultipleForest[0]);
15171498
deleteForest(testMultipleForest[1]);
15181499
deleteForest(testMultipleForest[2]);
1519-
Thread.sleep(10000);
15201500
}
15211501
}
15221502

@@ -1626,16 +1606,8 @@ public void testBatchClientLookupTimeout() throws IOException, InterruptedExcept
16261606
System.out.print(e.getMessage());
16271607
fail("testBatchClientLookupTimeout method failed");
16281608
} finally {
1629-
// Associate back the original DB.
1630-
try {
16311609
associateRESTServerWithDB(restServerName, dbName);
1632-
} catch (Exception e) {
1633-
e.printStackTrace();
1634-
}
1635-
detachForest(testMultipleDB, testMultipleForest[0]);
16361610
deleteDB(testMultipleDB);
1637-
deleteForest(testMultipleForest[0]);
1638-
Thread.sleep(10000);
16391611
}
16401612
}
16411613

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public static void setUp() throws Exception {
6363
public static void testCleanUp() throws Exception {
6464
associateRESTServerWithDB(getRestServerName(), "Documents");
6565
deleteDB(dbName);
66-
deleteForest(fNames[0]);
67-
System.out.println("Running clear script");
6866
}
6967

7068
@Test

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ public static void tearDownAfterClass() throws Exception {
7676
associateRESTServerWithDB(restServerName, "Documents");
7777
deleteRESTUser("eval-user");
7878
deleteUserRole("test-eval");
79-
detachForest(dbName, fNames[0]);
80-
8179
deleteDB(dbName);
82-
deleteForest(fNames[0]);
8380
}
8481

8582
@AfterEach

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,6 @@ public static void tearDownAfterClass() throws Exception {
182182
// Perform the setup on multiple nodes only.
183183
if (hostNames.length > 1) {
184184
associateRESTServerWithDB(server, "Documents");
185-
for (int i = 0; i < hostNames.length; i++) {
186-
System.out.println(dbName + "-" + (i + 1));
187-
detachForest(dbName, dbName + "-" + (i + 1));
188-
if (i != 0) {
189-
removeReplica(dbName + "-" + (i + 1));
190-
deleteForest(dbName + "-" + (i + 1) + "-replica");
191-
}
192-
deleteForest(dbName + "-" + (i + 1));
193-
}
194185
deleteDB(dbName);
195186
} else {
196187
System.out.println("Test skipped - tearDownAfterClass");

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ public static void setUpBeforeClass() throws Exception {
127127
@AfterAll
128128
public static void tearDownAfterClass() throws Exception {
129129
associateRESTServerWithDB(server, "Documents");
130-
for (int i = 0; i < hostNames.length; i++) {
131-
System.out.println(dbName + "-" + (i + 1));
132-
detachForest(dbName, dbName + "-" + (i + 1));
133-
deleteForest(dbName + "-" + (i + 1));
134-
}
135-
136130
deleteDB(dbName);
137131
}
138132

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

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class WriteHostBatcherTest extends BasicJavaClientREST {
8181
private static JsonNode jsonNode;
8282
private static JobTicket writeTicket;
8383
private static JobTicket testBatchJobTicket;
84-
private static int forestCount = 1;
84+
private static final int forestCount = 3;
8585

8686
@BeforeAll
8787
public static void setUpBeforeClass() throws Exception {
@@ -94,18 +94,9 @@ public static void setUpBeforeClass() throws Exception {
9494
hostNames = getHosts();
9595

9696
createDB(dbName);
97-
Thread.currentThread().sleep(500L);
98-
//Ensure db has atleast one forest
99-
createForestonHost(dbName + "-" + forestCount, dbName, hostNames[0]);
100-
forestCount++;
101-
for (String forestHost : hostNames) {
102-
for(int i = 0; i < new Random().nextInt(3); i++) {
103-
createForestonHost(dbName + "-" + forestCount, dbName, forestHost);
104-
forestCount++;
105-
}
106-
Thread.currentThread().sleep(500L);
107-
}
108-
// Create App Server if needed.
97+
for (int i = 1; i <= forestCount; i++) {
98+
createForest(dbName + "-" + i, dbName);
99+
}
109100
createRESTServerWithDB(server, port);
110101
assocRESTServer(server, dbName, port);
111102
if (IsSecurityEnabled()) {
@@ -151,12 +142,6 @@ public static void setUpBeforeClass() throws Exception {
151142
@AfterAll
152143
public static void tearDownAfterClass() throws Exception {
153144
associateRESTServerWithDB(server, "Documents");
154-
for (int i = 0; i < forestCount -1 ; i++) {
155-
System.out.println(dbName + "-" + (i + 1));
156-
detachForest(dbName, dbName + "-" + (i + 1));
157-
deleteForest(dbName + "-" + (i + 1));
158-
}
159-
160145
deleteDB(dbName);
161146
}
162147

@@ -476,17 +461,17 @@ public void testAddAs() throws Exception {
476461

477462
ihb3.flushAndWait();
478463
System.out.println("Size is " + dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue());
479-
assertTrue(dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 4);
464+
assertEquals(4, dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue());
480465

481466
DocumentMetadataHandle mHandle2 = readMetadataFromDocument(dbClient, "/doc/reader_xml", "XML");
482467
assertEquals(1, mHandle2.getQuality());
483468
assertEquals("Sample Collection 1", mHandle2.getCollections().iterator().next());
484-
assertTrue(mHandle2.getCollections().size() == 1);
469+
assertEquals(1, mHandle2.getCollections().size());
485470

486471
DocumentMetadataHandle mHandle3 = readMetadataFromDocument(dbClient, "/doc/jackson", "XML");
487472
assertEquals(0, mHandle3.getQuality());
488473
assertEquals("Sample Collection 2", mHandle3.getCollections().iterator().next());
489-
assertTrue(mHandle3.getCollections().size() == 1);
474+
assertEquals(1, mHandle3.getCollections().size());
490475

491476
assertTrue(uriExists(successBatch.toString(), "/doc/string"));
492477

@@ -942,7 +927,7 @@ public void testWithInvalidValues() throws Exception {
942927
}
943928

944929
@Test
945-
public void testflushAsync() throws Exception {
930+
public void testflushAsync() {
946931
System.out.println("In testflushAsync method");
947932

948933
final String query1 = "fn:count(fn:doc())";
@@ -976,51 +961,48 @@ public void testflushAsync() throws Exception {
976961
}
977962

978963
@Test
979-
public void testInsertoReadOnlyForest() throws Exception {
980-
System.out.println("In testInsertoReadOnlyForest method");
981-
982-
Map<String, String> properties = new HashMap<>();
983-
properties.put("updates-allowed", "read-only");
984-
for (int i = 0; i < forestCount; i++)
985-
changeProperty(properties, "/manage/v2/forests/" + dbName + "-" + (i + 1) + "/properties");
986-
final String query1 = "fn:count(fn:doc())";
964+
public void testInsertoReadOnlyForest() {
965+
try {
966+
Map<String, String> properties = new HashMap<>();
967+
properties.put("updates-allowed", "read-only");
968+
for (int i = 1; i <= forestCount; i++) {
969+
changeProperty(properties, "/manage/v2/forests/" + dbName + "-" + i + "/properties");
970+
}
971+
final String query1 = "fn:count(fn:doc())";
987972

988-
final AtomicInteger successCount = new AtomicInteger(0);
973+
final AtomicInteger successCount = new AtomicInteger(0);
989974

990-
final AtomicBoolean failState = new AtomicBoolean(false);
991-
final AtomicInteger failCount = new AtomicInteger(0);
975+
final AtomicBoolean failState = new AtomicBoolean(false);
976+
final AtomicInteger failCount = new AtomicInteger(0);
992977

993-
for (int i = 0; i < forestCount; i++)
994-
changeProperty(properties, "/manage/v2/forests/" + dbName + "-" + (i + 1) + "/properties");
978+
WriteBatcher ihb2 = dmManager.newWriteBatcher();
979+
ihb2.withBatchSize(25);
980+
ihb2.onBatchSuccess(batch -> {
981+
successCount.addAndGet(batch.getItems().length);
982+
}).onBatchFailure((batch, throwable) -> {
983+
failState.set(true);
984+
failCount.addAndGet(batch.getItems().length);
985+
});
995986

996-
WriteBatcher ihb2 = dmManager.newWriteBatcher();
997-
ihb2.withBatchSize(25);
998-
ihb2.onBatchSuccess(batch -> {
987+
dmManager.startJob(ihb2);
988+
for (int j = 0; j < 20; j++) {
989+
String uri = "/local/json-" + j;
990+
ihb2.addAs(uri, stringHandle);
991+
}
999992

1000-
successCount.addAndGet(batch.getItems().length);
1001-
}).onBatchFailure((batch, throwable) -> {
1002-
failState.set(true);
1003-
failCount.addAndGet(batch.getItems().length);
1004-
});
993+
ihb2.flushAndWait();
1005994

1006-
dmManager.startJob(ihb2);
1007-
for (int j = 0; j < 20; j++) {
1008-
String uri = "/local/json-" + j;
1009-
ihb2.addAs(uri, stringHandle);
995+
assertEquals(0, dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue());
996+
assertTrue(failState.get());
997+
assertEquals(0, successCount.intValue());
998+
assertEquals(20, failCount.intValue());
999+
} finally {
1000+
Map<String, String> properties = new HashMap<>();
1001+
properties.put("updates-allowed", "all");
1002+
for (int i = 1; i <= forestCount; i++) {
1003+
changeProperty(properties, "/manage/v2/forests/" + dbName + "-" + i + "/properties");
1004+
}
10101005
}
1011-
1012-
ihb2.flushAndWait();
1013-
1014-
properties.put("updates-allowed", "all");
1015-
for (int i = 0; i < forestCount; i++)
1016-
changeProperty(properties, "/manage/v2/forests/" + dbName + "-" + (i + 1) + "/properties");
1017-
1018-
assertTrue(dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0);
1019-
1020-
assertTrue(failState.get());
1021-
1022-
assertTrue(successCount.intValue() == 0);
1023-
assertTrue(failCount.intValue() == 20);
10241006
}
10251007

10261008
@Test
@@ -1065,10 +1047,10 @@ public void testInsertoDisabledDB() throws Exception {
10651047
System.out.println("Success : " + successCount.intValue());
10661048
System.out.println("Count : " + dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue());
10671049

1068-
assertTrue(dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0);
1050+
assertEquals(0, dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue());
10691051
assertTrue(failState.get());
10701052

1071-
assertTrue(failCount.intValue() == 20);
1053+
assertEquals(20, failCount.intValue());
10721054
}
10731055

10741056
@Test
@@ -1851,7 +1833,7 @@ public void testNPEFailureCallBack() throws Exception {
18511833
}
18521834

18531835
@Test
1854-
public void testEmptyFlush() throws Exception {
1836+
public void testEmptyFlush() {
18551837
System.out.println("In testEmptyFlush method");
18561838

18571839
WriteBatcher ihb2 = dmManager.newWriteBatcher();
@@ -1875,7 +1857,7 @@ public void testEmptyFlush() throws Exception {
18751857
ihb2.add("/new", fileHandle);
18761858
dmManager.stopJob(job);
18771859
final String query1 = "fn:count(fn:doc())";
1878-
assertTrue(dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue() == 0);
1860+
assertEquals(0, dbClient.newServerEval().xquery(query1).eval().next().getNumber().intValue());
18791861
}
18801862

18811863
@Test

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ public static void tearDownAfterClass() throws Exception {
340340
associateRESTServerWithModuleDB(restServerName, "Modules");
341341

342342
deleteDB(dbName);
343-
deleteForest(fNames[0]);
344343
deleteDB(dbNameMod);
345-
deleteForest(fNamesMod[0]);
346344
deleteDB("TestDynamicIngest-modules");
347345
deleteForest("TestDynamicIngest-modules-1");
348346
// release client

0 commit comments

Comments
 (0)