Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<proc>full</proc>
<maxmem>512M</maxmem>
</configuration>
</plugin>
Expand Down Expand Up @@ -172,7 +173,9 @@
每一个测试创建一个新进程,为每个测试创建新的JVM是单独测试的最彻底方式,但也是最慢的,不适合hudson上持续回归。 once:在一个进程中进行所有测试。once为默认设置,在Hudson上持续回归时建议使用默认设置。
always:在一个进程中并行的运行脚本,Junit4.7以上版本才可以使用,surefire的版本要在2.6以上提供这个功能,其中 threadCount:执行时,指定可分配的线程数量。只和参数parallel配合使用有效。默认:5。 -->
<forkMode>once</forkMode>
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8</argLine>
<!-- Temporary JE databases run inside the test JVM; the
host's free space must not gate isolated tests. -->
<argLine>${argLine} -Xmx1024m -Dfile.encoding=UTF-8 -Dje.freeDisk=0</argLine>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target/test-classes</additionalClasspathElement>
</additionalClasspathElements>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public Database catalogDatabase(Environment myDbEnvironment){

System.out.println(catalogDatabase.getDatabaseName());

this.catalogDatabase = catalogDatabase;
return catalogDatabase;

}
Expand Down Expand Up @@ -126,6 +127,7 @@ public Database berkeleyDatabase(Environment myDbEnvironment){

System.out.println(myDatabase.getDatabaseName());

this.myDatabase = myDatabase;
return myDatabase;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ public void otherMethod(){
List<String> list = myDbEnvironment.getDatabaseNames();//取得当前环境下数据库名称列表
System.out.println(list);

env.renameDatabase(null, databaseName, "newName");//给数据库改名
env.removeDatabase(null, databaseName);//删除当前环境数据库

long deleteNum = env.truncateDatabase(null, databaseName, true);//清空数据库中所有记录,并返回数量
// JE cannot truncate a database while its handle is open. Keep the
// template usable by reopening the same database after truncation.
com.sleepycat.je.DatabaseConfig config = myDatabase.getConfig();
myDatabase.close();
long deleteNum = env.truncateDatabase(null, databaseName, true);
myDatabase = env.openDatabase(null, databaseName, config);
System.out.println(deleteNum);


Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/sleepycat/berkeley/spring/boot/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public void getAllByCursor() throws UnsupportedEncodingException{
}

//向前遍历
while(myCursor.getPrev(databaseKey, databaseValue, LockMode.DEFAULT) == OperationStatus.SUCCESS){
myCursor.getFirst(databaseKey, databaseValue, LockMode.DEFAULT);
while(myCursor.getNext(databaseKey, databaseValue, LockMode.DEFAULT) == OperationStatus.SUCCESS){
String theKey = new String(databaseKey.getData(), "UTF-8");
String theData = new String(databaseValue.getData(), "UTF-8");
System.out.println("Key: " + theKey + "Data: " + theData);
Expand Down Expand Up @@ -92,7 +93,7 @@ public void searchMultipleByCursor(String key) throws UnsupportedEncodingExcepti
DatabaseEntry databaseValue = new DatabaseEntry();

OperationStatus res = myCursor.getSearchKey(databaseKey, databaseValue, LockMode.DEFAULT);
if(myCursor.count() > 1){
if(res == OperationStatus.SUCCESS){
while(res == OperationStatus.SUCCESS){
String foundKey = new String(databaseKey.getData(), "utf8");
String foundValue = new String(databaseValue.getData(), "utf8");
Expand Down Expand Up @@ -157,6 +158,7 @@ public void closeDatabase(){

public static void main(String[] args) throws UnsupportedEncodingException{
Cursor cursor = new Cursor();
if (args.length > 0) cursor.envDir = args[0];
cursor.configEnvironment();
cursor.createDatabase();
cursor.addDataByCursor("a", "www.baidu.com");
Expand All @@ -167,4 +169,4 @@ public static void main(String[] args) throws UnsupportedEncodingException{
cursor.closeDatabase();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.sleepycat.berkeley.spring.boot;

import com.sleepycat.berkeley.spring.boot.hooks.BerkeleyShutdownHook;
import com.sleepycat.bind.serial.StoredClassCatalog;
import com.sleepycat.je.Database;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.core.io.DefaultResourceLoader;

import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.*;

class BerkeleyConfigurationTest {
@TempDir Path home;

@Test
void configuresEnvironmentAndOpensCatalogAndDatabase() {
BerkeleyProperties properties = new BerkeleyProperties();
properties.setAllowCreate(true);
properties.setTransactional(true);
properties.setCatalogDatabaseName("catalog");
properties.setDatabaseName("items");
BerkeleyAutoConfiguration configuration = new BerkeleyAutoConfiguration();
ReflectionTestUtils.setField(configuration, "properties", properties);
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
configuration.setResourceLoader(resourceLoader);
assertSame(resourceLoader, ReflectionTestUtils.getField(configuration, "resourceLoader"));
EnvironmentConfig settings = configuration.configEnvironment();
assertTrue(settings.getAllowCreate());
assertTrue(settings.getTransactional());
assertFalse(settings.getReadOnly());
assertNotNull(configuration.repConfigProxy());

Environment environment = new Environment(home.toFile(), settings);
Database catalogDatabase = configuration.catalogDatabase(environment);
StoredClassCatalog catalog = configuration.catalog();
Database database = configuration.berkeleyDatabase(environment);
assertEquals("catalog", catalogDatabase.getDatabaseName());
assertEquals("items", database.getDatabaseName());
new BerkeleyShutdownHook(database, catalog, environment).run();
}
}
Loading
Loading