use of org.springframework.tests.sample.beans.SideEffectBean in project spring-framework by spring-projects.
the class ThreadLocalTargetSourceTests method testUseDifferentManagedInstancesInSameThread.
/**
* Check we can use two different ThreadLocalTargetSources
* managing objects of different types without them interfering
* with one another.
*/
@Test
public void testUseDifferentManagedInstancesInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT, apartment.getCount());
apartment.doWork();
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
ITestBean test = (ITestBean) beanFactory.getBean("threadLocal2");
assertEquals("Rod", test.getName());
assertEquals("Kerry", test.getSpouse().getName());
}
use of org.springframework.tests.sample.beans.SideEffectBean in project spring-framework by spring-projects.
the class ThreadLocalTargetSourceTests method testNewThreadHasOwnInstance.
@Test
public void testNewThreadHasOwnInstance() throws InterruptedException {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT, apartment.getCount());
apartment.doWork();
apartment.doWork();
apartment.doWork();
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
class Runner implements Runnable {
public SideEffectBean mine;
@Override
public void run() {
this.mine = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT, mine.getCount());
mine.doWork();
assertEquals(INITIAL_COUNT + 1, mine.getCount());
}
}
Runner r = new Runner();
Thread t = new Thread(r);
t.start();
t.join();
assertNotNull(r);
// Check it didn't affect the other thread's copy
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
// When we use other thread's copy in this thread
// it should behave like ours
assertEquals(INITIAL_COUNT + 3, r.mine.getCount());
// Bound to two threads
assertEquals(2, ((ThreadLocalTargetSourceStats) apartment).getObjectCount());
}
use of org.springframework.tests.sample.beans.SideEffectBean in project spring-framework by spring-projects.
the class HotSwappableTargetSourceTests method testBasicFunctionality.
/**
* Check it works like a normal invoker
*
*/
@Test
public void testBasicFunctionality() {
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
assertEquals(INITIAL_COUNT, proxied.getCount());
proxied.doWork();
assertEquals(INITIAL_COUNT + 1, proxied.getCount());
proxied = (SideEffectBean) beanFactory.getBean("swappable");
proxied.doWork();
assertEquals(INITIAL_COUNT + 2, proxied.getCount());
}
use of org.springframework.tests.sample.beans.SideEffectBean in project spring-framework by spring-projects.
the class ThreadLocalTargetSourceTests method testCanGetStatsViaMixin.
/**
* Relies on introduction.
*/
@Test
public void testCanGetStatsViaMixin() {
ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment");
// +1 because creating target for stats call counts
assertEquals(1, stats.getInvocationCount());
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
apartment.doWork();
// +1 again
assertEquals(3, stats.getInvocationCount());
// + 1 for states call!
assertEquals(3, stats.getHitCount());
apartment.doWork();
assertEquals(6, stats.getInvocationCount());
assertEquals(6, stats.getHitCount());
// Only one thread so only one object can have been bound
assertEquals(1, stats.getObjectCount());
}
use of org.springframework.tests.sample.beans.SideEffectBean in project spring-framework by spring-projects.
the class CommonsPool2TargetSourceTests method testConfigMixin.
@Test
public void testConfigMixin() {
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean("pooledWithMixin");
assertEquals(INITIAL_COUNT, pooled.getCount());
PoolingConfig conf = (PoolingConfig) beanFactory.getBean("pooledWithMixin");
// TODO one invocation from setup
//assertEquals(1, conf.getInvocations());
pooled.doWork();
// assertEquals("No objects active", 0, conf.getActive());
assertEquals("Correct target source", 25, conf.getMaxSize());
// assertTrue("Some free", conf.getFree() > 0);
//assertEquals(2, conf.getInvocations());
assertEquals(25, conf.getMaxSize());
}
Aggregations