From b30de00ea111b548fdc18e3d37f095c16eb13e39 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 8 Jan 2020 09:12:17 -0500 Subject: [PATCH] Add parser stress test --- .../jpa/stresstest/StressTestParserTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java new file mode 100644 index 00000000000..99a9759f409 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java @@ -0,0 +1,54 @@ +package ca.uhn.fhir.jpa.stresstest; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.test.BaseTest; +import ca.uhn.fhir.util.StopWatch; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Bundle; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +public class StressTestParserTest extends BaseTest { + + private static final Logger ourLog = LoggerFactory.getLogger(StressTestParserTest.class); + + @Test + public void test() throws IOException { + FhirContext ctx = FhirContext.forR4(); + String input = loadResource("/org/hl7/fhir/r4/model/valueset/valuesets.xml"); + + String json = ctx.newJsonParser().encodeResourceToString(ctx.newXmlParser().parseResource(input)); + + StopWatch sw = null; + int loops = 100; + + for (int i = 0; i < loops; i++) { + ctx.newXmlParser().parseResource(input); + if (i < 50) { + ourLog.info("Parsed XML {} times", i); + continue; + } else if (i == 50) { + sw = new StopWatch(); + continue; + } + ourLog.info("Parsed XML {} times - {}ms/pass", i, sw.getMillisPerOperation(i - 50)); + } + + for (int i = 0; i < loops; i++) { + Bundle parsed = (Bundle) ctx.newJsonParser().parseResource(json); + if (i < 50) { + ourLog.info("Parsed JSON with {} entries {} times", parsed.getEntry().size(), i); + continue; + } else if (i == 50) { + sw = new StopWatch(); + continue; + } + ourLog.info("Parsed JSON {} times - {}ms/pass", i, sw.getMillisPerOperation(i - 50)); + } + + + } +}