Skip to content

Commit 9f14e33

Browse files
committed
updated with a test for an issue 107
1 parent a228b77 commit 9f14e33

File tree

1 file changed

+56
-15
lines changed

1 file changed

+56
-15
lines changed

test-complete/src/test/java/com/marklogic/javaclient/TestBulkReadSample1.java

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.marklogic.javaclient;
22

33
import java.io.File;
4-
54
import java.util.HashMap;
65

76
import com.marklogic.client.DatabaseClient;
@@ -18,7 +17,6 @@
1817
import com.marklogic.client.io.Format;
1918
import com.marklogic.client.io.StringHandle;
2019
import com.marklogic.client.io.DOMHandle;
21-
2220
import com.marklogic.client.io.JacksonHandle;
2321

2422

@@ -27,6 +25,7 @@
2725
import com.fasterxml.jackson.databind.ObjectMapper;
2826

2927
import org.junit.*;
28+
import org.junit.runners.MethodSorters;
3029

3130
import static org.junit.Assert.*;
3231

@@ -41,7 +40,7 @@
4140
*/
4241

4342

44-
43+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
4544
public class TestBulkReadSample1 extends BasicJavaClientREST {
4645

4746
private static final int BATCH_SIZE=100;
@@ -80,7 +79,7 @@ public void testCleanUp() throws Exception
8079
* Test Bulk Read to see you can read all the documents?
8180
*/
8281
@Test
83-
public void testReadMultipleTextDoc()
82+
public void test1ReadMultipleTextDoc()
8483
{
8584
int count=1;
8685
TextDocumentManager docMgr = client.newTextDocumentManager();
@@ -116,7 +115,7 @@ public void testReadMultipleTextDoc()
116115
* Verified by reading individual documents
117116
*/
118117
@Test
119-
public void testReadMultipleXMLDoc() throws Exception
118+
public void test2ReadMultipleXMLDoc() throws Exception
120119
{
121120
int count=1;
122121
XMLDocumentManager docMgr = client.newXMLDocumentManager();
@@ -158,7 +157,7 @@ public void testReadMultipleXMLDoc() throws Exception
158157
*
159158
*/
160159
@Test
161-
public void testReadMultipleBinaryDoc() throws Exception
160+
public void test3ReadMultipleBinaryDoc() throws Exception
162161
{
163162
String docId[] = {"Sega-4MB.jpg"};
164163
int count=1;
@@ -213,7 +212,7 @@ public void testReadMultipleBinaryDoc() throws Exception
213212
* This test has a bug logged in github with tracking Issue#33
214213
*/
215214
@Test
216-
public void testWriteMultipleJSONDocs() throws Exception
215+
public void test4WriteMultipleJSONDocs() throws Exception
217216
{
218217
int count=1;
219218
JSONDocumentManager docMgr = client.newJSONDocumentManager();
@@ -257,13 +256,16 @@ public void testWriteMultipleJSONDocs() throws Exception
257256

258257

259258
}
259+
260+
261+
260262
/*
261263
* This test uses GenericManager to load all different document types
262264
* This test has a bug logged in github with tracking Issue#33
263265
*
264266
*/
265267
@Test
266-
public void testWriteGenericDocMgr() throws Exception
268+
public void test5WriteGenericDocMgr() throws Exception
267269
{
268270

269271
GenericDocumentManager docMgr = client.newDocumentManager();
@@ -281,13 +283,7 @@ public void testWriteGenericDocMgr() throws Exception
281283
}
282284
// for(String uri:uris){System.out.println(uri);}
283285
DocumentPage page = docMgr.read(uris);
284-
if(!page.hasNext()){
285-
testReadMultipleTextDoc();
286-
testReadMultipleXMLDoc();
287-
testReadMultipleBinaryDoc();
288-
testWriteMultipleJSONDocs();
289-
page = docMgr.read(uris);
290-
}
286+
291287
while(page.hasNext()){
292288
DocumentRecord rec = page.next();
293289
switch(rec.getFormat())
@@ -307,6 +303,51 @@ public void testWriteGenericDocMgr() throws Exception
307303
assertEquals("binary document count", 25,countJpg);
308304
assertEquals("Json document count", 25,countJson);
309305
}
306+
//test for Issue# 107
307+
@Test
308+
public void test6CloseMethodforReadMultipleDoc() throws Exception
309+
{
310+
int count=1;
311+
DocumentPage page;
312+
JSONDocumentManager docMgr = client.newJSONDocumentManager();
313+
DocumentWriteSet writeset =docMgr.newWriteSet();
314+
315+
HashMap<String,String> map= new HashMap<String,String>();
316+
for(int j=0;j<102;j++){
317+
for(int i =0;i<10;i++){
318+
JsonNode jn = new ObjectMapper().readTree("{\"animal"+i+"\":\"dog"+i+"\", \"says\":\"woof\"}");
319+
JacksonHandle jh = new JacksonHandle();
320+
jh.set(jn);
321+
writeset.add(DIRECTORY+j+"/dog"+i+".json",jh);
322+
map.put(DIRECTORY+j+"/dog"+i+".json", jn.toString());
323+
}
324+
docMgr.write(writeset);
325+
writeset = docMgr.newWriteSet();
326+
}
327+
328+
String uris[] = new String[100];
329+
for(int j=0;j<102;j++){
330+
for(int i =0;i<10;i++){
331+
uris[i]=DIRECTORY+j+"/dog"+i+".json";
332+
}
333+
count=0;
334+
page = docMgr.read(uris);
335+
336+
DocumentRecord rec;
337+
JacksonHandle jh = new JacksonHandle();
338+
while(page.hasNext()){
339+
rec = page.next();
340+
validateRecord(rec,Format.JSON);
341+
rec.getContent(jh);
342+
assertEquals("Comparing the content :",map.get(rec.getUri()),jh.get().toString());
343+
count++;
344+
} page.close();
345+
// validateRecord(rec,Format.JSON);
346+
assertEquals("document count", 10,count);
347+
}
348+
349+
}
350+
310351
@AfterClass
311352
public static void tearDown() throws Exception
312353
{

0 commit comments

Comments
 (0)