1 package org.kuali.ole.utility;
2
3 import org.junit.Test;
4 import org.kuali.ole.docstore.utility.BatchIngestStatistics;
5 import org.kuali.ole.docstore.utility.BulkIngestStatistics;
6 import org.kuali.ole.docstore.utility.FileIngestStatistics;
7 import org.kuali.ole.docstore.xstream.BaseTestCase;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import static junit.framework.Assert.assertNotNull;
15
16
17
18
19
20
21
22
23 public class BulkIngestStatistics_UT extends BaseTestCase {
24 private static final Logger LOG = LoggerFactory.getLogger(BulkIngestStatistics_UT.class);
25
26 @Test
27 public void testBulkIngestStatistics() throws Exception {
28 BulkIngestStatistics bulkIngestStatistics = BulkIngestStatistics.getInstance();
29 bulkIngestStatistics.setFirstBatch(false);
30 bulkIngestStatistics.setLastBatch(false);
31 bulkIngestStatistics.setBatchSize("10");
32 bulkIngestStatistics.setFileRecCount(2);
33 bulkIngestStatistics.setCommitRecCount(1);
34 bulkIngestStatistics.setSplitSize("2");
35 List<BatchIngestStatistics> batchIngestStatisticsList = new ArrayList<BatchIngestStatistics>();
36 List<FileIngestStatistics> fileIngestStatisticsList = new ArrayList<FileIngestStatistics>();
37 FileIngestStatistics fileIngestStatistics = bulkIngestStatistics.startFile();
38 StringBuilder sb = new StringBuilder();
39 fileIngestStatistics.setFileName("sample1.txt");
40 fileIngestStatistics.setFileStatus("");
41 BatchIngestStatistics batchIngestStatistics = fileIngestStatistics.startBatch();
42 long timeToConvertStringToReqObj = 1200;
43 long timeToCreateNodesInJcr = 3555;
44 long timeToSaveJcrSession = 1222;
45 long ingestingTime = 3400;
46 long timeToConvertXmlToPojo = 2000;
47 long timeToConvertToSolrInputDocs = 1400;
48 long timeToIndexSolrInputDocs = 1860;
49 long timeToSolrCommit = 1700;
50 long timeToSolrOptimize = 2500;
51 long indexingTime = 2200;
52 long ingestNIndexTotalTime = 1400;
53 long batchTime = 2500;
54 String batchStartTime = "0:0:1.333";
55 String batchEndTime = "0:0:5.222";
56 long startTime = 2200;
57 long endTime = 3200;
58 LOG.info(fileIngestStatistics.toString());
59 batchIngestStatistics.setTimeToConvertStringToReqObj(timeToConvertStringToReqObj);
60 batchIngestStatistics.setTimeToCreateNodesInJcr(timeToCreateNodesInJcr);
61 batchIngestStatistics.setTimeToSaveJcrSession(timeToSaveJcrSession);
62 batchIngestStatistics.setIngestingTime(ingestingTime);
63 batchIngestStatistics.setTimeToConvertXmlToPojo(timeToConvertXmlToPojo);
64 batchIngestStatistics.setTimeToConvertToSolrInputDocs(timeToConvertToSolrInputDocs);
65 batchIngestStatistics.setTimeToIndexSolrInputDocs(timeToIndexSolrInputDocs);
66 batchIngestStatistics.setTimeToSolrCommit(timeToSolrCommit);
67 batchIngestStatistics.setTimeToSolrOptimize(timeToSolrOptimize);
68 batchIngestStatistics.setIndexingTime(indexingTime);
69 batchIngestStatistics.setIngestNIndexTotalTime(ingestNIndexTotalTime);
70 batchIngestStatistics.setBatchTime(batchTime);
71 batchIngestStatisticsList.add(batchIngestStatistics);
72 batchIngestStatistics.setBatchStartTime(batchStartTime);
73 batchIngestStatistics.setBatchEndTime(batchEndTime);
74 batchIngestStatistics.buildBatchMetric(sb, batchIngestStatistics);
75 LOG.info(batchIngestStatistics.toString());
76 LOG.info("Batch Metrics:" + sb.toString());
77
78 fileIngestStatistics.setBatchStatisticsList(batchIngestStatisticsList);
79 fileIngestStatisticsList.add(fileIngestStatistics);
80 bulkIngestStatistics.setBatchStatisticsList(null);
81 assertNotNull(bulkIngestStatistics.getCurrentBatch());
82 bulkIngestStatistics.setBatchStatisticsList(batchIngestStatisticsList);
83 bulkIngestStatistics.setFileIngestStatistics(fileIngestStatistics);
84 bulkIngestStatistics.setFileIngestStatisticsList(fileIngestStatisticsList);
85 assertNotNull(bulkIngestStatistics.getFileIngestStatisticsList());
86 assertNotNull(bulkIngestStatistics.getFileIngestStatistics());
87 assertNotNull(bulkIngestStatistics.getBatchStatisticsList());
88 if (bulkIngestStatistics.isFirstBatch()) {
89 LOG.info("first batch");
90 } else if (bulkIngestStatistics.isLastBatch()) {
91 LOG.info("last batch");
92 }
93
94 for (FileIngestStatistics fileIngestStatistics1 : fileIngestStatisticsList) {
95 LOG.info("file name:" + fileIngestStatistics1.getFileName());
96 for (BatchIngestStatistics batchIngestStatistics1 : fileIngestStatistics1.getBatchStatisticsList()) {
97 LOG.info("Time To Convert String To ReqObj:" + DateTimeUtil
98 .formatTime(batchIngestStatistics1.getTimeToConvertStringToReqObj()));
99 LOG.info("Time To Create Nodes In Jcr:" + DateTimeUtil
100 .formatTime(batchIngestStatistics1.getTimeToCreateNodesInJcr()));
101 LOG.info("Time To Save Jcr Session:" + DateTimeUtil
102 .formatTime(batchIngestStatistics1.getTimeToSaveJcrSession()));
103 LOG.info("Ingesting Time:" + DateTimeUtil.formatTime(batchIngestStatistics1.getIngestingTime()));
104 LOG.info("Time To Convert Xml To Pojo:" + DateTimeUtil
105 .formatTime(batchIngestStatistics1.getTimeToConvertXmlToPojo()));
106 LOG.info("Time To Convert To SolrInputDocs:" + DateTimeUtil
107 .formatTime(batchIngestStatistics1.getTimeToConvertToSolrInputDocs()));
108 LOG.info("Time To Index SolrInputDocs:" + DateTimeUtil
109 .formatTime(batchIngestStatistics1.getTimeToIndexSolrInputDocs()));
110 LOG.info(
111 "Time To Solr Commit:" + DateTimeUtil.formatTime(batchIngestStatistics1.getTimeToSolrCommit()));
112 LOG.info("Time To Solr Optimize:" + DateTimeUtil
113 .formatTime(batchIngestStatistics1.getTimeToSolrOptimize()));
114 LOG.info("Indexing Time:" + DateTimeUtil.formatTime(batchIngestStatistics1.getIndexingTime()));
115 LOG.info("IngestNIndexTotalTime:" + DateTimeUtil
116 .formatTime(batchIngestStatistics1.getIngestNIndexTotalTime()));
117 LOG.info("Batch Time:" + DateTimeUtil.formatTime(batchIngestStatistics1.getBatchTime()));
118 }
119 DateTimeUtil dateTimeUtil = new DateTimeUtil();
120 String formatTime = dateTimeUtil.formatTime(3200, 2500);
121 LOG.info("Format Time:" + formatTime);
122
123
124 }
125
126 BatchIngestStatistics batchIngestStatistics1 = bulkIngestStatistics.getCurrentBatch();
127 sb = new StringBuilder();
128 batchIngestStatistics.buildBatchMetric(sb, batchIngestStatistics1);
129 LOG.info("Batch Size:" + bulkIngestStatistics.getBatchSize());
130 LOG.info("Split Size:" + bulkIngestStatistics.getSplitSize());
131 LOG.info("File Rec Count:" + bulkIngestStatistics.getFileRecCount());
132 LOG.info("Commit Rec Count:" + bulkIngestStatistics.getCommitRecCount());
133 LOG.info("Current Batch Metrics:" + sb.toString());
134 LOG.info("BulkIngestStatistics toString:" + bulkIngestStatistics.toString());
135 LOG.info("BulkIngestStatistics json:" + bulkIngestStatistics.getJsonString());
136 bulkIngestStatistics.clearBulkIngestStatistics();
137 }
138 }