Skip to content

Commit c9c62de

Browse files
Hendrik Leuschneraoles
authored andcommitted
fix: address sonarqube and copilot PR comments
1 parent ab8fc26 commit c9c62de

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

ors-benchmark/src/main/java/org/heigit/ors/benchmark/BenchmarkEnums.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class BenchmarkEnums {
99
public static final String PREFERENCE = "preference";
1010
// Constant for recommended
1111
public static final String RECOMMENDED = "recommended";
12+
public static final String OPTIONS = "options";
13+
1214

1315
public enum TestUnit {
1416
DISTANCE,
@@ -47,8 +49,8 @@ public Map<String, Object> getRequestParams() {
4749
return switch (this) {
4850
case ALGO_CH -> Map.of(PREFERENCE, RECOMMENDED);
4951
case ALGO_CORE -> Map.of(PREFERENCE,
50-
RECOMMENDED, "options", Map.of("avoid_features", List.of("ferries")));
51-
case ALGO_LM_ASTAR -> Map.of(PREFERENCE, RECOMMENDED, "options",
52+
RECOMMENDED, OPTIONS, Map.of("avoid_features", List.of("ferries")));
53+
case ALGO_LM_ASTAR -> Map.of(PREFERENCE, RECOMMENDED, OPTIONS,
5254
Map.of("avoid_polygons",
5355
Map.of("type", "Polygon", "coordinates",
5456
List.of(List.of(List.of(100.0, 100.0), List.of(100.001, 100.0),
@@ -87,7 +89,7 @@ public static MatrixModes fromString(String value) {
8789
case "algodijkstra" -> ALGO_DIJKSTRA_MATRIX;
8890
case "algocore" -> ALGO_CORE_MATRIX;
8991
case "algorphast" -> ALGO_RPHAST_MATRIX;
90-
default -> throw new IllegalArgumentException("Invalid directions mode: " + value);
92+
default -> throw new IllegalArgumentException("Invalid matrix mode: " + value);
9193
};
9294
}
9395

@@ -109,9 +111,9 @@ public Map<String, Object> getRequestParams() {
109111
return switch (this) {
110112
case ALGO_RPHAST_MATRIX -> Map.of(PREFERENCE, RECOMMENDED);
111113
case ALGO_CORE_MATRIX -> Map.of(PREFERENCE,
112-
RECOMMENDED, "options", Map.of("dynamic_speeds", "true"));
114+
RECOMMENDED, OPTIONS, Map.of("dynamic_speeds", "true"));
113115
case ALGO_DIJKSTRA_MATRIX -> Map.of(PREFERENCE,
114-
RECOMMENDED, "options", List.of(Map.of("dynamic_speeds", "false"), Map.of("avoid_features", List.of("ferries"))));
116+
RECOMMENDED, OPTIONS, List.of(Map.of("dynamic_speeds", "false"), Map.of("avoid_features", List.of("ferries"))));
115117

116118
};
117119
}

ors-benchmark/src/main/java/org/heigit/ors/benchmark/MatrixAlgorithmLoadTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected Stream<PopulationBuilder> createScenarios(boolean isParallel) {
9595
private PopulationBuilder createScenarioWithInjection(String sourceFile, boolean isParallel, MatrixModes mode,
9696
String profile) {
9797
String scenarioName = formatScenarioName(mode, profile, isParallel);
98-
return createMatrixScenario(scenarioName, sourceFile, config, mode, profile)
98+
return createMatrixScenario(scenarioName, sourceFile, mode, profile)
9999
.injectOpen(atOnceUsers(config.getNumConcurrentUsers()));
100100
}
101101

@@ -121,7 +121,7 @@ private String formatScenarioName(MatrixModes mode, String profile, boolean isPa
121121
* @param profile routing profile to test
122122
* @return ScenarioBuilder configured for matrix testing
123123
*/
124-
private static ScenarioBuilder createMatrixScenario(String name, String sourceFile, Config config,
124+
private static ScenarioBuilder createMatrixScenario(String name, String sourceFile,
125125
MatrixModes mode, String profile) {
126126
try {
127127
List<Map<String, Object>> records = csv(sourceFile).readRecords();
@@ -135,7 +135,7 @@ private static ScenarioBuilder createMatrixScenario(String name, String sourceFi
135135
return scenario(name)
136136
.feed(targetRecords.iterator(), 1)
137137
.asLongAs(session -> remainingRecords.decrementAndGet() >= 0)
138-
.on(exec(createRequest(name, config, mode, profile)));
138+
.on(exec(createRequest(name, mode, profile)));
139139

140140
} catch (IllegalStateException e) {
141141
logger.error("Error building scenario: ", e);
@@ -148,16 +148,15 @@ private static ScenarioBuilder createMatrixScenario(String name, String sourceFi
148148
* Creates an HTTP request action for the matrix API endpoint.
149149
*
150150
* @param name request name for identification in test results
151-
* @param config test configuration
152151
* @param mode matrix calculation mode
153152
* @param profile routing profile
154153
* @return HttpRequestActionBuilder configured for matrix API calls
155154
*/
156-
private static HttpRequestActionBuilder createRequest(String name, Config config, MatrixModes mode,
155+
private static HttpRequestActionBuilder createRequest(String name, MatrixModes mode,
157156
String profile) {
158157
return http(name)
159158
.post("/v2/matrix/" + profile)
160-
.body(StringBody(session -> createRequestBody(session, config, mode)))
159+
.body(StringBody(session -> createRequestBody(session, mode)))
161160
.asJson()
162161
.check(status().is(200));
163162
}
@@ -166,12 +165,11 @@ private static HttpRequestActionBuilder createRequest(String name, Config config
166165
* Creates the JSON request body for matrix API calls from CSV session data.
167166
*
168167
* @param session Gatling session containing CSV row data
169-
* @param config test configuration
170168
* @param mode matrix calculation mode providing additional parameters
171169
* @return JSON string representation of the request body
172170
* @throws RequestBodyCreationException if JSON serialization fails
173171
*/
174-
static String createRequestBody(Session session, Config config, MatrixModes mode) {
172+
static String createRequestBody(Session session, MatrixModes mode) {
175173
try {
176174
// Get the data from the CSV row
177175
String coordinatesStr = (String) session.get("coordinates");

ors-benchmark/src/test/java/org/heigit/ors/benchmark/MatrixAlgorithmLoadTestTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void setUp() {
4242
@Test
4343
void createRequestBody_ShouldCreateValidJson() throws JsonProcessingException {
4444
// when
45-
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockConfig, mockMode);
45+
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockMode);
4646

4747
// then
4848
JsonNode json = objectMapper.readTree(result);
@@ -55,7 +55,7 @@ void createRequestBody_ShouldCreateValidJson() throws JsonProcessingException {
5555
@Test
5656
void createRequestBody_ShouldIncludeCorrectLocations() throws JsonProcessingException {
5757
// when
58-
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockConfig, mockMode);
58+
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockMode);
5959
JsonNode json = objectMapper.readTree(result);
6060

6161
// then
@@ -72,7 +72,7 @@ void createRequestBody_ShouldIncludeCorrectLocations() throws JsonProcessingExce
7272
@Test
7373
void createRequestBody_ShouldIncludeCorrectSourcesAndDestinations() throws JsonProcessingException {
7474
// when
75-
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockConfig, mockMode);
75+
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockMode);
7676
JsonNode json = objectMapper.readTree(result);
7777

7878
// then
@@ -213,7 +213,7 @@ void createRequestBody_WithDifferentMatrixMode() throws JsonProcessingException
213213
"options", Map.of("avoid_features", Arrays.asList("highways"))));
214214

215215
// when
216-
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockConfig, mockMode);
216+
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockMode);
217217
JsonNode json = objectMapper.readTree(result);
218218

219219
// then
@@ -228,7 +228,7 @@ void createRequestBody_ShouldHandleComplexSourcesAndDestinations() throws JsonPr
228228
when(mockSession.get("destinations")).thenReturn("[4, 5, 6, 7, 8]");
229229

230230
// when
231-
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockConfig, mockMode);
231+
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockMode);
232232
JsonNode json = objectMapper.readTree(result);
233233

234234
// then
@@ -251,7 +251,7 @@ void createRequestBody_ShouldHandleSingleCoordinate() throws JsonProcessingExcep
251251
when(mockSession.get("destinations")).thenReturn("[0]");
252252

253253
// when
254-
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockConfig, mockMode);
254+
String result = MatrixAlgorithmLoadTest.createRequestBody(mockSession, mockMode);
255255
JsonNode json = objectMapper.readTree(result);
256256

257257
// then

0 commit comments

Comments
 (0)