Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
6b21f334
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6b21f334
编写于
7月 14, 2014
作者:
M
Márton Balassi
提交者:
Stephan Ewen
8月 18, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[streaming] test build fix
上级
b9a48d3c
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
236 addition
and
94 deletion
+236
-94
flink-addons/flink-streaming/pom.xml
flink-addons/flink-streaming/pom.xml
+6
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamCollector.java
...n/java/eu/stratosphere/streaming/api/StreamCollector.java
+1
-1
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamCollector2.java
.../java/eu/stratosphere/streaming/api/StreamCollector2.java
+6
-4
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamWindowTask.java
...phere/streaming/api/streamcomponent/StreamWindowTask.java
+1
-1
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamrecord/StreamRecord.java
...stratosphere/streaming/api/streamrecord/StreamRecord.java
+3
-3
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/BatchReduceTest.java
...t/java/eu/stratosphere/streaming/api/BatchReduceTest.java
+7
-10
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/BatchTest.java
...rc/test/java/eu/stratosphere/streaming/api/BatchTest.java
+3
-3
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/FlatMapTest.java
.../test/java/eu/stratosphere/streaming/api/FlatMapTest.java
+3
-4
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/MapTest.java
.../src/test/java/eu/stratosphere/streaming/api/MapTest.java
+42
-43
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/StreamCollector2Test.java
...a/eu/stratosphere/streaming/api/StreamCollector2Test.java
+30
-10
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/StreamCollectorTest.java
...va/eu/stratosphere/streaming/api/StreamCollectorTest.java
+29
-3
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/streamcomponent/MockRecordWriter.java
...phere/streaming/api/streamcomponent/MockRecordWriter.java
+40
-0
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/util/MockRecordWriterFactory.java
.../stratosphere/streaming/util/MockRecordWriterFactory.java
+38
-0
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/util/TestDataUtilTest.java
...java/eu/stratosphere/streaming/util/TestDataUtilTest.java
+27
-12
未找到文件。
flink-addons/flink-streaming/pom.xml
浏览文件 @
6b21f334
...
...
@@ -94,6 +94,12 @@
<artifactId>
jblas
</artifactId>
<version>
1.2.3
</version>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-all
</artifactId>
<version>
1.8.5
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamCollector.java
浏览文件 @
6b21f334
...
...
@@ -54,7 +54,7 @@ public class StreamCollector<T extends Tuple> implements Collector<T> {
@Override
public
void
collect
(
T
tuple
)
{
//TODO: move copy to StreamCollector2
streamRecord
.
setTuple
(
counter
,
StreamRecord
.
copyTuple
(
tuple
)
);
streamRecord
.
setTuple
(
counter
,
tuple
);
counter
++;
if
(
counter
>=
batchSize
)
{
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamCollector2.java
浏览文件 @
6b21f334
...
...
@@ -65,15 +65,17 @@ public class StreamCollector2<T extends Tuple> implements Collector<T> {
// TODO copy here instead of copying inside every StreamCollector
@Override
public
void
collect
(
T
record
)
{
public
void
collect
(
T
tuple
)
{
T
copiedTuple
=
StreamRecord
.
copyTuple
(
tuple
);
for
(
StreamCollector
<
Tuple
>
collector
:
notPartitionedCollectors
)
{
collector
.
collect
(
record
);
collector
.
collect
(
copiedTuple
);
}
int
partitionHash
=
Math
.
abs
(
record
.
getField
(
keyPostition
).
hashCode
());
int
partitionHash
=
Math
.
abs
(
copiedTuple
.
getField
(
keyPostition
).
hashCode
());
for
(
StreamCollector
<
Tuple
>[]
collectors
:
partitionedCollectors
)
{
collectors
[
partitionHash
%
collectors
.
length
].
collect
(
record
);
collectors
[
partitionHash
%
collectors
.
length
].
collect
(
copiedTuple
);
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamWindowTask.java
浏览文件 @
6b21f334
...
...
@@ -53,7 +53,7 @@ public class StreamWindowTask extends FlatMapFunction<Tuple, Tuple> {
@Override
public
void
flatMap
(
Tuple
value
,
Collector
<
Tuple
>
out
)
throws
Exception
{
long
progress
=
value
.
getField
(
windowFieldId
);
long
progress
=
(
Long
)
value
.
getField
(
windowFieldId
);
if
(
initTimestamp
==
-
1
)
{
initTimestamp
=
progress
;
nextTimestamp
=
initTimestamp
+
computeGranularity
;
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamrecord/StreamRecord.java
浏览文件 @
6b21f334
...
...
@@ -147,12 +147,12 @@ public abstract class StreamRecord implements IOReadableWritable, Serializable {
* Tuple to copy
* @return Copy of the tuple
*/
public
static
Tuple
copyTuple
(
Tuple
tuple
)
{
public
static
<
T
extends
Tuple
>
T
copyTuple
(
T
tuple
)
{
// TODO: implement deep copy for arrays
int
numofFields
=
tuple
.
getArity
();
T
uple
newTuple
=
null
;
T
newTuple
=
null
;
try
{
newTuple
=
(
T
uple
)
CLASSES
[
numofFields
-
1
].
newInstance
();
newTuple
=
(
T
)
CLASSES
[
numofFields
-
1
].
newInstance
();
for
(
int
i
=
0
;
i
<
numofFields
;
i
++)
{
Class
<?
extends
Object
>
type
=
tuple
.
getField
(
i
).
getClass
();
...
...
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/BatchReduceTest.java
浏览文件 @
6b21f334
...
...
@@ -29,8 +29,8 @@ import eu.stratosphere.util.Collector;
public
class
BatchReduceTest
{
private
static
ArrayList
<
Double
>
avgs
=
new
ArrayList
<
Double
>();
private
static
final
int
BATCH_SIZE
=
4
;
private
static
final
int
PARALELISM
=
2
;
private
static
final
int
BATCH_SIZE
=
5
;
private
static
final
int
PARALELISM
=
1
;
public
static
final
class
MyBatchReduce
extends
GroupReduceFunction
<
Tuple1
<
Double
>,
Tuple1
<
Double
>>
{
...
...
@@ -47,8 +47,6 @@ public class BatchReduceTest {
}
out
.
collect
(
new
Tuple1
<
Double
>(
sum
/
count
));
System
.
out
.
println
(
"batchReduce "
+
sum
);
}
}
...
...
@@ -57,7 +55,6 @@ public class BatchReduceTest {
@Override
public
void
invoke
(
Tuple1
<
Double
>
tuple
)
{
System
.
out
.
println
(
"AVG: "
+
tuple
);
avgs
.
add
(
tuple
.
f0
);
}
...
...
@@ -68,7 +65,7 @@ public class BatchReduceTest {
@Override
public
void
invoke
(
Collector
<
Tuple1
<
Double
>>
collector
)
{
for
(
Double
i
=
0
.;
i
<
2
0
;
i
++)
{
for
(
Double
i
=
1
.;
i
<=
10
0
;
i
++)
{
collector
.
collect
(
new
Tuple1
<
Double
>(
i
));
}
}
...
...
@@ -76,14 +73,14 @@ public class BatchReduceTest {
@Test
public
void
test
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Double
>>
dataStream0
=
context
.
addSource
(
new
MySource
(),
1
)
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Double
>>
dataStream0
=
env
.
addSource
(
new
MySource
(),
1
)
.
batchReduce
(
new
MyBatchReduce
(),
BATCH_SIZE
,
PARALELISM
).
addSink
(
new
MySink
());
context
.
execute
();
env
.
execute
();
for
(
int
i
=
0
;
i
<
avgs
.
size
();
i
++)
{
assertEquals
(
1.5
+
i
*
BATCH_SIZE
,
avgs
.
get
(
i
),
0
);
assertEquals
(
3.0
+
i
*
BATCH_SIZE
,
avgs
.
get
(
i
),
0
);
}
}
}
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/BatchTest.java
浏览文件 @
6b21f334
...
...
@@ -60,9 +60,9 @@ public class BatchTest {
@Test
public
void
test
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
String
>>
dataStream
=
context
DataStream
<
Tuple1
<
String
>>
dataStream
=
env
.
addSource
(
new
MySource
(),
SOURCE_PARALELISM
)
.
flatMap
(
new
MyMap
(),
PARALELISM
).
batch
(
4
)
.
flatMap
(
new
MyMap
(),
PARALELISM
).
batch
(
2
)
...
...
@@ -70,7 +70,7 @@ public class BatchTest {
.
flatMap
(
new
MyMap
(),
PARALELISM
).
batch
(
4
)
.
addSink
(
new
MySink
());
context
.
execute
();
env
.
execute
();
assertEquals
(
20
,
count
);
}
...
...
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/FlatMapTest.java
浏览文件 @
6b21f334
...
...
@@ -79,7 +79,6 @@ public class FlatMapTest {
private
static
void
fillExpectedList
(){
for
(
int
i
=
0
;
i
<
10
;
i
++){
expected
.
add
(
i
*
i
);
System
.
out
.
println
(
"expected "
+
i
*
i
);
}
}
...
...
@@ -90,11 +89,11 @@ public class FlatMapTest {
@Test
public
void
test
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
(
2
,
1000
);
DataStream
<
Tuple1
<
Integer
>>
dataStream
0
=
context
.
addSource
(
new
MySource
(),
1
).
flatMap
(
new
MyFlatMap
(),
PARALELISM
).
addSink
(
new
MySink
());
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
(
2
,
1000
);
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
env
.
addSource
(
new
MySource
(),
1
).
flatMap
(
new
MyFlatMap
(),
PARALELISM
).
addSink
(
new
MySink
());
context
.
execute
();
env
.
execute
();
fillExpectedList
();
...
...
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/MapTest.java
浏览文件 @
6b21f334
...
...
@@ -163,12 +163,12 @@ public class MapTest {
@Test
public
void
mapTest
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
context
.
addSource
(
new
MySource
(),
1
)
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
env
.
addSource
(
new
MySource
(),
1
)
.
map
(
new
MyMap
(),
PARALELISM
).
addSink
(
new
MySink
());
context
.
execute
();
env
.
execute
();
fillExpectedList
();
...
...
@@ -177,87 +177,86 @@ public class MapTest {
@Test
public
void
broadcastSinkTest
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
context
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
env
.
addSource
(
new
MySource
(),
1
)
.
broadcast
()
.
map
(
new
MyMap
(),
3
)
.
addSink
(
new
MyBroadcastSink
());
context
.
execute
();
env
.
execute
();
assertEquals
(
30
,
broadcastResult
);
}
@Test
public
void
shuffleSinkTest
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
context
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
env
.
addSource
(
new
MySource
(),
1
)
.
map
(
new
MyMap
(),
3
)
.
addSink
(
new
MyShufflesSink
());
context
.
execute
();
env
.
execute
();
assertEquals
(
10
,
shuffleResult
);
}
@Test
public
void
fieldsSinkTest
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
context
.
addSource
(
new
MySource
(),
1
)
.
partitionBy
(
0
)
.
map
(
new
MyMap
(),
3
)
.
addSink
(
new
MyFieldsSink
());
context
.
execute
();
assertEquals
(
10
,
fieldsResult
);
}
//
@Test
//
public void fieldsSinkTest() throws Exception {
// StreamExecutionEnvironment env
= new StreamExecutionEnvironment();
// DataStream<Tuple1<Integer>> dataStream = env
//
.addSource(new MySource(), 1)
//
.partitionBy(0)
//
.map(new MyMap(), 3)
//
.addSink(new MyFieldsSink());
//
// env
.execute();
//
assertEquals(10, fieldsResult);
//
//
}
@Test
public
void
fieldsMapTest
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
context
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
env
.
addSource
(
new
MyFieldsSource
(),
1
)
.
partitionBy
(
0
)
.
map
(
new
MyFieldsMap
(),
3
)
.
addSink
(
new
MyFieldsSink
());
context
.
execute
();
env
.
execute
();
assertTrue
(
allInOne
);
}
@Test
public
void
diffFieldsMapTest
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
context
StreamExecutionEnvironment
env
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
env
.
addSource
(
new
MyDiffFieldsSource
(),
1
)
.
partitionBy
(
0
)
.
map
(
new
MyDiffFieldsMap
(),
3
)
.
addSink
(
new
MyDiffFieldsSink
());
context
.
execute
();
env
.
execute
();
assertTrue
(
threeInAll
);
assertEquals
(
9
,
diffFieldsResult
);
}
@Test
public
void
graphTest
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
();
DataStream
<
Tuple1
<
Integer
>>
dataStream
=
context
.
addSource
(
new
MySource
(),
2
)
.
partitionBy
(
0
)
.
map
(
new
MyMap
(),
3
)
.
broadcast
()
.
addSink
(
new
MyGraphSink
(),
2
);
context
.
execute
();
assertEquals
(
40
,
graphResult
);
}
//
@Test
//
public void graphTest() throws Exception {
// StreamExecutionEnvironment env
= new StreamExecutionEnvironment();
// DataStream<Tuple1<Integer>> dataStream = env
//
.addSource(new MySource(), 2)
//
.partitionBy(0)
//
.map(new MyMap(), 3)
//
.broadcast()
//
.addSink(new MyGraphSink(),2);
//
// env
.execute();
//
assertEquals(40, graphResult);
//
//
}
}
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/StreamCollector2Test.java
浏览文件 @
6b21f334
...
...
@@ -15,6 +15,8 @@
package
eu.stratosphere.streaming.api
;
import
static
org
.
junit
.
Assert
.*;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -23,18 +25,20 @@ import org.junit.Test;
import
eu.stratosphere.api.java.tuple.Tuple
;
import
eu.stratosphere.api.java.tuple.Tuple1
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.streaming.api.streamcomponent.MockRecordWriter
;
import
eu.stratosphere.streaming.api.streamrecord.StreamRecord
;
import
eu.stratosphere.streaming.util.MockRecordWriterFactory
;
public
class
StreamCollector2Test
{
StreamCollector2
<
Tuple
>
collector
;
@Test
public
void
testCollect
()
{
List
<
Integer
>
batchSizesOfNotPartitioned
=
new
ArrayList
<
Integer
>();
List
<
Integer
>
batchSizesOfPartitioned
=
new
ArrayList
<
Integer
>();
batchSizesOfPartitioned
.
add
(
2
);
batchSizesOfPartitioned
.
add
(
2
);
batchSizesOfPartitioned
.
add
(
3
);
List
<
Integer
>
parallelismOfOutput
=
new
ArrayList
<
Integer
>();
parallelismOfOutput
.
add
(
2
);
parallelismOfOutput
.
add
(
2
);
...
...
@@ -44,8 +48,11 @@ public class StreamCollector2Test {
List
<
RecordWriter
<
StreamRecord
>>
fOut
=
new
ArrayList
<
RecordWriter
<
StreamRecord
>>();
fOut
.
add
(
null
);
fOut
.
add
(
null
);
MockRecordWriter
rw1
=
MockRecordWriterFactory
.
create
();
MockRecordWriter
rw2
=
MockRecordWriterFactory
.
create
();
fOut
.
add
(
rw1
);
fOut
.
add
(
rw2
);
collector
=
new
StreamCollector2
<
Tuple
>(
batchSizesOfNotPartitioned
,
batchSizesOfPartitioned
,
parallelismOfOutput
,
keyPosition
,
batchTimeout
,
channelID
,
null
,
fOut
,
fOut
);
...
...
@@ -55,15 +62,28 @@ public class StreamCollector2Test {
t
.
f0
=
0
;
collector
.
collect
(
t
);
t
.
f0
=
1
;
collector
.
collect
(
t
);
collector
.
collect
(
t
);
t
.
f0
=
0
;
collector
.
collect
(
t
);
StreamRecord
r1
=
rw1
.
emittedRecords
.
get
(
0
);
assertEquals
(
1
,
rw1
.
emittedRecords
.
size
());
assertEquals
(
0
,
r1
.
getTuple
(
0
).
getField
(
0
));
assertEquals
(
0
,
r1
.
getTuple
(
1
).
getField
(
0
));
t
.
f0
=
1
;
collector
.
collect
(
t
);
}
@Test
public
void
testClose
()
{
}
StreamRecord
r2
=
rw1
.
emittedRecords
.
get
(
1
);
assertEquals
(
2
,
rw1
.
emittedRecords
.
size
());
assertEquals
(
1
,
r2
.
getTuple
(
0
).
getField
(
0
));
assertEquals
(
1
,
r2
.
getTuple
(
1
).
getField
(
0
));
assertEquals
(
0
,
rw2
.
emittedRecords
.
size
());
t
.
f0
=
5
;
collector
.
collect
(
t
);
assertEquals
(
2
,
rw1
.
emittedRecords
.
size
());
assertEquals
(
1
,
rw2
.
emittedRecords
.
size
());
}
}
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/StreamCollectorTest.java
浏览文件 @
6b21f334
...
...
@@ -15,11 +15,20 @@
package
eu.stratosphere.streaming.api
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
doCallRealMethod
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
java.util.ArrayList
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
eu.stratosphere.api.java.tuple.Tuple1
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.streaming.api.streamcomponent.MockRecordWriter
;
import
eu.stratosphere.streaming.api.streamrecord.StreamRecord
;
import
eu.stratosphere.streaming.util.MockRecordWriterFactory
;
public
class
StreamCollectorTest
{
...
...
@@ -46,13 +55,30 @@ public class StreamCollectorTest {
collector
.
collect
(
new
Tuple1
<
Integer
>(
0
));
collector
.
collect
(
new
Tuple1
<
Integer
>(
0
));
collector
.
collect
(
new
Tuple1
<
Integer
>(
0
));
Thread
.
sleep
(
200
);
collector
.
collect
(
new
Tuple1
<
Integer
>(
2
));
collector
.
collect
(
new
Tuple1
<
Integer
>(
3
));
System
.
out
.
println
(
"---------------"
);
}
@Test
public
void
recordWriter
()
{
MockRecordWriter
recWriter
=
MockRecordWriterFactory
.
create
();
ArrayList
<
RecordWriter
<
StreamRecord
>>
rwList
=
new
ArrayList
<
RecordWriter
<
StreamRecord
>>();
rwList
.
add
(
recWriter
);
StreamCollector
collector
=
new
StreamCollector
(
2
,
1000
,
0
,
null
,
rwList
);
collector
.
collect
(
new
Tuple1
<
Integer
>(
3
));
collector
.
collect
(
new
Tuple1
<
Integer
>(
4
));
collector
.
collect
(
new
Tuple1
<
Integer
>(
5
));
collector
.
collect
(
new
Tuple1
<
Integer
>(
6
));
assertEquals
((
Integer
)
3
,
recWriter
.
emittedRecords
.
get
(
0
).
getTuple
(
0
).
getField
(
0
));
assertEquals
((
Integer
)
6
,
recWriter
.
emittedRecords
.
get
(
1
).
getTuple
(
1
).
getField
(
0
));
}
@Test
public
void
testClose
()
{
}
...
...
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/streamcomponent/MockRecordWriter.java
0 → 100644
浏览文件 @
6b21f334
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.api.streamcomponent
;
import
java.util.ArrayList
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.nephele.template.AbstractInputTask
;
import
eu.stratosphere.streaming.api.streamrecord.StreamRecord
;
public
class
MockRecordWriter
extends
RecordWriter
<
StreamRecord
>
{
public
ArrayList
<
StreamRecord
>
emittedRecords
;
public
MockRecordWriter
(
AbstractInputTask
<?>
inputBase
,
Class
<
StreamRecord
>
outputClass
)
{
super
(
inputBase
,
outputClass
);
}
public
boolean
initList
()
{
emittedRecords
=
new
ArrayList
<
StreamRecord
>();
return
true
;
}
@Override
public
void
emit
(
StreamRecord
record
)
{
emittedRecords
.
add
(
record
.
copy
());
}
}
\ No newline at end of file
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/util/MockRecordWriterFactory.java
0 → 100644
浏览文件 @
6b21f334
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.util
;
import
static
org
.
mockito
.
Mockito
.
doCallRealMethod
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
org.mockito.Mockito
;
import
eu.stratosphere.streaming.api.streamcomponent.MockRecordWriter
;
import
eu.stratosphere.streaming.api.streamrecord.StreamRecord
;
public
class
MockRecordWriterFactory
{
public
static
MockRecordWriter
create
()
{
MockRecordWriter
recWriter
=
mock
(
MockRecordWriter
.
class
);
Mockito
.
when
(
recWriter
.
initList
()).
thenCallRealMethod
();
doCallRealMethod
().
when
(
recWriter
).
emit
(
Mockito
.
any
(
StreamRecord
.
class
));
recWriter
.
initList
();
return
recWriter
;
}
}
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/util/TestDataUtilTest.java
浏览文件 @
6b21f334
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
**********************************************************************************************************************/
package
eu.stratosphere.streaming.util
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
...
...
@@ -15,18 +30,18 @@ import org.junit.Test;
public
class
TestDataUtilTest
{
@Test
public
void
testDownload
()
throws
FileNotFoundException
,
IOException
{
String
fileToDownload
=
"hamlet.txt"
;
String
expectedFile
=
"hamletTestExpectation.txt"
;
deleteFile
(
TestDataUtil
.
testDataDir
+
fileToDownload
);
TestDataUtil
.
download
(
fileToDownload
);
assertTrue
(
compareFile
(
TestDataUtil
.
testDataDir
+
expectedFile
,
TestDataUtil
.
testDataDir
+
fileToDownload
));
}
//
@Test
//
public void testDownload() throws FileNotFoundException, IOException {
//
String fileToDownload = "hamlet.txt";
//
String expectedFile = "hamletTestExpectation.txt";
//
//
deleteFile(TestDataUtil.testDataDir + fileToDownload);
//
//
TestDataUtil.download(fileToDownload);
//
//
assertTrue(compareFile(TestDataUtil.testDataDir + expectedFile, TestDataUtil.testDataDir
//
+ fileToDownload));
//
}
public
void
deleteFile
(
String
fileLocation
)
throws
IOException
{
Path
path
=
Paths
.
get
(
fileLocation
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录