Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
9292e5c4
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,发现更多精彩内容 >>
提交
9292e5c4
编写于
9月 07, 2015
作者:
S
Stephan Ewen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-2626] [core] Minor cleanups in AverageAccumulator and AverageAccumulatorTest
上级
2f8bcf53
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
18 deletion
+25
-18
flink-core/src/main/java/org/apache/flink/api/common/accumulators/AverageAccumulator.java
...che/flink/api/common/accumulators/AverageAccumulator.java
+6
-4
flink-core/src/test/java/org/apache/flink/api/common/accumulators/AverageAccumulatorTest.java
...flink/api/common/accumulators/AverageAccumulatorTest.java
+19
-14
未找到文件。
flink-core/src/main/java/org/apache/flink/api/common/accumulators/AverageAccumulator.java
浏览文件 @
9292e5c4
...
...
@@ -22,10 +22,12 @@ package org.apache.flink.api.common.accumulators;
* An accumulator that get the average values.
* Input can be {@code long}, {@code integer}, {@code double} as the result is {@code double}.
*/
public
class
AverageAccumulator
implements
SimpleAccumulator
<
Double
>
{
public
class
AverageAccumulator
implements
SimpleAccumulator
<
Double
>
{
private
double
localValue
=
0
;
private
long
count
=
0
;
private
static
final
long
serialVersionUID
=
3672555084179165255L
;
private
double
localValue
;
private
long
count
;
@Override
public
void
add
(
Double
value
)
{
...
...
@@ -69,7 +71,7 @@ public class AverageAccumulator implements SimpleAccumulator <Double> {
this
.
count
+=
temp
.
count
;
this
.
localValue
+=
other
.
getLocalValue
();
}
else
{
throw
new
Runtime
Exception
(
"The merged accumulator must be AverageAccumulator."
);
throw
new
IllegalArgument
Exception
(
"The merged accumulator must be AverageAccumulator."
);
}
}
...
...
flink-core/src/test/java/org/apache/flink/api/common/accumulators/AverageAccumulatorTest.java
浏览文件 @
9292e5c4
...
...
@@ -21,6 +21,7 @@ package org.apache.flink.api.common.accumulators;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
...
...
@@ -29,7 +30,7 @@ public class AverageAccumulatorTest {
@Test
public
void
testGet
()
{
AverageAccumulator
average
=
new
AverageAccumulator
();
assertEquals
(
Double
.
valueOf
(
0
),
average
.
getLocalValue
()
);
assertEquals
(
0.0
,
average
.
getLocalValue
(),
0.0
);
}
@Test
...
...
@@ -39,45 +40,45 @@ public class AverageAccumulatorTest {
for
(
i1
=
0
;
i1
<
10
;
i1
++)
{
average
.
add
(
i1
);
}
assertEquals
(
Double
.
valueOf
(
4.5
),
average
.
getLocalValue
()
);
assertEquals
(
4.5
,
average
.
getLocalValue
(),
0.0
);
average
.
resetLocal
();
Integer
i2
;
for
(
i2
=
0
;
i2
<
10
;
i2
++)
{
average
.
add
(
i2
);
}
assertEquals
(
Double
.
valueOf
(
4.5
),
average
.
getLocalValue
()
);
assertEquals
(
4.5
,
average
.
getLocalValue
(),
0.0
);
average
.
resetLocal
();
long
i3
;
for
(
i3
=
0
;
i3
<
10
;
i3
++)
{
average
.
add
(
i3
);
}
assertEquals
(
Double
.
valueOf
(
4.5
),
average
.
getLocalValue
()
);
assertEquals
(
4.5
,
average
.
getLocalValue
(),
0.0
);
average
.
resetLocal
();
Long
i4
;
for
(
i4
=
0L
;
i4
<
10
;
i4
++)
{
average
.
add
(
i4
);
}
assertEquals
(
Double
.
valueOf
(
4.5
),
average
.
getLocalValue
()
);
assertEquals
(
4.5
,
average
.
getLocalValue
(),
0.0
);
average
.
resetLocal
();
double
i5
;
for
(
i5
=
0
;
i5
<
10
;
i5
++)
{
average
.
add
(
i5
);
}
assertEquals
(
Double
.
valueOf
(
4.5
),
average
.
getLocalValue
()
);
assertEquals
(
4.5
,
average
.
getLocalValue
(),
0.0
);
average
.
resetLocal
();
Double
i6
;
for
(
i6
=
0.0
;
i6
<
10
;
i6
++)
{
average
.
add
(
i6
);
}
assertEquals
(
Double
.
valueOf
(
4.5
),
average
.
getLocalValue
()
);
assertEquals
(
4.5
,
average
.
getLocalValue
(),
0.0
);
average
.
resetLocal
();
assertEquals
(
Double
.
valueOf
(
0
),
average
.
getLocalValue
()
);
assertEquals
(
0.0
,
average
.
getLocalValue
(),
0.0
);
}
@Test
...
...
@@ -87,7 +88,7 @@ public class AverageAccumulatorTest {
average
.
add
(
1
);
averageNew
.
add
(
2
);
average
.
merge
(
averageNew
);
assertEquals
(
Double
.
valueOf
(
1.5
),
average
.
getLocalValue
()
);
assertEquals
(
1.5
,
average
.
getLocalValue
(),
0.0
);
}
@Test
...
...
@@ -97,11 +98,15 @@ public class AverageAccumulatorTest {
average
.
add
(
1
);
try
{
average
.
merge
(
averageNew
);
}
catch
(
Exception
e
)
{
assertTrue
(
e
.
toString
().
indexOf
(
"The merged accumulator must be AverageAccumulator."
)
!=
-
1
);
return
;
fail
(
"should fail with an exception"
);
}
catch
(
IllegalArgumentException
e
)
{
assertNotNull
(
e
.
getMessage
());
assertTrue
(
e
.
getMessage
().
contains
(
"The merged accumulator must be AverageAccumulator."
));
}
catch
(
Throwable
t
)
{
fail
(
"wrong exception; expected IllegalArgumentException but found "
+
t
.
getClass
().
getName
());
}
fail
();
}
@Test
...
...
@@ -109,6 +114,6 @@ public class AverageAccumulatorTest {
AverageAccumulator
average
=
new
AverageAccumulator
();
average
.
add
(
1
);
AverageAccumulator
averageNew
=
average
.
clone
();
assertEquals
(
Double
.
valueOf
(
1
),
averageNew
.
getLocalValue
()
);
assertEquals
(
1
,
averageNew
.
getLocalValue
(),
0.0
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录