1 5 package com.tc.objectserver.persistence.sleepycat; 6 7 import com.sleepycat.je.DatabaseConfig; 8 import com.sleepycat.je.EnvironmentConfig; 9 import com.tc.logging.TCLogger; 10 import com.tc.logging.TCLogging; 11 import com.tc.test.TCTestCase; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 import java.util.ArrayList ; 16 import java.util.HashMap ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 public class SleepycatMapStoreTest extends TCTestCase { 21 22 private File envHome; 23 private EnvironmentConfig ecfg; 24 private DatabaseConfig dbcfg; 25 private static int count = 0; 26 27 protected void setUp() throws Exception { 28 super.setUp(); 29 ecfg = new EnvironmentConfig(); 30 ecfg.setAllowCreate(true); 31 ecfg.setReadOnly(false); 32 ecfg.setTransactional(true); 33 34 dbcfg = new DatabaseConfig(); 35 dbcfg.setAllowCreate(true); 36 dbcfg.setReadOnly(false); 37 dbcfg.setTransactional(true); 38 while ((envHome = new File (this.getTempDirectory(), ++count + "")).exists()) { 39 } 41 System.out.println("DB home: " + envHome); 42 43 } 44 45 private DBEnvironment newEnv(boolean paranoid) throws IOException { 46 return newEnv(new HashMap (), new ArrayList (), paranoid); 47 } 48 49 private DBEnvironment newEnv(Map map, List list, boolean paranoid) throws IOException { 50 return new DBEnvironment(map, list, paranoid, envHome, ecfg, dbcfg); 51 } 52 53 public void testBasic() throws Exception { 54 DBEnvironment env = newEnv(true); 55 assertTrue(env.open().isClean()); 56 SleepycatPersistenceTransactionProvider persistenceTransactionProvider = new SleepycatPersistenceTransactionProvider( 57 env 58 .getEnvironment()); 59 TCLogger logger = TCLogging.getLogger(SleepycatSequenceTest.class); 60 61 SleepycatMapStore mapStore = new SleepycatMapStore(persistenceTransactionProvider, logger, env 62 .getClusterStateStoreDatabase()); 63 String val = mapStore.get("Hello"); 64 assertNull(val); 65 mapStore.put("Hello", "Saro"); 66 val = mapStore.get("Hello"); 67 assertEquals("Saro", val); 68 boolean removed = mapStore.remove("Hello"); 69 assertTrue(removed); 70 val = mapStore.get("Hello"); 71 assertNull(val); 72 73 for (int i = 0; i < 1000; i++) { 74 mapStore.put("day" + i, "cya" + i); 75 } 76 77 removed = mapStore.remove("Day1"); assertFalse(removed); 79 80 for (int i = 0; i < 1000; i++) { 81 val = mapStore.get("day" + i); 82 assertEquals("cya" + i, val); 83 removed = mapStore.remove("day" + i); 84 assertTrue(removed); 85 } 86 87 for (int i = 0; i < 1000; i++) { 88 val = mapStore.get("day" + i); 89 assertNull(val); 90 removed = mapStore.remove("day" + i); 91 assertFalse(removed); 92 } 93 } 94 95 } 96 | Popular Tags |