001package org.kuali.ole.utility; 002 003import org.junit.Test; 004import org.kuali.ole.docstore.utility.BatchIngestStatistics; 005import org.kuali.ole.docstore.utility.BulkIngestStatistics; 006import org.kuali.ole.docstore.utility.FileIngestStatistics; 007import org.kuali.ole.docstore.xstream.BaseTestCase; 008import org.slf4j.Logger; 009import org.slf4j.LoggerFactory; 010 011import java.util.ArrayList; 012import java.util.List; 013 014import static junit.framework.Assert.assertNotNull; 015 016/** 017 * Created with IntelliJ IDEA. 018 * User: ? 019 * Date: ? 020 * Time: ? 021 * To change this template use File | Settings | File Templates. 022 */ 023public class BulkIngestStatistics_UT extends BaseTestCase { 024 private static final Logger LOG = LoggerFactory.getLogger(BulkIngestStatistics_UT.class); 025 026 @Test 027 public void testBulkIngestStatistics() throws Exception { 028 BulkIngestStatistics bulkIngestStatistics = BulkIngestStatistics.getInstance(); 029 bulkIngestStatistics.setFirstBatch(false); 030 bulkIngestStatistics.setLastBatch(false); 031 bulkIngestStatistics.setBatchSize("10"); 032 bulkIngestStatistics.setFileRecCount(2); 033 bulkIngestStatistics.setCommitRecCount(1); 034 bulkIngestStatistics.setSplitSize("2"); 035 List<BatchIngestStatistics> batchIngestStatisticsList = new ArrayList<BatchIngestStatistics>(); 036 List<FileIngestStatistics> fileIngestStatisticsList = new ArrayList<FileIngestStatistics>(); 037 FileIngestStatistics fileIngestStatistics = bulkIngestStatistics.startFile(); 038 StringBuilder sb = new StringBuilder(); 039 fileIngestStatistics.setFileName("sample1.txt"); 040 fileIngestStatistics.setFileStatus(""); 041 BatchIngestStatistics batchIngestStatistics = fileIngestStatistics.startBatch(); 042 long timeToConvertStringToReqObj = 1200; 043 long timeToCreateNodesInJcr = 3555; 044 long timeToSaveJcrSession = 1222; 045 long ingestingTime = 3400; 046 long timeToConvertXmlToPojo = 2000; 047 long timeToConvertToSolrInputDocs = 1400; 048 long timeToIndexSolrInputDocs = 1860; 049 long timeToSolrCommit = 1700; 050 long timeToSolrOptimize = 2500; 051 long indexingTime = 2200; 052 long ingestNIndexTotalTime = 1400; 053 long batchTime = 2500; 054 String batchStartTime = "0:0:1.333"; 055 String batchEndTime = "0:0:5.222"; 056 long startTime = 2200; 057 long endTime = 3200; 058 LOG.info(fileIngestStatistics.toString()); 059 batchIngestStatistics.setTimeToConvertStringToReqObj(timeToConvertStringToReqObj); 060 batchIngestStatistics.setTimeToCreateNodesInJcr(timeToCreateNodesInJcr); 061 batchIngestStatistics.setTimeToSaveJcrSession(timeToSaveJcrSession); 062 batchIngestStatistics.setIngestingTime(ingestingTime); 063 batchIngestStatistics.setTimeToConvertXmlToPojo(timeToConvertXmlToPojo); 064 batchIngestStatistics.setTimeToConvertToSolrInputDocs(timeToConvertToSolrInputDocs); 065 batchIngestStatistics.setTimeToIndexSolrInputDocs(timeToIndexSolrInputDocs); 066 batchIngestStatistics.setTimeToSolrCommit(timeToSolrCommit); 067 batchIngestStatistics.setTimeToSolrOptimize(timeToSolrOptimize); 068 batchIngestStatistics.setIndexingTime(indexingTime); 069 batchIngestStatistics.setIngestNIndexTotalTime(ingestNIndexTotalTime); 070 batchIngestStatistics.setBatchTime(batchTime); 071 batchIngestStatisticsList.add(batchIngestStatistics); 072 batchIngestStatistics.setBatchStartTime(batchStartTime); 073 batchIngestStatistics.setBatchEndTime(batchEndTime); 074 batchIngestStatistics.buildBatchMetric(sb, batchIngestStatistics); 075 LOG.info(batchIngestStatistics.toString()); 076 LOG.info("Batch Metrics:" + sb.toString()); 077 //LOG.info(batchIngestStatistics.toString()); 078 fileIngestStatistics.setBatchStatisticsList(batchIngestStatisticsList); 079 fileIngestStatisticsList.add(fileIngestStatistics); 080 bulkIngestStatistics.setBatchStatisticsList(null); 081 assertNotNull(bulkIngestStatistics.getCurrentBatch()); 082 bulkIngestStatistics.setBatchStatisticsList(batchIngestStatisticsList); 083 bulkIngestStatistics.setFileIngestStatistics(fileIngestStatistics); 084 bulkIngestStatistics.setFileIngestStatisticsList(fileIngestStatisticsList); 085 assertNotNull(bulkIngestStatistics.getFileIngestStatisticsList()); 086 assertNotNull(bulkIngestStatistics.getFileIngestStatistics()); 087 assertNotNull(bulkIngestStatistics.getBatchStatisticsList()); 088 if (bulkIngestStatistics.isFirstBatch()) { 089 LOG.info("first batch"); 090 } else if (bulkIngestStatistics.isLastBatch()) { 091 LOG.info("last batch"); 092 } 093 094 for (FileIngestStatistics fileIngestStatistics1 : fileIngestStatisticsList) { 095 LOG.info("file name:" + fileIngestStatistics1.getFileName()); 096 for (BatchIngestStatistics batchIngestStatistics1 : fileIngestStatistics1.getBatchStatisticsList()) { 097 LOG.info("Time To Convert String To ReqObj:" + DateTimeUtil 098 .formatTime(batchIngestStatistics1.getTimeToConvertStringToReqObj())); 099 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}