Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
transmittable-thread-local
提交
b7c6038c
T
transmittable-thread-local
项目概览
阿啄debugIT
/
transmittable-thread-local
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
transmittable-thread-local
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b7c6038c
编写于
12月 10, 2018
作者:
R
rybalkinsd
提交者:
oldratlee
1月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ttl runnable ext
上级
4c9d909e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
110 addition
and
0 deletion
+110
-0
src/main/java/com/alibaba/ttl/TtlRunnableExt.kt
src/main/java/com/alibaba/ttl/TtlRunnableExt.kt
+60
-0
src/test/java/com/alibaba/ttl/TtlCallableExtKtTest.kt
src/test/java/com/alibaba/ttl/TtlCallableExtKtTest.kt
+6
-0
src/test/java/com/alibaba/ttl/TtlRunnableExtKtTest.kt
src/test/java/com/alibaba/ttl/TtlRunnableExtKtTest.kt
+44
-0
未找到文件。
src/main/java/com/alibaba/ttl/TtlRunnableExt.kt
0 → 100644
浏览文件 @
b7c6038c
package
com.alibaba.ttl
/**
* Extension function wrap {@link Runnable} into {@link TtlRunnable}.
* <p>
*
* @param releaseTtlValueReferenceAfterRun release TTL value reference after run, avoid memory leak even if {@link TtlRunnable} is referred.
* @param idempotent is idempotent mode or not. if {@code true}, just return input {@link Runnable} when it's {@link TtlRunnable},
* otherwise throw {@link IllegalStateException}.
* <B><I>Caution</I></B>: {@code true} will cover up bugs! <b>DO NOT</b> set, only when you know why.
* @return Wrapped {@link Runnable}
*
* * @since TODO
*/
fun
Runnable
.
wrap
(
releaseTtlValueReferenceAfterRun
:
Boolean
=
false
,
idempotent
:
Boolean
=
false
):
TtlRunnable
=
TtlRunnable
.
get
(
this
,
releaseTtlValueReferenceAfterRun
,
idempotent
)
!!
/**
* Extension function wrap input {@link Runnable} Collection to {@link TtlRunnable} Collection.
*
* @param releaseTtlValueReferenceAfterRun release TTL value reference after run, avoid memory leak even if {@link TtlRunnable} is referred.
* @param idempotent is idempotent mode or not. if {@code true}, just return input {@link Runnable} when it's {@link TtlRunnable},
* otherwise throw {@link IllegalStateException}.
* <B><I>Caution</I></B>: {@code true} will cover up bugs! <b>DO NOT</b> set, only when you know why.
* @return Wrapped list of {@link Runnable}
*
* @see #Runnable::wrap
* @since TODO
*/
fun
List
<
Runnable
>.
wrap
(
releaseTtlValueReferenceAfterRun
:
Boolean
=
false
,
idempotent
:
Boolean
=
false
):
List
<
TtlRunnable
>
=
map
{
it
.
wrap
(
releaseTtlValueReferenceAfterRun
,
idempotent
)
}
/**
* Extension function to unwrap {@link TtlRunnable} to the original/underneath one.
* <p>
* if input {@code Runnable} parameter is not a {@link TtlRunnable} just return input {@code Runnable}.
* <p>
* so {@code Runnable.wrap().unwrap()} will always return the same input {@code Runnable} object.
*
* @since TODO
*/
fun
Runnable
.
unwrap
():
Runnable
=
when
(
this
)
{
is
TtlRunnable
->
runnable
else
->
this
}
/**
* Extension function to unwrap {@link TtlRunnable} to the original/underneath one.
* <p>
* Invoke {@link #unwrap(Runnable)} for each element in collection.
* <p>
*
* @see #Runnable::unwrap
* @since TODO
*/
fun
List
<
Runnable
>.
unwrap
():
List
<
Runnable
>
=
map
{
it
.
unwrap
()
}
src/test/java/com/alibaba/ttl/TtlCallableExtKtTest.kt
浏览文件 @
b7c6038c
...
...
@@ -5,16 +5,22 @@ import com.alibaba.assertParentTtlValues
import
com.alibaba.copyTtlValues
import
com.alibaba.createParentTtlInstances
import
com.alibaba.createParentTtlInstancesAfterCreateChild
import
com.alibaba.support.junit.conditional.ConditionalIgnoreRule
import
com.alibaba.ttl.testmodel.Call
import
org.hamcrest.CoreMatchers
import
org.junit.Assert.assertEquals
import
org.junit.Assert.assertSame
import
org.junit.Assert.assertThat
import
org.junit.Assert.fail
import
org.junit.Rule
import
org.junit.Test
class
TtlCallableExtKtTest
{
@Rule
@JvmField
val
rule
=
ConditionalIgnoreRule
()
@Test
fun
`callable
wrap
extension
function
`
()
{
val
call
=
Call
(
"1"
)
...
...
src/test/java/com/alibaba/ttl/TtlRunnableExtKtTest.kt
0 → 100644
浏览文件 @
b7c6038c
package
com.alibaba.ttl
import
com.alibaba.support.junit.conditional.ConditionalIgnoreRule
import
com.alibaba.ttl.testmodel.Task
import
org.hamcrest.CoreMatchers
import
org.junit.Assert
import
org.junit.Rule
import
org.junit.Test
class
TtlRunnableExtKtTest
{
@Rule
@JvmField
val
rule
=
ConditionalIgnoreRule
()
@Test
fun
`runnable
wrap
extension
function
`
()
{
val
task
=
Task
(
"1"
)
val
ttlRunnable
=
task
.
wrap
()
Assert
.
assertSame
(
task
,
ttlRunnable
.
runnable
)
}
@Test
fun
`runnable
wrap
extension
function
multiple
times`
()
{
val
task
=
Task
(
"1"
).
wrap
()
try
{
task
.
wrap
()
Assert
.
fail
()
}
catch
(
e
:
IllegalStateException
)
{
Assert
.
assertThat
<
String
>(
e
.
message
,
CoreMatchers
.
containsString
(
"Already TtlRunnable"
))
}
}
@Test
fun
`list
of
runnable
wrap
extension
function`
()
{
val
taskList
=
listOf
(
Task
(
"1"
),
Task
(
"2"
),
Task
(
"3"
)).
wrap
()
Assert
.
assertEquals
(
3
,
taskList
.
size
)
taskList
.
forEach
{
Assert
.
assertThat
(
it
,
CoreMatchers
.
instanceOf
(
TtlRunnable
::
class
.
java
))
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录