Skip to content

Commit 6f65a96

Browse files
committed
Support for mongodb maximum fetch feature (including parameter in order to define the maximum nb of records that can be fetch)
parameter cerberus_testdatalib_fetchmax renamed to cerberus_testdatalib_sql_fetchmax and cerberus_testdatalib_mongodb_fetchmax created.
1 parent ca3c5c6 commit 6f65a96

12 files changed

Lines changed: 57 additions & 31 deletions

File tree

source/src/main/java/org/cerberus/core/crud/entity/Parameter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public class Parameter {
9898
public static final String VALUE_cerberus_gitlab_apitoken = "cerberus_gitlab_apitoken";
9999
public static final String VALUE_cerberus_use_w3c_capabilities = "cerberus_use_w3c_capabilities";
100100

101+
public static final String VALUE_cerberus_testdatalib_sql_fetchmax = "cerberus_testdatalib_sql_fetchmax";
102+
public static final String VALUE_cerberus_testdatalib_mongodb_fetchmax = "cerberus_testdatalib_mongodb_fetchmax";
103+
101104
public static final String VALUE_cerberus_tagcombofilterpersystem_boolean = "cerberus_tagcombofilterpersystem_boolean";
102105

103106
public static final String VALUE_cerberus_automatescore_changehorizon = "cerberus_automatescore_changehorizon";

source/src/main/java/org/cerberus/core/crud/service/impl/ParameterService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ public boolean isSystemManaged(Parameter parameter) {
483483
case "cerberus_proxy_nonproxyhosts":
484484
case "cerberus_proxy_port":
485485
case "cerberus_propertyexternalsql_timeout":
486-
case "cerberus_testdatalib_fetchmax":
486+
case Parameter.VALUE_cerberus_testdatalib_sql_fetchmax:
487+
case Parameter.VALUE_cerberus_testdatalib_mongodb_fetchmax:
487488
case "cerberus_notification_disableenvironment_body":
488489
case "cerberus_notification_disableenvironment_cc":
489490
case "cerberus_notification_disableenvironment_subject":

source/src/main/java/org/cerberus/core/crud/service/impl/TestDataLibService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.commons.fileupload.FileItem;
2525
import org.cerberus.core.crud.dao.ITestCaseCountryPropertiesDAO;
2626
import org.cerberus.core.crud.dao.ITestDataLibDAO;
27+
import org.cerberus.core.crud.entity.Parameter;
2728
import org.cerberus.core.crud.entity.TestCaseExecution;
2829
import org.cerberus.core.engine.entity.MessageEvent;
2930
import org.cerberus.core.engine.entity.MessageGeneral;
@@ -108,7 +109,7 @@ public AnswerList<HashMap<String, String>> readINTERNALWithSubdataByCriteria(Str
108109
List<HashMap<String, String>> result = new ArrayList<>();
109110

110111
// We start by calculating the max nb of row we can fetch. Either specified by rowLimit either defined by a parameter.
111-
int maxSecurityFetch = parameterService.getParameterIntegerByKey("cerberus_testdatalib_fetchmax", system, 100);
112+
int maxSecurityFetch = parameterService.getParameterIntegerByKey(Parameter.VALUE_cerberus_testdatalib_sql_fetchmax, system, 100);
112113
int maxFetch;
113114
if (rowLimit > 0 && rowLimit < maxSecurityFetch) {
114115
maxFetch = rowLimit;

source/src/main/java/org/cerberus/core/database/DocumentationDatabaseService.java

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

source/src/main/java/org/cerberus/core/engine/gwt/impl/ActionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ private MessageEvent doActionCallService(TestCaseStepActionExecution action, Str
18591859
TestCaseExecution execution = action.getTestCaseStepExecution().gettCExecution();
18601860
AnswerItem lastServiceCalledAnswer;
18611861

1862-
lastServiceCalledAnswer = serviceService.callService(value1, value2, value3, null, null, null, null, execution, robotServerService.getFromOptions(action.getOptions(), RobotServerService.OPTIONS_TIMEOUT_SYNTAX));
1862+
lastServiceCalledAnswer = serviceService.callService(value1, value2, value3, null, null, null, null, execution, robotServerService.getFromOptions(action.getOptions(), RobotServerService.OPTIONS_TIMEOUT_SYNTAX), 0);
18631863
message = lastServiceCalledAnswer.getResultMessage();
18641864

18651865
if (lastServiceCalledAnswer.getItem() != null) {

source/src/main/java/org/cerberus/core/service/appservice/IServiceService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ public interface IServiceService {
4747
* @param manualOperation Used when service not defined.
4848
* @param execution
4949
* @param timeoutMs
50+
* @param rowLimit
5051
* @return
5152
*/
52-
AnswerItem<AppService> callService(String service, String targetNbEvents, String targetNbSec, String database, String manualRequest, String manualServicePath, String manualOperation, TestCaseExecution execution, int timeoutMs);
53+
AnswerItem<AppService> callService(String service, String targetNbEvents, String targetNbSec, String database, String manualRequest, String manualServicePath, String manualOperation,
54+
TestCaseExecution execution, int timeoutMs, int rowLimit);
5355

5456
/**
5557
* Simulate a call from outside a normal testcase execution.

source/src/main/java/org/cerberus/core/service/appservice/impl/ServiceService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public class ServiceService implements IServiceService {
114114
private ICountryEnvironmentDatabaseService countryEnvironmentDatabaseService;
115115

116116
@Override
117-
public AnswerItem<AppService> callService(String service, String targetNbEvents, String targetNbSec, String database, String manualRequest, String manualServicePathParam, String manualOperation, TestCaseExecution execution, int timeoutMs) {
117+
public AnswerItem<AppService> callService(String service, String targetNbEvents, String targetNbSec, String database, String manualRequest, String manualServicePathParam, String manualOperation,
118+
TestCaseExecution execution, int timeoutMs, int rowLimit) {
118119
MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);
119120
String decodedRequest;
120121
String decodedRequestExtra1;
@@ -517,7 +518,7 @@ public AnswerItem<AppService> callService(String service, String targetNbEvents,
517518
* Call MONGODB and store it into the execution.
518519
*/
519520
result = mongodbService.callMONGODB(decodedServicePath, decodedRequest, decodedRequestExtra1, appService.getMethod(),
520-
appService.getOperation(), timeoutMs, system, execution);
521+
appService.getOperation(), timeoutMs, system, execution, rowLimit);
521522
message = result.getResultMessage();
522523
message.resolveDescription("SERVICENAME", service);
523524
break;
@@ -892,7 +893,7 @@ public AnswerItem<AppService> callAPI(String service, String country, String env
892893
// We can now start the call with all data prepared.
893894
try {
894895

895-
ans = this.callService(service, kafkaNb, kafkaTime, null, "", "", "", execution, timeout);
896+
ans = this.callService(service, kafkaNb, kafkaTime, null, "", "", "", execution, timeout, 0);
896897

897898
} catch (Exception e) {
898899
LOG.error(e, e);

source/src/main/java/org/cerberus/core/service/datalib/impl/DataLibService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ private AnswerList<HashMap<String, String>> getDataObjectList(TestDataLib lib, i
855855
columnsToHide = getListOfSecrets(lib.getTestDataLibID());
856856

857857
// Service Call is made here.
858-
AnswerItem ai = serviceService.callService(lib.getService(), null, null, lib.getDatabaseUrl(), lib.getEnvelope(), lib.getServicePath(), lib.getMethod(), execution, 0);
858+
AnswerItem ai = serviceService.callService(lib.getService(), null, null, lib.getDatabaseUrl(), lib.getEnvelope(), lib.getServicePath(), lib.getMethod(), execution, 0, rowLimit);
859859

860860
msg = ai.getResultMessage();
861861

source/src/main/java/org/cerberus/core/service/mongodb/IMongodbService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public interface IMongodbService {
4040
* @param timeOutMs
4141
* @param system
4242
* @param tcexecution
43+
* @param rowLimit
4344
* @return
4445
*/
45-
AnswerItem<AppService> callMONGODB(String servicePath, String queryString, String requestExtra1String, String method, String operation, int timeOutMs, String system, TestCaseExecution tcexecution);
46+
AnswerItem<AppService> callMONGODB(String servicePath, String queryString, String requestExtra1String, String method, String operation, int timeOutMs, String system, TestCaseExecution tcexecution, int rowLimit);
4647

4748
}

source/src/main/java/org/cerberus/core/service/mongodb/impl/MongodbService.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.mongodb.client.result.UpdateResult;
3434
import java.sql.Timestamp;
3535
import java.util.Date;
36-
import java.util.Iterator;
3736
import org.apache.logging.log4j.LogManager;
3837
import org.apache.logging.log4j.Logger;
3938
import org.cerberus.core.crud.entity.AppService;
@@ -52,6 +51,7 @@
5251

5352
import static java.util.concurrent.TimeUnit.MILLISECONDS;
5453
import org.bson.Document;
54+
import org.cerberus.core.crud.entity.Parameter;
5555
import org.cerberus.core.service.mongodb.IMongodbService;
5656
import org.cerberus.core.util.StringUtil;
5757
import org.json.JSONArray;
@@ -77,10 +77,11 @@ public class MongodbService implements IMongodbService {
7777
IProxyService proxyService;
7878

7979
private static final Logger LOG = LogManager.getLogger(MongodbService.class);
80+
private static final int MAW_ROW = 10000;
8081

8182
@Override
8283
public AnswerItem<AppService> callMONGODB(String servicePath, String requestString, String requestExtra1String, String method, String operation, int timeOutMs,
83-
String system, TestCaseExecution tcexecution) {
84+
String system, TestCaseExecution tcexecution, int rowLimit) {
8485
MessageEvent message = null;
8586
AnswerItem<AppService> result = new AnswerItem<>();
8687

@@ -165,23 +166,31 @@ public AnswerItem<AppService> callMONGODB(String servicePath, String requestStri
165166
switch (method) {
166167

167168
case AppService.METHOD_MONGODBFIND:
168-
try (
169-
MongoCursor<Document> cursor = collection.find(BasicDBObject.parse(requestString))
170-
.iterator()) {
171-
int i = 0;
172-
while (cursor.hasNext() && i < 5) {
173-
LOG.debug("Results found.");
174-
mongoDBResult = cursor.next().toJson();
175-
i++;
176-
mongoDBResultArray.put(new JSONObject(mongoDBResult));
177-
LOG.debug(mongoDBResult);
169+
170+
int maxSecurityFetch = parameterService.getParameterIntegerByKey(Parameter.VALUE_cerberus_testdatalib_mongodb_fetchmax, system, 10000);
171+
int maxFetch;
172+
if (rowLimit > 0 && rowLimit < maxSecurityFetch) {
173+
maxFetch = rowLimit;
174+
} else {
175+
maxFetch = maxSecurityFetch;
176+
}
177+
178+
try (MongoCursor<Document> cursor = collection.find(BasicDBObject.parse(requestString)).limit(maxFetch)
179+
.iterator()) {
180+
int i = 0;
181+
while (cursor.hasNext() && i < 5) {
182+
LOG.debug("Results found.");
183+
mongoDBResult = cursor.next().toJson();
184+
i++;
185+
mongoDBResultArray.put(new JSONObject(mongoDBResult));
186+
LOG.debug(mongoDBResult);
178187
// System.out.println(cursor.next().toJson());
179-
}
180-
serviceMONGODB.setResponseHTTPBody(mongoDBResultArray.toString());
181-
serviceMONGODB.setResponseNb(i);
182-
serviceMONGODB.setEnd(new Timestamp(new Date().getTime()));
188+
}
189+
serviceMONGODB.setResponseHTTPBody(mongoDBResultArray.toString());
190+
serviceMONGODB.setResponseNb(i);
191+
serviceMONGODB.setEnd(new Timestamp(new Date().getTime()));
183192

184-
}
193+
}
185194
break;
186195

187196
case AppService.METHOD_MONGODBUPDATEONE:
@@ -214,15 +223,15 @@ public AnswerItem<AppService> callMONGODB(String servicePath, String requestStri
214223
result.setResultMessage(message);
215224
serviceMONGODB.setEnd(new Timestamp(new Date().getTime()));
216225
return result;
217-
226+
218227
} catch (MongoSocketOpenException ex) {
219228
LOG.info("Exception when performing the MONGODB Call. " + ex.toString());
220229
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);
221230
message.resolveDescription("DESCRIPTION", ex.toString());
222231
result.setResultMessage(message);
223232
serviceMONGODB.setEnd(new Timestamp(new Date().getTime()));
224233
return result;
225-
234+
226235
} catch (Exception ex) {
227236
LOG.error(ex, ex);
228237
LOG.info("Exception when performing the MONGODB Call. " + ex.toString());

0 commit comments

Comments
 (0)