Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
ac6d5d65
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac6d5d65
编写于
3月 31, 2012
作者:
S
sean.wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more cked test case
上级
d58e2fed
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
520 addition
and
220 deletion
+520
-220
cat-core/src/main/java/com/dianping/cat/build/StorageComponentConfigurator.java
.../com/dianping/cat/build/StorageComponentConfigurator.java
+18
-14
cat-core/src/main/resources/META-INF/plexus/components.xml
cat-core/src/main/resources/META-INF/plexus/components.xml
+11
-0
cat-core/src/test/java/com/dianping/cat/storage/MesageTreeBucketTestCase.java
...va/com/dianping/cat/storage/MesageTreeBucketTestCase.java
+233
-0
cat-core/src/test/java/com/dianping/cat/storage/StringBucketTestCase.java
...t/java/com/dianping/cat/storage/StringBucketTestCase.java
+227
-0
cat-core/src/test/java/com/dianping/cat/storage/message/LocalLogviewBucketTest.java
.../dianping/cat/storage/message/LocalLogviewBucketTest.java
+6
-206
cat-core/src/test/java/com/dianping/cat/storage/report/LocalReportBucketTest.java
...om/dianping/cat/storage/report/LocalReportBucketTest.java
+25
-0
未找到文件。
cat-core/src/main/java/com/dianping/cat/build/StorageComponentConfigurator.java
浏览文件 @
ac6d5d65
...
@@ -34,11 +34,15 @@ class StorageComponentConfigurator extends AbstractResourceConfigurator {
...
@@ -34,11 +34,15 @@ class StorageComponentConfigurator extends AbstractResourceConfigurator {
.
is
(
PER_LOOKUP
)
//
.
is
(
PER_LOOKUP
)
//
.
req
(
MessagePathBuilder
.
class
)
//
.
req
(
MessagePathBuilder
.
class
)
//
.
req
(
MessageCodec
.
class
,
"plain-text"
));
.
req
(
MessageCodec
.
class
,
"plain-text"
));
all
.
add
(
C
(
Bucket
.
class
,
MessageTree
.
class
.
getName
()
+
"-message"
,
all
.
add
(
C
(
Bucket
.
class
,
MessageTree
.
class
.
getName
()
+
"-message"
,
//
com
.
dianping
.
cat
.
storage
.
message
.
LocalMessageBucket
.
class
)
//
com
.
dianping
.
cat
.
storage
.
message
.
LocalMessageBucket
.
class
)
//
.
is
(
PER_LOOKUP
)
//
.
is
(
PER_LOOKUP
)
//
.
req
(
MessagePathBuilder
.
class
)
//
.
req
(
MessagePathBuilder
.
class
)
//
.
req
(
MessageCodec
.
class
,
"plain-text"
));
.
req
(
MessageCodec
.
class
,
"plain-text"
));
all
.
add
(
C
(
Bucket
.
class
,
String
.
class
.
getName
()
+
"-report"
,
//
com
.
dianping
.
cat
.
storage
.
report
.
LocalReportBucket
.
class
)
//
.
is
(
PER_LOOKUP
)
//
.
req
(
MessagePathBuilder
.
class
));
return
all
;
return
all
;
}
}
...
...
cat-core/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
ac6d5d65
...
@@ -300,5 +300,16 @@
...
@@ -300,5 +300,16 @@
</requirement>
</requirement>
</requirements>
</requirements>
</component>
</component>
<component>
<role>
com.dianping.cat.storage.Bucket
</role>
<role-hint>
java.lang.String-report
</role-hint>
<implementation>
com.dianping.cat.storage.report.LocalReportBucket
</implementation>
<instantiation-strategy>
per-lookup
</instantiation-strategy>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessagePathBuilder
</role>
</requirement>
</requirements>
</component>
</components>
</components>
</plexus>
</plexus>
cat-core/src/test/java/com/dianping/cat/storage/MesageTreeBucketTestCase.java
0 → 100644
浏览文件 @
ac6d5d65
package
com.dianping.cat.storage
;
import
java.io.IOException
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
junit.framework.Assert
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.dianping.cat.message.spi.internal.DefaultMessageTree
;
import
com.site.lookup.ComponentTestCase
;
public
abstract
class
MesageTreeBucketTestCase
extends
ComponentTestCase
{
protected
final
static
int
threadNum
=
10
;
// notice: max 9, for creating asc order id bellow
protected
final
static
int
timesPerThread
=
1000
;
// notice: must be powers 10, fro creating asc order id bellow
protected
ExecutorService
pool
=
null
;
Bucket
<
MessageTree
>
bucket
=
null
;
protected
void
printFails
(
final
int
fails
,
final
long
start
)
{
System
.
out
.
println
(
new
Throwable
().
getStackTrace
()[
1
].
toString
()
+
" threads:"
+
threadNum
+
" total:"
+
threadNum
*
timesPerThread
+
" fails:"
+
fails
+
" waste:"
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms"
);
if
(
fails
>
0
)
{
Assert
.
fail
(
"fails:"
+
fails
);
}
}
protected
void
print
(
final
long
start
)
{
System
.
out
.
println
(
new
Throwable
().
getStackTrace
()[
1
].
toString
()
+
" threads:"
+
threadNum
+
" total:"
+
threadNum
*
timesPerThread
+
" waste:"
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms"
);
}
protected
void
resetSerial
(
final
AtomicInteger
serial
)
{
serial
.
set
(
10
*
timesPerThread
);
}
protected
AtomicInteger
createSerial
()
{
return
new
AtomicInteger
(
10
*
timesPerThread
);
}
protected
void
submit
(
Runnable
run
)
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
pool
.
submit
(
run
);
}
}
protected
CountDownLatch
createLatch
()
{
return
new
CountDownLatch
(
threadNum
);
}
@Before
public
void
setUp
()
throws
IOException
{
try
{
super
.
setUp
();
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
try
{
pool
=
Executors
.
newFixedThreadPool
(
threadNum
);
bucket
=
createBucket
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
protected
abstract
Bucket
<
MessageTree
>
createBucket
()
throws
Exception
;
@After
public
void
tearDown
()
throws
Exception
{
super
.
tearDown
();
bucket
.
close
();
bucket
.
deleteAndCreate
();
}
@Test
public
void
testReload
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
this
.
bucket
.
close
();
long
start
=
System
.
currentTimeMillis
();
bucket
=
createBucket
();
print
(
start
);
serialRead
(
serial
);
}
@Test
public
void
testConcurrentRead
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
null
;
String
expect
=
null
;
try
{
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
MessageTree
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
id
,
target
.
getMessageId
());
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
":"
+
id
+
":"
+
expect
);
e
.
printStackTrace
();
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
}
@Test
public
void
testConcurrentReadWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
null
;
String
expect
=
null
;
try
{
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
Assert
.
assertTrue
(
bucket
.
storeById
(
id
,
mt
));
MessageTree
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
id
,
target
.
getMessageId
());
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
":"
+
id
+
":"
+
expect
);
e
.
printStackTrace
();
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
}
@Test
public
void
testConcurrentWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
try
{
String
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
boolean
success
=
bucket
.
storeById
(
id
,
mt
);
if
(!
success
)
{
fail
.
incrementAndGet
();
}
}
catch
(
Throwable
e
)
{
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
resetSerial
(
serial
);
this
.
serialRead
(
serial
);
}
@Test
public
void
testSerialRead
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
long
start
=
System
.
currentTimeMillis
();
serialRead
(
serial
);
print
(
start
);
}
@Test
public
void
testSerialWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
long
start
=
System
.
currentTimeMillis
();
this
.
serialWrite
(
serial
);
print
(
start
);
resetSerial
(
serial
);
this
.
serialRead
(
serial
);
}
private
void
serialRead
(
final
AtomicInteger
serial
)
throws
IOException
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
""
+
serial
.
incrementAndGet
();
MessageTree
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
id
,
target
.
getMessageId
());
}
}
}
private
void
serialWrite
(
AtomicInteger
serial
)
throws
IOException
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
Assert
.
assertTrue
(
bucket
.
storeById
(
id
,
mt
));
}
}
}
}
cat-core/src/test/java/com/dianping/cat/storage/StringBucketTestCase.java
0 → 100644
浏览文件 @
ac6d5d65
package
com.dianping.cat.storage
;
import
java.io.IOException
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
junit.framework.Assert
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
com.site.lookup.ComponentTestCase
;
public
abstract
class
StringBucketTestCase
extends
ComponentTestCase
{
protected
final
static
int
threadNum
=
10
;
// notice: max 9, for creating asc order id bellow
protected
final
static
int
timesPerThread
=
1000
;
// notice: must be powers 10, fro creating asc order id bellow
protected
ExecutorService
pool
=
null
;
Bucket
<
String
>
bucket
=
null
;
protected
void
printFails
(
final
int
fails
,
final
long
start
)
{
System
.
out
.
println
(
new
Throwable
().
getStackTrace
()[
1
].
toString
()
+
" threads:"
+
threadNum
+
" total:"
+
threadNum
*
timesPerThread
+
" fails:"
+
fails
+
" waste:"
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms"
);
if
(
fails
>
0
)
{
Assert
.
fail
(
"fails:"
+
fails
);
}
}
protected
void
print
(
final
long
start
)
{
System
.
out
.
println
(
new
Throwable
().
getStackTrace
()[
1
].
toString
()
+
" threads:"
+
threadNum
+
" total:"
+
threadNum
*
timesPerThread
+
" waste:"
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms"
);
}
protected
void
resetSerial
(
final
AtomicInteger
serial
)
{
serial
.
set
(
10
*
timesPerThread
);
}
protected
AtomicInteger
createSerial
()
{
return
new
AtomicInteger
(
10
*
timesPerThread
);
}
protected
void
submit
(
Runnable
run
)
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
pool
.
submit
(
run
);
}
}
protected
CountDownLatch
createLatch
()
{
return
new
CountDownLatch
(
threadNum
);
}
@Before
public
void
setUp
()
throws
IOException
{
try
{
super
.
setUp
();
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
try
{
pool
=
Executors
.
newFixedThreadPool
(
threadNum
);
bucket
=
createBucket
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
protected
abstract
Bucket
<
String
>
createBucket
()
throws
Exception
;
@After
public
void
tearDown
()
throws
Exception
{
super
.
tearDown
();
bucket
.
close
();
bucket
.
deleteAndCreate
();
}
@Test
public
void
testConcurrentRead
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
null
;
String
expect
=
null
;
try
{
id
=
""
+
serial
.
incrementAndGet
();
String
value
=
"value:"
+
id
;
String
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
value
,
target
);
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
":"
+
id
+
":"
+
expect
);
e
.
printStackTrace
();
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
}
@Test
public
void
testConcurrentReadWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
null
;
String
expect
=
null
;
try
{
id
=
""
+
serial
.
incrementAndGet
();
String
value
=
"value:"
+
id
;
Assert
.
assertTrue
(
bucket
.
storeById
(
id
,
value
));
String
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
value
,
target
);
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
":"
+
id
+
":"
+
expect
);
e
.
printStackTrace
();
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
}
@Test
public
void
testConcurrentWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
try
{
String
id
=
""
+
serial
.
incrementAndGet
();
String
value
=
"value:"
+
id
;
boolean
success
=
bucket
.
storeById
(
id
,
value
);
if
(!
success
)
{
fail
.
incrementAndGet
();
}
}
catch
(
Throwable
e
)
{
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
resetSerial
(
serial
);
this
.
serialRead
(
serial
);
}
@Test
public
void
testSerialRead
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
long
start
=
System
.
currentTimeMillis
();
serialRead
(
serial
);
print
(
start
);
}
@Test
public
void
testReload
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
this
.
bucket
.
close
();
long
start
=
System
.
currentTimeMillis
();
bucket
=
createBucket
();
print
(
start
);
serialRead
(
serial
);
}
@Test
public
void
testSerialWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
long
start
=
System
.
currentTimeMillis
();
this
.
serialWrite
(
serial
);
print
(
start
);
resetSerial
(
serial
);
this
.
serialRead
(
serial
);
}
private
void
serialRead
(
final
AtomicInteger
serial
)
throws
IOException
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
""
+
serial
.
incrementAndGet
();
String
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
"value:"
+
id
,
target
);
}
}
}
private
void
serialWrite
(
AtomicInteger
serial
)
throws
IOException
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
""
+
serial
.
incrementAndGet
();
String
value
=
"value:"
+
id
;
Assert
.
assertTrue
(
bucket
.
storeById
(
id
,
value
));
}
}
}
}
cat-core/src/test/java/com/dianping/cat/storage/message/LocalLogviewBucketTest.java
浏览文件 @
ac6d5d65
...
@@ -2,217 +2,17 @@ package com.dianping.cat.storage.message;
...
@@ -2,217 +2,17 @@ package com.dianping.cat.storage.message;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
junit.framework.Assert
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.dianping.cat.message.spi.MessageTree
;
import
com.dianping.cat.message.spi.internal.DefaultMessageTree
;
import
com.dianping.cat.storage.Bucket
;
import
com.dianping.cat.storage.Bucket
;
import
com.site.lookup.ComponentTestCase
;
import
com.dianping.cat.storage.MesageTreeBucketTestCase
;
public
class
LocalLogviewBucketTest
extends
ComponentTestCase
{
protected
final
static
int
threadNum
=
10
;
// notice: max 9, for creating asc order id bellow
protected
final
static
int
timesPerThread
=
1000
;
// notice: must be powers 10, fro creating asc order id bellow
protected
void
printFails
(
final
int
fails
,
final
long
start
)
{
System
.
out
.
println
(
new
Throwable
().
getStackTrace
()[
1
].
toString
()
+
" threads:"
+
threadNum
+
" total:"
+
threadNum
*
timesPerThread
+
" fails:"
+
fails
+
" waste:"
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms"
);
if
(
fails
>
0
)
{
Assert
.
fail
(
"fails:"
+
fails
);
}
}
protected
void
print
(
final
long
start
)
{
System
.
out
.
println
(
new
Throwable
().
getStackTrace
()[
1
].
toString
()
+
" threads:"
+
threadNum
+
" total:"
+
threadNum
*
timesPerThread
+
" waste:"
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms"
);
}
protected
void
resetSerial
(
final
AtomicInteger
serial
)
{
serial
.
set
(
10
*
timesPerThread
);
}
protected
AtomicInteger
createSerial
()
{
return
new
AtomicInteger
(
10
*
timesPerThread
);
}
final
ExecutorService
pool
=
Executors
.
newFixedThreadPool
(
threadNum
);
public
class
LocalLogviewBucketTest
extends
MesageTreeBucketTestCase
{
protected
void
submit
(
Runnable
run
)
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
pool
.
submit
(
run
);
}
}
protected
CountDownLatch
createLatch
()
{
return
new
CountDownLatch
(
threadNum
);
}
Bucket
<
MessageTree
>
bucket
=
null
;
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Before
protected
Bucket
<
MessageTree
>
createBucket
()
throws
Exception
,
IOException
{
public
void
setUp
()
throws
IOException
{
Bucket
<
MessageTree
>
bucket
=
lookup
(
Bucket
.
class
,
MessageTree
.
class
.
getName
()
+
"-logview"
);
try
{
super
.
setUp
();
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
try
{
bucket
=
lookup
(
Bucket
.
class
,
MessageTree
.
class
.
getName
()
+
"-logview"
);
bucket
.
initialize
(
null
,
"cat"
,
new
Date
());
bucket
.
initialize
(
null
,
"cat"
,
new
Date
());
}
catch
(
Exception
e
)
{
return
bucket
;
e
.
printStackTrace
();
}
}
@After
public
void
tearDown
()
throws
Exception
{
super
.
tearDown
();
bucket
.
close
();
bucket
.
deleteAndCreate
();
}
@Test
public
void
testConcurrentRead
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
null
;
String
expect
=
null
;
try
{
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
MessageTree
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
id
,
target
.
getMessageId
());
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
":"
+
id
+
":"
+
expect
);
e
.
printStackTrace
();
fail
.
incrementAndGet
();
}
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
}
@Test
public
void
testConcurrentReadWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
null
;
String
expect
=
null
;
try
{
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
Assert
.
assertTrue
(
bucket
.
storeById
(
id
,
mt
));
MessageTree
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
id
,
target
.
getMessageId
());
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
Thread
.
currentThread
().
getName
()
+
":"
+
id
+
":"
+
expect
);
e
.
printStackTrace
();
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
}
@Test
public
void
testConcurrentWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
final
AtomicInteger
fail
=
new
AtomicInteger
();
final
CountDownLatch
latch
=
createLatch
();
long
start
=
System
.
currentTimeMillis
();
submit
(
new
Runnable
()
{
public
void
run
()
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
try
{
String
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
boolean
success
=
bucket
.
storeById
(
id
,
mt
);
if
(!
success
)
{
fail
.
incrementAndGet
();
}
}
catch
(
Throwable
e
)
{
fail
.
incrementAndGet
();
}
}
latch
.
countDown
();
}
});
latch
.
await
();
printFails
(
fail
.
get
(),
start
);
resetSerial
(
serial
);
this
.
serialRead
(
serial
);
}
@Test
public
void
testSerialRead
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
this
.
serialWrite
(
serial
);
resetSerial
(
serial
);
long
start
=
System
.
currentTimeMillis
();
serialRead
(
serial
);
print
(
start
);
}
@Test
public
void
testSerialWrite
()
throws
Exception
{
final
AtomicInteger
serial
=
createSerial
();
long
start
=
System
.
currentTimeMillis
();
this
.
serialWrite
(
serial
);
print
(
start
);
resetSerial
(
serial
);
this
.
serialRead
(
serial
);
}
private
void
serialRead
(
final
AtomicInteger
serial
)
throws
IOException
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
""
+
serial
.
incrementAndGet
();
MessageTree
target
=
bucket
.
findById
(
id
);
Assert
.
assertEquals
(
id
,
target
.
getMessageId
());
}
}
}
private
void
serialWrite
(
AtomicInteger
serial
)
throws
IOException
{
for
(
int
p
=
0
;
p
<
threadNum
;
p
++)
{
for
(
int
i
=
0
;
i
<
timesPerThread
;
i
++)
{
String
id
=
""
+
serial
.
incrementAndGet
();
DefaultMessageTree
mt
=
new
DefaultMessageTree
();
mt
.
setMessageId
(
id
);
Assert
.
assertTrue
(
bucket
.
storeById
(
id
,
mt
));
}
}
}
}
}
cat-core/src/test/java/com/dianping/cat/storage/report/LocalReportBucketTest.java
0 → 100644
浏览文件 @
ac6d5d65
package
com.dianping.cat.storage.report
;
import
java.io.IOException
;
import
java.util.Date
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
com.dianping.cat.storage.Bucket
;
import
com.dianping.cat.storage.StringBucketTestCase
;
public
class
LocalReportBucketTest
extends
StringBucketTestCase
{
@SuppressWarnings
(
"unchecked"
)
protected
Bucket
<
String
>
createBucket
()
throws
Exception
,
IOException
{
Bucket
<
String
>
bucket
=
lookup
(
Bucket
.
class
,
String
.
class
.
getName
()
+
"-report"
);
bucket
.
initialize
(
null
,
"cat"
,
new
Date
());
return
bucket
;
}
@Test
@Ignore
public
void
testReload
()
throws
Exception
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录