1 8 9 package com.sleepycat.je.cleaner; 10 11 import java.io.IOException ; 12 import java.util.Iterator ; 13 import java.util.Map ; 14 15 import junit.framework.TestCase; 16 17 import com.sleepycat.je.Cursor; 18 import com.sleepycat.je.DatabaseException; 19 import com.sleepycat.je.DbTestProxy; 20 import com.sleepycat.je.dbi.CursorImpl; 21 import com.sleepycat.je.dbi.EnvironmentImpl; 22 import com.sleepycat.je.log.UtilizationFileReader; 23 import com.sleepycat.je.tree.BIN; 24 import com.sleepycat.je.utilint.DbLsn; 25 26 29 public class CleanerTestUtils { 30 31 34 static long getLogFile(TestCase test, Cursor cursor) 35 throws DatabaseException { 36 37 CursorImpl impl = DbTestProxy.dbcGetCursorImpl(cursor); 38 int index; 39 BIN bin = impl.getDupBIN(); 40 if (bin != null) { 41 index = impl.getDupIndex(); 42 } else { 43 bin = impl.getBIN(); 44 TestCase.assertNotNull(bin); 45 index = impl.getIndex(); 46 } 47 TestCase.assertNotNull(bin.getTarget(index)); 48 long lsn = bin.getLsn(index); 49 TestCase.assertTrue(lsn != DbLsn.NULL_LSN); 50 long file = DbLsn.getFileNumber(lsn); 51 return file; 52 } 53 54 58 static void verifyUtilization(EnvironmentImpl env, 59 boolean expectAccurateObsoleteLNCount, 60 boolean expectAccurateObsoleteLNSize) 61 throws DatabaseException { 62 63 Map profileMap = env.getCleaner() 64 .getUtilizationProfile() 65 .getFileSummaryMap(true); 66 67 env.getLogManager().flushNoSync(); 68 Map recalcMap; 69 try { 70 recalcMap = UtilizationFileReader.calcFileSummaryMap(env); 71 } catch (IOException e) { 72 throw new DatabaseException(e); 73 } 74 Iterator i = profileMap.entrySet().iterator(); 75 while (i.hasNext()) { 76 Map.Entry entry = (Map.Entry ) i.next(); 77 Long file = (Long ) entry.getKey(); 78 FileSummary profileSummary = (FileSummary) entry.getValue(); 79 FileSummary recalcSummary = (FileSummary) recalcMap.remove(file); 80 TestCase.assertNotNull(recalcSummary); 81 if (expectAccurateObsoleteLNCount && 83 profileSummary.obsoleteLNCount != 84 recalcSummary.obsoleteLNCount) { 85 System.out.println("file=" + file); 86 System.out.println("profile=" + profileSummary); 87 System.out.println("recalc=" + recalcSummary); 88 } 89 TestCase.assertEquals(recalcSummary.totalCount, 91 profileSummary.totalCount); 92 TestCase.assertEquals(recalcSummary.totalSize, 93 profileSummary.totalSize); 94 TestCase.assertEquals(recalcSummary.totalINCount, 95 profileSummary.totalINCount); 96 TestCase.assertEquals(recalcSummary.totalINSize, 97 profileSummary.totalINSize); 98 TestCase.assertEquals(recalcSummary.totalLNCount, 99 profileSummary.totalLNCount); 100 TestCase.assertEquals(recalcSummary.totalLNSize, 101 profileSummary.totalLNSize); 102 106 if (false) { 107 TestCase.assertEquals(recalcSummary.obsoleteINCount, 108 profileSummary.obsoleteINCount); 109 } 110 111 117 if (expectAccurateObsoleteLNCount) { 118 TestCase.assertEquals(recalcSummary.obsoleteLNCount, 119 profileSummary.obsoleteLNCount); 120 121 128 if (expectAccurateObsoleteLNSize) { 129 TestCase.assertEquals(recalcSummary.getObsoleteLNSize(), 130 profileSummary.obsoleteLNSize); 131 } 132 } 133 } 134 TestCase.assertTrue(recalcMap.toString(), recalcMap.isEmpty()); 135 } 136 } 137 | Popular Tags |