mirror of
https://github.com/Geniusay/ChopperBot.git
synced 2026-05-28 00:55:01 +08:00
v1.0.3一些bug修改和一些模块重构优化
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
package org.example.cache;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSONPObject;
|
||||
import org.example.bean.ModuleSrcConfigFile;
|
||||
import org.example.bean.Student;
|
||||
import org.example.cache.FileCache;
|
||||
import org.example.common.ConfigFile;
|
||||
import org.example.constpool.GlobalFileCache;
|
||||
import org.example.pojo.CommonConfigFile;
|
||||
import org.example.pojo.Student;
|
||||
import org.example.pojo.configfile.ModuleSrcConfigFile;
|
||||
import org.example.exception.FileCacheException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.apache.logging.log4j.message.MapMessage.MapFormat.JSON;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
@@ -21,6 +18,23 @@ import static org.apache.logging.log4j.message.MapMessage.MapFormat.JSON;
|
||||
**/
|
||||
|
||||
public class FileCacheTest {
|
||||
static FileCache cache;
|
||||
|
||||
static{
|
||||
|
||||
try {
|
||||
cache = new FileCache<>(
|
||||
new CommonConfigFile(
|
||||
"E:\\Project\\ChopperBot\\FileModule\\src\\main\\resources\\",
|
||||
"test.json",
|
||||
new ConcurrentLinkedQueue<Student>()
|
||||
)
|
||||
);
|
||||
FileCacheManagerInstance.getInstance().addFileCache(cache);
|
||||
} catch (FileCacheException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestFileCache() throws FileCacheException, InterruptedException {
|
||||
@@ -55,55 +69,59 @@ public class FileCacheTest {
|
||||
|
||||
@Test
|
||||
public void TestAppend() throws FileCacheException, InterruptedException {
|
||||
ModuleSrcConfigFile moduleSrcConfigFile = new ModuleSrcConfigFile();
|
||||
FileCache fileCache = new FileCache(moduleSrcConfigFile);
|
||||
|
||||
FileCacheManager manager = new FileCacheManager(List.of(fileCache));
|
||||
manager.start();
|
||||
FileCacheManagerInstance.getInstance().start();
|
||||
//追加数组的某个元素
|
||||
for(int i=0;i<10;i++){
|
||||
fileCache.append(i,"sectionwork","src","0");
|
||||
GlobalFileCache.ModuleSrcConfigFile.append(i,"sectionwork","src","0");
|
||||
}
|
||||
//追加数组
|
||||
for(int i=0;i<10;i++){
|
||||
fileCache.append(i,"sectionwork","src","-1");
|
||||
GlobalFileCache.ModuleSrcConfigFile.append(i,"sectionwork","src","-1");
|
||||
}
|
||||
//追加类中的元素
|
||||
for(int i=0;i<10;i++){
|
||||
fileCache.append(i,"barrage","src");
|
||||
GlobalFileCache.ModuleSrcConfigFile.append(i,"barrage","src");
|
||||
}
|
||||
Thread.sleep(500000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestWrite() throws FileCacheException,InterruptedException{
|
||||
ModuleSrcConfigFile moduleSrcConfigFile = new ModuleSrcConfigFile();
|
||||
FileCache fileCache = new FileCache(moduleSrcConfigFile);
|
||||
|
||||
FileCacheManager manager = new FileCacheManager(List.of(fileCache));
|
||||
manager.start();
|
||||
FileCacheManagerInstance.getInstance().start();
|
||||
//更改数组元素
|
||||
for(int i=0;i<10;i++){
|
||||
fileCache.writeKeys(i,"sectionwork","src","0");
|
||||
GlobalFileCache.ModuleSrcConfigFile.writeKeys(i,"sectionwork","src","0");
|
||||
}
|
||||
//追加数组
|
||||
for(int i=0;i<10;i++){
|
||||
fileCache.writeKeys(i,"sectionwork","src","-1");
|
||||
GlobalFileCache.ModuleSrcConfigFile.writeKeys(i,"sectionwork","src","-1");
|
||||
}
|
||||
//更改类中的元素
|
||||
for(int i=0;i<10;i++){
|
||||
fileCache.writeKeys(i,"barrage","src");
|
||||
GlobalFileCache.ModuleSrcConfigFile.writeKeys(i,"barrage","src");
|
||||
}
|
||||
Thread.sleep(500000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestJson(){
|
||||
Student student = new Student("Genius",18,"qinghua","SC",List.of("1","2","3"),null);
|
||||
String s = JSONObject.toJSONString("");
|
||||
JSONObject jsonObject = JSONObject.parseObject(s);
|
||||
jsonObject.put("hobby",List.of("1","2","3","4").toString());
|
||||
System.out.println(jsonObject);
|
||||
public void TestArrayAdd() throws InterruptedException, FileCacheException {
|
||||
ModuleSrcConfigFile moduleSrcConfigFile = new ModuleSrcConfigFile();
|
||||
FileCache fileCache = new FileCache(moduleSrcConfigFile);
|
||||
|
||||
FileCacheManager manager = new FileCacheManager(List.of(fileCache));
|
||||
manager.start();
|
||||
|
||||
System.out.println(manager.addFileCache(fileCache));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestAddCache() throws FileCacheException, InterruptedException {
|
||||
FileCacheManagerInstance.getInstance().start();
|
||||
for(int i=0;i<10;i++){
|
||||
Student student = new Student(Integer.toString(i),i,"jsu"+i,"major"+i,null,null);
|
||||
cache.writeKeys(student,"-1");
|
||||
}
|
||||
Thread.sleep(500000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user