1 8 9 package com.sleepycat.je.txn; 10 11 import junit.framework.Test; 12 13 import com.sleepycat.je.Database; 14 import com.sleepycat.je.DatabaseConfig; 15 import com.sleepycat.je.DatabaseEntry; 16 import com.sleepycat.je.DbInternal; 17 import com.sleepycat.je.Environment; 18 import com.sleepycat.je.EnvironmentConfig; 19 import com.sleepycat.je.LockMode; 20 import com.sleepycat.je.OperationStatus; 21 import com.sleepycat.je.Transaction; 22 import com.sleepycat.je.config.EnvironmentParams; 23 import com.sleepycat.je.dbi.DbEnvPool; 24 import com.sleepycat.je.dbi.EnvironmentImpl; 25 import com.sleepycat.je.test.TxnTestCase; 26 import com.sleepycat.je.util.TestUtils; 27 28 37 38 public class TxnFSyncTest extends TxnTestCase { 39 40 private static final int NUM_RECS = 5; 41 42 private static EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 43 static { 44 envConfig.setAllowCreate(true); 45 setupEnvConfig(envConfig); 46 } 47 48 private static void setupEnvConfig(EnvironmentConfig envConfig) { 49 envConfig.setTransactional(true); 50 envConfig.setConfigParam( 51 EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false"); 52 } 53 54 public static Test suite() { 55 56 return txnTestSuite(TxnFSyncTest.class, 57 envConfig, 58 new String [] {TxnTestCase.TXN_USER, 59 TxnTestCase.TXN_AUTO}); 60 } 61 62 public void testFSyncButNoClose() 63 throws Exception { 64 65 try { 66 67 DatabaseConfig dbConfig = new DatabaseConfig(); 68 dbConfig.setTransactional(isTransactional); 69 dbConfig.setAllowCreate(true); 70 Transaction txn = txnBegin(); 71 Database db = env.openDatabase(txn, "foo", dbConfig); 72 73 74 DatabaseEntry key = new DatabaseEntry(); 75 DatabaseEntry data = new DatabaseEntry(); 76 for (int i = 0; i < NUM_RECS; i++) { 77 Integer val = new Integer (i); 78 key.setData(val.toString().getBytes()); 79 data.setData(val.toString().getBytes()); 80 81 assertEquals(OperationStatus.SUCCESS, 82 db.putNoOverwrite(txn, key, data)); 83 } 84 txnCommit(txn); 85 86 92 EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env); 93 envImpl.getFileManager().clear(); envImpl.getFileManager().close(); env = null; 96 DbEnvPool.getInstance().clear(); 97 98 102 EnvironmentConfig envConfig2 = TestUtils.initEnvConfig(); 103 setupEnvConfig(envConfig2); 104 env = new Environment(envHome, envConfig2); 105 dbConfig.setAllowCreate(false); 106 db = env.openDatabase(null, "foo", dbConfig); 107 108 109 for (int i = 0; i < NUM_RECS; i++) { 110 Integer val = new Integer (i); 111 key.setData(val.toString().getBytes()); 112 113 assertEquals(OperationStatus.SUCCESS, 114 db.get(null, key, data, LockMode.DEFAULT)); 115 116 } 117 db.close(); 118 } catch (Exception e) { 119 e.printStackTrace(); 120 throw e; 121 } 122 } 123 } 124 125 | Popular Tags |