Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4ecab392
提交
4ecab392
authored
4月 01, 2018
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused classes
上级
35062976
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
0 行增加
和
331 行删除
+0
-331
ConcurrentArrayList.java
h2/src/main/org/h2/mvstore/ConcurrentArrayList.java
+0
-122
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+0
-2
TestConcurrentLinkedList.java
h2/src/test/org/h2/test/store/TestConcurrentLinkedList.java
+0
-207
没有找到文件。
h2/src/main/org/h2/mvstore/ConcurrentArrayList.java
deleted
100644 → 0
浏览文件 @
35062976
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
;
import
java.util.Arrays
;
import
java.util.Iterator
;
/**
* A very simple array list that supports concurrent access.
* Internally, it uses immutable objects.
*
* @param <K> the key type
*/
public
class
ConcurrentArrayList
<
K
>
{
/**
* The array.
*/
@SuppressWarnings
(
"unchecked"
)
K
[]
array
=
(
K
[])
new
Object
[
0
];
/**
* Get the first element, or null if none.
*
* @return the first element
*/
public
K
peekFirst
()
{
K
[]
a
=
array
;
return
a
.
length
==
0
?
null
:
a
[
0
];
}
/**
* Get the last element, or null if none.
*
* @return the last element
*/
public
K
peekLast
()
{
K
[]
a
=
array
;
int
len
=
a
.
length
;
return
len
==
0
?
null
:
a
[
len
-
1
];
}
/**
* Add an element at the end.
*
* @param obj the element
*/
public
synchronized
void
add
(
K
obj
)
{
if
(
obj
==
null
)
{
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_INTERNAL
,
"adding null value to list"
);
}
int
len
=
array
.
length
;
array
=
Arrays
.
copyOf
(
array
,
len
+
1
);
array
[
len
]
=
obj
;
}
/**
* Remove the first element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
synchronized
boolean
removeFirst
(
K
obj
)
{
if
(
peekFirst
()
!=
obj
)
{
return
false
;
}
int
len
=
array
.
length
;
@SuppressWarnings
(
"unchecked"
)
K
[]
a
=
(
K
[])
new
Object
[
len
-
1
];
System
.
arraycopy
(
array
,
1
,
a
,
0
,
len
-
1
);
array
=
a
;
return
true
;
}
/**
* Remove the last element, if it matches.
*
* @param obj the element to remove
* @return true if the element matched and was removed
*/
public
synchronized
boolean
removeLast
(
K
obj
)
{
if
(
peekLast
()
!=
obj
)
{
return
false
;
}
array
=
Arrays
.
copyOf
(
array
,
array
.
length
-
1
);
return
true
;
}
/**
* Get an iterator over all entries.
*
* @return the iterator
*/
public
Iterator
<
K
>
iterator
()
{
return
new
Iterator
<
K
>()
{
K
[]
a
=
array
;
int
index
;
@Override
public
boolean
hasNext
()
{
return
index
<
a
.
length
;
}
@Override
public
K
next
()
{
return
a
[
index
++];
}
@Override
public
void
remove
()
{
throw
DataUtils
.
newUnsupportedOperationException
(
"remove"
);
}
};
}
}
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
4ecab392
...
@@ -135,7 +135,6 @@ import org.h2.test.store.TestCacheConcurrentLIRS;
...
@@ -135,7 +135,6 @@ import org.h2.test.store.TestCacheConcurrentLIRS;
import
org.h2.test.store.TestCacheLIRS
;
import
org.h2.test.store.TestCacheLIRS
;
import
org.h2.test.store.TestCacheLongKeyLIRS
;
import
org.h2.test.store.TestCacheLongKeyLIRS
;
import
org.h2.test.store.TestConcurrent
;
import
org.h2.test.store.TestConcurrent
;
import
org.h2.test.store.TestConcurrentLinkedList
;
import
org.h2.test.store.TestDataUtils
;
import
org.h2.test.store.TestDataUtils
;
import
org.h2.test.store.TestFreeSpace
;
import
org.h2.test.store.TestFreeSpace
;
import
org.h2.test.store.TestKillProcessWhileWriting
;
import
org.h2.test.store.TestKillProcessWhileWriting
;
...
@@ -882,7 +881,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
...
@@ -882,7 +881,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest
(
new
TestCacheConcurrentLIRS
());
addTest
(
new
TestCacheConcurrentLIRS
());
addTest
(
new
TestCacheLIRS
());
addTest
(
new
TestCacheLIRS
());
addTest
(
new
TestCacheLongKeyLIRS
());
addTest
(
new
TestCacheLongKeyLIRS
());
addTest
(
new
TestConcurrentLinkedList
());
addTest
(
new
TestDataUtils
());
addTest
(
new
TestDataUtils
());
addTest
(
new
TestFreeSpace
());
addTest
(
new
TestFreeSpace
());
addTest
(
new
TestKillProcessWhileWriting
());
addTest
(
new
TestKillProcessWhileWriting
());
...
...
h2/src/test/org/h2/test/store/TestConcurrentLinkedList.java
deleted
100644 → 0
浏览文件 @
35062976
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
store
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.Random
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.mvstore.ConcurrentArrayList
;
import
org.h2.test.TestBase
;
import
org.h2.util.Task
;
/**
* Test the concurrent linked list.
*/
public
class
TestConcurrentLinkedList
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestConcurrentLinkedList
test
=
(
TestConcurrentLinkedList
)
TestBase
.
createCaller
().
init
();
test
.
test
();
testPerformance
();
}
@Override
public
void
test
()
throws
Exception
{
testRandomized
();
testConcurrent
();
}
private
static
void
testPerformance
()
{
testPerformance
(
true
);
testPerformance
(
false
);
testPerformance
(
true
);
testPerformance
(
false
);
testPerformance
(
true
);
testPerformance
(
false
);
}
private
static
void
testPerformance
(
final
boolean
stock
)
{
System
.
out
.
print
(
stock
?
"stock "
:
"custom "
);
long
start
=
System
.
nanoTime
();
// final ConcurrentLinkedList<Integer> test =
// new ConcurrentLinkedList<Integer>();
final
ConcurrentArrayList
<
Integer
>
test
=
new
ConcurrentArrayList
<>();
final
LinkedList
<
Integer
>
x
=
new
LinkedList
<>();
final
AtomicInteger
counter
=
new
AtomicInteger
();
Task
task
=
new
Task
()
{
@Override
public
void
call
()
throws
Exception
{
while
(!
stop
)
{
if
(
stock
)
{
synchronized
(
x
)
{
Integer
y
=
x
.
peekFirst
();
if
(
y
==
null
)
{
counter
.
incrementAndGet
();
}
}
}
else
{
Integer
y
=
test
.
peekFirst
();
if
(
y
==
null
)
{
counter
.
incrementAndGet
();
}
}
}
}
};
task
.
execute
();
test
.
add
(-
1
);
x
.
add
(-
1
);
for
(
int
i
=
0
;
i
<
2000000
;
i
++)
{
Integer
value
=
Integer
.
valueOf
(
i
&
63
);
if
(
stock
)
{
synchronized
(
x
)
{
Integer
f
=
x
.
peekLast
();
if
(
f
!=
value
)
{
x
.
add
(
i
);
}
}
Math
.
sin
(
i
);
synchronized
(
x
)
{
if
(
x
.
peekFirst
()
!=
x
.
peekLast
())
{
x
.
removeFirst
();
}
}
}
else
{
Integer
f
=
test
.
peekLast
();
if
(
f
!=
value
)
{
test
.
add
(
i
);
}
Math
.
sin
(
i
);
f
=
test
.
peekFirst
();
if
(
f
!=
test
.
peekLast
())
{
test
.
removeFirst
(
f
);
}
}
}
task
.
get
();
System
.
out
.
println
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
System
.
nanoTime
()
-
start
));
}
private
void
testConcurrent
()
{
final
ConcurrentArrayList
<
Integer
>
test
=
new
ConcurrentArrayList
<>();
// final ConcurrentRing<Integer> test = new ConcurrentRing<Integer>();
final
AtomicInteger
counter
=
new
AtomicInteger
();
final
AtomicInteger
size
=
new
AtomicInteger
();
Task
task
=
new
Task
()
{
@Override
public
void
call
()
{
while
(!
stop
)
{
Thread
.
yield
();
if
(
size
.
get
()
<
10
)
{
test
.
add
(
counter
.
getAndIncrement
());
size
.
getAndIncrement
();
}
}
}
};
task
.
execute
();
for
(
int
i
=
0
;
i
<
1000000
;)
{
Thread
.
yield
();
Integer
x
=
test
.
peekFirst
();
if
(
x
==
null
)
{
continue
;
}
assertEquals
(
i
,
x
.
intValue
());
if
(
test
.
removeFirst
(
x
))
{
size
.
getAndDecrement
();
i
++;
}
}
task
.
get
();
}
private
void
testRandomized
()
{
Random
r
=
new
Random
(
0
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
ConcurrentArrayList
<
Integer
>
test
=
new
ConcurrentArrayList
<>();
// ConcurrentRing<Integer> test = new ConcurrentRing<Integer>();
LinkedList
<
Integer
>
x
=
new
LinkedList
<>();
StringBuilder
buff
=
new
StringBuilder
();
for
(
int
j
=
0
;
j
<
10000
;
j
++)
{
buff
.
append
(
"["
+
j
+
"] "
);
int
opType
=
r
.
nextInt
(
3
);
switch
(
opType
)
{
case
0
:
{
int
value
=
r
.
nextInt
(
100
);
buff
.
append
(
"add "
+
value
+
"\n"
);
test
.
add
(
value
);
x
.
add
(
value
);
break
;
}
case
1
:
{
Integer
value
=
x
.
peek
();
if
(
value
!=
null
&&
(
x
.
size
()
>
5
||
r
.
nextBoolean
()))
{
buff
.
append
(
"removeFirst\n"
);
x
.
removeFirst
();
test
.
removeFirst
(
value
);
}
else
{
buff
.
append
(
"removeFirst -1\n"
);
test
.
removeFirst
(-
1
);
}
break
;
}
case
2
:
{
Integer
value
=
x
.
peekLast
();
if
(
value
!=
null
&&
(
x
.
size
()
>
5
||
r
.
nextBoolean
()))
{
buff
.
append
(
"removeLast\n"
);
x
.
removeLast
();
test
.
removeLast
(
value
);
}
else
{
buff
.
append
(
"removeLast -1\n"
);
test
.
removeLast
(-
1
);
}
break
;
}
}
assertEquals
(
toString
(
x
.
iterator
()),
toString
(
test
.
iterator
()));
if
(
x
.
isEmpty
())
{
assertNull
(
test
.
peekFirst
());
assertNull
(
test
.
peekLast
());
}
else
{
assertEquals
(
x
.
peekFirst
().
intValue
(),
test
.
peekFirst
().
intValue
());
assertEquals
(
x
.
peekLast
().
intValue
(),
test
.
peekLast
().
intValue
());
}
}
}
}
private
static
<
T
>
String
toString
(
Iterator
<
T
>
it
)
{
StringBuilder
buff
=
new
StringBuilder
();
while
(
it
.
hasNext
())
{
buff
.
append
(
' '
).
append
(
it
.
next
());
}
return
buff
.
toString
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论