Skip to content

Commit adb6f5d

Browse files
Making unit and functional test fast (#303)
* change to one mongo and mb in tests * removing logging level for passing intravis
1 parent 3bb2e9d commit adb6f5d

File tree

70 files changed

+1070
-1084
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1070
-1084
lines changed

pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<springLdapVersion>2.3.2.RELEASE</springLdapVersion>
3030
<springSecurityVersion>5.0.6.RELEASE</springSecurityVersion>
3131
<springSessionVersion>2.0.2.RELEASE</springSessionVersion>
32-
<forkCountTests>2C</forkCountTests>
32+
<forkCountTests>1</forkCountTests>
3333
</properties>
3434

3535
<!-- Reporting Plugins -->
@@ -477,12 +477,12 @@
477477
<plugin>
478478
<groupId>org.apache.maven.plugins</groupId>
479479
<artifactId>maven-surefire-plugin</artifactId>
480-
<version>2.22.0</version>
480+
<version>2.22.2</version>
481481
<configuration>
482482
<skipTests>${skipUTs}</skipTests>
483483
<forkCountTests>${forkCountTests}</forkCountTests>
484484
<forkCount>${forkCountTests}</forkCount>
485-
<reuseForks>false</reuseForks>
485+
<reuseForks>true</reuseForks>
486486
<excludes>
487487
<exclude>**/*IT.java</exclude>
488488
<exclude>${someModule.test.excludes}</exclude>
@@ -491,6 +491,8 @@
491491
<includes>
492492
<include>${someModule.test.includes}</include>
493493
</includes>
494+
<parallel>classes</parallel>
495+
<threadCount>5</threadCount>
494496
</configuration>
495497
</plugin>
496498

src/functionaltests/java/com/ericsson/ei/files/DownloadFilesTestSteps.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.ericsson.ei.files;
22

3+
import static org.junit.Assert.assertEquals;
4+
35
import java.io.File;
6+
47
import org.apache.commons.io.FileUtils;
5-
import static org.junit.Assert.assertEquals;
68
import org.junit.Ignore;
79
import org.slf4j.Logger;
810
import org.slf4j.LoggerFactory;
@@ -11,6 +13,7 @@
1113
import org.springframework.http.HttpStatus;
1214
import org.springframework.http.MediaType;
1315
import org.springframework.http.ResponseEntity;
16+
import org.springframework.test.context.TestPropertySource;
1417

1518
import com.ericsson.ei.utils.FunctionalTestBase;
1619
import com.ericsson.ei.utils.HttpRequest;
@@ -23,6 +26,9 @@
2326
import cucumber.api.java.en.Then;
2427

2528
@Ignore
29+
@TestPropertySource(properties = { "spring.data.mongodb.database: DownloadFilesTestSteps",
30+
"rabbitmq.exchange.name: DownloadFilesTestSteps-exchange",
31+
"rabbitmq.consumerName: rabbitmq.consumerName: DownloadFilesTestStepsConsumer" })
2632
@AutoConfigureMockMvc
2733
public class DownloadFilesTestSteps extends FunctionalTestBase {
2834

@@ -40,14 +46,13 @@ public class DownloadFilesTestSteps extends FunctionalTestBase {
4046
private int applicationPort;
4147
private String hostName = getHostName();
4248

43-
4449
@Given("^Eiffel Intelligence instance is up and running$")
4550
public void eiffel_intelligence_instance_is_up_and_running() throws Exception {
4651
LOGGER.debug("Checking if Eiffel Intelligence instance is up and running.");
4752
httpRequest.setHost(hostName)
48-
.setPort(applicationPort)
49-
.addHeader("Content-type:", MediaType.APPLICATION_JSON_VALUE.toString())
50-
.setEndpoint("/subscriptions");
53+
.setPort(applicationPort)
54+
.addHeader("Content-type:", MediaType.APPLICATION_JSON_VALUE.toString())
55+
.setEndpoint("/subscriptions");
5156

5257
response = httpRequest.performRequest();
5358
assertEquals(response.getStatusCode(), HttpStatus.OK);
@@ -56,7 +61,7 @@ public void eiffel_intelligence_instance_is_up_and_running() throws Exception {
5661
@Then("^List available files$")
5762
public void list_available_files() throws Exception {
5863
LOGGER.debug("Listing all availble files that can be download via RestApi.");
59-
String expectedSubscriptionsValue = "/download/subscriptionsTemplate";
64+
String expectedSubscriptionsValue = "/download/subscriptionsTemplate";
6065

6166
httpRequest.setEndpoint("/download");
6267
response = httpRequest.performRequest();
@@ -71,17 +76,19 @@ public void list_available_files() throws Exception {
7176

7277
@And("^Get subscription template file$")
7378
public void get_subscription_template_file() throws Exception {
74-
String expectedSubscriptionTemplateContent = FileUtils.readFileToString(new File(SUBSCRIPTIONS_TEMPLATE_FILEPATH), "UTF-8");
79+
String expectedSubscriptionTemplateContent = FileUtils.readFileToString(
80+
new File(SUBSCRIPTIONS_TEMPLATE_FILEPATH), "UTF-8");
7581

7682
httpRequest.setEndpoint("/download/subscriptionsTemplate");
7783
response = httpRequest.performRequest();
7884

7985
assertEquals(HttpStatus.OK, response.getStatusCode());
8086

8187
String actualSubscriptionTemplateContent = response.getBody();
82-
assertEquals("Get SubscriptionTemplate file failed or contents is not as expected. \nExpected: "
83-
+ expectedSubscriptionTemplateContent + "\nActual: "+ actualSubscriptionTemplateContent,
84-
expectedSubscriptionTemplateContent, actualSubscriptionTemplateContent);
88+
assertEquals(
89+
"Get SubscriptionTemplate file failed or contents is not as expected. \nExpected: "
90+
+ expectedSubscriptionTemplateContent + "\nActual: " + actualSubscriptionTemplateContent,
91+
expectedSubscriptionTemplateContent, actualSubscriptionTemplateContent);
8592
}
8693

8794
@And("^Get rules template file$")
@@ -94,9 +101,10 @@ public void get_rules_template_file() throws Exception {
94101
assertEquals(HttpStatus.OK, response.getStatusCode());
95102

96103
String actualRulesTemplateContent = response.getBody();
97-
assertEquals("Get RulesTemplate file failed or contents is not as expected. \nExpected: "
98-
+ expectedRulesTemplateContent + "\nActual: "+ actualRulesTemplateContent,
99-
expectedRulesTemplateContent, actualRulesTemplateContent);
104+
assertEquals(
105+
"Get RulesTemplate file failed or contents is not as expected. \nExpected: "
106+
+ expectedRulesTemplateContent + "\nActual: " + actualRulesTemplateContent,
107+
expectedRulesTemplateContent, actualRulesTemplateContent);
100108
}
101109

102110
@And("^Get event template file$")
@@ -109,8 +117,9 @@ public void get_event_template_file() throws Exception {
109117
assertEquals(HttpStatus.OK, response.getStatusCode());
110118

111119
String actualEventsTemplateContent = response.getBody();
112-
assertEquals("Get EventsTemplate file failed or contents is not as expected. \nExpected: "
113-
+ expectedEventsTemplateContent + "\nActual: "+ actualEventsTemplateContent,
114-
expectedEventsTemplateContent, actualEventsTemplateContent);
120+
assertEquals(
121+
"Get EventsTemplate file failed or contents is not as expected. \nExpected: "
122+
+ expectedEventsTemplateContent + "\nActual: " + actualEventsTemplateContent,
123+
expectedEventsTemplateContent, actualEventsTemplateContent);
115124
}
116125
}

src/functionaltests/java/com/ericsson/ei/notifications/ttl/TestTTLSteps.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.IOException;
88
import java.util.ArrayList;
99
import java.util.List;
10+
import java.util.concurrent.TimeUnit;
1011

1112
import org.apache.commons.io.FileUtils;
1213
import org.json.JSONArray;
@@ -21,7 +22,6 @@
2122
import org.springframework.beans.factory.annotation.Autowired;
2223
import org.springframework.beans.factory.annotation.Value;
2324
import org.springframework.boot.web.server.LocalServerPort;
24-
import org.springframework.test.context.ContextConfiguration;
2525
import org.springframework.test.context.TestPropertySource;
2626
import org.springframework.util.SocketUtils;
2727

@@ -31,7 +31,6 @@
3131
import com.ericsson.ei.utils.FunctionalTestBase;
3232
import com.ericsson.ei.utils.HttpRequest;
3333
import com.ericsson.ei.utils.HttpRequest.HttpMethod;
34-
import com.ericsson.ei.utils.TestContextInitializer;
3534
import com.fasterxml.jackson.databind.JsonNode;
3635
import com.fasterxml.jackson.databind.ObjectMapper;
3736

@@ -43,8 +42,10 @@
4342

4443
@Ignore
4544
@TestPropertySource(properties = { "notification.ttl.value:1", "aggregated.collection.ttlValue:1",
46-
"notification.failAttempt:1" })
47-
@ContextConfiguration(initializers = TestContextInitializer.class)
45+
"notification.failAttempt:1", "spring.data.mongodb.database: TestTTLSteps",
46+
"rabbitmq.exchange.name: TestTTLSteps-exchange",
47+
"rabbitmq.consumerName: TestTTLStepsConsumer",
48+
"missedNotificationDataBaseName: TestTTLStepsMissedNotification" })
4849
public class TestTTLSteps extends FunctionalTestBase {
4950
private static final Logger LOGGER = LoggerFactory.getLogger(TestTTLSteps.class);
5051
private static final String BASE_URL = "localhost";
@@ -63,7 +64,7 @@ public class TestTTLSteps extends FunctionalTestBase {
6364
private static final String SUBSCRIPTION_FILE_PATH_CREATION = "src/functionaltests/resources/subscription_single_ttlTest.json";
6465
private static final String EIFFEL_EVENTS_JSON_PATH = "src/functionaltests/resources/eiffel_events_for_test.json";
6566

66-
private static final long MAX_WAIT_TIME = 65000;
67+
private static final long MAX_WAIT_TIME = 120000;
6768

6869
private static JsonNode subscriptionObject;
6970

@@ -147,9 +148,12 @@ public void a_subscription_is_created_at_the_end_point_with_non_existent_notific
147148
String readFileToString = FileUtils.readFileToString(new File(SUBSCRIPTION_FILE_PATH_CREATION), "UTF-8");
148149
JSONArray jsonArr = new JSONArray(readFileToString);
149150
httpRequest = new HttpRequest(HttpMethod.POST);
150-
httpRequest.setHost(hostName).setPort(applicationPort).setEndpoint(endPoint)
151-
.addHeader("content-type", "application/json").addHeader("Accept", "application/json")
152-
.setBody(jsonArr.toString());
151+
httpRequest.setHost(hostName)
152+
.setPort(applicationPort)
153+
.setEndpoint(endPoint)
154+
.addHeader("content-type", "application/json")
155+
.addHeader("Accept", "application/json")
156+
.setBody(jsonArr.toString());
153157
httpRequest.performRequest();
154158
}
155159

@@ -158,8 +162,8 @@ public void eiffel_events_are_sent() throws Throwable {
158162
LOGGER.debug("Sending an Eiffel event");
159163
List<String> eventNamesToSend = getEventNamesToSend();
160164
eventManager.sendEiffelEvents(EIFFEL_EVENTS_JSON_PATH, eventNamesToSend);
161-
List<String> missingEventIds = dbManager
162-
.verifyEventsInDB(eventManager.getEventsIdList(EIFFEL_EVENTS_JSON_PATH, eventNamesToSend));
165+
List<String> missingEventIds = dbManager.verifyEventsInDB(
166+
eventManager.getEventsIdList(EIFFEL_EVENTS_JSON_PATH, eventNamesToSend), 0);
163167
assertEquals("The following events are missing in mongoDB: " + missingEventIds.toString(), 0,
164168
missingEventIds.size());
165169
LOGGER.debug("Eiffel event is sent");
@@ -196,15 +200,17 @@ public void the_Notification_document_should_be_deleted_from_the_database() thro
196200

197201
@Then("^Aggregated Object document should be deleted from the database$")
198202
public void the_Aggregated_Object_document_should_be_deleted_from_the_database() throws Throwable {
199-
LOGGER.debug("Checking delition of aggregated object in db");
203+
LOGGER.debug("Checking deletion of aggregated object in db");
200204
List<String> allObjects = null;
205+
// To be sure at least one minute has passed since creation of aggregated object
206+
TimeUnit.MINUTES.sleep(1);
201207
allObjects = mongoDBHandler.getAllDocuments(dataBase, collection);
202208
assertEquals("Database is not empty.", true, allObjects.isEmpty());
203209
}
204210

205211
/**
206-
* Setting up mock server to receive calls on one endpoint and respond with
207-
* 500 to trigger retries of POST request
212+
* Setting up mock server to receive calls on one endpoint and respond with 500
213+
* to trigger retries of POST request
208214
*/
209215
private void setUpMockServer() {
210216
int port = SocketUtils.findAvailableTcpPort();
@@ -214,7 +220,7 @@ private void setUpMockServer() {
214220

215221
// set up expectations on mock server to get calls on this endpoint
216222
mockServerClient.when(request().withMethod("POST").withPath(ENDPOINT))
217-
.respond(HttpResponse.response().withStatusCode(500));
223+
.respond(HttpResponse.response().withStatusCode(500));
218224
}
219225

220226
/**
@@ -231,7 +237,8 @@ private int getNotificationForExpectedSize(int expectedSize, String condition) {
231237
List<String> notificationExist = null;
232238

233239
while (System.currentTimeMillis() < maxTime) {
234-
notificationExist = mongoDBHandler.find(missedNotificationDatabase, missedNotificationCollection, condition);
240+
notificationExist = mongoDBHandler.find(missedNotificationDatabase, missedNotificationCollection,
241+
condition);
235242

236243
if (notificationExist.size() == expectedSize) {
237244
return notificationExist.size();

0 commit comments

Comments
 (0)