From 9cf65383d7b59e25bcc17a898d790bd95c4e2ce3 Mon Sep 17 00:00:00 2001 From: jcrichlake <145698165+jcrichlake@users.noreply.github.com> Date: Mon, 6 May 2024 15:24:57 -0400 Subject: [PATCH] Stream1/1044/e2e tests (#1061) * Fixing e2e tests * Possible fix for load tests WIP * add received ID to list of linked IDs * Adding other implementation for FilePartnerMetadataStorage * revert ID addition, use IDs where expected * try running e2e against DB? * Revert "try running e2e against DB?" This reverts commit 4b512a2a8def4346e6fb3ac37d9e7dfe3f2dc501. * Load test and e2e test fixes for db and local file * Fixing unit tests --------- Co-authored-by: Sylvie --- .../e2e/ConsolidatedSummaryTest.groovy | 6 +++--- .../partner/PartnerMetadataOrchestrator.java | 7 ++----- .../partner/PartnerMetadataStorage.java | 3 +-- .../DatabasePartnerMetadataStorage.java | 20 ++++++++++++++----- .../localfile/FilePartnerMetadataStorage.java | 3 ++- .../PartnerMetadataOrchestratorTest.groovy | 2 +- .../FilePartnerMetadataStorageTest.groovy | 8 ++++---- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/e2e/ConsolidatedSummaryTest.groovy b/e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/e2e/ConsolidatedSummaryTest.groovy index e758d930f..e8834482d 100644 --- a/e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/e2e/ConsolidatedSummaryTest.groovy +++ b/e2e/src/test/groovy/gov/hhs/cdc/trustedintermediary/e2e/ConsolidatedSummaryTest.groovy @@ -19,7 +19,7 @@ class ConsolidatedSummaryTest extends Specification { def orderClient = new EndpointClient("/v1/etor/orders") def labOrderJsonFileString = Files.readString(Path.of("../examples/Test/e2e/orders/002_ORM_O01.fhir")) - def senderName = "centracare.com" + def senderId = "centracare.com" when: def orderResponse = orderClient.submit(labOrderJsonFileString, inboundSubmissionId, true) @@ -28,12 +28,12 @@ class ConsolidatedSummaryTest extends Specification { orderResponse.getCode() == expectedStatusCode when: - def senderNameResponse = ConsolidatedSummaryClient.get(senderName, true) + def senderNameResponse = ConsolidatedSummaryClient.get(senderId, true) def jsonBody = JsonParser.parseContent(senderNameResponse) then: jsonBody.get((jsonBody.keySet().toArray())[0]).stale != null - jsonBody.get((jsonBody.keySet().toArray())[0]).failureReason == null + jsonBody.get(jsonBody.keySet().toArray()[0]).containsKey("failureReason") jsonBody.get((jsonBody.keySet().toArray())[0]).status != null } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java index e8c034585..80dce9132 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestrator.java @@ -223,11 +223,8 @@ public Map> getConsolidatedMetadata(String senderNam public Set findMessagesIdsToLink(String receivedSubmissionId) throws PartnerMetadataException { - var metadataSet = - partnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId); - return metadataSet.stream() - .map(PartnerMetadata::receivedSubmissionId) - .collect(Collectors.toSet()); + + return partnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId); } public void linkMessages(Set messageIds) throws MessageLinkException { diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java index d7fee8ec0..5137a01f5 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataStorage.java @@ -31,6 +31,5 @@ Optional readMetadata(String receivedSubmissionId) */ Set readMetadataForSender(String sender) throws PartnerMetadataException; - Set readMetadataForMessageLinking(String submissionId) - throws PartnerMetadataException; + Set readMetadataForMessageLinking(String submissionId) throws PartnerMetadataException; } diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java index 0806dd5cc..8daff4f18 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/database/DatabasePartnerMetadataStorage.java @@ -92,7 +92,7 @@ public Set readMetadataForSender(String sender) try { PreparedStatement statement = connection.prepareStatement( - "SELECT * FROM metadata WHERE sender = ?"); + "SELECT * FROM metadata WHERE sending_facility_details->> 'universalId' = ?"); statement.setString(1, sender); return statement; } catch (SQLException e) { @@ -110,10 +110,10 @@ public Set readMetadataForSender(String sender) } @Override - public Set readMetadataForMessageLinking(String submissionId) + public Set readMetadataForMessageLinking(String submissionId) throws PartnerMetadataException { - Set metadataSet; + Set metadataSet; try { metadataSet = dao.fetchManyData( @@ -122,7 +122,7 @@ public Set readMetadataForMessageLinking(String submissionId) PreparedStatement statement = connection.prepareStatement( """ - SELECT m2.* + SELECT m2.received_message_id FROM metadata m1 JOIN metadata m2 ON m1.placer_order_number = m2.placer_order_number @@ -130,6 +130,7 @@ public Set readMetadataForMessageLinking(String submissionId) OR m1.sending_facility_details = m2.receiving_facility_details) AND m1.received_message_id <> m2.received_message_id WHERE m1.received_message_id = ?; + -- LIMIT 50 This is a potential fix for load test failures since they link all the ids together; """); statement.setString(1, submissionId); return statement; @@ -137,7 +138,7 @@ public Set readMetadataForMessageLinking(String submissionId) throw new RuntimeException(e); } }, - this::partnerMetadataFromResultSet, + this::idsFromResult, Collectors.toSet()); return metadataSet; @@ -187,6 +188,15 @@ PartnerMetadata partnerMetadataFromResultSet(ResultSet resultSet) { } } + String idsFromResult(ResultSet resultSet) { + + try { + return resultSet.getString(METADATA_TABLE_RECEIVED_MESSAGE_ID); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + private List createDbColumnsFromMetadata(PartnerMetadata metadata) throws FormatterProcessingException { return List.of( diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java index 0207bee02..641d04e9f 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorage.java @@ -114,7 +114,7 @@ public Set readMetadataForSender(String senderUniversalId) } @Override - public Set readMetadataForMessageLinking(String receivedSubmissionId) + public Set readMetadataForMessageLinking(String receivedSubmissionId) throws PartnerMetadataException { try { Set existingMetadata = getPartnerMetadata(); @@ -146,6 +146,7 @@ public Set readMetadataForMessageLinking(String receivedSubmiss .receivingFacilityDetails())) && !metadata.receivedSubmissionId() .equals(receivedSubmissionId)) + .map(PartnerMetadata::receivedSubmissionId) .collect(Collectors.toSet()); } catch (Exception e) { throw new PartnerMetadataException( diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy index e91377139..dd3af8f84 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/etor/metadata/partner/PartnerMetadataOrchestratorTest.groovy @@ -736,7 +736,7 @@ class PartnerMetadataOrchestratorTest extends Specification { def receivingFacilityDetails = new MessageHdDataType("receiving_facility_name", "receiving_facility_id", "receiving_facility_type") def partnerMetadata1 = new PartnerMetadata(receivedSubmissionId1, "hash1", PartnerMetadataMessageType.ORDER, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) def partnerMetadata2 = new PartnerMetadata(receivedSubmissionId2, "hash2", PartnerMetadataMessageType.RESULT, sendingAppDetails, sendingFacilityDetails, receivingAppDetails, receivingFacilityDetails, placerOrderNumber) - def metadataSetForMessageLinking = Set.of(partnerMetadata1, partnerMetadata2) + def metadataSetForMessageLinking = Set.of(receivedSubmissionId1, receivedSubmissionId2) mockPartnerMetadataStorage.readMetadataForMessageLinking(receivedSubmissionId) >> metadataSetForMessageLinking when: diff --git a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy index e634c865c..ecc94242f 100644 --- a/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy +++ b/etor/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/localfile/FilePartnerMetadataStorageTest.groovy @@ -144,8 +144,8 @@ class FilePartnerMetadataStorageTest extends Specification { def metadataSetWithMatchingSendingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId1) then: - metadataSetWithMatchingSendingFacilityDetails.contains(otherMatchingSendingFacilityDetailsMetadata1) - !metadataSetWithMatchingSendingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata1) + metadataSetWithMatchingSendingFacilityDetails.contains(otherMatchingSendingFacilityDetailsMetadata1.receivedSubmissionId()) + !metadataSetWithMatchingSendingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata1.receivedSubmissionId()) when: def receivedSubmissionId2 = "receivedSubmissionId2" @@ -158,8 +158,8 @@ class FilePartnerMetadataStorageTest extends Specification { def metadataSetWithMatchingSendingAndReceivingFacilityDetails = FilePartnerMetadataStorage.getInstance().readMetadataForMessageLinking(receivedSubmissionId2) then: - metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingReceivingFacilityDetailsMetadata2) - !metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata2) + metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingReceivingFacilityDetailsMetadata2.receivedSubmissionId()) + !metadataSetWithMatchingSendingAndReceivingFacilityDetails.contains(matchingSendingFacilityDetailsMetadata2.receivedSubmissionId()) } def "readMetadataForMessageLinking returns an empty set when no metadata is found"() {