@@ -713,7 +713,7 @@ public void testCanReferenceParentBeanFromChildViaAlias() {
713
713
RootBeanDefinition parentDefinition = new RootBeanDefinition (TestBean .class );
714
714
parentDefinition .setAbstract (true );
715
715
parentDefinition .getPropertyValues ().add ("name" , EXPECTED_NAME );
716
- parentDefinition .getPropertyValues ().add ("age" , new Integer ( EXPECTED_AGE ) );
716
+ parentDefinition .getPropertyValues ().add ("age" , EXPECTED_AGE );
717
717
718
718
ChildBeanDefinition childDefinition = new ChildBeanDefinition ("alias" );
719
719
@@ -1201,7 +1201,7 @@ public void testExpressionInStringArray() {
1201
1201
1202
1202
RootBeanDefinition rbd = new RootBeanDefinition (PropertiesFactoryBean .class );
1203
1203
MutablePropertyValues pvs = new MutablePropertyValues ();
1204
- pvs .add ("locations" , new String [] {"#{foo}" });
1204
+ pvs .add ("locations" , new String []{"#{foo}" });
1205
1205
rbd .setPropertyValues (pvs );
1206
1206
bf .registerBeanDefinition ("myProperties" , rbd );
1207
1207
Properties properties = (Properties ) bf .getBean ("myProperties" );
@@ -2264,32 +2264,6 @@ public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() {
2264
2264
assertTrue ("Prototype creation took too long: " + sw .getTotalTimeMillis (), sw .getTotalTimeMillis () < 3000 );
2265
2265
}
2266
2266
2267
- /**
2268
- * @Test
2269
- * public void testPrototypeCreationWithConstructorArgumentsIsFastEnough2() throws Exception {
2270
- * if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
2271
- * // Skip this test: Trace logging blows the time limit.
2272
- * return;
2273
- * }
2274
- * DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
2275
- * Constructor<TestBean> ctor = TestBean.class.getConstructor(String.class, int.class);
2276
- * Method setBeanNameMethod = TestBean.class.getMethod("setBeanName", String.class);
2277
- * Method setBeanFactoryMethod = TestBean.class.getMethod("setBeanFactory", BeanFactory.class);
2278
- * StopWatch sw = new StopWatch();
2279
- * sw.start("prototype");
2280
- * for (int i = 0; i < 100000; i++) {
2281
- * TestBean tb = ctor.newInstance("juergen", 99);
2282
- * setBeanNameMethod.invoke(tb, "test");
2283
- * setBeanFactoryMethod.invoke(tb, lbf);
2284
- * assertEquals("juergen", tb.getName());
2285
- * assertEquals(99, tb.getAge());
2286
- * }
2287
- * sw.stop();
2288
- * // System.out.println(sw.getTotalTimeMillis());
2289
- * assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1500);
2290
- * }
2291
- */
2292
-
2293
2267
@ Test
2294
2268
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough () {
2295
2269
Assume .group (TestGroup .PERFORMANCE );
@@ -2334,31 +2308,6 @@ public void testPrototypeCreationWithPropertiesIsFastEnough() {
2334
2308
assertTrue ("Prototype creation took too long: " + sw .getTotalTimeMillis (), sw .getTotalTimeMillis () < 3000 );
2335
2309
}
2336
2310
2337
- /**
2338
- * public void testPrototypeCreationWithPropertiesIsFastEnough2() throws Exception {
2339
- * if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
2340
- * // Skip this test: Trace logging blows the time limit.
2341
- * return;
2342
- * }
2343
- * DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
2344
- * StopWatch sw = new StopWatch();
2345
- * Method setBeanNameMethod = TestBean.class.getMethod("setBeanName", String.class);
2346
- * Method setBeanFactoryMethod = TestBean.class.getMethod("setBeanFactory", BeanFactory.class);
2347
- * Method setNameMethod = TestBean.class.getMethod("setName", String.class);
2348
- * Method setAgeMethod = TestBean.class.getMethod("setAge", int.class);
2349
- * sw.start("prototype");
2350
- * for (int i = 0; i < 100000; i++) {
2351
- * TestBean tb = TestBean.class.newInstance();
2352
- * setBeanNameMethod.invoke(tb, "test");
2353
- * setBeanFactoryMethod.invoke(tb, lbf);
2354
- * setNameMethod.invoke(tb, "juergen");
2355
- * setAgeMethod.invoke(tb, 99);
2356
- * }
2357
- * sw.stop();
2358
- * // System.out.println(sw.getTotalTimeMillis());
2359
- * assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 750);
2360
- * }
2361
- */
2362
2311
@ Test
2363
2312
public void testPrototypeCreationWithResolvedPropertiesIsFastEnough () {
2364
2313
Assume .group (TestGroup .PERFORMANCE );
@@ -2439,10 +2388,41 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
2439
2388
return bean ;
2440
2389
}
2441
2390
});
2442
- BeanWithDestroyMethod .closed = false ;
2391
+ BeanWithDestroyMethod .closeCount = 0 ;
2392
+ lbf .preInstantiateSingletons ();
2393
+ lbf .destroySingletons ();
2394
+ assertEquals ("Destroy methods invoked" , 1 , BeanWithDestroyMethod .closeCount );
2395
+ }
2396
+
2397
+ @ Test
2398
+ public void testDestroyMethodOnInnerBean () {
2399
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
2400
+ RootBeanDefinition innerBd = new RootBeanDefinition (BeanWithDestroyMethod .class );
2401
+ innerBd .setDestroyMethodName ("close" );
2402
+ RootBeanDefinition bd = new RootBeanDefinition (BeanWithDestroyMethod .class );
2403
+ bd .setDestroyMethodName ("close" );
2404
+ bd .getPropertyValues ().add ("inner" , innerBd );
2405
+ lbf .registerBeanDefinition ("test" , bd );
2406
+ BeanWithDestroyMethod .closeCount = 0 ;
2407
+ lbf .preInstantiateSingletons ();
2408
+ lbf .destroySingletons ();
2409
+ assertEquals ("Destroy methods invoked" , 2 , BeanWithDestroyMethod .closeCount );
2410
+ }
2411
+
2412
+ @ Test
2413
+ public void testDestroyMethodOnInnerBeanAsPrototype () {
2414
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
2415
+ RootBeanDefinition innerBd = new RootBeanDefinition (BeanWithDestroyMethod .class );
2416
+ innerBd .setScope (RootBeanDefinition .SCOPE_PROTOTYPE );
2417
+ innerBd .setDestroyMethodName ("close" );
2418
+ RootBeanDefinition bd = new RootBeanDefinition (BeanWithDestroyMethod .class );
2419
+ bd .setDestroyMethodName ("close" );
2420
+ bd .getPropertyValues ().add ("inner" , innerBd );
2421
+ lbf .registerBeanDefinition ("test" , bd );
2422
+ BeanWithDestroyMethod .closeCount = 0 ;
2443
2423
lbf .preInstantiateSingletons ();
2444
2424
lbf .destroySingletons ();
2445
- assertTrue ("Destroy method invoked" , BeanWithDestroyMethod .closed );
2425
+ assertEquals ("Destroy methods invoked" , 1 , BeanWithDestroyMethod .closeCount );
2446
2426
}
2447
2427
2448
2428
@ Test
@@ -2679,10 +2659,6 @@ public void resolveEmbeddedValue() throws Exception {
2679
2659
verify (r3 , never ()).resolveStringValue (isNull (String .class ));
2680
2660
}
2681
2661
2682
-
2683
- static class A { }
2684
- static class B { }
2685
-
2686
2662
/**
2687
2663
* Test that by-type bean lookup caching is working effectively by searching for a
2688
2664
* bean of type B 10K times within a container having 1K additional beans of type A.
@@ -2693,24 +2669,29 @@ static class B { }
2693
2669
* under the 1000 ms timeout, usually ~= 300ms. With caching removed and on the same
2694
2670
* hardware the method will take ~13000 ms. See SPR-6870.
2695
2671
*/
2696
- @ Test (timeout = 1000 )
2672
+ @ Test (timeout = 1000 )
2697
2673
public void testByTypeLookupIsFastEnough () {
2698
2674
Assume .group (TestGroup .PERFORMANCE );
2699
2675
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
2700
2676
2701
2677
for (int i = 0 ; i < 1000 ; i ++) {
2702
- bf .registerBeanDefinition ("a" + i , new RootBeanDefinition (A .class ));
2678
+ bf .registerBeanDefinition ("a" + i , new RootBeanDefinition (A .class ));
2703
2679
}
2704
2680
bf .registerBeanDefinition ("b" , new RootBeanDefinition (B .class ));
2705
2681
2706
2682
bf .freezeConfiguration ();
2707
2683
2708
- for (int i = 0 ; i < 10000 ; i ++) {
2684
+ for (int i = 0 ; i < 10000 ; i ++) {
2709
2685
bf .getBean (B .class );
2710
2686
}
2711
2687
}
2712
2688
2713
2689
2690
+ static class A { }
2691
+
2692
+ static class B { }
2693
+
2694
+
2714
2695
public static class NoDependencies {
2715
2696
2716
2697
private NoDependencies () {
@@ -2816,10 +2797,16 @@ public void close() {
2816
2797
2817
2798
public static class BeanWithDestroyMethod {
2818
2799
2819
- private static boolean closed ;
2800
+ private static int closeCount = 0 ;
2801
+
2802
+ private BeanWithDestroyMethod inner ;
2803
+
2804
+ public void setInner (BeanWithDestroyMethod inner ) {
2805
+ this .inner = inner ;
2806
+ }
2820
2807
2821
2808
public void close () {
2822
- closed = true ;
2809
+ closeCount ++ ;
2823
2810
}
2824
2811
}
2825
2812
@@ -2981,7 +2968,6 @@ private static class FactoryBeanDependentBean {
2981
2968
2982
2969
private FactoryBean <?> factoryBean ;
2983
2970
2984
-
2985
2971
public final FactoryBean <?> getFactoryBean () {
2986
2972
return this .factoryBean ;
2987
2973
}
0 commit comments