From db0995d1d8ddb29bad058c33b0a313f04cd6a5b7 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Thu, 1 Nov 2018 20:29:14 +0800 Subject: [PATCH] =?UTF-8?q?chore[litemall-core]:=20=E9=87=87=E7=94=A8SyncT?= =?UTF-8?q?askExecutor=E8=B0=83=E5=BA=A6=E5=99=A8=E6=9D=A5=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=BC=82=E6=AD=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linlinjava/litemall/core/MailTest.java | 23 ++++++++--- .../org/linlinjava/litemall/core/SmsTest.java | 41 ++++++++----------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java index f87c9ac8..37cc54f2 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java @@ -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(); - } } diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java index 10b422a8..400c295b 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java @@ -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(); - } } }