1 8 package com.sleepycat.persist.test; 9 10 import java.io.File ; 11 import java.io.IOException ; 12 13 import junit.framework.Test; 14 15 import com.sleepycat.je.util.TestUtils; 16 import com.sleepycat.persist.impl.PersistCatalog; 17 import com.sleepycat.persist.evolve.EvolveConfig; 18 import com.sleepycat.persist.evolve.EvolveEvent; 19 import com.sleepycat.persist.evolve.EvolveStats; 20 import com.sleepycat.persist.evolve.EvolveListener; 21 22 31 public class EvolveTest extends EvolveTestBase { 32 33 public static Test suite() 34 throws Exception { 35 36 return getSuite(EvolveTest.class); 37 } 38 39 private int evolveNRead; 40 private int evolveNConverted; 41 42 @Override 43 public void setUp() 44 throws IOException { 45 46 47 envHome = new File (System.getProperty(TestUtils.DEST_DIR)); 48 TestUtils.removeLogFiles("Setup", envHome, false); 49 TestUtils.copyFiles(getTestInitHome(), envHome); 50 } 51 52 public void testLazyEvolve() 53 throws Exception { 54 55 openEnv(); 56 57 62 openRawStore(); 63 caseObj.checkUnevolvedModel(rawStore.getModel(), env); 64 caseObj.readRawObjects 65 (rawStore, false , false ); 66 closeRawStore(); 67 68 if (openStoreReadWrite()) { 69 70 74 caseObj.checkEvolvedModel 75 (store.getModel(), env, true ); 76 caseObj.readObjects(store, false ); 77 closeStore(); 78 79 83 openRawStore(); 84 caseObj.checkEvolvedModel 85 (rawStore.getModel(), env, true ); 86 caseObj.readRawObjects 87 (rawStore, true , false ); 88 closeRawStore(); 89 90 94 PersistCatalog.expectNoClassChanges = true; 95 try { 96 openStoreReadOnly(); 97 } finally { 98 PersistCatalog.expectNoClassChanges = false; 99 } 100 caseObj.checkEvolvedModel 101 (store.getModel(), env, true ); 102 caseObj.readObjects(store, false ); 103 closeStore(); 104 105 109 openStoreReadWrite(); 110 caseObj.checkEvolvedModel 111 (store.getModel(), env, true ); 112 caseObj.readObjects(store, true ); 113 caseObj.checkEvolvedModel 114 (store.getModel(), env, true ); 115 closeStore(); 116 117 120 openRawStore(); 121 caseObj.checkEvolvedModel 122 (rawStore.getModel(), env, true ); 123 caseObj.readRawObjects 124 (rawStore, true , true ); 125 closeRawStore(); 126 } 127 128 closeAll(); 129 } 130 131 public void testEagerEvolve() 132 throws Exception { 133 134 135 if (caseObj.getStoreOpenException() != null) { 136 return; 137 } 138 139 EvolveConfig config = new EvolveConfig(); 140 config.setEvolveListener(new EvolveListener() { 141 public boolean evolveProgress(EvolveEvent event) { 142 EvolveStats stats = event.getStats(); 143 evolveNRead = stats.getNRead(); 144 evolveNConverted = stats.getNConverted(); 145 return true; 146 } 147 }); 148 149 openEnv(); 150 151 openStoreReadWrite(); 152 153 157 int nExpected = caseObj.getNRecordsExpected(); 158 evolveNRead = 0; 159 evolveNConverted = 0; 160 EvolveStats stats = store.evolve(config); 161 assertTrue(evolveNRead == nExpected); 162 assertTrue(evolveNConverted == nExpected); 163 assertTrue(evolveNConverted >= evolveNRead); 164 assertEquals(evolveNRead, stats.getNRead()); 165 assertEquals(evolveNConverted, stats.getNConverted()); 166 167 168 evolveNRead = 0; 169 evolveNConverted = 0; 170 stats = store.evolve(config); 171 assertTrue(evolveNRead == 0); 172 assertTrue(evolveNConverted == 0); 173 assertEquals(0, stats.getNRead()); 174 assertEquals(0, stats.getNConverted()); 175 176 180 181 182 caseObj.checkEvolvedModel 183 (store.getModel(), env, true ); 184 caseObj.readObjects(store, true ); 185 caseObj.checkEvolvedModel 186 (store.getModel(), env, true ); 187 closeStore(); 188 189 190 openStoreReadOnly(); 191 caseObj.checkEvolvedModel 192 (store.getModel(), env, true ); 193 caseObj.readObjects(store, false ); 194 caseObj.checkEvolvedModel 195 (store.getModel(), env, true ); 196 closeStore(); 197 198 199 openRawStore(); 200 caseObj.checkEvolvedModel 201 (rawStore.getModel(), env, true ); 202 caseObj.readRawObjects 203 (rawStore, true , true ); 204 205 210 openNewStore(); 211 caseObj.copyRawObjects(rawStore, newStore); 212 caseObj.readObjects(newStore, true ); 213 caseObj.checkEvolvedModel 214 (newStore.getModel(), env, false ); 215 closeNewStore(); 216 closeRawStore(); 217 218 closeAll(); 219 } 220 } 221 | Popular Tags |