@@ -2440,6 +2440,7 @@ public void testPrototypeCreationIsFastEnough() {
2440
2440
RootBeanDefinition rbd = new RootBeanDefinition (TestBean .class );
2441
2441
rbd .setScope (RootBeanDefinition .SCOPE_PROTOTYPE );
2442
2442
lbf .registerBeanDefinition ("test" , rbd );
2443
+ lbf .freezeConfiguration ();
2443
2444
StopWatch sw = new StopWatch ();
2444
2445
sw .start ("prototype" );
2445
2446
for (int i = 0 ; i < 100000 ; i ++) {
@@ -2460,6 +2461,7 @@ public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
2460
2461
rbd .setDependencyCheck (RootBeanDefinition .DEPENDENCY_CHECK_OBJECTS );
2461
2462
lbf .registerBeanDefinition ("test" , rbd );
2462
2463
lbf .addBeanPostProcessor (new LifecycleBean .PostProcessor ());
2464
+ lbf .freezeConfiguration ();
2463
2465
StopWatch sw = new StopWatch ();
2464
2466
sw .start ("prototype" );
2465
2467
for (int i = 0 ; i < 100000 ; i ++) {
@@ -2470,29 +2472,6 @@ public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
2470
2472
assertTrue ("Prototype creation took too long: " + sw .getTotalTimeMillis (), sw .getTotalTimeMillis () < 3000 );
2471
2473
}
2472
2474
2473
- /**
2474
- * @Test
2475
- * public void testPrototypeCreationIsFastEnough2() {
2476
- * if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
2477
- * // Skip this test: Trace logging blows the time limit.
2478
- * return;
2479
- * }
2480
- * DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
2481
- * Method setBeanNameMethod = TestBean.class.getMethod("setBeanName", String.class);
2482
- * Method setBeanFactoryMethod = TestBean.class.getMethod("setBeanFactory", BeanFactory.class);
2483
- * StopWatch sw = new StopWatch();
2484
- * sw.start("prototype");
2485
- * for (int i = 0; i < 100000; i++) {
2486
- * TestBean tb = TestBean.class.newInstance();
2487
- * setBeanNameMethod.invoke(tb, "test");
2488
- * setBeanFactoryMethod.invoke(tb, lbf);
2489
- * }
2490
- * sw.stop();
2491
- * // System.out.println(sw.getTotalTimeMillis());
2492
- * assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
2493
- * }
2494
- */
2495
-
2496
2475
@ Test
2497
2476
@ Ignore // TODO re-enable when ConstructorResolver TODO sorted out
2498
2477
public void testPrototypeCreationWithConstructorArgumentsIsFastEnough () {
@@ -2504,6 +2483,7 @@ public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() {
2504
2483
rbd .getConstructorArgumentValues ().addGenericArgumentValue ("juergen" );
2505
2484
rbd .getConstructorArgumentValues ().addGenericArgumentValue ("99" );
2506
2485
lbf .registerBeanDefinition ("test" , rbd );
2486
+ lbf .freezeConfiguration ();
2507
2487
StopWatch sw = new StopWatch ();
2508
2488
sw .start ("prototype" );
2509
2489
for (int i = 0 ; i < 100000 ; i ++) {
@@ -2526,6 +2506,7 @@ public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough()
2526
2506
rbd .getConstructorArgumentValues ().addGenericArgumentValue (new RuntimeBeanReference ("spouse" ));
2527
2507
lbf .registerBeanDefinition ("test" , rbd );
2528
2508
lbf .registerBeanDefinition ("spouse" , new RootBeanDefinition (TestBean .class ));
2509
+ lbf .freezeConfiguration ();
2529
2510
TestBean spouse = (TestBean ) lbf .getBean ("spouse" );
2530
2511
StopWatch sw = new StopWatch ();
2531
2512
sw .start ("prototype" );
@@ -2548,6 +2529,7 @@ public void testPrototypeCreationWithPropertiesIsFastEnough() {
2548
2529
rbd .getPropertyValues ().add ("name" , "juergen" );
2549
2530
rbd .getPropertyValues ().add ("age" , "99" );
2550
2531
lbf .registerBeanDefinition ("test" , rbd );
2532
+ lbf .freezeConfiguration ();
2551
2533
StopWatch sw = new StopWatch ();
2552
2534
sw .start ("prototype" );
2553
2535
for (int i = 0 ; i < 100000 ; i ++) {
@@ -2570,6 +2552,7 @@ public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() {
2570
2552
rbd .getPropertyValues ().add ("spouse" , new RuntimeBeanReference ("spouse" ));
2571
2553
lbf .registerBeanDefinition ("test" , rbd );
2572
2554
lbf .registerBeanDefinition ("spouse" , new RootBeanDefinition (TestBean .class ));
2555
+ lbf .freezeConfiguration ();
2573
2556
TestBean spouse = (TestBean ) lbf .getBean ("spouse" );
2574
2557
StopWatch sw = new StopWatch ();
2575
2558
sw .start ("prototype" );
@@ -2582,6 +2565,40 @@ public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() {
2582
2565
assertTrue ("Prototype creation took too long: " + sw .getTotalTimeMillis (), sw .getTotalTimeMillis () < 4000 );
2583
2566
}
2584
2567
2568
+ @ Test
2569
+ public void testSingletonLookupByNameIsFastEnough () {
2570
+ // Assume.group(TestGroup.PERFORMANCE);
2571
+ Assume .notLogging (factoryLog );
2572
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
2573
+ lbf .registerBeanDefinition ("test" , new RootBeanDefinition (TestBean .class ));
2574
+ lbf .freezeConfiguration ();
2575
+ StopWatch sw = new StopWatch ();
2576
+ sw .start ("singleton" );
2577
+ for (int i = 0 ; i < 1000000 ; i ++) {
2578
+ lbf .getBean ("test" );
2579
+ }
2580
+ sw .stop ();
2581
+ // System.out.println(sw.getTotalTimeMillis());
2582
+ assertTrue ("Singleton lookup took too long: " + sw .getTotalTimeMillis (), sw .getTotalTimeMillis () < 1000 );
2583
+ }
2584
+
2585
+ @ Test
2586
+ public void testSingletonLookupByTypeIsFastEnough () {
2587
+ // Assume.group(TestGroup.PERFORMANCE);
2588
+ Assume .notLogging (factoryLog );
2589
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
2590
+ lbf .registerBeanDefinition ("test" , new RootBeanDefinition (TestBean .class ));
2591
+ lbf .freezeConfiguration ();
2592
+ StopWatch sw = new StopWatch ();
2593
+ sw .start ("singleton" );
2594
+ for (int i = 0 ; i < 1000000 ; i ++) {
2595
+ lbf .getBean (TestBean .class );
2596
+ }
2597
+ sw .stop ();
2598
+ // System.out.println(sw.getTotalTimeMillis());
2599
+ assertTrue ("Singleton lookup took too long: " + sw .getTotalTimeMillis (), sw .getTotalTimeMillis () < 1000 );
2600
+ }
2601
+
2585
2602
@ Test
2586
2603
public void testBeanPostProcessorWithWrappedObjectAndDisposableBean () {
2587
2604
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
0 commit comments