Skip to content

Commit

Permalink
Added MT test for opaque proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ggeorgovassilis committed Sep 21, 2017
1 parent b4b2e38 commit 159849a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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<Future<Void>> results = new ArrayList<Future<Void>>();
long start = System.currentTimeMillis();
Expand All @@ -83,7 +85,7 @@ public void testMultithreaddedInvocation() throws Exception {

@Override
public Void call() throws Exception {
executeTest();
executeTest(bankService);
return null;
}
});
Expand All @@ -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);
}

}
2 changes: 1 addition & 1 deletion src/test/resources/test-context-bank-jaxrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<context:property-placeholder location="classpath:config.properties" />

<bean id="RemoteBankService"
<bean id="BankService"
class="com.github.ggeorgovassilis.springjsonmapper.jaxrs.JaxRsInvokerProxyFactoryBean">
<property name="baseUrl" value="http://localhost/bankservice" />
<property name="remoteServiceInterfaceClass"
Expand Down
18 changes: 15 additions & 3 deletions src/test/resources/test-context-bank-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

<context:property-placeholder location="classpath:config.properties" />

<bean id="RemoteBankService"
<bean id="BankService"
class="com.github.ggeorgovassilis.springjsonmapper.spring.SpringRestInvokerProxyFactoryBean">
<property name="baseUrl" value="http://localhost/bankservice" />
<property name="remoteServiceInterfaceClass"
value="com.github.ggeorgovassilis.springjsonmapper.services.spring.BankServiceSpring" />
</bean>

<bean id="BankServiceOpaque"
class="com.github.ggeorgovassilis.springjsonmapper.spring.SpringRestInvokerProxyFactoryBean">
<property name="baseUrl" value="http://localhost/bankservice" />
<property name="remoteServiceInterfaceClass" value="com.github.ggeorgovassilis.springjsonmapper.services.spring.BankServiceSpring"/>
<property name="remoteServiceInterfaceClass"
value="com.github.ggeorgovassilis.springjsonmapper.services.spring.BankServiceSpring" />
<property name="proxyFactory">
<bean
class="com.github.ggeorgovassilis.springjsonmapper.utils.CglibProxyFactory"></bean>
</property>
</bean>

</beans>

0 comments on commit 159849a

Please sign in to comment.