⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_recoverfulllog.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*   Derby - Class org.apache.derbyTesting.unitTests.store.T_RecoverFullLog   Copyright 1997, 2005 The Apache Software Foundation or its licensors, as applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License. */package org.apache.derbyTesting.unitTests.store;import org.apache.derbyTesting.unitTests.harness.T_Generic;import org.apache.derbyTesting.unitTests.harness.T_Fail;import org.apache.derbyTesting.unitTests.harness.UnitTest;import org.apache.derby.impl.store.raw.log.*;import org.apache.derby.iapi.services.context.ContextService;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.daemon.DaemonService;import org.apache.derby.iapi.services.property.PropertyUtil;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.monitor.ModuleFactory;import org.apache.derby.iapi.services.locks.LockFactory;import org.apache.derby.iapi.services.io.Storable;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.reference.Property;import org.apache.derby.iapi.reference.EngineType;import org.apache.derby.iapi.services.property.PropertyUtil;import org.apache.derby.iapi.services.io.FormatableBitSet;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.store.raw.*;import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo;import java.io.IOException;import java.io.RandomAccessFile;import java.io.File;import java.util.Properties;/**	A implementation unit test for log full condition    To run, create a derby.properties file in a new directory with the	contents	derby.module.test.recoverFullLog=org.apache.derbyTesting.unitTests.store.T_RecoverFullLog    Execute in order	java -DTestFillLog=true org.apache.derbyTesting.unitTests.harness.UnitTestMain	java -DTestLogSwitchFail=true org.apache.derbyTesting.unitTests.harness.UnitTestMain	java -DTestFullRecoveryFail=true org.apache.derbyTesting.unitTests.harness.UnitTestMain 		(run this serveral times, this simulate recovery running out of log)	java -DTestFullRecover=true org.apache.derbyTesting.unitTests.harness.UnitTestMain */public class T_RecoverFullLog extends T_Generic {	private static final String testService = "FullLogTest";	static final String REC_001 = "McLaren";	static final String REC_002 = "Ferrari";	static final String REC_003 = "Benetton";	static final String REC_004 = "Prost";	static final String REC_005 = "Tyrell";	static final String REC_006 = "Derby, Natscape, Goatscape, the popular names";	static final String REC_UNDO = "Lotus";	static final String SP1 = "savepoint1";	static final String SP2 = "savepoint2";	private RandomAccessFile infofile = null;	private static final String infoPath = "extinout/T_RecoverFullLog.info";	private boolean fillLog;	// test to full up the log	private boolean recoveryFail; // recovery fill up the log	private boolean logSwitchFail;	// log filled up during log switch	private boolean recover;	// successfully recover	private String TEST_FILL_LOG = "TestFillLog";	// test to full up the log	private String TEST_FULL_RECOVER_FAIL = "TestFullRecoveryFail"; // recovery fill up the log	private String TEST_LOG_SWITCH_FAIL = "TestLogSwitchFail"; // log filled up during log switch	private String TEST_FULL_RECOVER = "TestFullRecover";	// successfully recover	private static final String TEST_FULL_LOG_INFO = "TestFullLogInfo";	RawStoreFactory	factory;	LockFactory  lf;	ContextService contextService;	T_Util t_util;	public T_RecoverFullLog() {		super();	}	/*	** Methods required by T_Generic	*/	public String getModuleToTestProtocolName() {		return RawStoreFactory.MODULE;	}	/**	*/	private void getConfig()	{		String param;		param = PropertyUtil.getSystemProperty(TEST_FILL_LOG);		fillLog = Boolean.valueOf(param).booleanValue();		param = PropertyUtil.getSystemProperty(TEST_FULL_RECOVER_FAIL);		recoveryFail = Boolean.valueOf(param).booleanValue();		param = PropertyUtil.getSystemProperty(TEST_FULL_RECOVER);		recover = Boolean.valueOf(param).booleanValue();		param = PropertyUtil.getSystemProperty(TEST_LOG_SWITCH_FAIL);		logSwitchFail = Boolean.valueOf(param).booleanValue();	}	/**	    See T_Recovery for the general testing frame work		@exception T_Fail Unexpected behaviour from the API	 */	public void runTests() throws T_Fail {		getConfig();		int tests = 0;		if (fillLog) tests++;		if (recoveryFail) tests++;		if (recover) tests++;		if (logSwitchFail) tests++;		if (tests != 1)			throw T_Fail.testFailMsg("One & only one of the full log recovery test should be run, now " + tests + " set");		if (!SanityManager.DEBUG)		{			REPORT("recoverBadLog cannot be run on an insane server");			return;		}		try {			contextService = ContextService.getFactory();			File ifile = new File(infoPath);						//if external input output files dir does not exist ,create one			File ifdir = new File("extinout");			if(!ifdir.exists())				ifdir.mkdirs();			// see if we are testing encryption			startParams = T_Util.setEncryptionParam(startParams);			if (fillLog)				// the first test cleans up and start from fresh			{				// remove the service directory to ensure a clean run				REPORT("_______________________________________________________");				REPORT("\n\t\tcleaning up database for recovering from filled log");				REPORT("_______________________________________________________");				// don't automatic boot this service if it gets left around				if (startParams == null) 					startParams = new Properties();								startParams.put(Property.NO_AUTO_BOOT, Boolean.TRUE.toString());				// remove the service directory to ensure a clean run				startParams.put(Property.DELETE_ON_CREATE, Boolean.TRUE.toString());				factory = (RawStoreFactory) Monitor.createPersistentService(getModuleToTestProtocolName(),																  testService,																  startParams);				// create a database with nothing				// if exist, delete the info file				if (ifile.exists())					ifile.delete();				// create a new info file				try				{					infofile = new RandomAccessFile(ifile, "rw");				}				catch (IOException ioe)				{					System.out.println("Cannot write to temporary file " +									   infoPath + 									   ".  Please make sure it is correct, if not, please set the property " +									   "TestFullLogInfo=<where temp files should go>");					throw T_Fail.exceptionFail(ioe);				}								}			else			{				// see if we can recover the database				REPORT("_______________________________________________________");				if (recoveryFail)					REPORT("\n\t\trecovering database - recovery will fill up log");				else					REPORT("\n\t\trecovering database - recovery should succeed");				REPORT("_______________________________________________________");				try				{					// make sure it does exist					infofile = new RandomAccessFile(ifile, "rw");				}				catch (IOException ioe)				{					throw T_Fail.exceptionFail(ioe);				}				// let recovery log 10 records then run out of space				if (recoveryFail)				{					SanityManager.DEBUG_SET(LogToFile.TEST_LOG_FULL);					System.getProperties().put(LogToFile.TEST_RECORD_TO_FILL_LOG, "10");				}				if (!Monitor.startPersistentService(testService, startParams))					throw T_Fail.testFailMsg("Monitor didn't know how to restart service: " + testService);				factory = (RawStoreFactory) Monitor.findService(getModuleToTestProtocolName(), testService);				if (recoveryFail)				{					throw T_Fail.testFailMsg("recovery should have failed but did not - did you run the test in order?");				}			}		} catch (StandardException mse) {			if (recoveryFail) {						REPORT("_______________________________________________________");						REPORT("\n\tRecovery failed due to log full as requested ");						REPORT("\texception was " + mse.toString());						REPORT("_______________________________________________________");						return;			}			throw T_Fail.exceptionFail(mse);		} catch (NullPointerException npe) {			if (recoveryFail) {						REPORT("_______________________________________________________");						REPORT("\n\tRecovery failed due to log full as requested ");						REPORT("\texception was " + npe.toString());						REPORT("_______________________________________________________");						return;			}			throw T_Fail.exceptionFail(npe);		}		if (factory == null) {			throw T_Fail.testFailMsg(getModuleToTestProtocolName() + " service not started.");		}					lf = factory.getLockFactory();		if (lf == null) {			throw T_Fail.testFailMsg("LockFactory.MODULE not found");		}		// get a utility helper		t_util = new T_Util(factory, lf, contextService);		try		{			if (fillLog)			{				testBasic(1);				fillUpLog();			}			else if (logSwitchFail)			{				testBasic(2);				logSwitchFail1();				testBasic(3);				logSwitchFail2();			}			else if (!recoveryFail)			{				checkRecovery();			}		} catch (StandardException se) {			throw T_Fail.exceptionFail(se);		}	}	private long find(long inkey)	{		if (infofile == null)			return -1;		try 		{			infofile.seek(0);			long key;			while(true)			{				key = infofile.readLong();				if (key == inkey)				{					long value = infofile.readLong();					// System.out.println("found " + key + " " + value);					return value;				}				infofile.readLong();			}		} 		catch (IOException ioe)		{			// System.out.println("key not found " + inkey);			return -1;		}	}	private long key(int test, int param)	{		long i = test;		return ((i << 32) + param);	}	private void register(long key, long value)		 throws T_Fail	{		// System.out.println("registering " + key + " " + value);		try 		{			// go to the end			infofile.seek(infofile.length());			infofile.writeLong(key);			infofile.writeLong(value);		}		catch (IOException ioe)		{			T_Fail.exceptionFail(ioe);		}	}	/*	 * A basic routine to write a bunch of stuff to the log	 * There will be some committed transactions, some uncommitted transactions,	 * serveral checkpoints.	 */	protected void testBasic(int testNumber) throws T_Fail, StandardException	{		int numtrans = 7;		int numpages = 7;		int i,j;		// this is basically T_Recovery S203 		T_TWC[] t = new T_TWC[numtrans];		for (i = 0; i < numtrans; i++)			t[i] =  t_util.t_startTransactionWithContext();		long[] cid = new long[numtrans];		ContainerHandle[] c = new ContainerHandle[numtrans];		for (i = 0; i < numtrans; i++)		{			cid[i] = t_util.t_addContainer(t[i], 0);			t_util.t_commit(t[i]);			c[i] = t_util.t_openContainer(t[i], 0, cid[i], true);		}		Page page[][] = new Page[numtrans][numpages];		long pagenum[][] = new long[numtrans][numpages];		for (i = 0; i < numtrans; i++)		{			for (j = 0; j < numpages; j++)			{				t[i].switchTransactionContext();				page[i][j] = t_util.t_addPage(c[i]);				pagenum[i][j] = page[i][j].getPageNumber();				t[i].resetContext();			}		}		// set up numtrans (at least 5) transactions, each with one		// container and numpages pages.  Do the following test:		//		// 1) insert 1 row onto each page		// set savepoint SP1 on first transaction (t0)		//		// 2) update every rows		// set savepoint SP1 on all other transactions		//		// 3) update every rows		// set savepoint SP2 on all transactions		// 		// 4) update every rows		//		// 5) rollback t0 to SP1		//		// check that only page[0][x] have been rolled back		// past SP2		//		// 6) update every row

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -