db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r506899 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store: T_RawStoreFactory.java T_Util.java
Date Tue, 13 Feb 2007 08:09:39 GMT
Author: kahatlen
Date: Tue Feb 13 00:09:38 2007
New Revision: 506899

URL: http://svn.apache.org/viewvc?view=rev&rev=506899
Log:
DERBY-2107: Move page latching out of the lock manager

Added test case.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Util.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java?view=diff&rev=506899&r1=506898&r2=506899
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_RawStoreFactory.java
Tue Feb 13 00:09:38 2007
@@ -315,6 +315,7 @@
 		P021();		// test preAllocate
 		P022();
 		P023(0);	// overflowThreshold test
+		P024(0);	// test page latching
 
 		// long row tests
 		P030(0);
@@ -3662,6 +3663,50 @@
 		t_util.t_commit(t);
 		t.close();
 		PASS("P023");
+	}
+
+	/**
+	 * Test that latches are exclusive.
+	 *
+	 * @exception T_Fail Unexpected behaviour from the API
+	 * @exception StandardException Unexpected exception from the implementation
+	 */
+	protected void P024(long segment) throws StandardException, T_Fail
+	{
+		Transaction t = t_util.t_startTransaction();
+
+		long cid = t_util.t_addContainer(t, segment, 4096, 0, 1, false);
+
+		ContainerHandle c = t_util.t_openContainer(t, segment, cid, true);
+
+		Page page1 = t_util.t_getLastPage(c);
+		Page page2 = t_util.t_addPage(c);
+
+		long p1 = page1.getPageNumber();
+		long p2 = page2.getPageNumber();
+
+		// check that we cannot get any of the latched pages
+		t_util.t_checkGetLatchedPage(c, p1);
+		t_util.t_checkGetLatchedPage(c, p2);
+
+		page1.unlatch();
+
+		// check that we still cannot get page2
+		t_util.t_checkGetLatchedPage(c, p2);
+
+		// we should be able to get page1
+		page1 = t_util.t_getPage(c, p1);
+
+		page1.unlatch();
+		page2.unlatch();
+
+		// cleanup
+		t_util.t_dropContainer(t, segment, cid);
+
+		t_util.t_commit(t);
+		t.close();
+
+		PASS("P024");
 	}
 		
 	/**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Util.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Util.java?view=diff&rev=506899&r1=506898&r2=506899
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Util.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/store/T_Util.java Tue
Feb 13 00:09:38 2007
@@ -1133,6 +1133,43 @@
 			throw T_Fail.testFailMsg("got a deallcated page back");
 	} 
 
+	/**
+	 * Check that it's not possible to get a page which is latched.
+	 *
+	 * @param c a container handle
+	 * @param pageNumber the page number to check
+	 * @exception StandardException if an unexpected error occurs
+	 * @exception T_Fail if the test fails
+	 */
+	public void t_checkGetLatchedPage(ContainerHandle c, long pageNumber)
+			throws StandardException, T_Fail {
+		// we expect to hang in getPage() so make sure we are interrupted
+		final Thread me = Thread.currentThread();
+		Runnable r = new Runnable() {
+				public void run() {
+					try {
+						Thread.sleep(2000);
+					} catch (InterruptedException e) { }
+					me.interrupt();
+				}
+			};
+		Thread interrupter = new Thread(r);
+		interrupter.start();
+
+		try {
+			Page p = c.getPage(pageNumber);
+			throw T_Fail.testFailMsg("got latched page");
+		} catch (StandardException se) {
+			// expect thread interrupted exception
+			if (!se.getMessageId().equals("08000")) {
+				throw se;
+			}
+		}
+
+		try {
+			interrupter.join();
+		} catch (InterruptedException ie) { }
+	}
 
 	/**
 		Call page.insert() and ensure that the return record handle is not null.



Mime
View raw message