Skip to content

Commit b642d01

Browse files
author
taochen
committed
modify refreshableDatasource test
1 parent c954e4b commit b642d01

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/RefreshableDataSourceTest.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.ctrip.platform.dal.dao.configure.DataSourceConfigure;
44
import com.ctrip.platform.dal.dao.configure.DataSourceConfigureChangeEvent;
5+
import com.ctrip.platform.dal.dao.helper.ConnectionHelper;
56
import com.ctrip.platform.dal.dao.helper.CustomThreadFactory;
67
import com.mysql.jdbc.MySQLConnection;
78
import org.junit.Assert;
@@ -20,7 +21,7 @@ public class RefreshableDataSourceTest {
2021
private ExecutorService executor = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.SECONDS,
2122
new LinkedBlockingQueue<Runnable>(), new CustomThreadFactory("RefreshableDataSourceTest"));
2223

23-
private ExecutorService executorOne = new ThreadPoolExecutor(10, 120, 60L, TimeUnit.SECONDS,
24+
private ExecutorService executorOne = new ThreadPoolExecutor(100, 100, 60L, TimeUnit.SECONDS,
2425
new LinkedBlockingQueue<Runnable>(), new CustomThreadFactory("RefreshableDataSourceTest1"));
2526

2627
@Test
@@ -458,18 +459,22 @@ public void testGetConnection() throws Exception {
458459
refreshableDataSource.addDataSourceSwitchListener(listenerOne);
459460
refreshableDataSource.addDataSourceSwitchListener(listenerTwo);
460461

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) {
463464
final int time = i;
464465
executorOne.submit(new Runnable() {
465466
@Override
466467
public void run() {
467468
try {
468469
Thread.sleep(10);
469470
long startTime = System.currentTimeMillis();
470-
refreshableDataSource.getConnection();
471+
Connection connection = refreshableDataSource.getConnection();
471472
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+
}
473478
} catch (Exception e) {
474479

475480
}
@@ -478,8 +483,8 @@ public void run() {
478483
});
479484
}
480485
refreshableDataSource.configChanged(dataSourceConfigureChangeEvent1);
481-
Thread.sleep(10);
482-
refreshableDataSource.configChanged(dataSourceConfigureChangeEvent2);
486+
// Thread.sleep(10);
487+
// refreshableDataSource.configChanged(dataSourceConfigureChangeEvent2);
483488
latch.await();
484489
}
485490
}

0 commit comments

Comments
 (0)