Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JDChain
Bftsmart
提交
6973b767
B
Bftsmart
项目概览
JDChain
/
Bftsmart
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Bftsmart
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6973b767
编写于
12月 14, 2011
作者:
M
marcelmhs@gmail.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- Added ConsoleLogger and ConsoleTest to version control.
上级
ff16f40d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
247 addition
and
0 deletion
+247
-0
test/navigators/smart/tom/demo/keyvalue/ConsoleLogger.java
test/navigators/smart/tom/demo/keyvalue/ConsoleLogger.java
+47
-0
test/navigators/smart/tom/demo/keyvalue/ConsoleTest.java
test/navigators/smart/tom/demo/keyvalue/ConsoleTest.java
+200
-0
未找到文件。
test/navigators/smart/tom/demo/keyvalue/ConsoleLogger.java
0 → 100644
浏览文件 @
6973b767
package
navigators.smart.tom.demo.keyvalue
;
import
java.io.BufferedReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
public
class
ConsoleLogger
extends
Thread
{
private
InputStream
in
=
null
;
private
PrintStream
out
=
null
;
private
int
index
;
public
InputStream
getIn
()
{
return
in
;
}
public
void
setIn
(
InputStream
in
)
{
this
.
in
=
in
;
}
public
PrintStream
getOut
()
{
return
out
;
}
public
void
setOut
(
PrintStream
out
)
{
this
.
out
=
out
;
}
public
int
getIndex
()
{
return
index
;
}
public
void
setIndex
(
int
index
)
{
this
.
index
=
index
;
}
public
void
run
()
{
BufferedReader
stdInput
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
String
s
;
try
{
while
((
s
=
stdInput
.
readLine
())
!=
null
)
{
out
.
println
(
"Replica "
+
index
+
")"
+
s
);
}
}
catch
(
IOException
ioe
)
{
System
.
out
.
println
(
"----------- Exception writing replica log: "
+
ioe
.
getMessage
());
}
}
}
test/navigators/smart/tom/demo/keyvalue/ConsoleTest.java
0 → 100644
浏览文件 @
6973b767
package
navigators.smart.tom.demo.keyvalue
;
import
static
org
.
junit
.
Assert
.*;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.HashMap
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
public
class
ConsoleTest
{
private
static
Process
replica0
;
private
static
Process
replica1
;
private
static
Process
replica2
;
private
static
Process
replica3
;
private
static
String
[]
command
=
new
String
[
5
];
@BeforeClass
public
static
void
startServers
()
{
try
{
System
.
out
.
println
(
"Starting the servers"
);
command
[
0
]
=
"java"
;
command
[
1
]
=
"-cp"
;
command
[
2
]
=
"bin/SMaRt.jar:lib/slf4j-api-1.5.8.jar:lib/slf4j-jdk14-1.5.8.jar:lib/netty-3.1.1.GA.jar:lib/commons-codec-1.5.jar"
;
command
[
3
]
=
"navigators.smart.tom.demo.keyvalue.BFTMapImpl"
;
command
[
4
]
=
"0"
;
replica0
=
new
ProcessBuilder
(
command
).
redirectErrorStream
(
true
).
start
();
command
[
4
]
=
"1"
;
replica1
=
new
ProcessBuilder
(
command
).
redirectErrorStream
(
true
).
start
();
command
[
4
]
=
"2"
;
replica2
=
new
ProcessBuilder
(
command
).
redirectErrorStream
(
true
).
start
();
command
[
4
]
=
"3"
;
replica3
=
new
ProcessBuilder
(
command
).
redirectErrorStream
(
true
).
start
();
ConsoleLogger
log0
=
new
ConsoleLogger
();
log0
.
setIndex
(
0
);
log0
.
setIn
(
replica0
.
getInputStream
());
log0
.
setOut
(
System
.
out
);
log0
.
start
();
ConsoleLogger
log1
=
new
ConsoleLogger
();
log1
.
setIndex
(
1
);
log1
.
setIn
(
replica1
.
getInputStream
());
log1
.
setOut
(
System
.
out
);
log1
.
start
();
ConsoleLogger
log2
=
new
ConsoleLogger
();
log2
.
setIndex
(
2
);
log2
.
setIn
(
replica2
.
getInputStream
());
log2
.
setOut
(
System
.
out
);
log2
.
start
();
ConsoleLogger
log3
=
new
ConsoleLogger
();
log3
.
setIndex
(
3
);
log3
.
setIn
(
replica3
.
getInputStream
());
log3
.
setOut
(
System
.
out
);
log3
.
start
();
System
.
out
.
println
(
"Servers started"
);
}
catch
(
IOException
ioe
)
{
System
.
out
.
println
(
"Exception during KVClient test: "
);
System
.
out
.
println
(
ioe
.
getMessage
());
}
}
@AfterClass
public
static
void
stopServers
()
throws
IllegalArgumentException
,
IllegalAccessException
,
NoSuchFieldException
,
IOException
{
System
.
out
.
println
(
"Stopping servers"
);
replica0
.
destroy
();
replica1
.
destroy
();
replica2
.
destroy
();
replica3
.
destroy
();
System
.
out
.
println
(
"Servers stopped"
);
}
/**
* Test regular case where there is the creation of a table, insert of
* data and search for size of the table.
* No servers are killed nor behaves different than expected.
*/
@Test
public
void
testRegularCase
()
{
try
{
Thread
.
sleep
(
1000
);
BFTMap
bftMap
=
new
BFTMap
(
1001
);
bftMap
.
put
(
"TestTable1"
,
new
HashMap
<
String
,
byte
[]>());
bftMap
.
putEntry
(
"TestTable1"
,
"key1"
,
"value1"
.
getBytes
());
assertEquals
(
"Main table size should be 1"
,
1
,
bftMap
.
size1
(
"TestTable1"
));
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
String
key
=
"key"
+
(
2
+
i
);
String
value
=
"value"
+
(
2
+
i
);
bftMap
.
putEntry
(
"TestTable1"
,
key
,
value
.
getBytes
());
}
assertEquals
(
"Main table size should be 101"
,
101
,
bftMap
.
size1
(
"TestTable1"
));
bftMap
.
putEntry
(
"TestTable1"
,
"key102"
,
"value102"
.
getBytes
());
assertEquals
(
"Main table size should be 102"
,
102
,
bftMap
.
size1
(
"TestTable1"
));
}
catch
(
InterruptedException
ie
)
{
System
.
out
.
println
(
"Exception during Thread sleep: "
+
ie
.
getMessage
());
}
}
public
static
void
main
(
String
[]
args
)
{
ConsoleTest
test
=
new
ConsoleTest
();
startServers
();
test
.
testStopAndStartNonLeader
();
try
{
stopServers
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* This test insert and retrieve data.
* During this process a replica that is not the leader is killed.
* After that the replica is started back.
* During the whole process messages keep being sent, to test if
* the application works as expected.
*/
@Test
public
void
testStopAndStartNonLeader
()
{
try
{
Thread
.
sleep
(
1000
);
BFTMap
bftMap
=
new
BFTMap
(
1001
);
bftMap
.
put
(
"TestTable2"
,
new
HashMap
<
String
,
byte
[]>());
for
(
int
i
=
0
;
i
<
65
;
i
++)
{
String
key
=
"key"
+
(
1
+
i
);
String
value
=
"value"
+
(
2
+
i
);
bftMap
.
putEntry
(
"TestTable2"
,
key
,
value
.
getBytes
());
}
System
.
out
.
println
(
"---------Sleep1: "
+
new
java
.
util
.
Date
());
Thread
.
sleep
(
5000
);
System
.
out
.
println
(
"---------Wakeup1: "
+
new
java
.
util
.
Date
());
System
.
out
.
println
(
"---------Killing replica 1"
);
replica1
.
destroy
();
// Killing a non-leader replica, replica1
System
.
out
.
println
(
"---------Sleep2: "
+
new
java
.
util
.
Date
());
Thread
.
sleep
(
5000
);
System
.
out
.
println
(
"---------Wakeup2: "
+
new
java
.
util
.
Date
());
for
(
int
i
=
0
;
i
<
35
;
i
++)
{
String
key
=
"key"
+
(
66
+
i
);
String
value
=
"value"
+
(
66
+
i
);
bftMap
.
putEntry
(
"TestTable2"
,
key
,
value
.
getBytes
());
}
System
.
out
.
println
(
"---------Sleep3: "
+
new
java
.
util
.
Date
());
Thread
.
sleep
(
5000
);
System
.
out
.
println
(
"---------Wakeup3: "
+
new
java
.
util
.
Date
());
command
[
4
]
=
"1"
;
System
.
out
.
println
(
"---------Starting replica 1"
);
replica1
=
new
ProcessBuilder
(
command
).
start
();
// Starting replica1 back
ConsoleLogger
log1
=
new
ConsoleLogger
();
log1
.
setIndex
(
11
);
log1
.
setIn
(
replica1
.
getInputStream
());
log1
.
setOut
(
System
.
out
);
log1
.
start
();
System
.
out
.
println
(
"---------Sleep4: "
+
new
java
.
util
.
Date
());
Thread
.
sleep
(
20000
);
System
.
out
.
println
(
"---------Wakeup4: "
+
new
java
.
util
.
Date
());
for
(
int
i
=
0
;
i
<
35
;
i
++)
{
String
key
=
"key"
+
(
101
+
i
);
String
value
=
"value"
+
(
101
+
i
);
bftMap
.
putEntry
(
"TestTable2"
,
key
,
value
.
getBytes
());
}
System
.
out
.
println
(
"---------Sleep2: "
+
new
java
.
util
.
Date
());
Thread
.
sleep
(
20000
);
System
.
out
.
println
(
"---------Wakeup2: "
+
new
java
.
util
.
Date
());
replica2
.
destroy
();
// Killing another non-leader replica, replica3
for
(
int
i
=
0
;
i
<
35
;
i
++)
{
String
key
=
"key"
+
(
136
+
i
);
String
value
=
"value"
+
(
136
+
i
);
bftMap
.
putEntry
(
"TestTable2"
,
key
,
value
.
getBytes
());
}
System
.
out
.
println
(
"----------Table size:"
+
bftMap
.
size1
(
"TestTable2"
));
}
catch
(
InterruptedException
ie
)
{
System
.
out
.
println
(
"Exception during Thread sleep: "
+
ie
.
getMessage
());
}
catch
(
IOException
ioe
)
{
System
.
out
.
println
(
"Exception when starting replica 2: "
+
ioe
.
getMessage
());
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录