From 159849a88581ddf7584a6a8c830e9d6ff0664003 Mon Sep 17 00:00:00 2001 From: george georgovassilis Date: Thu, 21 Sep 2017 15:18:31 +0200 Subject: [PATCH] Added MT test for opaque proxy --- .../utils/CglibProxyFactory.java | 6 ++--- .../tests/AbstractBankServiceTest.java | 4 +-- .../tests/MultiThreaddedTest.java | 26 ++++++++++++++----- .../resources/test-context-bank-jaxrs.xml | 2 +- .../resources/test-context-bank-spring.xml | 18 ++++++++++--- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/github/ggeorgovassilis/springjsonmapper/utils/CglibProxyFactory.java b/src/main/java/com/github/ggeorgovassilis/springjsonmapper/utils/CglibProxyFactory.java index 6207d22..f24c2e8 100644 --- a/src/main/java/com/github/ggeorgovassilis/springjsonmapper/utils/CglibProxyFactory.java +++ b/src/main/java/com/github/ggeorgovassilis/springjsonmapper/utils/CglibProxyFactory.java @@ -13,14 +13,14 @@ */ public class CglibProxyFactory implements ProxyFactory { - protected Class baseClass; + protected Class baseClass = Object.class; protected ClassLoader classLoader; @Override public Object createProxy(ClassLoader classLoader, final Class[] interfaces, final InvocationHandler callback) { Enhancer enhancer = new Enhancer(); - enhancer.setSuperclass(Object.class); + enhancer.setSuperclass(baseClass); if (classLoader == null) classLoader = Thread.currentThread().getContextClassLoader(); enhancer.setClassLoader(classLoader); @@ -32,8 +32,6 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl } }); enhancer.setInterfaces(interfaces); - if (baseClass!=null) - enhancer.setSuperclass(baseClass); return enhancer.create(); } diff --git a/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/AbstractBankServiceTest.java b/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/AbstractBankServiceTest.java index 011b893..058a692 100644 --- a/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/AbstractBankServiceTest.java +++ b/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/AbstractBankServiceTest.java @@ -36,10 +36,10 @@ @RunWith(value = SpringJUnit4ClassRunner.class) public abstract class AbstractBankServiceTest { - @Autowired + @Resource(name="BankService") protected BankService bankService; - @Resource(name = "&RemoteBankService") + @Resource(name = "&BankService") protected BaseRestInvokerProxyFactoryBean httpProxyFactory; protected MockRequestFactory requestFactory; diff --git a/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/MultiThreaddedTest.java b/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/MultiThreaddedTest.java index 8282e90..7871f26 100644 --- a/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/MultiThreaddedTest.java +++ b/src/test/java/com/github/ggeorgovassilis/springjsonmapper/tests/MultiThreaddedTest.java @@ -41,10 +41,13 @@ public class MultiThreaddedTest { final long TEST_DURATION_MS = 3000; final int THREADS = 4; - @Autowired + @Resource(name="BankService") protected BankService bankService; - @Resource(name = "&RemoteBankService") + @Resource(name="BankServiceOpaque") + protected BankService bankServiceOpaque; + + @Resource(name = "&BankService") protected BaseRestInvokerProxyFactoryBean httpProxyFactory; protected MockRequestFactory requestFactory; @@ -57,7 +60,7 @@ public void setup() { requestFactory.createResponse(); } - void executeTest() throws Exception { + void executeTest(BankService bankService) throws Exception { // setup test Customer customer1 = customer("Customer 1"); @@ -72,9 +75,8 @@ void executeTest() throws Exception { // verify results assertTrue(result); } - - @Test - public void testMultithreaddedInvocation() throws Exception { + + void runMultiThreaddedTest(BankService service) throws Exception{ ExecutorService executorService = Executors.newFixedThreadPool(THREADS); List> results = new ArrayList>(); long start = System.currentTimeMillis(); @@ -83,7 +85,7 @@ public void testMultithreaddedInvocation() throws Exception { @Override public Void call() throws Exception { - executeTest(); + executeTest(bankService); return null; } }); @@ -98,4 +100,14 @@ public Void call() throws Exception { executorService.shutdown(); } + @Test + public void testMultithreaddedInvocation() throws Exception { + runMultiThreaddedTest(bankService); + } + + @Test + public void testMultithreaddedInvocationOnOpaqueService() throws Exception { + runMultiThreaddedTest(bankServiceOpaque); + } + } diff --git a/src/test/resources/test-context-bank-jaxrs.xml b/src/test/resources/test-context-bank-jaxrs.xml index 5418f3a..5366d0a 100644 --- a/src/test/resources/test-context-bank-jaxrs.xml +++ b/src/test/resources/test-context-bank-jaxrs.xml @@ -11,7 +11,7 @@ - - + - + + + + + - + + + +