Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
db0995d1
Commit
db0995d1
authored
Nov 01, 2018
by
Junling Bu
Browse files
chore[litemall-core]: 采用SyncTaskExecutor调度器来测试异步方法
parent
9dfdea3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java
View file @
db0995d1
...
...
@@ -5,9 +5,16 @@ import org.junit.runner.RunWith;
import
org.linlinjava.litemall.core.notify.NotifyService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.task.SyncTaskExecutor
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
java.util.concurrent.Executor
;
/**
* 测试邮件发送服务
*
...
...
@@ -23,18 +30,22 @@ import org.springframework.test.context.web.WebAppConfiguration;
@SpringBootTest
public
class
MailTest
{
@Configuration
@Import
(
Application
.
class
)
static
class
ContextConfiguration
{
@Bean
@Primary
public
Executor
executor
()
{
return
new
SyncTaskExecutor
();
}
}
@Autowired
private
NotifyService
notifyService
;
@Test
public
void
testMail
()
{
notifyService
.
notifyMail
(
"订单信息"
,
"订单1111111已付款,请发货"
);
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
...
...
litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java
View file @
db0995d1
...
...
@@ -6,9 +6,16 @@ import org.linlinjava.litemall.core.notify.NotifyService;
import
org.linlinjava.litemall.core.notify.NotifyType
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.task.SyncTaskExecutor
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
java.util.concurrent.Executor
;
/**
* 测试短信发送服务
*
...
...
@@ -25,6 +32,16 @@ import org.springframework.test.context.web.WebAppConfiguration;
@SpringBootTest
public
class
SmsTest
{
@Configuration
@Import
(
Application
.
class
)
static
class
ContextConfiguration
{
@Bean
@Primary
public
Executor
executor
()
{
return
new
SyncTaskExecutor
();
}
}
@Autowired
private
NotifyService
notifyService
;
...
...
@@ -34,12 +51,6 @@ public class SmsTest {
String
[]
params
=
new
String
[]
{
"123456"
};
notifyService
.
notifySmsTemplate
(
phone
,
NotifyType
.
CAPTCHA
,
params
);
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
@Test
...
...
@@ -48,12 +59,6 @@ public class SmsTest {
String
[]
params
=
new
String
[]
{
"123456"
};
notifyService
.
notifySmsTemplate
(
phone
,
NotifyType
.
PAY_SUCCEED
,
params
);
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
@Test
...
...
@@ -62,12 +67,6 @@ public class SmsTest {
String
[]
params
=
new
String
[]
{
"123456"
};
notifyService
.
notifySmsTemplate
(
phone
,
NotifyType
.
SHIP
,
params
);
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
@Test
...
...
@@ -76,11 +75,5 @@ public class SmsTest {
String
[]
params
=
new
String
[]
{
"123456"
};
notifyService
.
notifySmsTemplate
(
phone
,
NotifyType
.
REFUND
,
params
);
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment