From 0382d9b6eaba2a5f7218adf405826ea42113b3eb Mon Sep 17 00:00:00 2001 From: zhouhao Date: Thu, 11 Oct 2018 15:26:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=A5=BD=E7=9C=8B?= =?UTF-8?q?=E7=9A=84test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...TransactionSupportAsyncJobServiceTest.java | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 hsweb-concurrent/hsweb-concurrent-async-job/src/test/java/org/hswebframework/web/async/TransactionSupportAsyncJobServiceTest.java diff --git a/hsweb-concurrent/hsweb-concurrent-async-job/src/test/java/org/hswebframework/web/async/TransactionSupportAsyncJobServiceTest.java b/hsweb-concurrent/hsweb-concurrent-async-job/src/test/java/org/hswebframework/web/async/TransactionSupportAsyncJobServiceTest.java deleted file mode 100644 index ddb4485e3..000000000 --- a/hsweb-concurrent/hsweb-concurrent-async-job/src/test/java/org/hswebframework/web/async/TransactionSupportAsyncJobServiceTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.hswebframework.web.async; - -import lombok.SneakyThrows; -import org.hswebframework.ezorm.rdb.executor.SqlExecutor; -import org.hswebframework.web.tests.SimpleWebApplicationTests; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.sql.DataSource; - -/** - * @author zhouhao - */ -public class TransactionSupportAsyncJobServiceTest extends SimpleWebApplicationTests { - - @Autowired - private SqlExecutor sqlExecutor; - - @Autowired - private AsyncJobService asyncJobService; - - @Configuration - @EnableConfigurationProperties(DataSourceProperties.class) - public static class DataSourceConfig { - @Bean - @ConfigurationProperties(prefix = "spring.datasource") - public DataSource dataSource(DataSourceProperties properties) { - return properties.initializeDataSourceBuilder().build(); - } - } - - @Before - @SneakyThrows - public void init() { - sqlExecutor.exec("create table test(id varchar(32))"); - } - - @After - @SneakyThrows - public void cleanup() { - sqlExecutor.exec("drop table test"); - } - - @Test - public void test() throws Exception { - try { - BatchAsyncJobContainer jobContainer = asyncJobService.batch(); - jobContainer.submit(() -> { - Thread.sleep(50); - throw new RuntimeException("1234"); - }, true); - for (int i = 0; i < 10; i++) { - jobContainer.submit(() -> sqlExecutor.insert("insert into test values('test')", null), true); - } - - System.out.println(jobContainer.getResult().size()); - } catch (Exception ignore) { - ignore.printStackTrace(); - } - Assert.assertTrue(sqlExecutor.list("select * from test").isEmpty()); - } - - @Test - public void testSimple() throws Exception { - try { - BatchAsyncJobContainer jobContainer = asyncJobService.batch(); - - for (int i = 0; i < 10; i++) { - jobContainer.submit(() -> sqlExecutor.insert("insert into test values('test')", null), false); - } - - jobContainer.submit(() -> { - Thread.sleep(100); - jobContainer.cancel(); - throw new RuntimeException(); - }, false); - - System.out.println(jobContainer.getResult().size()); - - } catch (Exception ignore) { - ignore.printStackTrace(); - } - Assert.assertTrue(sqlExecutor.list("select * from test").size() > 0); - } -} \ No newline at end of file