Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
43c91a62
提交
43c91a62
authored
15 年前
作者:
Sergi Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added workaround for Windows problem with frequent socket connections.
上级
cb63bf48
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
150 行增加
和
6 行删除
+150
-6
NetUtils.java
h2/src/main/org/h2/util/NetUtils.java
+14
-6
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
TestNetUtils.java
h2/src/test/org/h2/test/unit/TestNetUtils.java
+134
-0
没有找到文件。
h2/src/main/org/h2/util/NetUtils.java
浏览文件 @
43c91a62
...
...
@@ -102,6 +102,8 @@ public class NetUtils {
* @return the socket
*/
public
static
Socket
createSocket
(
InetAddress
address
,
int
port
,
boolean
ssl
)
throws
IOException
{
for
(;;)
{
try
{
if
(
ssl
)
{
return
SecureSocketFactory
.
createSocket
(
address
,
port
);
}
...
...
@@ -109,6 +111,12 @@ public class NetUtils {
socket
.
connect
(
new
InetSocketAddress
(
address
,
port
),
SysProperties
.
SOCKET_CONNECT_TIMEOUT
);
return
socket
;
}
catch
(
BindException
e
)
{
// Workaround for Windows problem with frequent connections:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213296
// trying to connect again
}
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
43c91a62
...
...
@@ -117,6 +117,7 @@ import org.h2.test.unit.TestFtp;
import
org.h2.test.unit.TestIntArray
;
import
org.h2.test.unit.TestIntIntHashMap
;
import
org.h2.test.unit.TestMathUtils
;
import
org.h2.test.unit.TestNetUtils
;
import
org.h2.test.unit.TestOverflow
;
import
org.h2.test.unit.TestPageStore
;
import
org.h2.test.unit.TestPattern
;
...
...
@@ -594,6 +595,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new
TestIntArray
().
runTest
(
this
);
new
TestIntIntHashMap
().
runTest
(
this
);
new
TestMathUtils
().
runTest
(
this
);
new
TestNetUtils
().
runTest
(
this
);
new
TestMultiThreadedKernel
().
runTest
(
this
);
new
TestOverflow
().
runTest
(
this
);
new
TestPageStore
().
runTest
(
this
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestNetUtils.java
0 → 100644
浏览文件 @
43c91a62
/**
*
*/
package
org
.
h2
.
test
.
unit
;
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.engine.Constants
;
import
org.h2.test.TestBase
;
import
org.h2.util.NetUtils
;
/**
* @author Sergi Vladykin
*/
public
class
TestNetUtils
extends
TestBase
{
/**
* @param args
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
Exception
{
testFrequentConnections
(
false
);
testFrequentConnections
(
true
);
}
private
void
testFrequentConnections
(
boolean
ssl
)
throws
Exception
{
final
ServerSocket
serverSock
=
NetUtils
.
createServerSocket
(
Constants
.
DEFAULT_TCP_PORT
,
ssl
);
Thread
serverThread
=
new
Thread
()
{
@Override
public
void
run
()
{
while
(!
isInterrupted
())
{
try
{
Socket
socket
=
serverSock
.
accept
();
socket
.
close
();
}
catch
(
Exception
e
)
{
// ignore
}
}
}
};
serverThread
.
start
();
// System.out.println("Server started.");
AtomicInteger
counter
=
new
AtomicInteger
();
try
{
Set
<
ConnectWorker
>
workers
=
new
HashSet
<
ConnectWorker
>();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
workers
.
add
(
new
ConnectWorker
(
ssl
,
workers
,
counter
));
}
for
(
ConnectWorker
worker
:
workers
)
{
worker
.
start
();
}
// System.out.println("Workers started.");
Exception
exception
=
null
;
for
(
ConnectWorker
worker
:
workers
)
{
worker
.
join
();
if
(
exception
==
null
)
{
exception
=
worker
.
getException
();
// if (exception != null) {
// System.out.println("Exception set.");
// }
}
}
// System.out.println("All joined.");
if
(
exception
!=
null
)
{
throw
exception
;
}
}
finally
{
serverThread
.
interrupt
();
try
{
serverSock
.
close
();
}
catch
(
Exception
e
)
{
// ignore
}
// System.out.println("Server stopped.");
}
}
/**
*
*/
private
class
ConnectWorker
extends
Thread
{
private
static
final
int
MAX_CONNECT_COUNT
=
10000
;
private
final
boolean
ssl
;
private
final
Set
<
ConnectWorker
>
workers
;
private
final
AtomicInteger
counter
;
private
volatile
Exception
exception
;
public
ConnectWorker
(
boolean
ssl
,
Set
<
ConnectWorker
>
workers
,
AtomicInteger
counter
)
{
this
.
ssl
=
ssl
;
this
.
workers
=
workers
;
this
.
counter
=
counter
;
}
@Override
public
void
run
()
{
try
{
while
(!
isInterrupted
()
&&
counter
.
incrementAndGet
()
<
MAX_CONNECT_COUNT
)
{
Socket
sock
=
NetUtils
.
createSocket
(
"127.0.0.1"
,
Constants
.
DEFAULT_TCP_PORT
,
ssl
);
// System.out.println(COUNTER.get());
try
{
sock
.
close
();
}
catch
(
IOException
e
)
{
// ignore
}
}
}
catch
(
Exception
e
)
{
this
.
exception
=
e
;
for
(
ConnectWorker
worker
:
workers
)
{
worker
.
interrupt
();
}
}
}
/**
* @return the exception
*/
public
Exception
getException
()
{
return
exception
;
}
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论