Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
bff2d2cc
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bff2d2cc
编写于
9月 04, 2018
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
ab086f42
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
66 addition
and
51 deletion
+66
-51
spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java
...ringframework/context/support/SimpleThreadScopeTests.java
+7
-7
spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java
...gframework/scheduling/annotation/AsyncExecutionTests.java
+10
-9
spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
...ringframework/scheduling/annotation/EnableAsyncTests.java
+35
-21
spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java
...uling/concurrent/AbstractSchedulingTaskExecutorTests.java
+14
-14
未找到文件。
spring-context/src/test/java/org/springframework/context/support/SimpleThreadScopeTests.java
浏览文件 @
bff2d2cc
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
8
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -39,17 +39,17 @@ public class SimpleThreadScopeTests {
@Test
public
void
getFromScope
()
throws
Exception
{
String
name
=
"threadScopedObject"
;
TestBean
bean
=
(
TestBean
)
this
.
applicationContext
.
getBean
(
name
);
TestBean
bean
=
this
.
applicationContext
.
getBean
(
name
,
TestBean
.
class
);
assertNotNull
(
bean
);
assertSame
(
bean
,
this
.
applicationContext
.
getBean
(
name
));
TestBean
bean2
=
(
TestBean
)
this
.
applicationContext
.
getBean
(
name
);
TestBean
bean2
=
this
.
applicationContext
.
getBean
(
name
,
TestBean
.
class
);
assertSame
(
bean
,
bean2
);
}
@Test
public
void
getMultipleInstances
()
throws
Exception
{
// Arrange
final
TestBean
[]
beans
=
new
TestBean
[
2
];
TestBean
[]
beans
=
new
TestBean
[
2
];
Thread
thread1
=
new
Thread
(()
->
beans
[
0
]
=
applicationContext
.
getBean
(
"threadScopedObject"
,
TestBean
.
class
));
Thread
thread2
=
new
Thread
(()
->
beans
[
1
]
=
applicationContext
.
getBean
(
"threadScopedObject"
,
TestBean
.
class
));
// Act
...
...
@@ -57,9 +57,9 @@ public class SimpleThreadScopeTests {
thread2
.
start
();
// Assert
Awaitility
.
await
()
.
pollInterval
(
1
0
,
TimeUnit
.
MILLISECONDS
)
.
atMost
(
50
0
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
beans
[
0
]
!=
null
&
beans
[
1
]
!=
null
);
.
atMost
(
50
0
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
1
0
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
(
beans
[
0
]
!=
null
)
&&
(
beans
[
1
]
!=
null
)
);
assertNotSame
(
beans
[
0
],
beans
[
1
]);
}
...
...
spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncExecutionTests.java
浏览文件 @
bff2d2cc
...
...
@@ -378,10 +378,11 @@ public class AsyncExecutionTests {
context
.
refresh
();
// Assert
Awaitility
.
await
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
listenerCalled
==
1
);
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
listenerCalled
==
1
);
assertEquals
(
listenerCalled
,
1
);
context
.
close
();
}
@Test
...
...
@@ -399,9 +400,9 @@ public class AsyncExecutionTests {
context
.
close
();
// Assert
Awaitility
.
await
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
listenerCalled
==
2
);
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
listenerCalled
==
2
);
assertEquals
(
2
,
listenerCalled
);
assertEquals
(
1
,
listenerConstructed
);
}
...
...
@@ -423,9 +424,9 @@ public class AsyncExecutionTests {
context
.
close
();
// Assert
Awaitility
.
await
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
listenerCalled
==
2
);
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
listenerCalled
==
2
);
assertEquals
(
2
,
listenerCalled
);
assertEquals
(
2
,
listenerConstructed
);
}
...
...
spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
浏览文件 @
bff2d2cc
...
...
@@ -77,6 +77,7 @@ public class EnableAsyncTests {
AsyncBean
asyncBean
=
ctx
.
getBean
(
AsyncBean
.
class
);
assertThat
(
AopUtils
.
isAopProxy
(
asyncBean
),
is
(
true
));
asyncBean
.
work
();
ctx
.
close
();
}
@Test
...
...
@@ -89,6 +90,7 @@ public class EnableAsyncTests {
AsyncBean
asyncBean
=
asyncBeanUser
.
getAsyncBean
();
assertThat
(
AopUtils
.
isAopProxy
(
asyncBean
),
is
(
true
));
asyncBean
.
work
();
ctx
.
close
();
}
@Test
...
...
@@ -103,6 +105,7 @@ public class EnableAsyncTests {
catch
(
UnsatisfiedDependencyException
ex
)
{
assertTrue
(
ex
.
getCause
()
instanceof
BeanNotOfRequiredTypeException
);
}
ctx
.
close
();
}
@Test
...
...
@@ -117,6 +120,8 @@ public class EnableAsyncTests {
catch
(
UnsatisfiedDependencyException
ex
)
{
assertTrue
(
ex
.
getCause
()
instanceof
BeanNotOfRequiredTypeException
);
}
ctx
.
close
();
}
@Test
...
...
@@ -134,6 +139,8 @@ public class EnableAsyncTests {
assertThat
(
workerThread2
.
get
().
getName
(),
startsWith
(
"otherExecutor-"
));
Future
<
Thread
>
workerThread3
=
asyncBean
.
work3
();
assertThat
(
workerThread3
.
get
().
getName
(),
startsWith
(
"otherExecutor-"
));
ctx
.
close
();
}
@Test
...
...
@@ -144,6 +151,8 @@ public class EnableAsyncTests {
AsyncAnnotationBeanPostProcessor
bpp
=
ctx
.
getBean
(
AsyncAnnotationBeanPostProcessor
.
class
);
assertThat
(
bpp
.
getOrder
(),
is
(
Ordered
.
LOWEST_PRECEDENCE
));
ctx
.
close
();
}
@Test
...
...
@@ -154,6 +163,8 @@ public class EnableAsyncTests {
AsyncAnnotationBeanPostProcessor
bpp
=
ctx
.
getBean
(
AsyncAnnotationBeanPostProcessor
.
class
);
assertThat
(
bpp
.
getOrder
(),
is
(
Ordered
.
HIGHEST_PRECEDENCE
));
ctx
.
close
();
}
@Test
...
...
@@ -172,6 +183,8 @@ public class EnableAsyncTests {
}
}
assertTrue
(
"bean was not async advised as expected"
,
isAsyncAdvised
);
ctx
.
close
();
}
/**
...
...
@@ -179,6 +192,7 @@ public class EnableAsyncTests {
*/
@Test
(
expected
=
BeanDefinitionStoreException
.
class
)
public
void
aspectModeAspectJAttemptsToRegisterAsyncAspect
()
{
@SuppressWarnings
(
"resource"
)
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
AspectJAsyncAnnotationConfig
.
class
);
ctx
.
refresh
();
...
...
@@ -195,9 +209,9 @@ public class EnableAsyncTests {
asyncBean
.
work
();
// Assert
Awaitility
.
await
()
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
assertThat
(
asyncBean
.
getThreadOfExecution
().
getName
(),
startsWith
(
"Custom-"
));
ctx
.
close
();
}
...
...
@@ -213,9 +227,9 @@ public class EnableAsyncTests {
asyncBean
.
work
();
// Assert
Awaitility
.
await
()
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
assertThat
(
asyncBean
.
getThreadOfExecution
().
getName
(),
startsWith
(
"Custom-"
));
ctx
.
close
();
}
...
...
@@ -235,9 +249,9 @@ public class EnableAsyncTests {
asyncBean
.
fail
();
// Assert
Awaitility
.
await
()
.
pollInterval
(
1
0
,
TimeUnit
.
MILLISECONDS
)
.
atMost
(
50
0
,
TimeUnit
.
MILLISECONDS
)
.
untilAsserted
(()
->
exceptionHandler
.
assertCalledWith
(
method
,
UnsupportedOperationException
.
class
));
.
atMost
(
50
0
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
1
0
,
TimeUnit
.
MILLISECONDS
)
.
untilAsserted
(()
->
exceptionHandler
.
assertCalledWith
(
method
,
UnsupportedOperationException
.
class
));
ctx
.
close
();
}
...
...
@@ -252,9 +266,9 @@ public class EnableAsyncTests {
asyncBean
.
work
();
// Assert
Awaitility
.
await
()
.
pollInterval
(
1
0
,
TimeUnit
.
MILLISECONDS
)
.
atMost
(
50
0
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
.
atMost
(
50
0
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
1
0
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
assertThat
(
asyncBean
.
getThreadOfExecution
().
getName
(),
startsWith
(
"Post-"
));
ctx
.
close
();
}
...
...
@@ -274,9 +288,9 @@ public class EnableAsyncTests {
asyncBean
.
fail
();
// Assert
Awaitility
.
await
()
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
untilAsserted
(()
->
exceptionHandler
.
assertCalledWith
(
method
,
UnsupportedOperationException
.
class
));
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
untilAsserted
(()
->
exceptionHandler
.
assertCalledWith
(
method
,
UnsupportedOperationException
.
class
));
ctx
.
close
();
}
...
...
@@ -289,9 +303,9 @@ public class EnableAsyncTests {
asyncBean
.
work
();
// Assert
Awaitility
.
await
()
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
asyncBean
.
getThreadOfExecution
()
!=
null
);
assertThat
(
asyncBean
.
getThreadOfExecution
().
getName
(),
startsWith
(
"Custom-"
));
ctx
.
close
();
}
...
...
@@ -305,9 +319,9 @@ public class EnableAsyncTests {
asyncBean
.
work
();
// Assert
Awaitility
.
await
()
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()->
asyncBean
.
getThreadOfExecution
()
!=
null
);
.
atMost
(
500
,
TimeUnit
.
MILLISECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()->
asyncBean
.
getThreadOfExecution
()
!=
null
);
assertThat
(
asyncBean
.
getThreadOfExecution
().
getName
(),
startsWith
(
"Custom-"
));
ctx
.
close
();
}
...
...
spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java
浏览文件 @
bff2d2cc
...
...
@@ -119,9 +119,9 @@ public abstract class AbstractSchedulingTaskExecutorTests {
future
.
addCallback
(
result
->
outcome
=
result
,
ex
->
outcome
=
ex
);
// Assert
Awaitility
.
await
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(
future:
:
isDone
);
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(
future:
:
isDone
);
assertNull
(
outcome
);
assertThreadNamePrefix
(
task
);
}
...
...
@@ -133,10 +133,10 @@ public abstract class AbstractSchedulingTaskExecutorTests {
future
.
addCallback
(
result
->
outcome
=
result
,
ex
->
outcome
=
ex
);
Awaitility
.
await
()
.
dontCatchUncaughtExceptions
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
future
.
isDone
()
&&
outcome
!=
null
);
.
dontCatchUncaughtExceptions
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
future
.
isDone
()
&&
outcome
!=
null
);
assertSame
(
RuntimeException
.
class
,
outcome
.
getClass
());
}
...
...
@@ -186,9 +186,9 @@ public abstract class AbstractSchedulingTaskExecutorTests {
future
.
addCallback
(
result
->
outcome
=
result
,
ex
->
outcome
=
ex
);
// Assert
Awaitility
.
await
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
future
.
isDone
()
&&
outcome
!=
null
);
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
future
.
isDone
()
&&
outcome
!=
null
);
assertEquals
(
THREAD_NAME_PREFIX
,
outcome
.
toString
().
substring
(
0
,
THREAD_NAME_PREFIX
.
length
()));
}
...
...
@@ -200,10 +200,10 @@ public abstract class AbstractSchedulingTaskExecutorTests {
future
.
addCallback
(
result
->
outcome
=
result
,
ex
->
outcome
=
ex
);
// Assert
Awaitility
.
await
()
.
dontCatchUncaughtExceptions
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
future
.
isDone
()
&&
outcome
!=
null
);
.
dontCatchUncaughtExceptions
()
.
atMost
(
1
,
TimeUnit
.
SECONDS
)
.
pollInterval
(
10
,
TimeUnit
.
MILLISECONDS
)
.
until
(()
->
future
.
isDone
()
&&
outcome
!=
null
);
assertSame
(
RuntimeException
.
class
,
outcome
.
getClass
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录