2
2
3
3
import com .ctrip .platform .dal .dao .configure .DataSourceConfigure ;
4
4
import com .ctrip .platform .dal .dao .configure .DataSourceConfigureChangeEvent ;
5
+ import com .ctrip .platform .dal .dao .helper .ConnectionHelper ;
5
6
import com .ctrip .platform .dal .dao .helper .CustomThreadFactory ;
6
7
import com .mysql .jdbc .MySQLConnection ;
7
8
import org .junit .Assert ;
@@ -20,7 +21,7 @@ public class RefreshableDataSourceTest {
20
21
private ExecutorService executor = new ThreadPoolExecutor (1 , 1 , 60L , TimeUnit .SECONDS ,
21
22
new LinkedBlockingQueue <Runnable >(), new CustomThreadFactory ("RefreshableDataSourceTest" ));
22
23
23
- private ExecutorService executorOne = new ThreadPoolExecutor (10 , 120 , 60L , TimeUnit .SECONDS ,
24
+ private ExecutorService executorOne = new ThreadPoolExecutor (100 , 100 , 60L , TimeUnit .SECONDS ,
24
25
new LinkedBlockingQueue <Runnable >(), new CustomThreadFactory ("RefreshableDataSourceTest1" ));
25
26
26
27
@ Test
@@ -458,18 +459,22 @@ public void testGetConnection() throws Exception {
458
459
refreshableDataSource .addDataSourceSwitchListener (listenerOne );
459
460
refreshableDataSource .addDataSourceSwitchListener (listenerTwo );
460
461
461
- final CountDownLatch latch = new CountDownLatch (50 );
462
- for (int i = 0 ; i < 50 ; ++i ) {
462
+ final CountDownLatch latch = new CountDownLatch (100 );
463
+ for (int i = 0 ; i < 100 ; ++i ) {
463
464
final int time = i ;
464
465
executorOne .submit (new Runnable () {
465
466
@ Override
466
467
public void run () {
467
468
try {
468
469
Thread .sleep (10 );
469
470
long startTime = System .currentTimeMillis ();
470
- refreshableDataSource .getConnection ();
471
+ Connection connection = refreshableDataSource .getConnection ();
471
472
long endTime = System .currentTimeMillis ();
472
- System .out .println (endTime - startTime );
473
+ System .out .println (startTime + ":" + (endTime - startTime ));
474
+ if ("jdbc:mysql://10.32.20.139:3306/llj_test" .equalsIgnoreCase (ConnectionHelper .obtainUrl (connection ))) {
475
+ Assert .assertEquals (listenerOne .getStep (), 10 );
476
+ Assert .assertEquals (listenerTwo .getStep (), 20 );
477
+ }
473
478
} catch (Exception e ) {
474
479
475
480
}
@@ -478,8 +483,8 @@ public void run() {
478
483
});
479
484
}
480
485
refreshableDataSource .configChanged (dataSourceConfigureChangeEvent1 );
481
- Thread .sleep (10 );
482
- refreshableDataSource .configChanged (dataSourceConfigureChangeEvent2 );
486
+ // Thread.sleep(10);
487
+ // refreshableDataSource.configChanged(dataSourceConfigureChangeEvent2);
483
488
latch .await ();
484
489
}
485
490
}
0 commit comments