1 package org.kuali.ole.docstore.engine.service.rest;
2
3 import org.kuali.ole.docstore.common.client.DocstoreRestClient;
4 import org.kuali.ole.docstore.common.search.SearchParams;
5 import org.kuali.ole.docstore.common.search.SearchResponse;
6 import org.kuali.ole.docstore.model.enums.DocType;
7 import org.springframework.util.StopWatch;
8
9 import java.util.ArrayList;
10 import java.util.Date;
11 import java.util.List;
12 import java.util.concurrent.*;
13
14
15
16
17 public class TestUpdateAndSearch {
18
19 private static int NTHREADS = 10;
20 private DocstoreRestClient restClient = new DocstoreRestClient();
21
22 public void testUpdateAndSearch() throws Exception {
23
24
25
26 ExecutorService executor = Executors.newFixedThreadPool(NTHREADS);
27
28 List<Future<Long>> list = new ArrayList<Future<Long>>();
29
30 int itemId = 7692010;
31 StopWatch stopWatch = new StopWatch();
32 stopWatch.start();
33
34
35
36 for(int i=0; i< 50; i++){
37
38 Callable<Long> worker = new TestUpdateAndSearchCals("wio-" + (itemId), ""+(i+17000));
39
40
41 Future<Long> future = executor.submit(worker);
42
43 list.add(future);
44 }
45
46 for(Future<Long> fut : list){
47 try {
48
49
50 System.out.println(new Date()+ "::"+fut.get());
51 } catch (InterruptedException | ExecutionException e) {
52 e.printStackTrace();
53 }
54 }
55 stopWatch.stop();
56 System.out.println(stopWatch.prettyPrint());
57 searchItem("wio-7692010");
58 executor.shutdown();
59 }
60
61
62 private void searchItem(String itemId) {
63 SearchParams searchParams = new SearchParams();
64 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("", searchParams.buildSearchField(DocType.ITEM.getCode(), "id", itemId), "AND"));
65 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.ITEM.getCode(), "ENUMERATION"));
66 SearchResponse response = restClient.search(searchParams);
67 if(response.getSearchResults() != null && response.getSearchResults().size() > 0 && response.getSearchResults().get(0).getSearchResultFields() != null && response.getSearchResults().get(0).getSearchResultFields().size() > 0 && response.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue() != null) {
68 String enumeration = response.getSearchResults().get(0).getSearchResultFields().get(0).getFieldValue();
69 System.out.println("item id " + itemId + " with enumeration " + enumeration);
70
71 }
72
73 }
74
75
76 }