Commit 893c581c835cfdfeaf21792e5d6d1ddd7e1aee0d

Authored by Paulo Graça
1 parent b81eea4908
Exists in tests

Performance tests

ptcrisync-test/src/pt/ptcris/test/ImportTest.java
... ... @@ -103,7 +103,6 @@ public class ImportTest {
103 103 List<BigInteger> putCodesList = ORCIDHelper.getWorkSummaryPutCodes(activitiesSummary);
104 104  
105 105  
106   -
107 106 if (!ignoreLimits) {
108 107 int nRecordsImport = Integer.parseInt(properties.getProperty("test_import_limit"));
109 108 // Limit the numbers to import
... ... @@ -111,7 +110,8 @@ public class ImportTest {
111 110 putCodesList = putCodesList.subList(0, nRecordsImport);
112 111 }
113 112 }
114   -
  113 +
  114 + //Will delete existing and import new works to ORCID
115 115 List<Work> localWorks = WorkTestPrepare.createAndLoadWorks(orcidClient,putCodesList);
116 116  
117 117 try {
... ... @@ -119,7 +119,7 @@ public class ImportTest {
119 119 // Check the number of exported works
120 120 ORCIDHelper helper = new ORCIDHelper(orcidClient);
121 121  
122   - numberOfWorks = helper.getAllWorkSummaries().size();
  122 + numberOfWorks = helper.getSourcedWorkSummaries().size();
123 123  
124 124 List<Work> remoteWorks = PTCRISync.importWorks(orcidClient, localWorks, progressHandler);
125 125 numberOfImportedWorks = remoteWorks.size();
... ...
ptcrisync-test/src/pt/ptcris/test/PerformanceTest.java
... ... @@ -10,7 +10,6 @@ import org.um.dsi.gavea.orcid.model.work.Work;
10 10 import org.um.dsi.gavea.orcid.model.work.WorkSummary;
11 11  
12 12 import pt.ptcris.ORCIDClient;
13   -import pt.ptcris.ORCIDClientImpl;
14 13 import pt.ptcris.ORCIDHelper;
15 14 import pt.ptcris.PTCRISync;
16 15 import pt.ptcris.test.dummy.ORCIDClientDummyImpl;
... ... @@ -35,108 +34,122 @@ import javax.xml.bind.JAXBException;
35 34 import org.apache.logging.log4j.LogManager;
36 35 import org.apache.logging.log4j.Logger;
37 36  
38   -
39 37 public class PerformanceTest {
40 38 private final Properties properties = TestPropertiesLoader.getInstance().getProperties();
41 39 private static final Logger _log = LogManager.getLogger(PerformanceTest.class);
42 40 private static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
43 41 private static ProgressHandlerDummyImpl progressHandler = new ProgressHandlerDummyImpl();
44   -
  42 +
45 43 /**
46   - * Empty ORCID profile and we want to measure the time of the export N works process from local app to ORCID
  44 + * Empty ORCID profile and we want to measure the time of the export N works
  45 + * process from local app to ORCID
47 46 */
48   - //@Test
  47 + @Test
49 48 public void exportTimetoOrcid() {
50 49 boolean testResult = false;
51 50 String orcidId = properties.getProperty("orcid_id");
52 51 boolean isTestClient = Boolean.parseBoolean(properties.getProperty("test_dummy_client"));
53   -
  52 + String[] nTestRecords = properties.getProperty("test_performance_limits").split(",");
  53 +
54 54 _log.info("Prepare data for: " + orcidId);
55   -
  55 +
56 56 ORCIDClient orcidClient;
57   - //To test the With and W/O the API
  57 + // To test the With and W/O the API
58 58 if (isTestClient) {
59 59 orcidClient = ORCIDClientDummyImpl.getDefaultClientInstance();
60 60 } else {
61   - orcidClient = DefaultTestOrcidClient.getDefaultClient();
  61 + orcidClient = DefaultTestOrcidClient.getDefaultClient();
62 62 }
63   -
  63 +
64 64 Date date = new Date();
65 65 _log.info("Date: " + dateFormat.format(date));
66 66 _log.info("Version: " + PTCRISync.class.getPackage().getImplementationVersion());
67 67 try {
  68 + // Test cycle - perform several configured tests
68 69 ActivitiesSummary activitiesSummary = ActivitiesSummaryTestPrepare.loadFromResources();
69   - List<BigInteger> putCodesList = ORCIDHelper.getWorkSummaryPutCodes(activitiesSummary);
70   -
71   - //int nRecords = Integer.parseInt(properties.getProperty("test_export_limit"));
72   - int nRecords = 5;
73   - //Limit the numbers to export
74   - int putCodesListSize = putCodesList.size();
75   - if ( putCodesListSize > nRecords ) {
76   - putCodesList.subList(nRecords, putCodesListSize).clear();
77   - }
78   -
79   - List<Work> localWorks = WorkTestPrepare.loadLocalWorksFromResources(putCodesList);
80   -
81   - int numberOfLocalWorks = localWorks.size();
82   - int numberOfExportedWorks = 0;
  70 + for (int i = 0; i < nTestRecords.length; i++) {
  71 + List<BigInteger> putCodesList = ORCIDHelper.getWorkSummaryPutCodes(activitiesSummary);
  72 +
  73 + int nRecords = Integer.parseInt(nTestRecords[i].trim());
  74 + int nPutCodes = nRecords;
  75 +
  76 + //Limit the number of load
  77 + if (nPutCodes > putCodesList.size() ) {
  78 + nPutCodes = putCodesList.size();
  79 + }
  80 +
  81 + List<Work> localWorks = WorkTestPrepare.loadLocalWorksFromResources(putCodesList.subList(0, nPutCodes));
  82 +
  83 + int numberOfLocalWorks = localWorks.size();
  84 + int numberOfExportedWorks = 0;
83 85  
84   - try {
85 86 // Check the number of exported works
86 87 ORCIDHelper helper = new ORCIDHelper(orcidClient);
87 88  
88 89 _log.info("Deleting all existing works");
89   - helper.deleteAllSourcedWorks();
90   -
91   - long start = System.nanoTime();
92   - _log.info("Start testing: " + orcidId);
93   - PTCRISync.export(orcidClient, localWorks, progressHandler);
94   - _log.info("End testing: " + (((double)(System.nanoTime() - start))/1E9) + " sec");
  90 + helper.deleteAllSourcedWorks();
95 91  
96   - List<WorkSummary> exportedWorkSummary = helper.getSourcedWorkSummaries();
97   - numberOfExportedWorks = exportedWorkSummary.size();
98   -
99   - _log.info("Localworks to export: " + numberOfLocalWorks);
100   - _log.info("Exported content: " + numberOfExportedWorks);
101   - testResult = true;
102   -
103   - assertTrue("Number of exported that should match: " + numberOfLocalWorks,
104   - (numberOfExportedWorks == numberOfLocalWorks));
105   - _log.info("[exportToNewProfile] " + "PASSED");
106   - } catch (OrcidClientException orcidException) {
107   - _log.fatal(orcidException.getDeveloperMessage());
108   - _log.error("[exportToNewProfile] " + "FAILED");
109   - } catch (Exception e) {
110   - e.printStackTrace();
111   - } finally {
112   - System.out.println(progressHandler.getReport());
113   - assertTrue("Export to new profile", testResult);
114   - }
115   -
  92 + try {
  93 +
  94 + long start = System.nanoTime();
  95 + _log.info("Start testing: " + orcidId);
  96 + PTCRISync.export(orcidClient, localWorks, progressHandler);
  97 + _log.info("End testing: " + (((double) (System.nanoTime() - start)) / 1E9) + " sec");
  98 +
  99 + List<WorkSummary> exportedWorkSummary = helper.getSourcedWorkSummaries();
  100 + numberOfExportedWorks = exportedWorkSummary.size();
  101 +
  102 + _log.info("Localworks to export: " + numberOfLocalWorks);
  103 + _log.info("Exported content: " + numberOfExportedWorks);
  104 + testResult = true;
  105 +
  106 + assertTrue("Number of exported that should match: " +
  107 + numberOfLocalWorks,
  108 + (numberOfExportedWorks == numberOfLocalWorks));
  109 + _log.info("[exportTimetoOrcid] " + "PASSED");
  110 + } catch (OrcidClientException orcidException) {
  111 + testResult = false;
  112 + _log.fatal(orcidException.getDeveloperMessage());
  113 + _log.error("[exportTimetoOrcid] " + "FAILED");
  114 + } catch (AssertionError e) {
  115 + testResult = false;
  116 + _log.error("[exportTimetoOrcid] " + e.getMessage());
  117 + } catch (Exception e) {
  118 + testResult = false;
  119 + e.printStackTrace();
  120 + } finally {
  121 + System.out.println(progressHandler.getReport());
  122 + assertTrue("Export to new profile", testResult);
  123 + }
  124 + } // For loop end
116 125 } catch (JAXBException e) {
117 126 // TODO Auto-generated catch block
118 127 e.printStackTrace();
  128 + } catch (OrcidClientException e1) {
  129 + e1.printStackTrace();
119 130 }
120   -
  131 +
121 132 }
122   -
  133 +
123 134 /**
124   - * Empty Local APP and we want to measure the time of the import M works process from ORCID to an empty local app
  135 + * Empty Local APP and we want to measure the time of the import M works
  136 + * process from ORCID to an empty local app
125 137 */
126 138 @Test
127 139 public void importTimetoOrcid() {
128 140 boolean testResult = false;
129 141 String orcidId = properties.getProperty("orcid_id");
130 142 boolean isTestClient = Boolean.parseBoolean(properties.getProperty("test_dummy_client"));
  143 + String[] nTestRecords = properties.getProperty("test_performance_limits").split(",");
131 144  
132 145 _log.info("Prepare data for: " + orcidId);
133 146 ORCIDClient orcidClient;
134   - //To test the With and W/O the API
  147 + // To test the With and W/O the API
135 148 if (isTestClient) {
136 149 orcidClient = ORCIDClientDummyImpl.getDefaultClientInstance();
137 150 } else {
138   - orcidClient = DefaultTestOrcidClient.getDefaultClient();
139   - }
  151 + orcidClient = DefaultTestOrcidClient.getDefaultClient();
  152 + }
140 153  
141 154 // Empty list of local works
142 155 List<Work> localWorks = new LinkedList<Work>();
... ... @@ -145,35 +158,56 @@ public class PerformanceTest {
145 158 int numberOfImportedWorks = 0;
146 159  
147 160 try {
148   - // Check the number of exported works
  161 + ActivitiesSummary activitiesSummary = ActivitiesSummaryTestPrepare.loadFromResources();
  162 + List<BigInteger> putCodesList = ORCIDHelper.getWorkSummaryPutCodes(activitiesSummary);
  163 +
149 164 ORCIDHelper helper = new ORCIDHelper(orcidClient);
150 165  
151   - numberOfWorks = helper.getAllWorkSummaries().size();
  166 + // Test cycle - perform several configured tests
  167 + for (int i = 0; i < nTestRecords.length; i++) {
  168 + int nRecords = Integer.parseInt(nTestRecords[i].trim());
  169 + int nPutCodes = nRecords;
152 170  
153   - long start = System.nanoTime();
154   - _log.info("Start testing: " + orcidId);
155   - List<Work> remoteWorks = PTCRISync.importWorks(orcidClient, localWorks, progressHandler);
156   - _log.info("End testing: " + (((double)(System.nanoTime() - start))/1E9) + " sec");
157   - numberOfImportedWorks = remoteWorks.size();
  171 + //Limit the number of load
  172 + if (nPutCodes > putCodesList.size() ) {
  173 + nPutCodes = putCodesList.size();
  174 + }
158 175  
159   - _log.info("Import works: " + numberOfWorks);
160   - _log.info("Number of imported works: " + numberOfImportedWorks);
161   - testResult = true;
  176 + //Will delete existing and import new works to ORCID, it will take a while
  177 + List<Work> uploadedWorks = WorkTestPrepare.createAndLoadWorks(orcidClient,putCodesList.subList(0, nPutCodes));
  178 + numberOfWorks = uploadedWorks.size();
162 179  
163   - assertTrue("Number of exported that should match: " + numberOfWorks,
164   - (numberOfImportedWorks == numberOfWorks));
165   - _log.info("[exportToNewProfile] " + "PASSED");
  180 + long start = System.nanoTime();
  181 + _log.info("Start testing: " + orcidId);
  182 + PTCRISync.importWorks(orcidClient, localWorks, progressHandler);
  183 + _log.info("End testing: " + (((double) (System.nanoTime() - start)) / 1E9) + " sec");
  184 + List<WorkSummary> importedWorkSummary = helper.getSourcedWorkSummaries();
  185 + numberOfImportedWorks = importedWorkSummary.size();
  186 +
  187 + _log.info("Import works: " + numberOfWorks);
  188 + _log.info("Number of imported works: " + numberOfImportedWorks);
  189 + testResult = true;
  190 +
  191 + assertTrue("Number of exported that should match: " + numberOfWorks,
  192 + (numberOfImportedWorks == numberOfWorks));
  193 + _log.info("[importTimetoOrcid] " + "PASSED");
  194 +
  195 + } //End of For loop
  196 +
166 197 } catch (OrcidClientException orcidException) {
167 198 _log.fatal(orcidException.getDeveloperMessage());
168   - _log.error("[exportToNewProfile] " + "FAILED");
  199 + _log.error("[importTimetoOrcid] " + "FAILED");
  200 + } catch (AssertionError e) {
  201 + testResult = false;
  202 + _log.error("[importTimetoOrcid] " + e.getMessage());
169 203 } catch (Exception e) {
170 204 e.printStackTrace();
171 205 } finally {
172 206 System.out.println(progressHandler.getReport());
173 207 assertTrue("Import new works", testResult);
174   - }
175   - }
176   -
  208 + }
  209 + }
  210 +
177 211 public static void main(String[] args) {
178 212 Result result = JUnitCore.runClasses(PerformanceTest.class);
179 213 for (Failure failure : result.getFailures()) {
... ...
ptcrisync-test/src/pt/ptcris/test/dummy/ORCIDClientDummyImpl.java
... ... @@ -4,15 +4,20 @@ import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
4 4  
5 5 import java.math.BigInteger;
6 6 import java.util.HashMap;
  7 +import java.util.Iterator;
7 8 import java.util.LinkedList;
8 9 import java.util.List;
  10 +import java.util.Map;
9 11 import java.util.Properties;
10 12 import java.util.Random;
11 13  
12 14 import javax.xml.bind.JAXBException;
13 15  
14 16 import org.um.dsi.gavea.orcid.client.OrcidAccessToken;
  17 +import org.um.dsi.gavea.orcid.model.work.ExternalIdentifier;
15 18 import org.um.dsi.gavea.orcid.model.work.Work;
  19 +import org.um.dsi.gavea.orcid.model.work.WorkExternalIdentifiers;
  20 +import org.um.dsi.gavea.orcid.model.work.WorkSummary;
16 21  
17 22 import pt.ptcris.ORCIDClient;
18 23 import pt.ptcris.ORCIDHelper;
... ... @@ -21,6 +26,10 @@ import pt.ptcris.test.preparation.WorkTestPrepare;
21 26 import pt.ptcris.test.properties.TestPropertiesLoader;
22 27  
23 28 import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
  29 +import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary.Works;
  30 +import org.um.dsi.gavea.orcid.model.activities.Identifier;
  31 +import org.um.dsi.gavea.orcid.model.activities.Identifiers;
  32 +import org.um.dsi.gavea.orcid.model.activities.WorkGroup;
24 33 import org.um.dsi.gavea.orcid.model.common.ClientId;
25 34 import org.um.dsi.gavea.orcid.model.common.OrcidId;
26 35 import org.um.dsi.gavea.orcid.model.common.SourceName;
... ... @@ -109,14 +118,47 @@ public class ORCIDClientDummyImpl implements ORCIDClient {
109 118 }
110 119  
111 120 public ActivitiesSummary getActivitiesSummary() throws OrcidClientException {
112   - try {
113   - return ActivitiesSummaryTestPrepare.loadFromResources();
114   -
115   - } catch (JAXBException e) {
116   - // TODO Auto-generated catch block
117   - e.printStackTrace();
  121 + ActivitiesSummary activitiesSummary = new ActivitiesSummary();
  122 + if (dummyWorks.isEmpty()) {
  123 + try {
  124 + return ActivitiesSummaryTestPrepare.loadFromResources();
  125 +
  126 + } catch (JAXBException e) {
  127 + // TODO Auto-generated catch block
  128 + e.printStackTrace();
  129 + }
  130 + } else {
  131 + Works works = new Works();
  132 + List<WorkGroup> workGroupList = new LinkedList<WorkGroup>();
  133 + //Create Activity Summary based on HashMap
  134 + for (Map.Entry<BigInteger, Work> entry : dummyWorks.entrySet()) {
  135 + BigInteger key = entry.getKey();
  136 + Work value = entry.getValue();
  137 +
  138 + List<Identifier> identifierList = new LinkedList<Identifier>();
  139 + //Identifiers
  140 + for(ExternalIdentifier workIdentifier:value.getExternalIdentifiers().getWorkExternalIdentifier()) {
  141 + Identifier identifier = new Identifier( workIdentifier.getExternalIdentifierType().toString(),
  142 + workIdentifier.getExternalIdentifierId());
  143 + identifierList.add(identifier);
  144 + }
  145 + Identifiers identifiers = new Identifiers(identifierList);
  146 +
  147 + WorkSummary workSummary = new WorkSummary();
  148 + workSummary.setPutCode(key);
  149 +
  150 + workSummary.setTitle(value.getTitle());
  151 + workSummary.setSource(value.getSource());
  152 +
  153 + List<WorkSummary> workSummaryList = new LinkedList<WorkSummary>();
  154 + workSummaryList.add(workSummary);
  155 +
  156 + workGroupList.add(new WorkGroup(identifiers,workSummaryList));
  157 + }
  158 + works.setGroup(workGroupList);
  159 + activitiesSummary.setWorks(works);
118 160 }
119   - return null;
  161 + return activitiesSummary;
120 162 }
121 163  
122 164 public String getClientId() {
... ...
ptcrisync-test/src/pt/ptcris/test/dummy/ProgressHandlerDummyImpl.java
... ... @@ -16,9 +16,9 @@ public class ProgressHandlerDummyImpl implements ProgressHandler {
16 16 private Long time_init;
17 17 private Long time_overall;
18 18 private Long time_process;
19   - private int n_executions = 0;
20 19 private List<Long> timeEachExecution;
21 20 private List<String> report = new Vector<String>();
  21 + private String message;
22 22  
23 23 public void setProgress(int progress) {
24 24 if (progress == 0) {
... ... @@ -29,7 +29,6 @@ public class ProgressHandlerDummyImpl implements ProgressHandler {
29 29 }
30 30 // TODO Auto-generated method stub
31 31 timeEachExecution.add(System.nanoTime());
32   - n_executions++;
33 32  
34 33  
35 34 }
... ... @@ -41,7 +40,8 @@ public class ProgressHandlerDummyImpl implements ProgressHandler {
41 40 case "ORCID_SYNC_EXPORT_STARTED":
42 41 case "ORCID_SYNC_IMPORT_WORKS_STARTED":
43 42 case "ORCID_SYNC_IMPORT_UPDATES_STARTED":
44   - start_init = System.nanoTime();
  43 + this.message = message;
  44 + start_init = System.nanoTime();
45 45 break;
46 46 //case "ORCID_SYNC_EXPORT_UPDATING_WORKS":
47 47 //case "ORCID_SYNC_EXPORT_ADDING_WORKS":
... ... @@ -67,7 +67,7 @@ public class ProgressHandlerDummyImpl implements ProgressHandler {
67 67  
68 68 public void done() {
69 69 // TODO Auto-generated method stub
70   - _log.info("Done");
  70 + _log.debug("[ProgressHandlerDummyImpl] Done");
71 71 if (time_process == null) {
72 72 time_process = System.nanoTime() - start_process;
73 73 }
... ... @@ -77,15 +77,18 @@ public class ProgressHandlerDummyImpl implements ProgressHandler {
77 77 report.add(generateReport());
78 78 time_init = null;
79 79 time_process = null;
  80 + //Reset the overall time
  81 + start_overall = 0L;
80 82 }
81 83  
82 84 private String generateReport () {
83   - String report = "{\"NUM\":" + (n_executions-1) + "}," +
84   - "{\"TIME\":" + (((double)time_overall)/1E9) + "}," +
85   - "{\"INIT\":" + (((double)time_init)/1E9) + "}," +
86   - "{\"PROC\":" + (((double)time_process)/1E9) + "}," +
87   - "{\"AVG\":" + (this.calculateAverage()/1E9) + "}," +
88   - "{\"MAX\":" + (((double)this.calculateMax())/1E9) + "}"
  85 + String report = "[{\"MSG\":\"" + message + "\"},"
  86 + + "{\"NUM\":" + (timeEachExecution.size()) + "},"
  87 + + "{\"TIME\":" + (((double)time_overall)/1E9) + "},"
  88 + + "{\"INIT\":" + (((double)time_init)/1E9) + "},"
  89 + + "{\"PROC\":" + (((double)time_process)/1E9) + "},"
  90 + + "{\"AVG\":" + (this.calculateAverage()/1E9) + "},"
  91 + + "{\"MAX\":" + (((double)this.calculateMax())/1E9) + "}]\n"
89 92 ;
90 93 return report;
91 94 }
... ...
ptcrisync-test/src/pt/ptcris/test/preparation/ActivitiesSummaryTestPrepare.java
... ... @@ -43,6 +43,7 @@ public class ActivitiesSummaryTestPrepare {
43 43 return activitiesSummary;
44 44 }
45 45  
  46 +
46 47 public static void activitiesSummaryToXMLFile (ActivitiesSummary activitiesSummary, String filename) throws JAXBException {
47 48 AbstractTestSerializer<ActivitiesSummary> prepareActivitiesSummary = new AbstractTestSerializer<ActivitiesSummary>(){};
48 49 _log.info("saving: " + filename);
... ...