From 3aebff0ab9b6f10377b7bbdbaa907551c2b37898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=93=81?= Date: Sun, 27 Mar 2016 15:36:53 +0800 Subject: [PATCH] fixed fixed for large datasource test in small memory --- .../druid/bvt/pool/Large10ConcurrentTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/alibaba/druid/bvt/pool/Large10ConcurrentTest.java b/src/test/java/com/alibaba/druid/bvt/pool/Large10ConcurrentTest.java index ec62a12a7f..50db9322ae 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/Large10ConcurrentTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/Large10ConcurrentTest.java @@ -1,5 +1,6 @@ package com.alibaba.druid.bvt.pool; +import java.lang.management.ManagementFactory; import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.CountDownLatch; @@ -19,12 +20,25 @@ import com.alibaba.druid.util.JdbcUtils; public class Large10ConcurrentTest extends TestCase { - private DruidDataSource[] dataSources = new DruidDataSource[10000]; + private DruidDataSource[] dataSources; private ScheduledExecutorService scheduler; private ExecutorService executor; protected void setUp() throws Exception { + long xmx = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() / (1000 * 1000); // m + + final int dataSourceCount; + if (xmx <= 500) { + dataSourceCount = 500; + } else if (xmx <= 1000) { + dataSourceCount = 1000; + } else { + dataSourceCount = 10000; + } + + dataSources = new DruidDataSource[10000]; + executor = Executors.newFixedThreadPool(100); scheduler = Executors.newScheduledThreadPool(10); for (int i = 0; i < dataSources.length; ++i) {