Skip to content
Browse files

Added a Unit test for checking share behavior.

  • Loading branch information...
1 parent 087e9d7 commit 9462de9afa7cb66e8239f598d5ca1dee2f3ae735 @bbansal bbansal committed Feb 10, 2009
Showing with 108 additions and 13 deletions.
  1. +108 −13 test/unit/voldemort/store/bdb/BdbSplitStorageEngineTest.java
View
121 test/unit/voldemort/store/bdb/BdbSplitStorageEngineTest.java
@@ -17,7 +17,6 @@
package voldemort.store.bdb;
import java.io.File;
-import java.util.Random;
import junit.framework.TestCase;
@@ -28,6 +27,14 @@
import voldemort.utils.Props;
import voldemort.versioning.Versioned;
+import com.sleepycat.je.Database;
+import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DatabaseException;
+import com.sleepycat.je.Environment;
+import com.sleepycat.je.EnvironmentConfig;
+import com.sleepycat.je.EnvironmentStats;
+import com.sleepycat.je.StatsConfig;
+
/**
* checks that
*
@@ -37,10 +44,11 @@
public class BdbSplitStorageEngineTest extends TestCase {
private File bdbMasterDir;
- private BdbStorageEngine storeA;
- private BdbStorageEngine storeB;
- private Random random;
- BdbStorageConfiguration bdbStorage;
+
+ private BdbStorageConfiguration bdbStorage;
+
+ // Berkeley DB keeps growing cache till 500MB
+ private static long CACHE_SIZE = 500 * 1000 * 1000;
@Override
protected void setUp() throws Exception {
@@ -54,24 +62,27 @@ protected void setUp() throws Exception {
protected void tearDown() throws Exception {
super.tearDown();
try {
- bdbStorage.close();
+ if(bdbStorage != null) {
+ bdbStorage.close();
+ }
} finally {
FileDeleteStrategy.FORCE.delete(bdbMasterDir);
}
}
- public void testNoMultipleFiles() {
+ public void testNoMultipleEnvironment() {
// lets use all the default values.
Props props = new Props();
props.put("node.id", 1);
props.put("voldemort.home", "test/common/voldemort/config");
VoldemortConfig voldemortConfig = new VoldemortConfig(props);
voldemortConfig.setBdbCacheSize(1 * 1024 * 1024);
voldemortConfig.setBdbDataDirectory(bdbMasterDir.toURI().getPath());
+ voldemortConfig.setBdbOneEnvPerStore(false);
bdbStorage = new BdbStorageConfiguration(voldemortConfig);
- storeA = (BdbStorageEngine) bdbStorage.getStore("storeA");
- storeB = (BdbStorageEngine) bdbStorage.getStore("storeB");
+ BdbStorageEngine storeA = (BdbStorageEngine) bdbStorage.getStore("storeA");
+ BdbStorageEngine storeB = (BdbStorageEngine) bdbStorage.getStore("storeB");
storeA.put("testKey1".getBytes(), new Versioned<byte[]>("value".getBytes()));
storeA.put("testKey2".getBytes(), new Versioned<byte[]>("value".getBytes()));
@@ -92,19 +103,19 @@ public void testNoMultipleFiles() {
+ "storeB").exists()));
}
- public void testMultipleFiles() {
+ public void testMultipleEnvironment() {
// lets use all the default values.
Props props = new Props();
props.put("node.id", 1);
props.put("voldemort.home", "test/common/voldemort/config");
VoldemortConfig voldemortConfig = new VoldemortConfig(props);
voldemortConfig.setBdbCacheSize(1 * 1024 * 1024);
- voldemortConfig.setBdbFilePerStore(true);
+ voldemortConfig.setBdbOneEnvPerStore(true);
voldemortConfig.setBdbDataDirectory(bdbMasterDir.toURI().getPath());
bdbStorage = new BdbStorageConfiguration(voldemortConfig);
- storeA = (BdbStorageEngine) bdbStorage.getStore("storeA");
- storeB = (BdbStorageEngine) bdbStorage.getStore("storeB");
+ BdbStorageEngine storeA = (BdbStorageEngine) bdbStorage.getStore("storeA");
+ BdbStorageEngine storeB = (BdbStorageEngine) bdbStorage.getStore("storeB");
storeA.put("testKey1".getBytes(), new Versioned<byte[]>("value".getBytes()));
storeA.put("testKey2".getBytes(), new Versioned<byte[]>("value".getBytes()));
@@ -122,4 +133,88 @@ public void testMultipleFiles() {
assertEquals("StoreB BDB file should exists.", true, (new File(bdbMasterDir + "/"
+ "storeB").exists()));
}
+
+ public void testUnsharedCache() throws DatabaseException {
+ EnvironmentConfig environmentConfig = new EnvironmentConfig();
+ environmentConfig = new EnvironmentConfig();
+ environmentConfig.setTxnNoSync(true);
+ environmentConfig.setAllowCreate(true);
+ environmentConfig.setTransactional(true);
+ environmentConfig.setSharedCache(false);
+
+ // set cache size to 95 % of max memory available
+ environmentConfig.setCacheSize((long) (CACHE_SIZE));
+
+ DatabaseConfig databaseConfig = new DatabaseConfig();
+ databaseConfig.setAllowCreate(true);
+ databaseConfig.setTransactional(true);
+ databaseConfig.setSortedDuplicates(true);
+
+ long maxCacheSize = getMaxCacheUsage(environmentConfig, databaseConfig);
+
+ assertEquals("MaxCacheSize > CACHE_SIZE", true, maxCacheSize > CACHE_SIZE);
+ }
+
+ public void testsharedCache() throws DatabaseException {
+ EnvironmentConfig environmentConfig = new EnvironmentConfig();
+ environmentConfig = new EnvironmentConfig();
+ environmentConfig.setTxnNoSync(true);
+ environmentConfig.setAllowCreate(true);
+ environmentConfig.setTransactional(true);
+ environmentConfig.setSharedCache(true);
+ environmentConfig.setCacheSize(CACHE_SIZE);
+
+ DatabaseConfig databaseConfig = new DatabaseConfig();
+ databaseConfig.setAllowCreate(true);
+ databaseConfig.setTransactional(true);
+ databaseConfig.setSortedDuplicates(true);
+
+ long maxCacheSize = getMaxCacheUsage(environmentConfig, databaseConfig);
+ assertEquals("MaxCacheSize <= CACHE_SIZE", true, maxCacheSize <= CACHE_SIZE);
+ }
+
+ private long getMaxCacheUsage(EnvironmentConfig environmentConfig, DatabaseConfig databaseConfig)
+ throws DatabaseException {
+ File dirA = new File(bdbMasterDir + "/" + "storeA");
+ if(!dirA.exists()) {
+ dirA.mkdirs();
+ }
+ Environment environmentA = new Environment(dirA, environmentConfig);
+ Database databaseA = environmentA.openDatabase(null, "storeA", databaseConfig);
+ BdbStorageEngine storeA = new BdbStorageEngine("storeA", environmentA, databaseA);
+
+ File dirB = new File(bdbMasterDir + "/" + "storeB");
+ if(!dirB.exists()) {
+ dirB.mkdirs();
+ }
+ Environment environmentB = new Environment(dirB, environmentConfig);
+ Database databaseB = environmentB.openDatabase(null, "storeB", databaseConfig);
+ BdbStorageEngine storeB = new BdbStorageEngine("storeB", environmentB, databaseB);
+
+ long maxCacheUsage = 0;
+ for(int i = 0; i <= 4; i++) {
+
+ byte[] value = new byte[(int) (CACHE_SIZE / 4)];
+ // try to push values in cache
+ storeA.put((i + "A").getBytes(), new Versioned<byte[]>(value));
+ storeA.get((i + "A").getBytes());
+
+ storeB.put((i + "B").getBytes(), new Versioned<byte[]>(value));
+ storeB.get((i + "B").getBytes());
+
+ EnvironmentStats statsA = environmentA.getStats(new StatsConfig());
+ EnvironmentStats statsB = environmentB.getStats(new StatsConfig());
+
+ long totalCacheSize = statsA.getCacheTotalBytes() + statsB.getCacheTotalBytes();
+ System.out.println("A.size:" + statsA.getCacheTotalBytes() + " B.size:"
+ + statsB.getCacheTotalBytes() + " total:" + totalCacheSize + " max:"
+ + maxCacheUsage + " cacheMax:"
+ + environmentA.getConfig().getCacheSize());
+ System.out.println("Shared.A:" + statsA.getSharedCacheTotalBytes() + " nSharedEnv:"
+ + statsA.getNSharedCacheEnvironments());
+ maxCacheUsage = Math.max(maxCacheUsage, totalCacheSize);
+ }
+
+ return maxCacheUsage;
+ }
}

0 comments on commit 9462de9

Please sign in to comment.
Something went wrong with that request. Please try again.