From 517fafbd0a3e3f7a316c363de66a0094fd8a4144 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 20 Jul 2017 10:18:46 -0400 Subject: [PATCH] Add check --- .../uhn/fhir/jpa/config/TestDstu3Config.java | 4 +-- .../jpa/stresstest/StressTestDstu3Test.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java index 0a964f37767..13b3bcaa318 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java @@ -37,11 +37,11 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 { retVal.setUrl("jdbc:derby:memory:myUnitTestDB;create=true"); retVal.setUsername(""); retVal.setPassword(""); - retVal.setMaxTotal(4); + retVal.setMaxTotal((int)(Math.random() * 6) + 1); DataSource dataSource = ProxyDataSourceBuilder .create(retVal) - .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") +// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") .logSlowQueryBySlf4j(10, TimeUnit.SECONDS) .countQuery() .build(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestDstu3Test.java index b3f72096863..059b27b9801 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestDstu3Test.java @@ -42,6 +42,37 @@ public class StressTestDstu3Test extends BaseResourceProviderDstu3Test { ourRestServer.unregisterInterceptor(myRequestValidatingInterceptor); } + + + @Test + public void testMultithreadedSearch() throws Exception { + Bundle input = new Bundle(); + input.setType(BundleType.TRANSACTION); + for (int i = 0; i < 500; i++) { + Patient p = new Patient(); + p.addIdentifier().setSystem("http://test").setValue("BAR"); + input.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); + } + ourClient.transaction().withBundle(input).execute(); + + + List tasks = Lists.newArrayList(); + try { + for (int threadIndex = 0; threadIndex < 10; threadIndex++) { + SearchTask task = new SearchTask(); + tasks.add(task); + task.start(); + } + } finally { + for (BaseTask next : tasks) { + next.join(); + } + } + + validateNoErrors(tasks); + + } + /** * This test prevents a deadlock that was detected with a large number of @@ -89,6 +120,10 @@ public class StressTestDstu3Test extends BaseResourceProviderDstu3Test { } } + validateNoErrors(tasks); + } + + private void validateNoErrors(List tasks) { int total = 0; for (BaseTask next : tasks) { if (next.getError() != null) {