use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class ExposeBeanNameAdvisorsTests method testWithIntroduction.
@Test
public void testWithIntroduction() {
String beanName = "foo";
TestBean target = new RequiresBeanNameBoundTestBean(beanName);
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorIntroducingNamedBean(beanName));
ITestBean proxy = (ITestBean) pf.getProxy();
boolean condition = proxy instanceof NamedBean;
assertThat(condition).as("Introduction was made").isTrue();
// Requires binding
proxy.getAge();
NamedBean nb = (NamedBean) proxy;
assertThat(nb.getBeanName()).as("Name returned correctly").isEqualTo(beanName);
}
use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class ConcurrencyThrottleInterceptorTests method testSerializable.
@Test
public void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean.class);
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
ITestBean serializedProxy = SerializationTestUtils.serializeAndDeserialize(proxy);
Advised advised = (Advised) serializedProxy;
ConcurrencyThrottleInterceptor serializedCti = (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
assertThat(serializedCti.getConcurrencyLimit()).isEqualTo(cti.getConcurrencyLimit());
serializedProxy.getAge();
}
use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class ConcurrencyThrottleInterceptorTests method testMultipleThreads.
private void testMultipleThreads(int concurrencyLimit) {
TestBean tb = new TestBean();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean.class);
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
cti.setConcurrencyLimit(concurrencyLimit);
proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
Thread[] threads = new Thread[NR_OF_THREADS];
for (int i = 0; i < NR_OF_THREADS; i++) {
threads[i] = new ConcurrencyThread(proxy, null);
threads[i].start();
}
for (int i = 0; i < NR_OF_THREADS / 10; i++) {
try {
Thread.sleep(5);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
threads[i] = new ConcurrencyThread(proxy, i % 2 == 0 ? new OutOfMemoryError() : new IllegalStateException());
threads[i].start();
}
for (int i = 0; i < NR_OF_THREADS; i++) {
try {
threads[i].join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class ClassUtilsTests method getShortNameForCglibClass.
@Test
void getShortNameForCglibClass() {
TestBean tb = new TestBean();
ProxyFactory pf = new ProxyFactory();
pf.setTarget(tb);
pf.setProxyTargetClass(true);
TestBean proxy = (TestBean) pf.getProxy();
String className = ClassUtils.getShortName(proxy.getClass());
assertThat(className).as("Class name did not match").isEqualTo("TestBean");
}
use of cn.taketoday.aop.framework.ProxyFactory in project today-infrastructure by TAKETODAY.
the class NameMatchMethodPointcutTests method setup.
/**
* Create an empty pointcut, populating instance variables.
*/
@BeforeEach
public void setup() {
ProxyFactory pf = new ProxyFactory(new SerializablePerson());
nop = new SerializableNopInterceptor();
pc = new NameMatchMethodPointcut();
pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
proxied = (Person) pf.getProxy();
}
Aggregations