新增H2数据库快速体验项目

This commit is contained in:
thinkgem
2022-04-24 12:09:30 +08:00
parent 07e705fee7
commit 93a09be05d
74 changed files with 10272 additions and 4 deletions

View File

@@ -0,0 +1,33 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import com.jeesite.common.tests.BaseInitDataTests;
import com.jeesite.modules.FastApplication;
/**
* 初始化数据表
* @author ThinkGem
* @version 2020-5-26
*/
@ActiveProfiles("test")
@SpringBootTest(classes = FastApplication.class)
public class InitData extends BaseInitDataTests {
@Test
public void initData01() throws Exception{
logger.info("数据库初始化完成。");
}
@Override
public void initProperty() {
System.setProperty("jeesite.initdata", "true");
}
}

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import com.jeesite.common.callback.MethodCallback;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.FastApplication;
import com.jeesite.modules.test.dao.TestDataDao;
import com.jeesite.modules.test.entity.TestData;
/**
* 批量插入测试
* @author ThinkGem
* @version 2019年10月28日
*/
@ActiveProfiles("test")
@SpringBootTest(classes = FastApplication.class)
public class InsertBatchTest extends BaseSpringContextTests {
@Autowired
private TestDataDao testDataDao;
@Test
public void testData() throws Exception{
List<TestData> list = ListUtils.newArrayList();
for(int i=0; i<5000; i++){
TestData testData = new TestData();
testData.setTestInput("test"+i);
list.add(testData);
}
ListUtils.pageList(list, 100, new MethodCallback() {
@SuppressWarnings("unchecked")
public Object execute(Object... objs) {
return testDataDao.insertBatch((List<TestData>)objs[0]);
}
});
list = testDataDao.findList(new TestData());
System.out.println("size: " + list.size());
}
}

View File

@@ -0,0 +1,72 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.idgen.IdGen;
import com.jeesite.common.tests.BaseSpringContextTests;
import com.jeesite.modules.FastApplication;
import com.jeesite.modules.test.entity.TestData;
import com.jeesite.modules.test.entity.TestDataChild;
import com.jeesite.modules.test.service.TestDataService;
/**
* 多数据源并发测试<br>
* 1、将 TestDataChildDao 的数据源设置为 ds2<br>
* 2、将 TestDataChild 的表名设置为 test_data_child2<br>
* 3、配置 ds2 数据源,并创建 test_data_child2 表
* @author ThinkGem
* @version 2019-6-26
*/
@ActiveProfiles("test")
@SpringBootTest(classes = FastApplication.class)
public class MultiDataSourceTest extends BaseSpringContextTests {
@Autowired
private TestDataService testDataService;
@Test
public void testData() throws Exception{
ExecutorService pool = Executors.newCachedThreadPool();
CountDownLatch latch = new CountDownLatch(10);
Runnable runnable = new Runnable() {
@Override
public void run() {
try{
Thread.sleep(IdGen.randomInt(1000, 3000));
TestData testData = new TestData();
testData.setTestDataChildList(ListUtils.newArrayList(
new TestDataChild(), new TestDataChild(), new TestDataChild()));
testDataService.save(testData);
List<TestData> list = testDataService.findList(new TestData());
System.out.println("size: " + list.size());
list.forEach(e -> {
System.out.println("get: " + testDataService.get(e));
});
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
latch.countDown();
}
}
};
for (int i = 0; i < latch.getCount(); i++) {
pool.execute(runnable);
}
latch.await();
pool.shutdown();
}
}

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
*/
package com.jeesite.test;
import org.apache.shiro.crypto.AesCipherService;
/**
* v4.1.8 开始将不为记住我功能,设置默认密钥,即启动系统时生成新密钥。
* 这样会造成一个问题,比如:重启服务后,记住登录的用户因为解密失败,而需要重新登录。
* 为了解决这个问题,您可以通过这个类获取一个新密钥,设置到 shiro.rememberMe.secretKey 中即可。
* 另外,如果你从配置文件里将 shiro.rememberMe.secretKey 设置为空,启动系统时也会自动设置一个新的密钥。
* @author ThinkGem
* @version 2019年11月6日
*/
public class RememberMeKeyGen {
public static void main(String[] args) {
byte[] cipherKey = new AesCipherService().generateNewKey().getEncoded();
String secretKey = org.apache.shiro.codec.Base64.encodeToString(cipherKey);
System.out.println("shiro.rememberMe.secretKey = " + secretKey);
}
}

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<!-- Framework level setting -->
<include resource="config/logger-core.xml"/>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %clr(%-5p) %clr([%-39logger{39}]){cyan} - %m%n%wEx</pattern>
</encoder>
</appender>
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="WARN">
<appender-ref ref="console" />
</root>
</configuration>