package com.walker.push.mail; import com.walker.infrastructure.utils.WaitConsoleInput; import com.walker.push.Notification; import com.walker.push.NotificationChannel; import com.walker.push.util.PushUtils; import org.junit.Test; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ThreadPoolExecutor; public class TestMail { // @Test public void testMultipleChannelParallel(){ DefaultSystemPush systemPush = new DefaultSystemPush(); systemPush.startup(); WebsocketPush websocketPush = new WebsocketPush(); websocketPush.startup(); DefaultPushManager pushManager = new DefaultPushManager(); pushManager.setThreadPoolTaskExecutor(this.acquireThreadPoolTask()); pushManager.register(systemPush); pushManager.register(websocketPush); List channels = new ArrayList<>(4); channels.add(NotificationChannel.System); channels.add(NotificationChannel.WebSocket); List userList = new ArrayList<>(2); userList.add("shikeying"); Notification notification = PushUtils.acquireNotification("标题", "sfsfd", "平台", userList, "creator", true, channels, false); pushManager.push(notification, null); WaitConsoleInput.waitInput(); } // @Test public void testMailPush(){ MailPush mailPush = new DefaultMailPush(); mailPush.setMailServerHost("smtp.126.com"); mailPush.setMailServerPort("25"); mailPush.setFromAddress("hnzzzhsl@126.com"); mailPush.setFromPassword("UWBUXNLFJEANRCXX"); mailPush.startup(); ThreadPoolTaskExecutor executor = this.acquireThreadPoolTask(); DefaultPushManager pushManager = new DefaultPushManager(); pushManager.setThreadPoolTaskExecutor(executor); pushManager.register(mailPush); // pushManager.addStrategy(); Notification notification = PushUtils.acquireEmailNotificationOne("测试邮件标题" , "您的验证码是:0098", "123333@126.com", "shikeying", "0"); pushManager.push(notification, null); WaitConsoleInput.waitInput(); // try { // PushResult pushResult = mailPush.push(notification); // System.out.println(pushResult); // } catch (PushException e) { // throw new RuntimeException(e); // } } private ThreadPoolTaskExecutor acquireThreadPoolTask(){ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setMaxPoolSize(4); executor.setCorePoolSize(2); executor.setQueueCapacity(16); executor.setKeepAliveSeconds(300); // 线程池对拒绝任务(无线程可用)的处理策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize(); return executor; } }