Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
409ea231
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,发现更多精彩内容 >>
提交
409ea231
编写于
12月 04, 2017
作者:
P
Piotr Nowojski
提交者:
Stefan Richter
1月 08, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[hotfix][network-tests] Simplify TestPooledBufferProvider
上级
91c72b9d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
45 deletion
+22
-45
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/util/TestBufferFactory.java
...ache/flink/runtime/io/network/util/TestBufferFactory.java
+14
-21
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/util/TestPooledBufferProvider.java
...ink/runtime/io/network/util/TestPooledBufferProvider.java
+8
-24
未找到文件。
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/util/TestBufferFactory.java
浏览文件 @
409ea231
...
@@ -18,18 +18,17 @@
...
@@ -18,18 +18,17 @@
package
org.apache.flink.runtime.io.network.util
;
package
org.apache.flink.runtime.io.network.util
;
import
org.apache.flink.core.memory.HeapMemorySegment
;
import
org.apache.flink.core.memory.MemorySegment
;
import
org.apache.flink.core.memory.MemorySegmentFactory
;
import
org.apache.flink.core.memory.MemorySegmentFactory
;
import
org.apache.flink.runtime.io.network.buffer.Buffer
;
import
org.apache.flink.runtime.io.network.buffer.Buffer
;
import
org.apache.flink.runtime.io.network.buffer.BufferRecycler
;
import
org.apache.flink.runtime.io.network.buffer.BufferRecycler
;
import
org.apache.flink.runtime.testutils.DiscardingRecycler
;
import
org.apache.flink.runtime.testutils.DiscardingRecycler
;
import
java
.util.concurrent.atomic.AtomicInteger
;
import
java
x.annotation.concurrent.ThreadSafe
;
import
static
org
.
apache
.
flink
.
util
.
Preconditions
.
checkArgument
;
import
static
org
.
apache
.
flink
.
util
.
Preconditions
.
checkArgument
;
import
static
org
.
apache
.
flink
.
util
.
Preconditions
.
checkNotNull
;
import
static
org
.
apache
.
flink
.
util
.
Preconditions
.
checkNotNull
;
@ThreadSafe
public
class
TestBufferFactory
{
public
class
TestBufferFactory
{
public
static
final
int
BUFFER_SIZE
=
32
*
1024
;
public
static
final
int
BUFFER_SIZE
=
32
*
1024
;
...
@@ -40,37 +39,31 @@ public class TestBufferFactory {
...
@@ -40,37 +39,31 @@ public class TestBufferFactory {
private
final
BufferRecycler
bufferRecycler
;
private
final
BufferRecycler
bufferRecycler
;
private
AtomicInteger
numberOfCreatedBuffers
=
new
AtomicInteger
()
;
private
final
int
poolSize
;
public
TestBufferFactory
()
{
private
int
numberOfCreatedBuffers
=
0
;
this
(
BUFFER_SIZE
,
RECYCLER
);
}
public
TestBufferFactory
(
int
bufferSize
)
{
this
(
bufferSize
,
RECYCLER
);
}
public
TestBufferFactory
(
int
bufferSize
,
BufferRecycler
bufferRecycler
)
{
public
TestBufferFactory
(
int
poolSize
,
int
bufferSize
,
BufferRecycler
bufferRecycler
)
{
checkArgument
(
bufferSize
>
0
);
checkArgument
(
bufferSize
>
0
);
this
.
poolSize
=
poolSize
;
this
.
bufferSize
=
bufferSize
;
this
.
bufferSize
=
bufferSize
;
this
.
bufferRecycler
=
checkNotNull
(
bufferRecycler
);
this
.
bufferRecycler
=
checkNotNull
(
bufferRecycler
);
}
}
public
Buffer
create
()
{
public
synchronized
Buffer
create
()
{
numberOfCreatedBuffers
.
incrementAndGet
();
if
(
numberOfCreatedBuffers
>=
poolSize
)
{
return
null
;
}
numberOfCreatedBuffers
++;
return
new
Buffer
(
MemorySegmentFactory
.
allocateUnpooledSegment
(
bufferSize
),
bufferRecycler
);
return
new
Buffer
(
MemorySegmentFactory
.
allocateUnpooledSegment
(
bufferSize
),
bufferRecycler
);
}
}
public
Buffer
createFrom
(
MemorySegment
segment
)
{
public
synchronized
int
getNumberOfCreatedBuffers
()
{
return
new
Buffer
(
segment
,
bufferRecycler
);
return
numberOfCreatedBuffers
;
}
public
int
getNumberOfCreatedBuffers
()
{
return
numberOfCreatedBuffers
.
get
();
}
}
public
int
getBufferSize
()
{
public
synchronized
int
getBufferSize
()
{
return
bufferSize
;
return
bufferSize
;
}
}
...
...
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/util/TestPooledBufferProvider.java
浏览文件 @
409ea231
...
@@ -36,58 +36,42 @@ import static org.apache.flink.util.Preconditions.checkArgument;
...
@@ -36,58 +36,42 @@ import static org.apache.flink.util.Preconditions.checkArgument;
public
class
TestPooledBufferProvider
implements
BufferProvider
{
public
class
TestPooledBufferProvider
implements
BufferProvider
{
private
final
Object
bufferCreationLock
=
new
Object
();
private
final
BlockingQueue
<
Buffer
>
buffers
=
new
LinkedBlockingDeque
<>();
private
final
BlockingQueue
<
Buffer
>
buffers
=
new
LinkedBlockingDeque
<>();
private
final
TestBufferFactory
bufferFactory
;
private
final
TestBufferFactory
bufferFactory
;
private
final
PooledBufferProviderRecycler
bufferRecycler
;
private
final
PooledBufferProviderRecycler
bufferRecycler
;
private
final
int
poolSize
;
public
TestPooledBufferProvider
(
int
poolSize
)
{
public
TestPooledBufferProvider
(
int
poolSize
)
{
checkArgument
(
poolSize
>
0
);
checkArgument
(
poolSize
>
0
);
this
.
poolSize
=
poolSize
;
this
.
bufferRecycler
=
new
PooledBufferProviderRecycler
(
buffers
);
this
.
bufferRecycler
=
new
PooledBufferProviderRecycler
(
buffers
);
this
.
bufferFactory
=
new
TestBufferFactory
(
32
*
1024
,
bufferRecycler
);
this
.
bufferFactory
=
new
TestBufferFactory
(
poolSize
,
32
*
1024
,
bufferRecycler
);
}
}
@Override
@Override
public
Buffer
requestBuffer
()
throws
IOException
{
public
Buffer
requestBuffer
()
throws
IOException
{
final
Buffer
buffer
=
buffers
.
poll
();
final
Buffer
buffer
=
buffers
.
poll
();
if
(
buffer
!=
null
)
{
if
(
buffer
!=
null
)
{
return
buffer
;
return
buffer
;
}
}
else
{
synchronized
(
bufferCreationLock
)
{
if
(
bufferFactory
.
getNumberOfCreatedBuffers
()
<
poolSize
)
{
return
bufferFactory
.
create
();
}
}
return
null
;
return
bufferFactory
.
create
();
}
}
}
@Override
@Override
public
Buffer
requestBufferBlocking
()
throws
IOException
,
InterruptedException
{
public
Buffer
requestBufferBlocking
()
throws
IOException
,
InterruptedException
{
final
Buffer
buffer
=
buffers
.
poll
();
Buffer
buffer
=
buffers
.
poll
();
if
(
buffer
!=
null
)
{
if
(
buffer
!=
null
)
{
return
buffer
;
return
buffer
;
}
}
else
{
synchronized
(
bufferCreationLock
)
{
if
(
bufferFactory
.
getNumberOfCreatedBuffers
()
<
poolSize
)
{
return
bufferFactory
.
create
();
}
}
return
buffers
.
take
();
buffer
=
bufferFactory
.
create
();
if
(
buffer
!=
null
)
{
return
buffer
;
}
}
return
buffers
.
take
();
}
}
@Override
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录