Skip to content

Commit bf49dd9

Browse files
fix internal composition (#85)
Make tests to run in parallel
1 parent ad60fa2 commit bf49dd9

28 files changed

+567
-520
lines changed

.travis.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
sudo: required
2+
addons:
3+
apt:
4+
packages:
5+
- oracle-java8-installer
26

37
language: java
48

5-
services:
6-
- mongodb
7-
- rabbitmq
8-
99
jdk:
1010
- oraclejdk8
1111

1212
before_install:
13+
- uname -a
1314
- chmod +x pom.xml
1415

1516
script:
16-
- mvn clean install
17+
# since we run parallel tests using embedded mongodb in fresh environment all tests run first in parallel
18+
# will try to download the embedded mongo to this travis instance but the late ones will fail to write.
19+
# We will therefore run one test using mongodb first that will download the mongo instance and
20+
# then the rest of the test that will no longer need to download the embedded mongo since it will exist.
21+
#
22+
# It is also importan that the first test to be run is a Spring Boot Test since spring boot also downloads
23+
# another version of embedded mongo db so all Spring Boot tests will end up in a race condition also
24+
- mvn -DsomeModule.test.includes="**/QueryServiceTest.java" test
25+
- mvn -DsomeModule.test.excludes="**/QueryServiceTest.java" test
26+

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@
202202
<groupId>org.springframework.boot</groupId>
203203
<artifactId>spring-boot-maven-plugin</artifactId>
204204
</plugin>
205-
206-
<!-- PhoenixNAP RAML Code Generator plugin used to generate sources
205+
206+
<!-- PhoenixNAP RAML Code Generator plugin used to generate sources
207207
from raml -->
208208
<plugin>
209209
<groupId>com.phoenixnap.oss</groupId>
@@ -254,15 +254,15 @@
254254
</configuration>
255255
</execution>
256256
</executions>
257-
</plugin>
258-
257+
</plugin>
258+
259259
<plugin>
260260
<groupId>org.apache.maven.plugins</groupId>
261261
<artifactId>maven-surefire-plugin</artifactId>
262262
<version>2.20</version>
263263
<configuration>
264-
<forkCount>1</forkCount>
265-
<reuseForks>false</reuseForks>
264+
<forkCount>8</forkCount>
265+
<reuseForks>false</reuseForks>
266266
<excludes>
267267
<exclude>${someModule.test.excludes}</exclude>
268268
</excludes>
@@ -282,4 +282,4 @@
282282

283283
</plugins>
284284
</build>
285-
</project>
285+
</project>

src/main/java/com/ericsson/ei/queryservice/ProcessQueryParams.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public class ProcessQueryParams {
5858
private ProcessMissedNotification processMissedNotification;
5959

6060
/**
61-
* This method takes the parameters from the REST POST request body.
62-
* If the Aggregated Object matches the condition, then it is returned.
61+
* This method takes the parameters from the REST POST request body. If the
62+
* Aggregated Object matches the condition, then it is returned.
6363
*
6464
* @param request
6565
* @return JSONArray
@@ -88,15 +88,19 @@ public JSONArray filterFormParam(JsonNode request) throws IOException {
8888
*/
8989
private static JSONArray concatArray(JSONArray firstArray, JSONArray secondArray) throws JSONException {
9090
JSONArray result = new JSONArray();
91-
IntStream.range(0, firstArray.length()).mapToObj(firstArray::get).forEach(result::put);
92-
IntStream.range(0, secondArray.length()).mapToObj(secondArray::get).forEach(result::put);
91+
JSONArray[] inputs = new JSONArray[] { firstArray, secondArray };
92+
for (JSONArray input : inputs) {
93+
for (int i = 0; i < input.length(); i++) {
94+
result.put(input.get(i));
95+
}
96+
}
97+
9398
return result;
9499
}
95100

96101
/**
97-
* This method takes the parameters from the REST GET request query.
98-
* If the Aggregated Object matches the condition, then
99-
* it is returned.
102+
* This method takes the parameters from the REST GET request query. If the
103+
* Aggregated Object matches the condition, then it is returned.
100104
*
101105
* @param request
102106
* @return JSONArray
@@ -120,15 +124,17 @@ public JSONArray filterQueryParam(String request) {
120124
}
121125

122126
/**
123-
* Process parameters to create a JsonNode request to query the
124-
* Aggregated Objects.
127+
* Process parameters to create a JsonNode request to query the Aggregated
128+
* Objects.
125129
*
126130
* @param criteria
127131
* @return
128132
*/
129133
private JSONArray getProcessQuery(JsonNode criteria) {
130-
JSONArray resultAggregatedObject = processAggregatedObject.processQueryAggregatedObject(criteria, dataBaseName, aggregationCollectionName);
131-
JSONArray resultMissedNotification = processMissedNotification.processQueryMissedNotification(criteria, missedNotificationDataBaseName, missedNotificationCollectionName);
134+
JSONArray resultAggregatedObject = processAggregatedObject.processQueryAggregatedObject(criteria, dataBaseName,
135+
aggregationCollectionName);
136+
JSONArray resultMissedNotification = processMissedNotification.processQueryMissedNotification(criteria,
137+
missedNotificationDataBaseName, missedNotificationCollectionName);
132138
LOGGER.debug("resultAggregatedObject : " + resultAggregatedObject.toString());
133139
LOGGER.debug("resultMissedNotification : " + resultMissedNotification.toString());
134140
JSONArray result = null;

src/main/java/com/ericsson/ei/subscriptionhandler/SubscriptionHandler.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020
import com.fasterxml.jackson.databind.node.ArrayNode;
2121
import lombok.Getter;
22+
import lombok.Setter;
23+
2224
import org.slf4j.Logger;
2325
import org.slf4j.LoggerFactory;
2426
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,7 +34,8 @@
3234
/**
3335
* This class is responsible to take a aggregatedObject and match it with all
3436
* the Subscription Object, to check ALL Conditions/requirement for
35-
* notification. (AND between conditions in requirements, "OR" between requirements with conditions)
37+
* notification. (AND between conditions in requirements, "OR" between
38+
* requirements with conditions)
3639
*
3740
* @author xjibbal
3841
*/
@@ -53,8 +56,9 @@ public class SubscriptionHandler {
5356
@Autowired
5457
private InformSubscription informSubscription;
5558

59+
@Setter
5660
@Autowired
57-
private MongoDBHandler handler;
61+
private MongoDBHandler mongoDBHandler;
5862

5963
@Autowired
6064
private RunSubscription runSubscription;
@@ -71,7 +75,8 @@ public class SubscriptionHandler {
7175
*/
7276
public void checkSubscriptionForObject(final String aggregatedObject) {
7377
Thread subscriptionThread = new Thread(() -> {
74-
List<String> subscriptions = handler.getAllDocuments(subscriptionDataBaseName, subscriptionCollectionName);
78+
List<String> subscriptions = mongoDBHandler.getAllDocuments(subscriptionDataBaseName,
79+
subscriptionCollectionName);
7580
subscriptions.forEach(subscription -> extractConditions(aggregatedObject, subscription));
7681
});
7782
subscriptionThread.setName("SubscriptionHandler");
@@ -113,7 +118,7 @@ private void extractConditions(String aggregatedObject, String subscriptionData)
113118
public void print() {
114119
LOGGER.debug("SubscriptionDataBaseName : " + subscriptionDataBaseName);
115120
LOGGER.debug("SubscriptionCollectionName : " + subscriptionCollectionName);
116-
LOGGER.debug("MongoDBHandler object : " + handler);
121+
LOGGER.debug("MongoDBHandler object : " + mongoDBHandler);
117122
LOGGER.debug("JmesPathInterface : " + jmespath);
118123

119124
}

src/main/java/com/ericsson/ei/waitlist/WaitListStorageHandler.java

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,64 +63,45 @@ public class WaitListStorageHandler {
6363

6464
public void addEventToWaitList(String event, RulesObject rulesObject) throws Exception {
6565
String input = addProprtiesToEvent(event, rulesObject);
66-
boolean result=mongoDbHandler.insertDocument(databaseName,collectionName, input);
66+
boolean result = mongoDbHandler.insertDocument(databaseName, collectionName, input);
6767
if (result == false) {
6868
throw new Exception("failed to insert the document into database");
6969
}
70-
updateTestEventCount(true);
7170
}
7271

7372
private String addProprtiesToEvent(String event, RulesObject rulesObject) {
7473
String time = null;
75-
Date date=null;
74+
Date date = null;
7675
String idRule = rulesObject.getIdRule();
7776
JsonNode id = jmesPathInterface.runRuleOnEvent(idRule, event);
78-
String condition = "{Event:" + JSON.parse(event).toString()+"}";
77+
String condition = "{Event:" + JSON.parse(event).toString() + "}";
7978
ArrayList<String> documents = mongoDbHandler.find(databaseName, collectionName, condition);
80-
if (documents.size() == 0){
79+
if (documents.size() == 0) {
8180
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
8281
date = new Date();
8382
time = dateFormat.format(date);
8483
try {
85-
date=dateFormat.parse(time);
84+
date = dateFormat.parse(time);
8685
} catch (ParseException e) {
87-
log.info(e.getMessage(),e);
86+
log.info(e.getMessage(), e);
8887
}
8988

9089
}
9190
BasicDBObject document = new BasicDBObject();
9291
document.put("_id", id.textValue());
93-
document.put("Time", date);
92+
document.put("Time", date);
9493
document.put("Event", JSON.parse(event));
95-
mongoDbHandler.createTTLIndex(databaseName, collectionName, "Time",ttlValue);
94+
mongoDbHandler.createTTLIndex(databaseName, collectionName, "Time", ttlValue);
9695
return document.toString();
9796
}
9897

9998
public ArrayList<String> getWaitList() {
100-
ArrayList<String> documents = mongoDbHandler.getAllDocuments(databaseName,collectionName);
99+
ArrayList<String> documents = mongoDbHandler.getAllDocuments(databaseName, collectionName);
101100
return documents;
102101
}
103102

104103
public boolean dropDocumentFromWaitList(String document) {
105104
boolean result = mongoDbHandler.dropDocument(databaseName, collectionName, document);
106-
107-
if (result) {
108-
updateTestEventCount(false);
109-
}
110-
111105
return result;
112106
}
113-
114-
private void updateTestEventCount(boolean increase) {
115-
if (System.getProperty("flow.test") == "true") {
116-
String countStr = System.getProperty("eiffel.intelligence.waitListEventsCount");
117-
int count = Integer.parseInt(countStr);
118-
if (increase) {
119-
count++;
120-
} else {
121-
count--;
122-
}
123-
System.setProperty("eiffel.intelligence.waitListEventsCount", "" + count);
124-
}
125-
}
126107
}

src/main/java/com/ericsson/ei/waitlist/WaitListWorker.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,51 +39,51 @@
3939
@Component
4040
public class WaitListWorker {
4141

42-
@Autowired
43-
private WaitListStorageHandler waitListStorageHandler;
42+
@Autowired
43+
private WaitListStorageHandler waitListStorageHandler;
4444

45-
@Autowired
46-
private RmqHandler rmqHandler;
45+
@Autowired
46+
private RmqHandler rmqHandler;
4747

48-
@Autowired
49-
private RulesHandler rulesHandler;
48+
@Autowired
49+
private RulesHandler rulesHandler;
5050

51-
@Autowired
52-
private JmesPathInterface jmesPathInterface;
51+
@Autowired
52+
private JmesPathInterface jmesPathInterface;
5353

54-
@Autowired
55-
private MatchIdRulesHandler matchIdRulesHandler;
54+
@Autowired
55+
private MatchIdRulesHandler matchIdRulesHandler;
5656

57-
static Logger log = (Logger) LoggerFactory.getLogger(WaitListWorker.class);
57+
static Logger log = (Logger) LoggerFactory.getLogger(WaitListWorker.class);
5858

59-
@Bean
60-
public TaskScheduler taskScheduler() {
61-
return new ConcurrentTaskScheduler();
62-
}
59+
@Bean
60+
public TaskScheduler taskScheduler() {
61+
return new ConcurrentTaskScheduler();
62+
}
6363

64-
@Scheduled(initialDelayString = "${waitlist.initialDelayResend}", fixedRateString = "${waitlist.fixedRateResend}")
65-
public void run() {
66-
RulesObject rulesObject;
67-
List<String> documents = waitListStorageHandler.getWaitList();
68-
for (String document : documents) {
69-
DBObject dbObject = (DBObject) JSON.parse(document);
70-
String event = dbObject.get("Event").toString();
71-
rulesObject = rulesHandler.getRulesForEvent(event);
72-
String idRule = rulesObject.getIdentifyRules();
64+
@Scheduled(initialDelayString = "${waitlist.initialDelayResend}", fixedRateString = "${waitlist.fixedRateResend}")
65+
public void run() {
66+
RulesObject rulesObject;
67+
List<String> documents = waitListStorageHandler.getWaitList();
68+
for (String document : documents) {
69+
DBObject dbObject = (DBObject) JSON.parse(document);
70+
String event = dbObject.get("Event").toString();
71+
rulesObject = rulesHandler.getRulesForEvent(event);
72+
String idRule = rulesObject.getIdentifyRules();
7373

74-
if (idRule != null && !idRule.isEmpty()) {
75-
JsonNode ids = jmesPathInterface.runRuleOnEvent(idRule, event);
76-
if (ids.isArray()) {
77-
for (final JsonNode idJsonObj : ids) {
78-
Collection<String> objects = matchIdRulesHandler.fetchObjectsById(rulesObject,
79-
idJsonObj.textValue());
80-
if (objects.size() > 0) {
81-
rmqHandler.publishObjectToWaitlistQueue(event);
82-
waitListStorageHandler.dropDocumentFromWaitList(document);
83-
}
84-
}
85-
}
86-
}
87-
}
88-
}
74+
if (idRule != null && !idRule.isEmpty()) {
75+
JsonNode ids = jmesPathInterface.runRuleOnEvent(idRule, event);
76+
if (ids.isArray()) {
77+
for (final JsonNode idJsonObj : ids) {
78+
Collection<String> objects = matchIdRulesHandler.fetchObjectsById(rulesObject,
79+
idJsonObj.textValue());
80+
if (objects.size() > 0) {
81+
rmqHandler.publishObjectToWaitlistQueue(event);
82+
waitListStorageHandler.dropDocumentFromWaitList(document);
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
8989
}

src/main/resources/application.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ server.port: 8090
77

88
rules.path: /ArtifactRules_new.json
99

10-
logging.level.root: INFO
11-
logging.level.org.springframework.web: INFO
12-
logging.level.com.ericsson.ei: INFO
10+
logging.level.root: OFF
11+
logging.level.org.springframework.web: OFF
12+
logging.level.com.ericsson.ei: OFF
1313

1414
rabbitmq.host: localhost
1515
rabbitmq.port: 5672

src/test/java/com/ericsson/ei/flowtests/AMQPBrokerManager.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
package com.ericsson.ei.flowtests;
22

3+
import com.google.common.io.Files;
4+
35
import org.apache.qpid.server.Broker;
46
import org.apache.qpid.server.BrokerOptions;
57

68
public class AMQPBrokerManager {
7-
private static final String PORT = "8672";
9+
810
private final Broker broker = new Broker();
911
private String path;
12+
private int port;
1013

11-
public AMQPBrokerManager(String path) {
14+
public AMQPBrokerManager(String path, int port) {
1215
super();
1316
this.path = path;
17+
this.port = port;
1418
}
1519

1620
public void startBroker() throws Exception {
1721
final BrokerOptions brokerOptions = new BrokerOptions();
18-
brokerOptions.setConfigProperty("qpid.amqp_port", PORT);
22+
brokerOptions.setConfigProperty("qpid.amqp_port", "" + port);
1923
brokerOptions.setConfigProperty("qpid.pass_file", "src/test/resources/configs/password.properties");
24+
brokerOptions.setConfigProperty("qpid.work_dir", Files.createTempDir().getAbsolutePath());
2025
brokerOptions.setInitialConfigurationLocation(path);
2126

2227
broker.startup(brokerOptions);

0 commit comments

Comments
 (0)