You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by fu...@apache.org on 2005/03/03 02:30:45 UTC

svn commit: r155990 [4/15] - in incubator/derby/code/trunk: ./ java/testing/ java/testing/org/apache/derbyTesting/functionTests/harness/ java/testing/org/apache/derbyTesting/functionTests/master/ java/testing/org/apache/derbyTesting/functionTests/suites/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/ java/testing/org/apache/derbyTesting/functionTests/tests/store/ java/testing/org/apache/derbyTesting/functionTests/tests/unit/ java/testing/org/apache/derbyTesting/unitTests/ java/testing/org/apache/derbyTesting/unitTests/crypto/ java/testing/org/apache/derbyTesting/unitTests/harness/ java/testing/org/apache/derbyTesting/unitTests/lang/ java/testing/org/apache/derbyTesting/unitTests/services/ java/testing/org/apache/derbyTesting/unitTests/store/ java/testing/org/apache/derbyTesting/unitTests/util/

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_MultiThreadedIterations.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_MultiThreadedIterations.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_MultiThreadedIterations.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_MultiThreadedIterations.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,246 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.harness.T_MultiThreadedIterations
+
+   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.harness;
+
+import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.iapi.services.property.PropertyUtil;
+
+import java.util.Properties;
+
+/**
+	Abstract class which executes T_MultiIterations. This allows multiple
+	threads running T_MultiIterations.
+
+	This allows the setup to be performed once, and then the
+	test itself to be run with multiple threads for a number of iterations. 
+	The number of threads and iterations are set by the property 
+	derby.unittests.numThreads and derby.unittests.iterations
+	and default to 1.
+	<P>
+	Statistics are provided about each iteration in the error log. The statistics
+	are time for each iteration, used and total memory changes per iteration.
+
+	@see T_Generic
+*/
+public abstract class T_MultiThreadedIterations extends T_MultiIterations implements Runnable
+{
+	protected int threadNumber = 0;
+
+	static volatile boolean inError = false;
+
+	static int numThreads = 1;
+	static int iterations = 1;
+
+	Throwable error = null;
+	static Thread[] TestThreads;
+	static T_MultiThreadedIterations[] TestObjects;
+
+	protected T_MultiThreadedIterations()
+	{
+		super();
+	}
+
+	/**
+	  Run the test. The test should raise an exception if it
+	  fails. runTests should return if the tests pass.
+
+	  @exception T_Fail Test code throws these
+	  */
+	protected void runTests() throws T_Fail 
+	{
+		/*
+		** The property name for the number of iterations is
+		** derby.className.numThreads.  For example, if the test
+		** class is derby.com.package.to.test.T_Tester,
+		** the property name is derby.T_Tester.numThreads.
+		*/
+		String myClass = this.getClass().getName();
+		String noPackage = myClass.substring(myClass.lastIndexOf('.') + 1);
+		String propertyName = "derby." + noPackage + ".numThreads";
+
+		String nthread = PropertyUtil.getSystemProperty(propertyName);
+		if (nthread != null) {
+			try {
+					numThreads = Integer.parseInt(nthread);
+			} catch (NumberFormatException nfe) {
+				numThreads = 1;
+			}
+			if (numThreads <= 0)
+				numThreads = 1;
+		}
+
+		if (numThreads == 1)	// just use this thread
+			super.runTests();	// use T_MultiIterations runtest
+		else
+		{
+			// start numThreads new threads, each with its own test object
+			TestThreads = new Thread[numThreads];
+			TestObjects = new T_MultiThreadedIterations[numThreads];
+
+			inError = false;
+
+			for (int i = 0; i < numThreads; i++)
+			{
+				TestObjects[i] = newTestObject();
+				TestObjects[i].out = this.out;
+
+				TestThreads[i] = new Thread(TestObjects[i], "Thread_" + i);
+			}
+
+			// use the first test object to setup the test
+			TestObjects[0].setupTest();
+			TestObjects[0].threadNumber = 0;
+
+			// make the other test objects to join in the setup
+			for (int i = 1; i < numThreads; i++)
+			{
+				TestObjects[i].threadNumber = i;
+				TestObjects[i].joinSetupTest();
+			}
+
+			// now run them 
+			propertyName = "derby." + noPackage + ".iterations";
+
+			String iter = PropertyUtil.getSystemProperty(propertyName);
+			if (iter != null) {
+				try {
+					iterations = Integer.parseInt(iter);
+				} catch (NumberFormatException nfe) {
+					// leave at one
+				}
+				if (iterations <= 0)
+					iterations = 1;
+			}
+
+			for (int i = 0; i < numThreads; i++)
+			{
+				TestThreads[i].start();
+			}
+
+			// wait for the threads to end
+			try
+			{
+				for (int i = 0; i < numThreads; i++)
+				{
+					TestThreads[i].join();
+				}
+			}
+			catch (InterruptedException ie) {
+				throw T_Fail.exceptionFail(ie);
+			}
+
+			// report error
+			for (int i = 0; i < numThreads; i++)
+			{
+				if (TestObjects[i].error != null)
+					throw T_Fail.exceptionFail(TestObjects[i].error);
+			}
+		}
+	}
+
+	/*
+	 * run each worker test thread
+	 */
+	public void run()
+	{
+		String threadName = "[" + Thread.currentThread().getName() + "] ";
+
+		out.println(threadName + "started");
+
+		try
+		{
+
+			for (int i = 0; i < iterations; i++) 
+			{
+				Runtime.getRuntime().gc();
+				long btm = Runtime.getRuntime().totalMemory();
+				long bfm = Runtime.getRuntime().freeMemory();
+				long bum = btm - bfm;
+
+				long start = System. currentTimeMillis();
+
+				runTestSet();
+				long end = System. currentTimeMillis();
+
+				Runtime.getRuntime().gc();
+				long atm = Runtime.getRuntime().totalMemory();
+				long afm = Runtime.getRuntime().freeMemory();
+				long aum = atm - afm;
+
+				out.println(threadName + "Iteration " + i + " took " + (end - start) + "ms");
+				out.println(threadName + "Total memory increased by " + (atm - btm) + " is " + atm);
+				out.println(threadName + "Used  memory increased by " + (aum - bum) + " is " + aum);
+			}
+		}
+		catch (ThreadDeath death) // some other thread has died and want to see my stack 
+		{
+			out.println(threadName + "caught thread death, printing stack");
+			death.printStackTrace(out.getPrintWriter());
+			Thread.dumpStack();
+
+			throw death;
+		}
+		catch (Throwable t)
+		{
+			error = t;
+		}
+
+		if (error == null)
+			out.println(threadName + "finished with no error");
+		else if (!inError)
+		{
+			inError = true;
+
+			error.printStackTrace(out.getPrintWriter());
+			for (int i = 0; i < numThreads; i++)
+			{
+				if (this != TestObjects[i]) // don't kill myself again
+					TestThreads[i].interrupt();
+			}
+		}
+	}
+
+	/*
+	 * multi threaded test abstract methods
+	 */
+
+	/* 
+	 * joins an existing setup - do whatever remaining setup the test may need
+	 * to do given that setupTest has already been run by another test object
+	 *
+	 * This call will be executed in the main (parent) thread
+	 */
+	protected abstract void joinSetupTest() throws T_Fail;
+
+	/*
+	 * make a new test object instance
+	 */
+	protected abstract T_MultiThreadedIterations newTestObject();
+
+
+	/*
+	 * class specific method
+	 */
+	protected int getNumThreads()
+	{
+		return numThreads;
+	}
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/T_MultiThreadedIterations.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTest.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTest.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTest.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTest.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,69 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.harness.UnitTest
+
+   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.harness;
+
+import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
+
+/**
+ * The UnitTest interface is implemented by the class
+ * that tests a class.  Such a class has the name XUnitTest
+ * and is the test for the class named X.
+ * <p>
+ *
+ * @version 0.1
+ * @author Ames
+ */
+
+
+public interface UnitTest 
+{
+	/**
+	 * Execute the test.
+	 *
+	 * @param out	A HeaderPrintWriter the test may use for tracing.
+	 *				To disable tracing the caller may provide a
+	 *				HeaderPrintWriter which throws away all the data
+	 *				the test writes.
+	 *
+	 * @return	true iff the test passes
+	 */
+	public boolean Execute (HeaderPrintWriter out);
+
+	/**
+	 *	UnitTestDuration
+	 *
+	 *  @return	The tests duration. 
+	 *
+	 *  @see	UnitTestConstants
+	 **/
+	public int UnitTestDuration();
+
+	/**
+	 *	UnitTestDuration
+	 *
+	 *  @return	The tests duration. 
+	 *
+	 *  @see	UnitTestConstants
+	 **/
+	public int UnitTestType();
+
+}
+

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTest.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestConstants.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestConstants.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestConstants.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestConstants.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,92 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.harness.UnitTestConstants
+
+   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.harness;
+
+/**
+ * UnitTestConstants contains the constants for the
+ * unit tests to use when registering and running
+ * the tests.
+ *
+ */
+public interface UnitTestConstants 
+{
+	/**
+	  * the duration of a test can be from MICRO to FOREVER.
+	  * <p>
+	  * MICRO means the test is practically nothing more than
+	  * the call; a simple field examination, for example.
+	  */
+	static final int DURATION_MICRO = 0;
+	/**
+	  * SHORT means the test is less than a second.
+	  */
+	static final int DURATION_SHORT = 1;
+	/**
+	  * MEDIUM means the test is less than 30 seconds.
+	  */
+	static final int DURATION_MEDIUM = 2;
+	/**
+	  * LONG means the test might take 1-5 minutes.
+	  */
+	static final int DURATION_LONG = 3;
+	/**
+	  * FOREVER means the test takes more than 5 minutes,
+	  * or could loop forever if it fails.
+	  */
+	static final int DURATION_FOREVER = 4;
+	
+	/**
+	  * The TYPE of test says what sort of completeness it
+	  * tests; its thoroughness.
+	  * <p>
+	  * Note the types given here are ordered from simple to
+	  * comprehensive. Each category of tests includes 
+	  * tests in earlier, simpler catagories. Thus all SANITY
+	  * tests are also BASIC tests.
+	  */
+	
+	/**
+	  * SANITY means the test is simply a check that
+	  * the system is running.  Little more than a consistency
+	  * check would be done.
+	  */
+	static final int TYPE_SANITY = 0;
+	/**
+	  * BASIC means the test is a basic check that
+	  * the system is working. A single, very common construct
+	  * would be verified to be working.
+	  */
+	static final int TYPE_BASIC = 1;
+	/**
+	  * COMMON means the test verify that the most common 
+	  * cases of use of this object are working properly.
+	  */
+	static final int TYPE_COMMON = 2;
+	/**
+	  * COMPLETE means that the tests verify that the
+	  * object is performing all expected functionality
+	  * correctly.
+	  */
+	static final int TYPE_COMPLETE = 3;
+	
+	
+}// UnitTestConstants
+

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestConstants.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestMain.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestMain.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestMain.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestMain.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,52 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.harness.UnitTestMain
+
+   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.harness;
+
+import org.apache.derby.iapi.services.monitor.Monitor;
+
+import org.apache.derbyTesting.unitTests.harness.UnitTestManager;
+
+import java.util.Properties;
+
+/** 
+	A very simple class to boot up a system based upon a configuration file
+	passed in as the first argument. The optional second argument is taken
+	as a boolean. If the argument is missing or false, the configuration
+	is started, otherwise the configuration is created.
+	
+
+    Usage: java org.apache.derbyTesting.unitTests.harness.UnitTestMain config-file [true]
+**/
+
+
+public class UnitTestMain  { 
+
+	public static void main(String args[]) {
+
+
+		Properties bootProperties = new Properties();
+
+		// request that a unit test manager service is started
+		bootProperties.put("derby.service.unitTestManager", UnitTestManager.MODULE);
+
+		Monitor.startMonitor(bootProperties, System.err);
+	}
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestMain.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestManager.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestManager.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestManager.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestManager.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,100 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.harness.UnitTestManager
+
+   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.harness;
+
+/**
+ *
+ * The UnitTestManager provides a mechanism for
+ * registering subsystem tests and then invoking
+ * them. It can produce an output report specifying
+ * the results, the timing, and any output produced
+ * by the tests. If the run fails, the invoker of
+ * the tests should shut down the system.
+ */
+public interface UnitTestManager 
+{
+	public static final String MODULE = "org.apache.derbyTesting.unitTests.harness.UnitTestManager";
+	
+	/**
+	 * Debug flag to allow the cloudscape system running the tests
+	 * to run forever. By default test systems are killed 
+	 * after an interval of T_Bomb.DEFAULT_BOMB_DELAY to avoid tests
+	 * hanging.
+	 */
+	public static final String RUN_FOREVER = "RunForever";
+
+	/**
+	 * Debug flag to skip unit tests.
+	 */
+	public static final String SKIP_UNIT_TESTS = "SkipUnitTests";
+
+	/**
+	 * register an object that has the UnitTest interface,
+	 * marking what type it has and its duration.
+	 * Tests are run in the order they were registered.
+	 * <p>
+	 *
+	 */
+	public void registerTest(UnitTest objectToTest, String testName);
+	
+
+	/**
+     * run the tests. Tests are run
+     * in the order they were registered, filtered by type
+     * and duration set for the unit test manager.
+     */
+	public boolean runTests();
+	
+
+	/**
+	 * Convenience function to set the test type and duration
+	 * for the UnitTestManager and then run the tests.
+	 * <p>
+	 * @see UnitTestConstants
+	 */
+	public boolean runTests(int testType, int testDuration);
+	
+
+	/**
+     * the test duration is set.  This will be used when the
+     * tests are run; no tests with duration more than
+	  * specified will be run.
+     */
+	public void setTestDuration(int testDuration);
+	
+
+	/**
+     * the test duration is set.  This will be used when the
+     * tests are run; no tests with duration more than
+	  * specified will be run.
+     */
+	public void setTestType(int testType);
+	
+	/**
+     * specify whether performance statistics should be
+	 * gathered when tests are run. The manager will collect
+	 * the duration of each test, and will compare it to
+	 * any previous runs it may have done of that test.
+     */
+	public void setPerformanceReportOn(boolean performanceReportOn);
+	
+}
+

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/harness/UnitTestManager.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/EmptyResultSetStatisticsFactory.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/EmptyResultSetStatisticsFactory.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/EmptyResultSetStatisticsFactory.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/EmptyResultSetStatisticsFactory.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,104 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.lang.EmptyResultSetStatisticsFactory
+
+   Copyright 1999, 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.lang;
+
+import org.apache.derby.iapi.services.monitor.Monitor;
+
+import org.apache.derby.iapi.error.StandardException;
+
+
+import org.apache.derby.iapi.sql.Activation;
+import org.apache.derby.iapi.sql.ResultSet;
+import org.apache.derby.iapi.sql.PreparedStatement;
+
+import org.apache.derby.iapi.sql.execute.NoPutResultSet;
+import org.apache.derby.iapi.sql.execute.ResultSetFactory;
+import org.apache.derby.iapi.sql.execute.ResultSetStatisticsFactory;
+
+import org.apache.derby.iapi.sql.execute.RunTimeStatistics;
+
+import org.apache.derby.impl.sql.execute.rts.ResultSetStatistics;
+
+import java.util.Properties;
+
+/**
+ * ResultSetStatisticsFactory provides a wrapper around all of
+ * objects associated with run time statistics.
+ * <p>
+ * This implementation of the protocol is for stubbing out
+ * the RunTimeStatistics feature at execution time..
+ *
+ * @author jerry
+ */
+public class EmptyResultSetStatisticsFactory 
+		implements ResultSetStatisticsFactory
+{
+	//
+	// ExecutionFactory interface
+	//
+	//
+	// ResultSetStatisticsFactory interface
+	//
+
+	/**
+		@see ResultSetStatisticsFactory#getRunTimeStatistics
+	 */
+	public RunTimeStatistics getRunTimeStatistics(
+			Activation activation, 
+			ResultSet rs,
+			NoPutResultSet[] subqueryTrackingArray)
+		throws StandardException
+	{
+		return null;
+	}
+
+	/**
+		@see ResultSetStatisticsFactory#getResultSetStatistics
+	 */
+	public ResultSetStatistics getResultSetStatistics(ResultSet rs)
+	{
+		return null;
+	}
+
+	/**
+		@see ResultSetStatisticsFactory#getResultSetStatistics
+	 */
+	public ResultSetStatistics getResultSetStatistics(NoPutResultSet rs)
+	{
+		return null;
+	}
+
+	/**
+		@see ResultSetStatisticsFactory#getNoRowsResultSetStatistics
+	 */
+	public ResultSetStatistics getNoRowsResultSetStatistics(ResultSet rs)
+	{
+		return null;
+	}
+
+	//
+	// class interface
+	//
+	public EmptyResultSetStatisticsFactory() 
+	{
+	}
+
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/EmptyResultSetStatisticsFactory.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/T_Like.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/T_Like.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/T_Like.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/T_Like.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,220 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.lang.T_Like
+
+   Copyright 1999, 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.lang;
+
+import org.apache.derbyTesting.unitTests.harness.T_Generic;
+import org.apache.derbyTesting.unitTests.harness.T_Fail;
+
+import org.apache.derby.iapi.types.*;
+
+import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.iapi.reference.Property;
+
+import org.apache.derby.iapi.sql.execute.ExecutionFactory;
+
+import org.apache.derby.iapi.error.StandardException;
+
+import java.util.Properties;
+
+/**
+	@see Like
+
+	@author ames
+ */
+public class T_Like extends T_Generic
+{
+	private static final String testService = "likeTest";
+	boolean didFAIL;
+
+	/*
+	** Methods required by T_Generic
+	*/
+
+	public String getModuleToTestProtocolName() {
+		// actually, we're just testing LIKE; but it is reached through
+		// the ExecutionFactory MODULE, and this wants a MODULE, so...
+		return ExecutionFactory.MODULE;
+	}
+
+	/**
+		@exception T_Fail test failed.
+	*/
+	protected void runTests() throws T_Fail
+	{
+		ExecutionFactory f = null;
+		boolean pass = false;
+		didFAIL = false;
+
+        out.println(testService+" underway");
+
+		// 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());
+
+		REPORT("(unitTestMain) Testing " + testService);
+
+		// REMIND: add tests here
+		try {
+			tests();
+		} catch (StandardException e) {
+			FAIL("exception:"+e);
+		}
+		if (didFAIL) throw T_Fail.testFailMsg("see log for details");
+
+        out.println(testService+" complete");
+	}
+
+	// testing support:
+	private void expect(String desc, Boolean test, Boolean result) {
+		boolean pass =
+			( (test == null && result == null) ||
+			  (test != null && result != null && test.equals(result)) );
+
+		if (pass)
+			PASS("TEST ["+desc+"] == result["+result+"] ");
+		else
+			FAIL("TEST ["+desc+"] != result["+result+"] ");
+	}
+
+	// testing mechanism:
+	private void tests() throws StandardException {
+		boolean gotLE = false;
+		Boolean t = null;
+		char[] caNull = null;
+		char[] caHello = "hello".toCharArray();
+		String msg=null;
+		String desc=null;
+
+		REPORT("testing null combinations...");
+		try {
+		expect("null like null escape null", Like.like(caNull, 0, caNull, 0, caNull, 0), null);
+		expect("null like 'hello' escape null", Like.like(caNull, 0, caHello, caHello.length, caNull, 0), null);
+		expect("'hello' like null escape null", Like.like(caHello, caHello.length, caNull, 0, caNull, 0), null);
+		expect("null like null escape '\\'", Like.like(caNull, 0, caNull, 0, "\\".toCharArray(), "\\".toCharArray().length), null);
+
+		// gets back a null before it evaluates the escape
+		expect("null like null escape 'hello'", Like.like(caNull, 0, caNull, 0, caHello, caHello.length), null);
+		// gets back a null before it evaluates the pattern
+		expect("null like 'hello\\' escape '\\'", Like.like(caNull, 0, "hello\\".toCharArray(), "hello\\".toCharArray().length, "\\".toCharArray(), "\\".toCharArray().length), null);
+
+		} catch(StandardException leOuter1) {
+			leOuter1.printStackTrace();
+			FAIL("unexpected exception");
+		}
+
+		REPORT("testing valid match cases...");
+		try {
+		expect("'hello' like 'hello' escape null", Like.like(caHello, caHello.length, caHello, caHello.length, caNull, 0), Boolean.TRUE);
+		expect("'hello' like 'h_llo' escape null", Like.like(caHello, caHello.length, "h_llo".toCharArray(), "h_llo".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'hello' like '_ello' escape null", Like.like(caHello, caHello.length, "_ello".toCharArray(), "_ello".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'hello' like 'hell_' escape null", Like.like(caHello, caHello.length, "hell_".toCharArray(), "hell_".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'hello' like '_____' escape null", Like.like(caHello, caHello.length, "_____".toCharArray(), "_____".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'hello' like 'h___e' escape null", Like.like(caHello, caHello.length, "h___o".toCharArray(), "h___o".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'h' like 'h' escape null", Like.like("h".toCharArray(), "h".toCharArray().length, "h".toCharArray(), "h".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'h' like '_' escape null", Like.like("h".toCharArray(), "h".toCharArray().length, "_".toCharArray(), "_".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'h' like '%' escape null", Like.like("h".toCharArray(), "h".toCharArray().length, "%".toCharArray(), "%".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'h' like '_%' escape null", Like.like("h".toCharArray(), "h".toCharArray().length, "_%".toCharArray(), "_%".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'h' like '%_' escape null", Like.like("h".toCharArray(), "h".toCharArray().length, "%_".toCharArray(), "%_".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'h' like '%' escape null", Like.like("h".toCharArray(), "h".toCharArray().length, "%".toCharArray(), "%".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'' like '%' escape null", Like.like("".toCharArray(), "".toCharArray().length, "%".toCharArray(), "%".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'' like '%%' escape null", Like.like("".toCharArray(), "".toCharArray().length, "%%".toCharArray(), "%%".toCharArray().length, caNull, 0), Boolean.TRUE);
+		expect("'' like '%%%' escape null", Like.like("".toCharArray(), "".toCharArray().length, "%%%".toCharArray(), "%%%".toCharArray().length, caNull, 0), Boolean.TRUE);
+		} catch(StandardException leOuter2) {
+			leOuter2.printStackTrace();
+			FAIL("unexpected exception");
+		}
+
+		REPORT("testing valid nonmatch cases...");
+		try {
+		expect("'hello' like 'hello ' escape null", Like.like(caHello, caHello.length, "hello ".toCharArray(), "hello ".toCharArray().length, caNull, 0), Boolean.FALSE);
+		expect("'hello ' like 'hello' escape null", Like.like("hello ".toCharArray(), "hello ".toCharArray().length, caHello, caHello.length, caNull, 0), Boolean.FALSE);
+		expect("'hello' like 'hellox' escape null", Like.like(caHello, caHello.length, "hellox".toCharArray(), "hellox".toCharArray().length, caNull, 0), Boolean.FALSE);
+		expect("'hellox' like 'hello' escape null", Like.like("hellox".toCharArray(), "hellox".toCharArray().length, caHello, caHello.length, caNull, 0), Boolean.FALSE);
+		expect("'xhellox' like 'hello' escape null", Like.like("xhellox".toCharArray(), "xhellox".toCharArray().length, caHello, caHello.length, caNull, 0), Boolean.FALSE);
+		expect("'hello' like 'xhellox' escape null", Like.like(caHello, caHello.length, "xhellox".toCharArray(), "xhellox".toCharArray().length, null, 0), Boolean.FALSE);
+		expect("'hello' like 'h___' escape null", Like.like(caHello, caHello.length, "h___".toCharArray(), "h___".toCharArray().length, caNull, 0), Boolean.FALSE);
+		expect("'h' like '_%_' escape null", Like.like("h".toCharArray(), "h".toCharArray().length, "_%_".toCharArray(), "_%_".toCharArray().length, caNull, 0), Boolean.FALSE);
+		expect("'' like '_' escape null", Like.like("".toCharArray(), "".toCharArray().length, "_".toCharArray(), "_".toCharArray().length, caNull, 0), Boolean.FALSE);
+		} catch(StandardException leOuter3) {
+			leOuter3.printStackTrace();
+			FAIL("unexpected exception");
+		}
+
+		REPORT("testing error cases...");
+
+		try {
+			msg = null;
+			gotLE=false;
+			desc="null like null escape 'hello'";
+			t=Like.like(caHello, caHello.length, caHello, caHello.length, caHello, caHello.length);
+		} catch (StandardException le) {
+			gotLE=true;
+			msg = le.getMessage();
+		} finally {
+			if (gotLE)
+				PASS("TEST ["+desc+"] got exception "+msg);
+			else
+				FAIL("TEST ["+desc+"] didn't get exception");
+		}
+
+		try {
+			msg = null;
+			gotLE=false;
+			desc="'hello' like 'hhh' escape 'h'";
+			t=Like.like(caHello, caHello.length, "hhh".toCharArray(), "hhh".toCharArray().length, "h".toCharArray(), "h".toCharArray().length);
+		} catch (StandardException le) {
+			gotLE=true;
+			msg = le.getMessage();
+		} finally {
+			if (gotLE)
+				PASS("TEST ["+desc+"] got exception "+msg);
+			else
+				FAIL("TEST ["+desc+"] didn't get exception");
+		}
+
+		try {
+			msg = null;
+			gotLE=false;
+			desc="'hello' like 'he%' escape 'h'";
+			t=Like.like(caHello, caHello.length, "he%".toCharArray(), "he%".toCharArray().length, "h".toCharArray(), "h".toCharArray().length);
+		} catch (StandardException le) {
+			gotLE=true;
+			msg = le.getMessage();
+		} finally {
+			if (gotLE)
+				PASS("TEST ["+desc+"] got exception "+msg);
+			else
+				FAIL("TEST ["+desc+"] didn't get exception");
+		}
+
+	}
+
+	/*
+		override to mark the test as failed when dumping the message.
+	 */
+	protected boolean FAIL(String msg) {
+		super.FAIL(msg);
+		return didFAIL = true;
+	}
+}
+

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/lang/T_Like.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/D_T_DiagTestClass1.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/D_T_DiagTestClass1.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/D_T_DiagTestClass1.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/D_T_DiagTestClass1.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,61 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.D_T_DiagTestClass1
+
+   Copyright 1998, 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.services;
+
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.diag.DiagnosticableGeneric;
+
+/**
+
+A diagnostic class for the T_DiagTestClass1 class.  This class is used for
+unit testing by T_Diagnosticable.
+
+**/
+
+public class D_T_DiagTestClass1 extends DiagnosticableGeneric
+{
+    /* Constructors for This class: */
+    /* Private/Protected methods of This class: */
+    /* Public Methods of This class: */
+
+    /* Public Methods of Diagnosticable interface: */
+
+    /**
+     * Default implementation of diagnostic on the object.
+     * <p>
+     * This routine returns a string with whatever diagnostic information
+     * you would like to provide about this object.
+     * <p>
+     * This routine should be overriden by a real implementation of the
+     * diagnostic information you would like to provide.
+     * <p>
+     *
+	 * @return A string with diagnostic information about the object.
+     *
+     *
+	 * @exception  StandardException  Standard exception policy.
+     **/
+    public String diag()
+        throws StandardException
+    {
+        return("D_T_DiagTestClass1: " + ((T_DiagTestClass1) diag_object).state);
+    }
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/D_T_DiagTestClass1.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/MarkedLimitInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/MarkedLimitInputStream.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/MarkedLimitInputStream.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/MarkedLimitInputStream.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,192 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.MarkedLimitInputStream
+
+   Copyright 2001, 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.services;
+
+import org.apache.derby.iapi.services.sanity.SanityManager;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+  An input stream whose internal data is in blocks, the format of each block is
+    (boolean isLastBlock, int blockLength, sequence of blockLength bytes)
+  All blocks except for the last block must have isLastBlock set to false.
+  The last block must have isLastBlock set to true.
+
+  This class implements an input stream whose length is limited, yet
+  the creator (writer) of the stream does not need to know the entire length
+  before creating it.
+*/
+
+public class MarkedLimitInputStream extends org.apache.derby.iapi.services.io.LimitInputStream
+{
+    protected boolean isLastBlock;
+    protected int blockLength;
+
+
+	public MarkedLimitInputStream(DataInputStream in)
+        throws IOException
+    {
+		super(in);
+        start();
+	}
+
+    private void start()
+        throws IOException
+    {
+        isLastBlock = ((DataInputStream) in).readBoolean();
+        blockLength = ((DataInputStream) in).readInt();
+
+        if (SanityManager.DEBUG)
+        {
+            if (!isLastBlock)
+            {
+                SanityManager.ASSERT(blockLength > 0);
+            }
+            else
+            {
+                SanityManager.ASSERT(blockLength >= 0, "blockLength " + blockLength + " is negative");
+            }
+        }
+        setLimit(blockLength);
+
+    }
+
+	public int read()
+        throws IOException
+    {
+        int i = super.read();
+        if (i == -1)
+        {
+            if (isLastBlock)
+            {
+                return -1;
+            }
+            else
+            {
+                start();
+                return this.read();
+            }
+        }
+        else
+        {
+            return i;
+        }
+	}
+
+
+	public int read(byte b[], int off, int len)
+        throws IOException
+    {
+		if (isLastBlock)
+        {
+            // get as many bytes as we can, superclass may return less
+            // bytes than we asked for without good reason
+	        int m = 0;
+	        while (m < len)
+            {
+	            int count = super.read(b, off + m, len - m);
+	            if (count < 0)
+                {
+		            break;
+                }
+	            m += count;
+	        }
+			return m;
+        }
+
+        // read until either get back all the bytes we asked for
+        // or until we get -1
+	    int n = 0;
+	    while (n < len)
+        {
+	        int count = super.read(b, off + n, len - n);
+	        if (count < 0)
+            {
+		        break;
+            }
+	        n += count;
+	    }
+
+        if (SanityManager.DEBUG)
+        {
+            SanityManager.ASSERT(n <= len);
+        }
+        if (n == len)
+        {
+            return n;
+        }
+
+        // n < len, we didn't finish yet
+        // init next block
+        start();
+        // read rest
+        if (n < 0)
+        {
+            return this.read(b,off,len);
+        }
+
+        return n + this.read(b, off+n, len-n);
+	}
+
+
+    public long skip(long count)
+        throws IOException
+    {
+        if (isLastBlock)
+        {
+            return super.skip(count);
+        }
+
+        // long n = super.skip(count);
+        // read until either skip all the bytes we asked to
+        // or until we get a result which is <= 0
+	    long n = 0;
+	    while (n < count)
+        {
+	        long c = super.skip(count-n);
+	        if (c <= 0)
+            {
+		        break;
+            }
+	        n += c;
+	    }
+
+        if (SanityManager.DEBUG)
+        {
+            SanityManager.ASSERT(n <= count);
+        }
+        if (n == count)
+        {
+            return n;
+        }
+        // if n < count, we didn't finish skipping yet
+        // init next block
+        start();
+        // read rest
+        if (n < 0)
+        {
+            return this.skip(count);
+        }
+        return n + this.skip(count-n);
+    }
+
+
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/MarkedLimitInputStream.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheException.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheException.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheException.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheException.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,53 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_CacheException
+
+   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.services;
+
+import org.apache.derby.iapi.error.StandardException;
+
+/**
+
+*/
+public  class T_CacheException extends T_StandardException {
+
+	public static final int		ERROR = 0;
+	public static final int     INVALID_KEY = 1;
+	public static final int		IDENTITY_FAIL = 2;
+
+	protected int type;
+
+		
+	protected T_CacheException(String message, int type) {
+		super("cache.S", message);
+		this.type = type;
+	}
+
+	public static StandardException invalidKey() {
+		return new T_CacheException("invalid key passed", INVALID_KEY);
+	}
+	public static StandardException identityFail() {
+		return new T_CacheException("identity change failed", IDENTITY_FAIL);
+	}
+
+	protected int getType() {
+		return type;
+	}
+}
+

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheException.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheService.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheService.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheService.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheService.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,341 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_CacheService
+
+   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.services;
+
+import org.apache.derbyTesting.unitTests.harness.T_Generic;
+import org.apache.derbyTesting.unitTests.harness.T_Fail;
+
+import org.apache.derby.iapi.services.cache.*;
+
+import org.apache.derby.iapi.services.daemon.*;
+
+import org.apache.derby.iapi.services.monitor.Monitor;
+
+import org.apache.derby.iapi.error.StandardException;
+
+public class T_CacheService extends T_Generic implements CacheableFactory {
+
+	protected CacheFactory	cf;
+
+	public Cacheable newCacheable(CacheManager cm) {
+		return new T_CachedInteger();
+	}
+
+	/**
+		@exception T_Fail - the test has failed.
+	*/
+	protected void runTests() throws T_Fail {
+
+		DaemonFactory df;
+		try {
+			cf = (CacheFactory) Monitor.startSystemModule(getModuleToTestProtocolName());
+			df = (DaemonFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.DaemonFactory);
+		} catch (StandardException mse) {
+			throw T_Fail.exceptionFail(mse);
+		}
+		if (cf == null) {
+			throw T_Fail.testFailMsg(getModuleToTestProtocolName() + " module not started.");
+		}
+		if (df == null)
+			throw T_Fail.testFailMsg(org.apache.derby.iapi.reference.Module.DaemonFactory + " module not started.");
+	
+
+		try {
+
+			DaemonService ds = df.createNewDaemon("CacheTester");
+			if (ds == null)
+				throw T_Fail.testFailMsg("Can't create deamon service");
+
+			CacheManager cm1 = cf.newCacheManager(this, "testCache1", 20, 40);
+			if (cm1 == null)
+				throw T_Fail.testFailMsg("unable to create cache manager");
+			T001(cm1, 40);
+			cm1.useDaemonService(ds);
+			thrashCache(cm1, 10, 1000);
+			cm1.shutdown();
+			cm1 = null;
+
+			CacheManager cm2 = cf.newCacheManager(this, "testCache2", 0, 1);
+			if (cm2 == null)
+				throw T_Fail.testFailMsg("unable to create cache manager");
+			T001(cm2, 1);
+			cm2.useDaemonService(ds);
+			thrashCache(cm2, 10, 1000);
+			cm2.shutdown();
+			cm2 = null;
+
+			CacheManager cm3= cf.newCacheManager(this, "testCache3", 2000, 40);
+			if (cm3 == null)
+				throw T_Fail.testFailMsg("unable to create cache manager");
+			T001(cm3, 40);
+			cm3.useDaemonService(ds);
+			thrashCache(cm3, 10, 1000);
+			cm3.shutdown();
+			cm3 = null;
+
+			// now two that don't use the daemon service
+			CacheManager cm4 = cf.newCacheManager(this, "testCache4", 2000, 40);
+			if (cm4 == null)
+				throw T_Fail.testFailMsg("unable to create cache manager");
+			T001(cm4, 40);
+			thrashCache(cm4, 10, 1000);
+			cm4.shutdown();
+			cm4 = null;
+
+			CacheManager cm5 = cf.newCacheManager(this, "testCache5", 0, 40);
+			if (cm5 == null)
+				throw T_Fail.testFailMsg("unable to create cache manager");
+			T001(cm5, 40);
+			thrashCache(cm5, 10, 1000);
+			cm5.shutdown();
+			cm5 = null;
+
+		} catch (StandardException se) {
+			throw T_Fail.exceptionFail(se);
+		} catch (Throwable t) {
+			t.printStackTrace();
+			throw T_Fail.exceptionFail(t);	
+		}
+	}
+
+	/**
+	  Get the name of the protocol for the module to test.
+	  This is the 'factory.MODULE' variable.
+	  
+	  'moduleName' to the name of the module to test. 
+
+	  @param testConfiguration the configuration for this test.
+	  */
+	protected String getModuleToTestProtocolName() {
+		return org.apache.derby.iapi.reference.Module.CacheFactory;
+	}
+
+
+	/*
+	** The tests
+	*/
+
+	/**
+		Test the find and findCached calls.
+		@exception StandardException  Standard Derby Error policy
+		@exception T_Fail  Some error
+	*/
+	protected void T001(CacheManager cm, int cacheSize) throws T_Fail, StandardException {
+
+		T_Key tkey1 = T_Key.simpleInt(1);
+
+		// cahce is empty, nothing should be there
+		t_findCachedFail(cm, tkey1);
+
+		// find a valid entry
+		cm.release(t_findSucceed(cm, tkey1));
+
+		// check it is still in the cache
+		cm.release(t_findCachedSucceed(cm, tkey1));
+
+		// look for an item that can't be found
+		T_Key tkey2 = T_Key.dontFindInt(2);
+		t_findCachedFail(cm, tkey2);
+		t_findFail(cm, tkey2);
+
+		// see if the first item still can be found
+		// can't assume it can be cached as it may have aged out ...
+		cm.release(t_findSucceed(cm, tkey1));
+
+		// now ensure we can find an item with the key that just couldn't
+		// be found
+		tkey2 = T_Key.simpleInt(2);
+		cm.release(t_findSucceed(cm, tkey2));
+		cm.release(t_findSucceed(cm, tkey1));
+
+
+		// now create a key that will cause an exception ...
+		T_Key tkey3 = T_Key.exceptionInt(3);
+		t_findCachedFail(cm, tkey3);
+		try {
+			
+			t_findFail(cm, tkey3);
+			throw T_Fail.testFailMsg("find call lost user exception");
+		} catch (StandardException se) {
+			if (!(se instanceof T_CacheException))
+				throw se;
+			if (((T_CacheException) se).getType() != T_CacheException.IDENTITY_FAIL)
+				throw se;
+		}
+
+		tkey3 = T_Key.simpleInt(3);
+		cm.release(t_findSucceed(cm, tkey3));
+		cm.release(t_findSucceed(cm, tkey2));
+		cm.release(t_findSucceed(cm, tkey1));
+
+		// since this cache is in use by only this method we should
+		// be able to call clean with deadlocking and then ageOut
+		// leaving the cache empty.
+		cm.cleanAll();
+		cm.ageOut();
+
+		t_findCachedFail(cm, tkey1);
+		t_findCachedFail(cm, tkey2);
+		t_findCachedFail(cm, tkey3);
+
+
+		// now put many valid objects into the cache
+		for (int i = 0; i < 4 * cacheSize ; i++) {
+			T_Key tkeyi = T_Key.simpleInt(i);
+			cm.release(t_findSucceed(cm, tkeyi));
+			cm.release(t_findCachedSucceed(cm, tkeyi));
+		}
+		cm.cleanAll();
+		cm.ageOut();
+		for (int i = 0; i < 4 * cacheSize ; i++) {
+			T_Key tkeyi = T_Key.simpleInt(i);
+			t_findCachedFail(cm, tkeyi);
+		}
+
+
+		// Ensure that we can find an object multiple times
+		Cacheable e1 = t_findSucceed(cm, tkey1);
+		Cacheable e2 = t_findSucceed(cm, tkey2);
+
+		if (e1 == e2)
+			throw T_Fail.testFailMsg("same object returned for two different keys");
+
+		if (t_findSucceed(cm, tkey1) != e1)
+			throw T_Fail.testFailMsg("different object returned for same key");
+		if (t_findSucceed(cm, tkey2) != e2)
+			throw T_Fail.testFailMsg("different object returned for same key");
+
+		cm.release(e1);
+		cm.release(e1);
+		e1 = null;
+		cm.release(e2);
+		cm.release(e2);
+		e2 = null;
+
+
+
+		
+		PASS("T001");
+	}
+
+
+
+
+	/*
+	** Multi-user tests
+	*/
+
+
+	protected void thrashCache(CacheManager cm, int threads, int iterations) throws T_Fail {
+
+		Thread[] children = new Thread[threads];
+
+		for (int i = 0; i < threads; i++) {
+
+			children[i] = new Thread(new T_CacheUser(cm, iterations, this, out));
+			
+		}
+
+		for (int i = 0; i < threads; i++) {
+			children[i].start();
+		}
+
+		try {
+			for (int i = 0; i < threads; i++) {
+				if (threadFail != null)
+					throw threadFail;
+
+				children[i].join();
+
+				if (threadFail != null)
+					throw threadFail;
+			}
+		} catch (InterruptedException ie) {
+			throw T_Fail.exceptionFail(ie);
+		}
+
+		PASS("thrashCache");
+
+	}
+	protected T_Fail threadFail;
+	public synchronized void setChildException(T_Fail tf) {
+		if (threadFail == null)
+			threadFail = tf;
+	}
+
+
+	/**
+		A call to findCached() that is expected to return nothing.
+		@exception StandardException  Standard Derby Error policy
+		@exception T_Fail Something was found.
+	*/
+	protected void t_findCachedFail(CacheManager cm, Object key) throws StandardException, T_Fail {
+		Cacheable entry = cm.findCached(key);
+		if (entry != null) {
+			throw T_Fail.testFailMsg("found cached item unexpectedly");
+		}
+	}
+
+	/**
+		A call to findCached() that is expected to find something.
+		@exception StandardException  Standard Derby Error policy
+		@exception T_Fail Nothing was found.
+	*/
+	protected Cacheable t_findCachedSucceed(CacheManager cm, Object key) throws StandardException, T_Fail {
+		Cacheable entry = cm.findCached(key);
+		if (entry == null) {
+			throw T_Fail.testFailMsg("expected item to be in cache");
+		}
+
+		if (!entry.getIdentity().equals(key))
+			throw T_Fail.testFailMsg("item returned does not match key");
+		return entry;
+	}
+	/**
+		A call to find() that is expected to return nothing.
+
+		@exception T_Fail Something was found.
+		@exception StandardException  Standard Derby Error policy
+	*/
+	protected void t_findFail(CacheManager cm, Object key) throws T_Fail, StandardException {
+		Cacheable entry = cm.find(key);
+		if (entry != null) {
+			throw T_Fail.testFailMsg("found item unexpectedly");
+		}
+	}
+
+	/**
+		A call to findCached() that is expected to find something.
+
+		@exception T_Fail Nothing was found.
+		@exception StandardException  Standard Derby Error policy
+	*/
+	protected Cacheable t_findSucceed(CacheManager cm, Object key) throws T_Fail, StandardException {
+		Cacheable entry = cm.find(key);
+		if (entry == null) {
+			throw T_Fail.testFailMsg("expected item to be found");
+		}
+		if (!entry.getIdentity().equals(key))
+			throw T_Fail.testFailMsg("item returned does not match key");
+
+		return entry;
+	}
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheService.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheUser.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheUser.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheUser.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheUser.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,194 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_CacheUser
+
+   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.services;
+
+import org.apache.derby.iapi.services.cache.*;
+
+import org.apache.derbyTesting.unitTests.harness.T_Fail;
+
+import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
+
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.SQLState;
+
+public class T_CacheUser implements Runnable {
+
+	protected CacheManager	cm;
+	protected int           iterations;
+	protected HeaderPrintWriter out;
+	protected T_CacheService parent;
+
+	public T_CacheUser(CacheManager cm, int iterations, T_CacheService parent, HeaderPrintWriter out) {
+		this.cm = cm;
+		this.iterations = iterations;
+		this.parent = parent;
+		this.out = out;
+	}
+
+
+	public void run() {
+		try {
+			thrashCache();
+		} catch (T_Fail tf) {
+			parent.setChildException(tf);
+		} catch (StandardException se) {
+			parent.setChildException(T_Fail.exceptionFail(se));
+		}
+	}
+	/**
+		T_CachedInteger range - 0 - 100
+
+		pick a key randomly
+					48%/48%/4% chance of Int/String/invalid key
+					90%/5%/5% chance of can find / can't find / raise exception
+					50%/30%/20% find/findCached/create
+					
+
+		@exception StandardException  Standard Derby Error policy
+		@exception T_Fail  Some error
+				
+		
+	*/
+
+	public void thrashCache() throws StandardException, T_Fail {
+
+		// stats
+		int f = 0, fs = 0, ff = 0, fe = 0;
+		int fc = 0, fcs = 0, fcf = 0;
+		int c = 0, cs = 0, cf = 0, ce = 0, cse = 0;
+		int cleanAll = 0, ageOut = 0;
+		int release = 0, remove = 0;
+
+
+		for (int i = 0; i < iterations; i++) {
+
+			if ((i % 100) == 0)
+				out.printlnWithHeader("iteration " + i);
+
+			T_Key tkey = T_Key.randomKey();
+
+			double rand = Math.random();
+			T_Cacheable e = null;
+			if (rand < 0.5) {
+				f++;
+
+				try {
+
+					e = (T_Cacheable) cm.find(tkey);
+					if (e == null) {
+						ff++;
+						continue;
+					}
+
+					fs++;
+
+				} catch (T_CacheException tc) {
+					if (tc.getType() == T_CacheException.ERROR)
+						throw tc;
+
+					// acceptable error
+					fe++;
+					continue;
+				}			
+			} else if (rand < 0.8)  {
+
+				fc++;
+
+				e = (T_Cacheable) cm.findCached(tkey);
+				if (e == null) {
+					fcf++;
+					continue;
+				}
+				fcs++;
+
+			} else {
+				c++;
+
+				try {
+
+					e = (T_Cacheable) cm.create(tkey, Thread.currentThread());
+					if (e == null) {
+						cf++;
+						continue;
+					}
+
+					cs++;
+ 
+				} catch (T_CacheException tc) {
+					if (tc.getType() == T_CacheException.ERROR)
+						throw tc;
+
+					// acceptable error
+					ce++;
+					continue;
+				} catch (StandardException se) {
+
+					if (se.getMessageId().equals(SQLState.OBJECT_EXISTS_IN_CACHE)) {
+						cse++;
+						continue;
+					}
+					throw se;
+				}			
+			}
+
+			// ensure we can find it cached and that the key matches
+			cm.release(parent.t_findCachedSucceed(cm, tkey));
+
+			if (Math.random() < 0.25)
+				e.setDirty();
+
+			if (Math.random() < 0.75)
+				Thread.yield();
+
+			if ((Math.random() < 0.10) && (e.canRemove())) {
+				remove++;
+				cm.remove(e);
+			} else {
+				release++;
+				cm.release(e);
+			}
+			e = null;
+
+			double rand2 = Math.random();
+			
+			if (rand2 < 0.02) {
+				cleanAll++;
+				cm.cleanAll();
+			}
+			else if (rand2 < 0.04) {
+				ageOut++;
+				cm.ageOut();
+			}
+		}
+
+		// ensure all our output in grouped.
+		synchronized (parent) {
+			out.printlnWithHeader("find()       calls " + f  + " : found/not found/exception : " + fs + "/" + ff + "/" + fe);
+			out.printlnWithHeader("findCached() calls " + fc + " : found/not found           : " + fcs + "/" + fcf);
+			out.printlnWithHeader("create()     calls " + c  + " : found/not found/exception/standard exception : " + cs + "/" + cf + "/" + ce + "/" + cse);
+			out.printlnWithHeader("release()    calls " + release);
+			out.printlnWithHeader("remove()     calls " + remove);
+			out.printlnWithHeader("cleanAll()   calls " + cleanAll);
+			out.printlnWithHeader("ageOut()     calls " + ageOut);
+		}
+
+	}
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CacheUser.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Cacheable.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Cacheable.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Cacheable.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Cacheable.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,150 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_Cacheable
+
+   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.services;
+
+import org.apache.derby.iapi.services.cache.*;
+
+import org.apache.derby.iapi.error.StandardException;
+
+/**
+
+*/
+public abstract class T_Cacheable implements Cacheable {
+
+	protected boolean	isDirty;
+
+	protected Thread       owner;
+		
+	public T_Cacheable() {
+	}
+
+	/*
+	** Cacheable methods
+	*/
+
+	public Cacheable setIdentity(Object key) throws StandardException {
+		// we expect a key of type Object[]
+		if (!(key instanceof T_Key)) {
+			throw T_CacheException.invalidKey();
+		}
+
+		owner = null;
+
+		return null; // must be overriden by super class	
+	}
+
+
+
+	public Cacheable createIdentity(Object key, Object createParameter) throws StandardException {
+
+		// we expect a key of type Object[]
+		if (!(key instanceof T_Key)) {
+			throw T_CacheException.invalidKey();
+		}
+
+		owner = (Thread) createParameter;
+
+		return null; // must be overriden by super class
+	}
+
+	/**
+		Returns true of the object is dirty. Will only be called when the object is unkept.
+
+		<BR> MT - thread safe 
+
+	*/
+	public boolean isDirty() {
+		synchronized (this) {
+			return isDirty;
+		}
+	}
+
+
+
+	public void clean(boolean forRemove) throws StandardException {
+		synchronized (this) {
+			isDirty = false;
+		}
+	}
+
+	/*
+	** Implementation specific methods
+	*/
+
+	protected Cacheable getCorrectObject(Object keyValue) throws StandardException {
+
+		Cacheable correctType;
+
+		if (keyValue instanceof Integer) {
+
+			correctType = new T_CachedInteger();
+		//} else if (keyValue instanceof String) {
+			//correctType = new T_CachedString();
+		} else {
+
+			throw T_CacheException.invalidKey();
+		}
+
+		return correctType;
+	}
+
+	protected boolean dummySet(T_Key tkey) throws StandardException {
+
+		// first wait
+		if (tkey.getWait() != 0) {
+			synchronized (this) {
+
+				try {
+					wait(tkey.getWait());
+				} catch (InterruptedException ie) {
+					// RESOLVE
+				}
+			}
+		}
+
+		if (!tkey.canFind())
+			return false;
+
+		if (tkey.raiseException())
+			throw T_CacheException.identityFail();
+
+		return true;
+	}
+
+	public void setDirty() {
+		synchronized (this) {
+			isDirty = true;
+		}
+	}
+
+	public boolean canRemove() {
+
+		synchronized (this) {
+			if (owner == null)
+				owner = Thread.currentThread();
+
+			if (owner == Thread.currentThread())
+				return true;
+			return false;
+		}
+	}
+}
+

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Cacheable.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CachedInteger.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CachedInteger.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CachedInteger.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CachedInteger.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,117 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_CachedInteger
+
+   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.services;
+
+import org.apache.derby.iapi.services.cache.*;
+
+import org.apache.derby.iapi.error.StandardException;
+
+/**
+
+*/
+public class T_CachedInteger extends T_Cacheable {
+
+	protected T_Key		keyValue;
+		
+	public T_CachedInteger() {
+	}
+
+	/*
+	** Cacheable methods
+	*/
+
+
+	/**
+		@exception StandardException  Standard Derby Error policy
+	*/
+	public Cacheable setIdentity(Object key) throws StandardException {
+
+		super.setIdentity(key);
+
+		T_Key tkey = (T_Key) key;	// instanceof check provided by superclass
+
+		if (!(tkey.getValue() instanceof Integer)) {
+
+			return getCorrectObject(tkey.getValue()).setIdentity(key);
+		}
+
+		// potentially pretend to wait and potentally behave as not found.
+		if (!dummySet(tkey))
+			return null;
+		keyValue = tkey;
+
+		return this;
+	}
+
+	/**
+		@exception StandardException  Standard Derby Error policy
+	*/
+	public Cacheable createIdentity(Object key, Object createParameter) throws StandardException {
+		super.createIdentity(key, createParameter);
+
+		T_Key tkey = (T_Key) key;	// instanceof check provided by superclass
+
+		if (!(tkey.getValue() instanceof Integer)) {
+
+			return getCorrectObject(tkey.getValue()).createIdentity(key, createParameter);
+		}
+
+
+		// potentially pretend to wait and potentally behave as not found.
+		if (!dummySet(tkey))
+			return null;
+
+		keyValue = tkey;
+
+		return this;
+	}
+
+
+
+	/**
+		Put the object into the No Identity state. 
+
+		<BR> MT - single thread required - Method must only be called be cache manager
+		and the cache manager will guarantee only one thread can be calling it.
+
+	*/
+	public void clearIdentity() {
+		keyValue = null;
+	}
+
+	/**
+		Get the identity of this object.
+
+		<BR> MT - thread safe.
+
+	*/
+	public Object getIdentity() {
+		return keyValue;
+	}
+
+	/**
+		@exception StandardException  Standard Derby Error policy
+	*/
+	public void clean(boolean forRemove) throws StandardException {
+		super.clean(forRemove);
+	}
+}
+

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_CachedInteger.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DaemonService.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DaemonService.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DaemonService.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DaemonService.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,310 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_DaemonService
+
+   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.services;
+
+import org.apache.derbyTesting.unitTests.harness.T_Fail;
+import org.apache.derbyTesting.unitTests.harness.T_MultiThreadedIterations;
+import org.apache.derby.iapi.services.context.ContextService;
+import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.daemon.*;
+
+import java.util.Random;
+import java.util.Vector;
+/**
+	This test exercices the DaemonFactory and DaemonService implementation
+*/
+public class T_DaemonService extends T_MultiThreadedIterations 
+{
+	private static DaemonService testDaemon;
+	private static Random random;
+
+	/*
+	 * fields for testing serviceable, one per test object
+	 */
+	private Vector serviceRecord; // a vectory of T_Serviceable
+
+	public T_DaemonService()
+	{
+		super();
+		serviceRecord = new Vector(9, 1);
+		random = new Random();
+	}
+
+
+	/*
+	** Methods required by T_Generic
+	*/
+
+	protected String getModuleToTestProtocolName() {
+		return org.apache.derby.iapi.reference.Module.DaemonFactory;
+	}
+
+	/**
+	** Methods required by T_MultiIterations
+	** @exception T_Fail unexpected behaviour from the API
+	*/
+	protected void setupTest() throws T_Fail
+	{
+
+		DaemonFactory daemonFactory;
+		try {
+			daemonFactory = (DaemonFactory)Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.DaemonFactory);
+		} catch (StandardException mse) {
+			throw T_Fail.exceptionFail(mse);
+		}
+		if (daemonFactory == null)
+			throw T_Fail.testFailMsg("cannot find daemon factory " + org.apache.derby.iapi.reference.Module.DaemonFactory);
+			
+		try
+		{
+			testDaemon = daemonFactory.createNewDaemon("testDaemon");
+		}
+		catch (StandardException se)
+		{
+			throw T_Fail.exceptionFail(se);
+		}
+		if (testDaemon == null)
+			throw T_Fail.testFailMsg("cannot create new Daemon Service");
+
+
+	}
+
+
+	/**
+	** Methods required by T_MultiThreadedIterations
+	** @exception T_Fail unexpected behaviour from the API
+	*/
+	protected void joinSetupTest() throws T_Fail
+	{
+		if (testDaemon == null)
+			throw T_Fail.testFailMsg("test deamon not set");
+	}
+
+	protected T_MultiThreadedIterations newTestObject()
+	{
+		return new T_DaemonService(); // clone myself
+	}
+
+
+	/**
+		@exception T_Fail - test failed
+	*/
+	protected void runTestSet() throws T_Fail
+	{
+		try
+		{
+			/* test basic DaemonService interface */
+			T01(testDaemon);	// basic subscription
+			T02(testDaemon);	// basic enqueue
+			T03(testDaemon);	// mixture of everything
+
+			t_checkStatus(testDaemon);	// make sure all serviceables I created got serviced
+		}
+		catch (StandardException se)
+		{
+			throw T_Fail.exceptionFail(se);			
+		}
+
+	}
+
+	/*
+	 *  tests
+	 */
+
+	/* test 1 - basic subscription */
+	private void T01(DaemonService daemon) throws T_Fail, StandardException
+	{
+		// add a couple of subscriptions to the deamon
+		T_Serviceable s1 = new T_Serviceable(false);  // not on demand
+		serviceRecord.addElement(s1);
+		int clientNumber1 = daemon.subscribe(s1, false);
+		s1.setClientNumber(clientNumber1);
+
+		T_Serviceable s2 = new T_Serviceable(true);  // on demand only
+		serviceRecord.addElement(s2);
+		int clientNumber2 = daemon.subscribe(s2, true);
+		s2.setClientNumber(clientNumber2);
+
+		daemon.serviceNow(clientNumber2); // s2 should be serviced exactly once
+
+		s2.t_wait(1); // wait for s2 to be serviced
+
+		randomSleep();
+
+		// don't demand service, let daemon service it by itself
+		s1.t_wait(1); // wait for s1 to be serviced
+
+		s2.t_check(1);  // s2 should be serviced exactly once
+
+		PASS("T01");
+
+		randomSleep();
+	}
+
+	/* test 1 - basic enqueue */
+	private void T02(DaemonService daemon) throws T_Fail, StandardException
+	{
+		int requeue = 10;
+
+		T_Serviceable e1 = new T_Serviceable(1); // service now and don't requeue
+		serviceRecord.addElement(e1);
+		daemon.enqueue(e1, true);
+
+		T_Serviceable e2 = new T_Serviceable(requeue); // service now and requeue
+		serviceRecord.addElement(e2);
+		daemon.enqueue(e2, true);
+
+		T_Serviceable e3 = new T_Serviceable(1); // don't requeue
+		serviceRecord.addElement(e3);
+		daemon.enqueue(e3, false);
+
+		T_Serviceable e4 = new T_Serviceable(requeue); // requeue
+		serviceRecord.addElement(e4);
+		daemon.enqueue(e4, false);
+
+		randomSleep();
+
+		e1.t_wait(1);				// make sure they are all serviced at least once
+		e2.t_wait(1);
+		e3.t_wait(1);
+		e4.t_wait(1);
+
+		e2.t_wait(requeue);	// e2 and e4 are requeued
+		e4.t_wait(requeue);	// e2 and e4 are requeued
+
+		// meanwhile, e1 and e3 should not be service more than once
+		e1.t_check(1);
+		e3.t_check(1);
+
+		PASS("T02");
+
+		randomSleep();
+	}
+
+	/* test 4 - mixture */
+	private void T03(DaemonService daemon) throws T_Fail, StandardException
+	{
+		T_Serviceable s1 = new T_Serviceable(false);  // unsubscribe this laster
+		serviceRecord.addElement(s1);
+		int sub1 = daemon.subscribe(s1, false);
+
+		T_Serviceable e1 = new T_Serviceable(1); 
+		serviceRecord.addElement(e1);
+		daemon.enqueue(e1, false); // enqueue the same thing 5 times
+		daemon.enqueue(e1, false);
+		daemon.enqueue(e1, false);
+		daemon.enqueue(e1, false);
+		daemon.enqueue(e1, false);
+
+		T_Serviceable s2 = new T_Serviceable(false); // not on demand
+		serviceRecord.addElement(s2);
+		int sub2 = daemon.subscribe(s2, false); 
+		int realsub2 = daemon.subscribe(s2, false); 
+		s2.setClientNumber(realsub2);
+
+		daemon.unsubscribe(sub1);
+		daemon.unsubscribe(sub2); // it has another subscriptions
+
+		int save;
+		synchronized(s1)
+		{
+			save = s1.timesServiced;
+		}
+		daemon.serviceNow(sub1); // should be silently igored
+
+		randomSleep();
+
+		e1.t_wait(5);			// it is enqueued 5 times, it should be serviced 5 times
+
+		daemon.serviceNow(sub1); // should be silently igored
+
+		s2.t_wait(3);		// wait long enough for it to be serviced at least 3 times
+
+		daemon.serviceNow(sub1); // should be silently igored
+
+		synchronized(s1)
+		{
+			if (save != s1.timesServiced)
+				throw T_Fail.testFailMsg("unsubscribed continue to get serviced");
+
+			// unsubscribed can subscribe again
+			s1.timesServiced = 0;
+		}
+		
+		sub1 = daemon.subscribe(s1, false); // resubscribe
+		s1.setClientNumber(sub1);
+		daemon.serviceNow(sub1);
+		s1.t_wait(1);
+
+		// e1 should not be serviced for > 5 times
+		e1.t_check(5);
+
+		PASS("T03");
+		randomSleep();
+
+	}
+
+	private void t_checkStatus(DaemonService daemon) throws T_Fail
+	{
+		for (int i = 0; i < serviceRecord.size(); i++)
+		{
+			T_Serviceable check = (T_Serviceable)serviceRecord.elementAt(i);
+			if (check != null)
+			{
+				if (check.subscribed)
+				{
+					if (check.onDemandOnly)
+						check.t_check(1);
+					else
+						check.t_wait(10); // sooner or later, it will be serviced this many times
+
+					daemon.unsubscribe(check.getClientNumber());
+				}
+				else			// enqueued
+				{
+					check.t_wait(check.timesRequeue);
+				}
+			}
+		}
+		PASS("T_CheckStatus");
+	}
+
+	private void randomSleep()
+		 throws StandardException
+	{
+		// randomly sleep for a bit if this is a multi-threaded test to make it more interesting
+		if (getNumThreads() > 1)
+		{
+			int nap = random.nextInt()%100;
+			if (nap < 0) nap = -nap;
+			try
+			{
+				Thread.sleep(nap);
+			}
+			catch (InterruptedException ie)
+			{
+				throw StandardException.interrupt(ie);
+			}
+		}	
+	}
+
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DaemonService.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,47 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_DiagTestClass1
+
+   Copyright 1998, 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.services;
+
+import org.apache.derby.iapi.error.StandardException;
+
+/**
+
+A test class for T_Diagnosticable.  A diagnostic class will be provided 
+on this class.
+
+**/
+
+public class T_DiagTestClass1 
+{
+    protected String state;
+
+    public T_DiagTestClass1(String input_state)
+    {
+        this.state = input_state;
+    }
+
+    /* Private/Protected methods of This class: */
+    /* Public Methods of This class: */
+    public String toString()
+    {
+        return("T_DiagTestClass1.toString(): " + state);
+    }
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1Sub.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1Sub.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1Sub.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1Sub.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,38 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_DiagTestClass1Sub
+
+   Copyright 1999, 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.services;
+
+import org.apache.derby.iapi.error.StandardException;
+
+/**
+
+A test class for T_Diagnosticable.  A diagnostic class will be provided 
+on this class.
+
+**/
+
+public class T_DiagTestClass1Sub extends T_DiagTestClass1
+{
+    public T_DiagTestClass1Sub(String input_state)
+    {
+        super(input_state);
+    }
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_DiagTestClass1Sub.java
------------------------------------------------------------------------------
    snv:eol-style = native

Added: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Diagnosticable.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Diagnosticable.java?view=auto&rev=155990
==============================================================================
--- incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Diagnosticable.java (added)
+++ incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Diagnosticable.java Wed Mar  2 17:30:05 2005
@@ -0,0 +1,211 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.unitTests.services.T_Diagnosticable
+
+   Copyright 1998, 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.services;
+
+import org.apache.derby.iapi.services.context.ContextService;
+import org.apache.derby.iapi.services.diag.Diagnosticable;
+import org.apache.derby.iapi.services.diag.DiagnosticUtil;
+import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.iapi.services.sanity.SanityManager;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.store.access.AccessFactory;
+import org.apache.derby.iapi.store.access.ConglomerateController;
+import org.apache.derby.iapi.store.access.TransactionController;
+import org.apache.derby.iapi.store.raw.ContainerHandle;
+import org.apache.derby.iapi.store.raw.ContainerKey;
+import org.apache.derby.iapi.store.raw.Page;
+import org.apache.derby.iapi.store.raw.Transaction;
+import org.apache.derby.iapi.store.raw.RawStoreFactory;
+
+
+import org.apache.derbyTesting.unitTests.harness.T_MultiIterations;
+import org.apache.derbyTesting.unitTests.harness.T_Fail;
+import org.apache.derby.iapi.reference.Property;
+
+import java.util.Properties;
+
+// DEBUGGING:
+
+/**
+
+  This T_Diagnosticable class provides a sample of how to use the "Diagnostic"
+  facility.  The classes methods are built to be called by a "values" or
+  a "call" statement from "ij".  Eventually there will be some sort of 
+  diagnostic monitor which will be used to call the various "D_*" routines.
+
+**/
+
+
+public class T_Diagnosticable extends T_MultiIterations
+{
+    private static final String testService = "DiagnosticableTest";
+
+
+    /* Constructors for This class: */
+
+    /**
+     * No arg Constructor.
+     **/
+    public T_Diagnosticable()
+    {
+    }
+
+    /* Private/Protected methods of This class: */
+
+    /**
+     * Simple test of DiagnosticUtil interfaces.
+     * <p>
+     * Simple test of DiagnosticUtil.toDiagString() and 
+     * DiagnosticUtil.findDiagnostic() interfaces.
+     *
+	 * @exception  T_Fail  If test fails for some reason.
+     **/
+    private void t_001()
+        throws T_Fail
+    {
+        // Create object with also has a diagnostic interface:
+        Object diag_obj = new T_DiagTestClass1("object with diag interface");
+
+		// Create an object in a sub-class that doesn't have a D_ class, but
+		// its super-class does.
+		Object diagSubObj = new T_DiagTestClass1Sub("sub-class");
+
+        // Create object with neither Diagnosticable:
+        Object obj = new Long(5);
+
+        // Test just getting a single string back, from each type of object.
+        String          str          = null;
+        String          expected_str = null;
+        Diagnosticable  helper_class = null;
+
+        // Here the string should come from the Diagnostic object's diag().
+        str          = DiagnosticUtil.toDiagString(diag_obj);
+        expected_str = "D_T_DiagTestClass1: object with diag interface";
+
+        if (str.compareTo(expected_str) != 0)
+        {
+			throw T_Fail.testFailMsg(
+                "DiagnosticUtil.toDiagString() failed, got: (" + str + 
+                "), expected: (" + expected_str + ").");
+        }
+
+
+        // make sure right class was found.
+      
+        helper_class = DiagnosticUtil.findDiagnostic(diag_obj);
+        
+        if (!(helper_class instanceof D_T_DiagTestClass1))
+            throw T_Fail.testFailMsg("Bad helper class lookup.");
+
+        // make sure helper class gives right string.
+        
+        try
+        {
+            str = helper_class.diag();
+        }
+        catch (Throwable t)
+        {
+			throw T_Fail.testFailMsg(
+                "Unexpected exception from helper_class.diag() call");
+        }
+
+        if (!str.equals(expected_str))
+        {
+			throw T_Fail.testFailMsg(
+                "DiagnosticUtil.toDiagString() failed, got: (" + str + 
+                "), expected: (" + expected_str + ").");
+        }
+
+		// make sure the Diagnostic class picks up a super-version of the D_ class
+        str          = DiagnosticUtil.toDiagString(diagSubObj);
+        expected_str = "D_T_DiagTestClass1: sub-class";
+        if (!str.equals(expected_str))
+        {
+			throw T_Fail.testFailMsg(
+                "DiagnosticUtil.toDiagString() failed, got: (" + str + 
+                "), expected: (" + expected_str + ").");
+        }
+        
+        // Here the string should just be the system's default toString.
+        str          = DiagnosticUtil.toDiagString(obj);
+        expected_str = "5";
+
+        if (str.compareTo(expected_str) != 0)
+        {
+			throw T_Fail.testFailMsg(
+                "DiagnosticUtil.toDiagString() failed, got: (" + str + 
+                "), expected: (" + expected_str + ").");
+        }
+
+        // check that lookup for this class return correctly returns null,
+        // since help class does not exist.
+        helper_class = DiagnosticUtil.findDiagnostic(obj);
+
+        if (helper_class != null)
+            throw T_Fail.testFailMsg("Bad helper class - should be null.");
+    }
+
+
+    /* Public Methods of T_MultiIterations class: */
+
+    /**
+     * Routine one once per invocation of the test by the driver.
+     * <p>
+     * Do work that should only be done once, no matter how many times
+     * runTests() may be executed.
+     *
+	 * @exception  T_Fail  Thrown on any error.
+     **/
+    protected void setupTest()
+		throws T_Fail
+    {
+		// 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());
+    }
+
+	/*
+	** Methods required by T_Generic
+	*/
+
+	public String getModuleToTestProtocolName() {
+        return("org.apache.derby.iapi.services.diag.DiagnosticUtil");
+	}
+
+    /**
+     * Driver routine for the btree secondary index tests.
+     * <p>
+     *
+	 * @exception  T_Fail  Throws T_Fail on any test failure.
+     **/
+	protected void runTestSet() throws T_Fail
+	{
+        out.println("Executing " + testService + " test.");
+
+        t_001();
+
+        out.println("Finished Executing " + testService + " test.");
+	}
+}

Propchange: incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/services/T_Diagnosticable.java
------------------------------------------------------------------------------
    snv:eol-style = native