Package org.springframework.aop.interceptor

Examples of org.springframework.aop.interceptor.SideEffectBean


   * Test that multiple invocations of the prototype bean will result
   * in no change to visible state, as a new instance is used.
   * With the singleton, there will be change.
   */
  public void testPrototypeAndSingletonBehaveDifferently() {
    SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
    assertEquals(INITIAL_COUNT, singleton.getCount() );
    singleton.doWork();
    assertEquals(INITIAL_COUNT + 1, singleton.getCount() );
   
    SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
    assertEquals(INITIAL_COUNT, prototype.getCount() );
    prototype.doWork();
    assertEquals(INITIAL_COUNT, prototype.getCount() );
  }
View Full Code Here


   * Check we can use two different ThreadLocalTargetSources
   * managing objects of different types without them interfering
   * with one another.
   */
  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());
  }
View Full Code Here

    assertEquals("Rod", test.getName());
    assertEquals("Kerry", test.getSpouse().getName());
  }

  public void testReuseInSameThread() {
    SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
    assertEquals(INITIAL_COUNT, apartment.getCount() );
    apartment.doWork();
    assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
   
    apartment = (SideEffectBean) beanFactory.getBean("apartment");
    assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
  }
View Full Code Here

   */
  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());
  }
View Full Code Here

    // Only one thread so only one object can have been bound
    assertEquals(1, stats.getObjectCount());
  }
 
  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;
      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() );
   
View Full Code Here

  /**
   * Check it works like a normal invoker
   *
   */
  public void testBasicFunctionality() {
    SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
    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() );
  }
View Full Code Here

    proxied.doWork();
    assertEquals(INITIAL_COUNT + 2, proxied.getCount() );
  }
 
  public void testValidSwaps() {
    SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
    SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
   
    SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
  //  assertEquals(target1, ((Advised) proxied).getTarget());
    assertEquals(target1.getCount(), proxied.getCount() );
    proxied.doWork();
    assertEquals(INITIAL_COUNT + 1, proxied.getCount() );
 
    HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
    Object old = swapper.swap(target2);
    assertEquals("Correct old target was returned", target1, old);
   
    // TODO should be able to make this assertion: need to fix target handling
    // in AdvisedSupport
    //assertEquals(target2, ((Advised) proxied).getTarget());
   
    assertEquals(20, proxied.getCount());
    proxied.doWork();
    assertEquals(21, target2.getCount());
   
    // Swap it back
    swapper.swap(target1);
    assertEquals(target1.getCount(), proxied.getCount());
  }
View Full Code Here

    // Will call pool.close()
    this.beanFactory.destroySingletons();
  }

  private void testFunctionality(String name) {
    SideEffectBean pooled = (SideEffectBean) beanFactory.getBean(name);
    assertEquals(INITIAL_COUNT, pooled.getCount());
    pooled.doWork();
    assertEquals(INITIAL_COUNT + 1, pooled.getCount());

    pooled = (SideEffectBean) beanFactory.getBean(name);
    // Just check that it works--we can't make assumptions
    // about the count
    pooled.doWork();
    //assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
  }
View Full Code Here

  public void testFunctionalityWithNoInterceptors() {
    testFunctionality("pooledNoInterceptors");
  }

  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());
View Full Code Here

    int INITIAL_COUNT = 10;
   
    BeanFactory bf = new XmlBeanFactory(new ClassPathResource("prototypeTests.xml", getClass()));
   
    // Check it works without AOP
    SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget");
    assertEquals(INITIAL_COUNT, raw.getCount() );
    raw.doWork();
    assertEquals(INITIAL_COUNT+1, raw.getCount() );
    raw = (SideEffectBean) bf.getBean("prototypeTarget");
    assertEquals(INITIAL_COUNT, raw.getCount() );
   
    // Now try with advised instances
    SideEffectBean prototype2FirstInstance = (SideEffectBean) bf.getBean(beanName);
    assertEquals(INITIAL_COUNT, prototype2FirstInstance.getCount() );
    prototype2FirstInstance.doWork();
    assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount() );

    SideEffectBean prototype2SecondInstance = (SideEffectBean) bf.getBean(beanName);
    assertFalse("Prototypes are not ==", prototype2FirstInstance == prototype2SecondInstance);
    assertEquals(INITIAL_COUNT, prototype2SecondInstance.getCount() );
    assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount() );
   
    return prototype2FirstInstance;
  }
View Full Code Here

TOP

Related Classes of org.springframework.aop.interceptor.SideEffectBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.