|
@@ -4,20 +4,25 @@ import org.hswebframework.web.concurrent.lock.LockManager;
|
|
import org.hswebframework.web.tests.SimpleWebApplicationTests;
|
|
import org.hswebframework.web.tests.SimpleWebApplicationTests;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
+import org.junit.runner.RunWith;
|
|
import org.redisson.Redisson;
|
|
import org.redisson.Redisson;
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
/**
|
|
/**
|
|
* TODO 完成注释
|
|
* TODO 完成注释
|
|
*
|
|
*
|
|
* @author zhouhao
|
|
* @author zhouhao
|
|
*/
|
|
*/
|
|
-@Configuration
|
|
|
|
-public class LockAnnotationTest extends SimpleWebApplicationTests {
|
|
|
|
-
|
|
|
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
|
+@SpringBootTest(classes = TestApplication.class)
|
|
|
|
+public class LockAnnotationTest extends AbstractTransactionalJUnit4SpringContextTests {
|
|
@Autowired
|
|
@Autowired
|
|
private LockService lockService;
|
|
private LockService lockService;
|
|
|
|
|
|
@@ -27,15 +32,9 @@ public class LockAnnotationTest extends SimpleWebApplicationTests {
|
|
@Test
|
|
@Test
|
|
public void testLock() throws InterruptedException {
|
|
public void testLock() throws InterruptedException {
|
|
new Thread(() -> {
|
|
new Thread(() -> {
|
|
- try {
|
|
|
|
- System.out.println("锁住");
|
|
|
|
- lockManager.getLock("lock_test").lock();
|
|
|
|
- Thread.sleep(2000);
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ System.out.println("锁住");
|
|
|
|
+ lockService.testLockSleep("test", 2000);
|
|
System.out.println("解锁");
|
|
System.out.println("解锁");
|
|
- lockManager.getLock("lock_test").unlock();
|
|
|
|
}).start();
|
|
}).start();
|
|
Thread.sleep(200);
|
|
Thread.sleep(200);
|
|
System.out.println("开始任务1");
|
|
System.out.println("开始任务1");
|