summaryrefslogtreecommitdiffstats
path: root/vid-ext-services-simulator/src/main/java
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-11-13 17:06:13 +0200
committerIttay Stern <ittay.stern@att.com>2019-11-13 17:08:14 +0200
commit894532bfbf6c6a304e90d2ad89f430ce4c50646a (patch)
tree0f26a48e992a89b4024e3498726233abe7ac4c59 /vid-ext-services-simulator/src/main/java
parenta0c5b4a55c6ea58ecf2ebc2ccbc801558989b856 (diff)
Retry Simulator's DB queries upon failure
In tests env, sometimes DB drops unused connections with error: java.sql.SQLNonTransientConnectionException: (conn=3439) Connection reset Issue-ID: VID-647 Change-Id: If8211db653d4b3b3efc4edbe8b3ad6d3dd7d65e2 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-ext-services-simulator/src/main/java')
-rw-r--r--vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java15
1 files changed, 13 insertions, 2 deletions
diff --git a/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java b/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java
index b6cc6759f..296d9fcbf 100644
--- a/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java
+++ b/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java
@@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.PostConstruct;
@@ -253,7 +254,7 @@ public class SimulatorController {
String userName = reqUri.substring(reqUri.lastIndexOf('/') + 1);
TypedQuery<User> userQuery = entityManager.createQuery("select u from fn_user u where u.loginId = :userName", User.class);
userQuery.setParameter("userName", userName);
- User user = userQuery.getSingleResult();
+ User user = doWithSingleRetry(userQuery::getSingleResult);
Gson g = new Gson();
String jsonString = g.toJson(user);
@@ -269,7 +270,7 @@ public class SimulatorController {
return new ResponseEntity<>("Centralized Role Access is disabled", HttpStatus.SERVICE_UNAVAILABLE);
}
TypedQuery<Function> userQuery = entityManager.createQuery("select f from fn_function f", Function.class);
- List<Function> functions = userQuery.getResultList();
+ List<Function> functions = doWithSingleRetry(userQuery::getResultList);
Gson g = new Gson();
String jsonString = g.toJson(functions);
@@ -341,6 +342,16 @@ public class SimulatorController {
return responseEntity;
}
+ private <T> T doWithSingleRetry(Supplier<T> supplier) {
+ try {
+ return supplier.get();
+ } catch (Exception e) {
+ logger.error("exception was thrown; will retry the same action one more time", e);
+ // here exceptions will be thrown
+ return supplier.get();
+ }
+ }
+
private void register(SimulatorRequestResponseExpectation expectationModel) throws VidSimulatorException{
//Setting request according to what is passed
HttpRequest request = HttpRequest.request();