Skip to content

Commit 4d61ea3

Browse files
committed
loadtest-controller: throw exception instead of System.exit(1) on errors
1 parent 31552de commit 4d61ea3

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.openvidu.loadtest.exceptions;
2+
3+
public class LoadTestInitializationException extends RuntimeException {
4+
5+
public LoadTestInitializationException(String message) {
6+
super(message);
7+
}
8+
9+
public LoadTestInitializationException(String message, Throwable cause) {
10+
super(message, cause);
11+
}
12+
}

loadtest-controller/src/main/java/io/openvidu/loadtest/monitoring/ElasticSearchClient.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.fasterxml.jackson.databind.JsonNode;
2929

3030
import io.openvidu.loadtest.config.LoadTestConfig;
31+
import io.openvidu.loadtest.exceptions.LoadTestInitializationException;
3132

3233
@Service
3334
public class ElasticSearchClient {
@@ -81,9 +82,11 @@ public void init() {
8182
log.info("Connection to Elasticsearch established at {}", elasticsearchHost);
8283
}
8384
} catch (Exception e) {
84-
log.error("Failed to initialize Elasticsearch client: {}", e.getMessage());
85-
log.error(
86-
"If property 'ELASTICSEARCH_HOST' is defined, then it is mandatory that OpenVidu Load Test is able to connect to it");
85+
throw new LoadTestInitializationException(
86+
"Connection to Elasticsearch failed at " + loadTestConfig.getElasticsearchHost()
87+
+ " (" + e.getMessage()
88+
+ "). If property 'ELASTICSEARCH_HOST' is defined, then it is mandatory that OpenVidu Load Test is able to connect to it",
89+
e);
8790
}
8891
}
8992

@@ -93,11 +96,11 @@ private boolean doPing() {
9396
BooleanResponse response = this.client.ping();
9497
pingSuccess = response.value();
9598
} catch (IOException e) {
96-
log.error("Connection to Elasticsearch failed at {} ({})", loadTestConfig.getElasticsearchHost(),
97-
e.getMessage());
98-
log.error(
99-
"If property 'ELASTICSEARCH_HOST' is defined, then it is mandatory that OpenVidu Load Test is able to connect to it");
100-
System.exit(1);
99+
throw new LoadTestInitializationException(
100+
"Connection to Elasticsearch failed at " + loadTestConfig.getElasticsearchHost()
101+
+ " (" + e.getMessage()
102+
+ "). If property 'ELASTICSEARCH_HOST' is defined, then it is mandatory that OpenVidu Load Test is able to connect to it",
103+
e);
101104
}
102105
return pingSuccess;
103106
}

loadtest-controller/src/main/java/io/openvidu/loadtest/services/Ec2Client.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import software.amazon.awssdk.services.ec2.model.InstanceState;
3737

3838
import io.openvidu.loadtest.config.LoadTestConfig;
39+
import io.openvidu.loadtest.exceptions.LoadTestInitializationException;
3940
import io.openvidu.loadtest.models.testcase.WorkerType;
4041

4142
@Service
@@ -86,9 +87,9 @@ public void init() {
8687
.credentialsProvider(StaticCredentialsProvider.create(awsCreds))
8788
.build();
8889
} else {
89-
log.error("AWS credentials are empty in application.properties");
9090
if (this.loadTestConfig.getWorkerUrlList().isEmpty()) {
91-
System.exit(0);
91+
throw new LoadTestInitializationException(
92+
"No workers or AWS credentials provided. Please provide at least one of them to run the load test");
9293
}
9394
}
9495
}

0 commit comments

Comments
 (0)