Skip to content

Commit

Permalink
initial version: include failed tests in history
Browse files Browse the repository at this point in the history
  • Loading branch information
cproof committed Jul 22, 2024
1 parent 54e3205 commit 36ba63a
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/java/at/rtr/rmbt/mapper/TestHistoryMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

public interface TestHistoryMapper {

HistoryItemResponse testHistoryToHistoryItemResponse(TestHistory testHistory, Integer classificationCount, Locale locale);
HistoryItemResponse testHistoryToHistoryItemResponse(TestHistory testHistory, Integer classificationCount, Locale locale, boolean includeFailedTests);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Service
public class TestHistoryMapperImpl implements TestHistoryMapper {
@Override
public HistoryItemResponse testHistoryToHistoryItemResponse(TestHistory testHistory, Integer classificationCount, Locale locale) {
public HistoryItemResponse testHistoryToHistoryItemResponse(TestHistory testHistory, Integer classificationCount, Locale locale, boolean includeFailedTests) {
HistoryItemResponse.HistoryItemResponseBuilder historyItemResponseBuilder = HistoryItemResponse.builder()
.testUUID(testHistory.getUuid())
.openTestUuid(testHistory.getOpenTestUuid() != null ? "O" + testHistory.getOpenTestUuid() : null)
Expand All @@ -36,6 +36,9 @@ public HistoryItemResponse testHistoryToHistoryItemResponse(TestHistory testHist
.speedDownloadClassification(ClassificationUtils.classify(ClassificationUtils.THRESHOLD_DOWNLOAD, ObjectUtils.defaultIfNull(testHistory.getSpeedDownload(), NumberUtils.INTEGER_ZERO), classificationCount))
.pingClassification(ClassificationUtils.classify(ClassificationUtils.THRESHOLD_PING, ObjectUtils.defaultIfNull(testHistory.getPingMedian(), NumberUtils.LONG_ZERO), classificationCount))
.pingShortestClassification(ClassificationUtils.classify(ClassificationUtils.THRESHOLD_PING, ObjectUtils.defaultIfNull(testHistory.getPingMedian(), NumberUtils.LONG_ZERO), classificationCount));
if (includeFailedTests) {
historyItemResponseBuilder.status(testHistory.getStatus().toLowerCase());
}
setSignalFields(testHistory, historyItemResponseBuilder, classificationCount);
return historyItemResponseBuilder.build();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/at/rtr/rmbt/model/TestHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ public class TestHistory {

@Column(name = "model")
private String model;

@Column(name = "status")
private String status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ List<TestHistory> getTestHistoryByDevicesAndNetworksAndClient(
Integer resultOffset,
List<String> devices,
List<String> networks,
RtrClient client
RtrClient client,
boolean includeFailedTests
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,32 @@ public class TestHistoryRepositoryImpl implements TestHistoryRepository {

private final JdbcTemplate jdbcTemplate;
private final static String GET_TEST_HISTORY = "SELECT DISTINCT"
+ " t.uuid, t.open_test_uuid, time, timezone, speed_upload, speed_download, ping_median, lte_rsrp, signal_strength, dual_sim, sim_count, network_type, nt.group_name network_type_group_name, l.loop_uuid loop_uuid,"
+ " t.status, t.uuid, t.open_test_uuid, time, timezone, speed_upload, speed_download, ping_median, lte_rsrp, signal_strength, dual_sim, sim_count, network_type, nt.group_name network_type_group_name, l.loop_uuid loop_uuid,"
+ " COALESCE(adm.fullname, t.model) model"
+ " FROM test t"
+ " LEFT JOIN device_map adm ON adm.codename=t.model"
+ " LEFT JOIN network_type nt ON t.network_type=nt.uid"
+ " LEFT JOIN test_loopmode l ON (l.test_uuid = t.uuid)"
+ " WHERE t.deleted = false AND t.implausible = false AND t.status = 'FINISHED'"
+ " %s %s %s" + " ORDER BY time DESC" + " %s";
+ " WHERE t.deleted = false AND t.implausible = false "
+ " %s %s %s %s" + " ORDER BY time DESC" + " %s";

@Override
public List<TestHistory> getTestHistoryByDevicesAndNetworksAndClient(Integer resultLimit, Integer resultOffset, List<String> devices, List<String> networks, RtrClient client) {
public List<TestHistory> getTestHistoryByDevicesAndNetworksAndClient(Integer resultLimit, Integer resultOffset, List<String> devices, List<String> networks, RtrClient client, boolean includeFailedTests) {
ArrayList<Object> args = new ArrayList<>();
String testStatusRequest = " AND t.status IN (%s)";
args.add("FINISHED");
if (includeFailedTests) {
args.add("ERROR");
testStatusRequest = String.format(testStatusRequest, "?, ?");
}
else {
testStatusRequest = String.format(testStatusRequest, "?");
}
String limitRequest = getLimitRequest(resultLimit, resultOffset);
String devicesRequest = getDevicesRequest(devices, args);
String networksRequest = getNetworksRequest(networks, args);
String clientSyncRequest = getClientSyncRequest(client, args);
String finalQuery = String.format(GET_TEST_HISTORY, clientSyncRequest, devicesRequest, networksRequest, limitRequest);
String finalQuery = String.format(GET_TEST_HISTORY, testStatusRequest, clientSyncRequest, devicesRequest, networksRequest, limitRequest);
return jdbcTemplate.query(finalQuery, new ArgumentPreparedStatementSetter(args.toArray()), new BeanPropertyRowMapper<>(TestHistory.class));
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/at/rtr/rmbt/request/HistoryRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public class HistoryRequest {
@JsonProperty(value = "networks")
private final List<String> networks;

@Schema(description = "Include also failed tests")
@JsonProperty(value="include_failed_tests", defaultValue = "false")
private final boolean includeFailedTests;

@Schema(description = "Capabilities")
@JsonProperty(value = "capabilities")
private final CapabilitiesRequest capabilities;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/at/rtr/rmbt/response/HistoryItemResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ public class HistoryItemResponse {
@Schema(description = "Signal classification of test")
@JsonProperty(value = "signal_classification")
private final Integer signalClassification;

@JsonProperty(value = "status")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String status;
}
4 changes: 2 additions & 2 deletions src/main/java/at/rtr/rmbt/service/impl/TestServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public HistoryResponse getHistory(HistoryRequest historyRequest) {
.map(CapabilitiesRequest::getClassification)
.map(ClassificationRequest::getCount)
.orElse(0);
List<HistoryItemResponse> historyItemResponses = testHistoryRepository.getTestHistoryByDevicesAndNetworksAndClient(historyRequest.getResultLimit(), historyRequest.getResultOffset(), historyRequest.getDevices(), historyRequest.getNetworks(), client).stream()
.map(testHistory -> testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, count, locale))
List<HistoryItemResponse> historyItemResponses = testHistoryRepository.getTestHistoryByDevicesAndNetworksAndClient(historyRequest.getResultLimit(), historyRequest.getResultOffset(), historyRequest.getDevices(), historyRequest.getNetworks(), client, historyRequest.isIncludeFailedTests()).stream()
.map(testHistory -> testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, count, locale, historyRequest.isIncludeFailedTests()))
.collect(Collectors.toList());
return HistoryResponse.builder()
.history(historyItemResponses)
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/at/rtr/rmbt/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ public interface TestConstants {
String DEFAULT_FORMATTED_PING = "58";
String DEFAULT_FORMATTED_PING_SHORTEST = "58";
String DEFAULT_HISTORY_RESPONSE_ITEM_LOOP_UUID = "L2458713e-9362-11eb-a8b3-0242ac130003";
String DEFAULT_TEST_HISTORY_FINAL_QUERY = "SELECT DISTINCT t.uuid, t.open_test_uuid, time, timezone, speed_upload, speed_download, ping_median, lte_rsrp, signal_strength, dual_sim, sim_count, network_type, nt.group_name network_type_group_name, l.loop_uuid loop_uuid, COALESCE(adm.fullname, t.model) model FROM test t LEFT JOIN device_map adm ON adm.codename=t.model LEFT JOIN network_type nt ON t.network_type=nt.uid LEFT JOIN test_loopmode l ON (l.test_uuid = t.uuid) WHERE t.deleted = false AND t.implausible = false AND t.status = 'FINISHED' AND client_id = ? AND (COALESCE(adm.fullname, t.model) IN (?)) AND nt.group_name IN (?) ORDER BY time DESC LIMIT 1 OFFSET 2";
String DEFAULT_TEST_HISTORY_FINAL_QUERY_CLIENT_SYNCED = "SELECT DISTINCT t.uuid, t.open_test_uuid, time, timezone, speed_upload, speed_download, ping_median, lte_rsrp, signal_strength, dual_sim, sim_count, network_type, nt.group_name network_type_group_name, l.loop_uuid loop_uuid, COALESCE(adm.fullname, t.model) model FROM test t LEFT JOIN device_map adm ON adm.codename=t.model LEFT JOIN network_type nt ON t.network_type=nt.uid LEFT JOIN test_loopmode l ON (l.test_uuid = t.uuid) WHERE t.deleted = false AND t.implausible = false AND t.status = 'FINISHED' AND (t.client_id IN (SELECT 2 UNION SELECT uid FROM client WHERE sync_group_id = 5 )) AND (COALESCE(adm.fullname, t.model) IN ('DEFAULT_DEVICE')) AND nt.group_name IN ('2G (GSM)') ORDER BY time DESC LIMIT 1 OFFSET 2";
String DEFAULT_TEST_HISTORY_FINAL_QUERY = "SELECT DISTINCT t.uuid, t.open_test_uuid, time, timezone, speed_upload, speed_download, ping_median, lte_rsrp, signal_strength, dual_sim, sim_count, network_type, nt.group_name network_type_group_name, l.loop_uuid loop_uuid, COALESCE(adm.fullname, t.model) model FROM test t LEFT JOIN device_map adm ON adm.codename=t.model LEFT JOIN network_type nt ON t.network_type=nt.uid LEFT JOIN test_loopmode l ON (l.test_uuid = t.uuid) WHERE t.deleted = false AND t.implausible = false AND t.status IN (?) AND client_id = ? AND (COALESCE(adm.fullname, t.model) IN (?)) AND nt.group_name IN (?) ORDER BY time DESC LIMIT 1 OFFSET 2";
String DEFAULT_TEST_HISTORY_FINAL_QUERY_CLIENT_SYNCED = "SELECT DISTINCT t.uuid, t.open_test_uuid, time, timezone, speed_upload, speed_download, ping_median, lte_rsrp, signal_strength, dual_sim, sim_count, network_type, nt.group_name network_type_group_name, l.loop_uuid loop_uuid, COALESCE(adm.fullname, t.model) model FROM test t LEFT JOIN device_map adm ON adm.codename=t.model LEFT JOIN network_type nt ON t.network_type=nt.uid LEFT JOIN test_loopmode l ON (l.test_uuid = t.uuid) WHERE t.deleted = false AND t.implausible = false AND t.status IN (?) AND (t.client_id IN (SELECT ? UNION SELECT uid FROM client WHERE sync_group_id = ? )) AND (COALESCE(adm.fullname, t.model) IN (?)) AND nt.group_name IN (?) ORDER BY time DESC LIMIT 1 OFFSET 2";
Integer DEFAULT_CLIENT_SYNC_GROUP_ID = 5;
MeasurementType DEFAULT_MEASUREMENT_TYPE_FLAG = MeasurementType.REGULAR;
String DEFAULT_SYNC_CODE = "DEFAULT_SYNC_CODE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testHistoryToHistoryItemResponse_whenSignalStrengthNotNull_expectHis
.signalStrength(TestConstants.DEFAULT_SIGNAL_STRENGTH_FIRST)
.signalClassification(TestConstants.DEFAULT_TEST_RESULT_MEASUREMENT_RESPONSE_SIGNAL_STRENGTH_CLASSIFICATION)
.build();
var response = testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, TestConstants.DEFAULT_CLASSIFICATION_COUNT, Locale.ENGLISH);
var response = testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, TestConstants.DEFAULT_CLASSIFICATION_COUNT, Locale.ENGLISH, false);

assertEquals(expectedHistoryItemResponse, response);
}
Expand All @@ -72,7 +72,7 @@ public void testHistoryToHistoryItemResponse_whenLteRSPRNotNull_expectHistoryIte
.lteRSRP(TestConstants.DEFAULT_LTE_RSRP_FIRST)
.signalClassification(TestConstants.DEFAULT_TEST_RESULT_MEASUREMENT_RESPONSE_CLASSIFICATION)
.build();
var response = testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, TestConstants.DEFAULT_CLASSIFICATION_COUNT, Locale.ENGLISH);
var response = testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, TestConstants.DEFAULT_CLASSIFICATION_COUNT, Locale.ENGLISH, false);

assertEquals(expectedHistoryItemResponse, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public void getTestHistoryByDevicesAndNetworksAndClient_whenClientIsNotSynced_ex
TestConstants.DEFAULT_RESULT_LIMIT,
TestConstants.DEFAULT_RESULT_OFFSET,
List.of(TestConstants.DEFAULT_DEVICE),
List.of(TestConstants.DEFAULT_NETWORK_NAME + "\') OR ('1'='1 "),
client
List.of(TestConstants.DEFAULT_NETWORK_NAME),
client,
false
);

verify(jdbcTemplate).query(queryArgumentCaptor.capture(), any(ArgumentPreparedStatementSetter.class), any(BeanPropertyRowMapper.class));
Expand All @@ -62,10 +63,11 @@ public void getTestHistoryByDevicesAndNetworksAndClient_whenClientIsSynced_expec
TestConstants.DEFAULT_RESULT_OFFSET,
List.of(TestConstants.DEFAULT_DEVICE),
List.of(TestConstants.DEFAULT_NETWORK_NAME),
client
client,
false
);

verify(jdbcTemplate).query(queryArgumentCaptor.capture(), any(BeanPropertyRowMapper.class));
verify(jdbcTemplate).query(queryArgumentCaptor.capture(), any(ArgumentPreparedStatementSetter.class), any(BeanPropertyRowMapper.class));
assertEquals(TestConstants.DEFAULT_TEST_HISTORY_FINAL_QUERY_CLIENT_SYNCED, queryArgumentCaptor.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,10 @@ public void getHistory_whenCommonData_expectHistoryResponse() {
TestConstants.DEFAULT_RESULT_OFFSET,
List.of(TestConstants.DEFAULT_DEVICE),
List.of(TestConstants.DEFAULT_NETWORK_NAME),
client))
client,
false))
.thenReturn(List.of(testHistory));
when(testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, TestConstants.DEFAULT_CLASSIFICATION_COUNT, Locale.ENGLISH)).thenReturn(historyItemResponse);
when(testHistoryMapper.testHistoryToHistoryItemResponse(testHistory, TestConstants.DEFAULT_CLASSIFICATION_COUNT, Locale.ENGLISH, false)).thenReturn(historyItemResponse);

var response = testService.getHistory(historyRequest);
assertEquals(List.of(historyItemResponse), response.getHistory());
Expand Down

0 comments on commit 36ba63a

Please sign in to comment.