1 8 9 package com.sleepycat.je.test; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 14 import junit.framework.TestCase; 15 16 import com.sleepycat.bind.tuple.IntegerBinding; 17 import com.sleepycat.je.Database; 18 import com.sleepycat.je.DatabaseConfig; 19 import com.sleepycat.je.DatabaseEntry; 20 import com.sleepycat.je.Environment; 21 import com.sleepycat.je.EnvironmentConfig; 22 import com.sleepycat.je.util.TestUtils; 23 24 27 public class MultiEnvOpenCloseTest extends TestCase { 28 29 private File envHome; 30 31 public void setUp() 32 throws IOException { 33 34 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 35 TestUtils.removeLogFiles("Setup", envHome, false); 36 } 37 38 public void tearDown() 39 throws Exception { 40 41 TestUtils.removeLogFiles("TearDown", envHome, false); 42 } 43 44 public void testMultiOpenClose() 45 throws Exception { 46 47 55 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 56 envConfig.setAllowCreate(true); 57 58 DatabaseConfig dbConfig = new DatabaseConfig(); 59 dbConfig.setAllowCreate(true); 60 61 final int DATA_SIZE = 1024 * 10; 62 final int N_RECORDS = 1000; 63 final int N_ITERS = 30; 64 65 DatabaseEntry key = new DatabaseEntry(); 66 DatabaseEntry data = new DatabaseEntry(new byte[DATA_SIZE]); 67 68 Environment env = new Environment(envHome, envConfig); 69 Database db = env.openDatabase(null, "MultiEnvOpenCloseTest", 70 dbConfig); 71 for (int i = 0; i < N_RECORDS; i += 1) { 72 IntegerBinding.intToEntry(i, key); 73 db.put(null, key, data); 74 } 75 76 db.close(); 77 env.close(); 78 79 envConfig.setAllowCreate(false); 80 envConfig.setReadOnly(true); 81 dbConfig.setAllowCreate(false); 82 dbConfig.setReadOnly(true); 83 84 for (int i = 1; i <= N_ITERS; i += 1) { 85 env = new Environment(envHome, envConfig); 87 db = env.openDatabase(null, "MultiEnvOpenCloseTest", dbConfig); 88 for (int j = 0; j < N_RECORDS; j += 1) { 89 IntegerBinding.intToEntry(j, key); 90 db.get(null, key, data, null); 91 } 92 db.close(); 93 env.close(); 94 } 95 } 96 } 97 | Popular Tags |