1 8 9 package com.sleepycat.je; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 14 import junit.framework.TestCase; 15 16 import com.sleepycat.je.config.EnvironmentParams; 17 import com.sleepycat.je.dbi.MemoryBudget; 18 import com.sleepycat.je.util.TestUtils; 19 20 public class EnvironmentStatTest extends TestCase { 21 22 private Environment env; 23 private File envHome; 24 25 public EnvironmentStatTest() { 26 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 27 } 28 29 public void setUp() 30 throws IOException { 31 32 TestUtils.removeLogFiles("Setup", envHome, false); 33 } 34 35 public void tearDown() 36 throws Exception { 37 38 41 try { 42 if (env != null) { 43 env.close(); 44 env = null; 45 } 46 } catch (DatabaseException e) { 47 48 } 49 50 TestUtils.removeLogFiles("TearDown", envHome, false); 51 } 52 53 56 public void testCacheStats() 57 throws Throwable { 58 59 try { 60 EnvironmentConfig envConfig = TestUtils.initEnvConfig(); 61 envConfig.setTransactional(true); 62 envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "6"); 63 envConfig.setAllowCreate(true); 64 env = new Environment(envHome, envConfig); 65 EnvironmentStats stat = env.getStats(TestUtils.FAST_STATS); 66 env.close(); 67 env = null; 68 assertEquals(0, stat.getNCacheMiss()); 69 assertEquals(0, stat.getNNotResident()); 70 71 envConfig.setAllowCreate(false); 73 envConfig.setConfigParam 74 (EnvironmentParams.JE_LOGGING_LEVEL.getName(), "CONFIG"); 75 env = new Environment(envHome, envConfig); 76 stat = env.getStats(TestUtils.FAST_STATS); 77 MemoryBudget mb = 78 DbInternal.envGetEnvironmentImpl(env).getMemoryBudget(); 79 long cacheSize = mb.getCacheMemoryUsage(); 80 long bufferSize = mb.getLogBufferBudget(); 81 82 assertEquals(12, stat.getNCacheMiss()); 83 assertEquals(12, stat.getNNotResident()); 84 85 assertEquals(cacheSize, stat.getCacheDataBytes()); 86 87 92 assertTrue(Math.abs(bufferSize-stat.getBufferBytes()) < 100); 93 assertTrue(Math.abs((cacheSize + bufferSize)- 94 stat.getCacheTotalBytes()) < 100); 95 env.close(); 96 } catch (Throwable t) { 97 t.printStackTrace(); 98 throw t; 99 } 100 } 101 } 102 | Popular Tags |