|
38 | 38 | import org.junit.BeforeClass; |
39 | 39 | import org.junit.Test; |
40 | 40 |
|
| 41 | +import com.marklogic.client.DatabaseClient; |
| 42 | +import com.marklogic.client.DatabaseClientFactory; |
| 43 | +import com.marklogic.client.DatabaseClientFactory.Authentication; |
| 44 | +import com.marklogic.client.Transaction; |
41 | 45 | import com.marklogic.client.document.DocumentDescriptor; |
42 | 46 | import com.marklogic.client.document.DocumentManager.Metadata; |
43 | 47 | import com.marklogic.client.document.DocumentPage; |
|
46 | 50 | import com.marklogic.client.document.JSONDocumentManager; |
47 | 51 | import com.marklogic.client.document.TextDocumentManager; |
48 | 52 | import com.marklogic.client.document.XMLDocumentManager; |
| 53 | +import com.marklogic.client.eval.EvalResultIterator; |
| 54 | +import com.marklogic.client.eval.ServerEvaluationCall; |
49 | 55 | import com.marklogic.client.io.DocumentMetadataHandle; |
50 | 56 | import com.marklogic.client.io.Format; |
51 | 57 | import com.marklogic.client.io.JacksonHandle; |
52 | 58 | import com.marklogic.client.io.JAXBHandle; |
53 | 59 | import com.marklogic.client.io.SearchHandle; |
54 | 60 | import com.marklogic.client.io.StringHandle; |
55 | 61 | import com.marklogic.client.query.DeleteQueryDefinition; |
| 62 | +import com.marklogic.client.query.QueryDefinition; |
56 | 63 | import com.marklogic.client.query.QueryManager; |
57 | 64 | import com.marklogic.client.query.StructuredQueryBuilder; |
58 | 65 |
|
@@ -394,6 +401,67 @@ public void testF_DefaultMetadata() { |
394 | 401 | } |
395 | 402 | } |
396 | 403 |
|
| 404 | + @Test |
| 405 | + public void test_171() throws Exception{ |
| 406 | + DatabaseClient client = DatabaseClientFactory.newClient( |
| 407 | + // the following line breaks things but should not: https://github.com/marklogic/java-client-api/issues/171 |
| 408 | + // TODO: uncomment the following line when https://bugtrack.marklogic.com/30299 is fixed |
| 409 | + //Common.HOST, Common.PORT, "Documents", Common.EVAL_USERNAME, Common.EVAL_PASSWORD, Authentication.DIGEST); |
| 410 | + Common.HOST, Common.PORT, Common.EVAL_USERNAME, Common.EVAL_PASSWORD, Authentication.DIGEST); |
| 411 | + int count=1; |
| 412 | + boolean tstatus =true; |
| 413 | + String directory = "/test_171/"; |
| 414 | + Transaction t1 = client.openTransaction(); |
| 415 | + try{ |
| 416 | + QueryManager queryMgr = client.newQueryManager(); |
| 417 | + DeleteQueryDefinition deleteQuery = queryMgr.newDeleteDefinition(); |
| 418 | + deleteQuery.setDirectory(directory); |
| 419 | + queryMgr.delete(deleteQuery); |
| 420 | + |
| 421 | + XMLDocumentManager docMgr = client.newXMLDocumentManager(); |
| 422 | + HashMap<String,String> map= new HashMap<String,String>(); |
| 423 | + DocumentWriteSet writeset =docMgr.newWriteSet(); |
| 424 | + for(int i =0;i<2;i++) { |
| 425 | + String contents = "<xml>test" + i + "</xml>"; |
| 426 | + String docId = directory + "sec"+i+".xml"; |
| 427 | + writeset.add(docId, new StringHandle(contents).withFormat(Format.XML)); |
| 428 | + map.put(docId, contents); |
| 429 | + if(count%100 == 0){ |
| 430 | + docMgr.write(writeset,t1); |
| 431 | + writeset = docMgr.newWriteSet(); |
| 432 | + } |
| 433 | + count++; |
| 434 | + } |
| 435 | + if(count%100 > 0){ |
| 436 | + docMgr.write(writeset,t1); |
| 437 | + } |
| 438 | + |
| 439 | + QueryDefinition directoryQuery = queryMgr.newStringDefinition(); |
| 440 | + directoryQuery.setDirectory(directory); |
| 441 | + SearchHandle outOfTransactionResults = queryMgr.search(directoryQuery, new SearchHandle()); |
| 442 | + |
| 443 | + SearchHandle inTransactionResults = queryMgr.search(directoryQuery, new SearchHandle(), t1); |
| 444 | + |
| 445 | + assertEquals("Count of documents outside of the transaction",0,outOfTransactionResults.getTotalResults()); |
| 446 | + assertEquals("Count of documents inside of the transaction", 2, inTransactionResults.getTotalResults()); |
| 447 | + |
| 448 | + //String query = "(fn:count(xdmp:directory('" + directory + "')))"; |
| 449 | + //ServerEvaluationCall evl= client.newServerEval().xquery(query); |
| 450 | + //EvalResultIterator evr = evl.eval(); |
| 451 | + //assertEquals("Count of documents outside of the transaction",0,evr.next().getNumber().intValue()); |
| 452 | + //evl= client.newServerEval().xquery(query).transaction(t1); |
| 453 | + //evr = evl.eval(); |
| 454 | + //assertEquals("Count of documents outside of the transaction",103,evr.next().getNumber().intValue()); |
| 455 | + }catch(Exception e){ |
| 456 | + System.out.println(e.getMessage()); |
| 457 | + tstatus=true; |
| 458 | + throw e; |
| 459 | + }finally{ |
| 460 | + if(tstatus){ |
| 461 | + t1.rollback(); |
| 462 | + } |
| 463 | + } |
| 464 | + } |
397 | 465 |
|
398 | 466 | private static void addCountry(String line, Map<String, Country> countries) { |
399 | 467 | // skip comment lines |
|
0 commit comments