|
@@ -1,27 +1,22 @@
|
|
|
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.condition.ConditionalOnProperty;
|
|
|
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 org.springframework.transaction.support.TransactionTemplate;
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.util.List;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-
|
|
|
-import static org.junit.Assert.*;
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @author zhouhao
|
|
|
*/
|
|
|
public class TransactionSupportAsyncJobServiceTest extends SimpleWebApplicationTests {
|
|
@@ -42,11 +37,20 @@ public class TransactionSupportAsyncJobServiceTest extends SimpleWebApplicationT
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void test() throws Exception {
|
|
|
-
|
|
|
+ @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(() -> {
|
|
@@ -66,9 +70,6 @@ public class TransactionSupportAsyncJobServiceTest extends SimpleWebApplicationT
|
|
|
|
|
|
@Test
|
|
|
public void testSimple() throws Exception {
|
|
|
-
|
|
|
- sqlExecutor.exec("create table test(id varchar(32))");
|
|
|
-
|
|
|
try {
|
|
|
BatchAsyncJobContainer jobContainer = asyncJobService.batch();
|
|
|
jobContainer.submit(() -> {
|
|
@@ -85,6 +86,6 @@ public class TransactionSupportAsyncJobServiceTest extends SimpleWebApplicationT
|
|
|
} catch (Exception ignore) {
|
|
|
ignore.printStackTrace();
|
|
|
}
|
|
|
- Assert.assertTrue(sqlExecutor.list("select * from test").size()>0);
|
|
|
+ Assert.assertTrue(sqlExecutor.list("select * from test").size() > 0);
|
|
|
}
|
|
|
}
|