incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r883384 [30/47] - in /incubator/kato/trunk/org.apache.kato: ./ kato.anttasks/src/main/java/org/apache/kato/anttasks/ kato.anttasks/src/main/java/org/apache/kato/anttasks/sitebuilder/ kato.anttasks/src/main/java/org/apache/kato/anttasks/tck/...
Date Mon, 23 Nov 2009 15:54:15 GMT
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaMonitor_ObjectMonitors.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaMonitor_ObjectMonitors.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaMonitor_ObjectMonitors.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaMonitor_ObjectMonitors.java Mon Nov 23 15:53:48 2009
@@ -1,1137 +1,1137 @@
-/*******************************************************************************
- * 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.kato.tck.tests.javaruntime;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.tools.diagnostics.image.CorruptData;
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.image.ImagePointer;
-import javax.tools.diagnostics.runtime.java.JavaClass;
-import javax.tools.diagnostics.runtime.java.JavaField;
-import javax.tools.diagnostics.runtime.java.JavaMonitor;
-import javax.tools.diagnostics.runtime.java.JavaObject;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-import javax.tools.diagnostics.runtime.java.JavaThread;
-
-import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
-import org.apache.kato.tck.scenario142.javaruntime.SetupJavaMonitor_ObjectMonitors;
-import org.apache.kato.tck.scenario142.javaruntime.SetupJavaMonitor_ObjectMonitors.MonitorThreadConfig;
-
-
-/**
- * Tests that monitors work correctly.
- * 
- * Tests with variations on the number of notify waiters, enter waiters and owners,
- * up to a maximum of 2 waiters of each type (there can be only one owner, of course).
- * 
- * TODO Add tests where threads own one monitor and wait on another.
- * 
- */
-public class TestJavaMonitor_ObjectMonitors extends TCKJavaRuntimeTestcase {
-	
-
-	public SetupJavaMonitor_ObjectMonitors setup=new SetupJavaMonitor_ObjectMonitors();
-
-	
-	/**
-	 * Not executed anywhere - for debugging
-	 */
-	private void printMonitors() {
-		System.out.println("JVM "+ System.getProperty("java.vm.name")+ ", "+System.getProperty("java.vm.vendor")+
-				System.getProperty("java.vm.version"));
-		
-		for (int i = 0; i < setup.monitorConfigs.length; i++) {
-			System.out.println("Printing out status of "+ setup.monitorConfigs[i].id);
-			System.out.println("==================================");
-			JavaMonitor monitor = (JavaMonitor) setup.monitorConfigs[i].getMonitor();
-			
-			if (monitor == null) {
-				System.out.println("monitor = null");
-				continue;
-			}
-			
-			try {
-				System.out.println("monitor.getName()"+ monitor.getName());
-			} catch (CorruptDataException e) {
-				assertNotNull(e.getCorruptData());
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-			
-			System.out.println("\nmonitor.getEntersWaiters():");
-			
-			Iterator enters = monitor.getEnterWaiters().iterator();
-			
-			while (enters.hasNext()) {
-				Object next = enters.next();
-				
-				if (next instanceof CorruptData) {
-					System.out.println("enter waiter corrupt: "+ next);
-					continue;
-				}
-				
-				JavaThread thread = (JavaThread) next;
-				
-				try {
-					System.out.println("EnterWaiter: "+thread.getName());
-				} catch (CorruptDataException e) {
-					assertNotNull(e.getCorruptData());
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}
-								
-								
-			}
-			
-			System.out.println("\nmonitor.getNotifyWaiters():");
-			
-			Iterator notifiers = monitor.getNotifyWaiters().iterator();
-			
-			while (notifiers.hasNext()) {
-				Object next = notifiers.next();
-				
-				if (next instanceof CorruptData) {
-					System.out.println("notify waiter corrupt: "+ next);
-					continue;
-				}
-				
-				JavaThread thread = (JavaThread) next;
-				
-				try {
-					System.out.println("NotifyWaiter: "+thread.getName());
-				} catch (CorruptDataException e) {
-					assertNotNull(e.getCorruptData());
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}								
-			}
-			
-			JavaThread thread;
-			try {
-				thread = monitor.getOwner();
-				if (thread == null) {
-					System.out.println("Owner thread = null");
-				} else {
-					try {
-						System.out.println("Owner thread = "+thread.getName());
-					} catch (CorruptDataException e) {
-						assertNotNull(e.getCorruptData());
-						// TODO Auto-generated catch block
-						e.printStackTrace();
-					}
-				}
-			} catch (CorruptDataException e1) {
-				assertNotNull(e1.getCorruptData());
-				// TODO Auto-generated catch block
-				e1.printStackTrace();
-			}			
-			
-			System.out.println("\n\n");
-		}
-	}
-	
-	
-
-	private static String generatePrefix(int waiters, int enters, int owners) {
-		return SetupJavaMonitor_ObjectMonitors.namePrefix + waiters + "-" + owners + "-" + enters;
-	}
-
-	
-
-	public class MonitorNotifyThread extends Thread {
-		private Object monitor;
-		private volatile boolean almostReady = false;
-
-		public MonitorNotifyThread(String name, Object monitor) {
-			super(name);
-			this.setDaemon(true); // Allow JVM to exit.
-			this.monitor = monitor;
-		}
-
-		public void run() {
-			synchronized (monitor) {
-				synchronized (this) {
-					almostReady = true;
-					this.notify();
-				}
-				while (true) {
-					try {
-						monitor.wait();
-					} catch (InterruptedException e) {
-						// Keep waiting...
-					}
-				}
-			}
-		}
-
-		/**
-		 * Start thread, and waits until the thread is about to release the
-		 * monitor.
-		 */
-		public void start() {
-			super.start();
-			synchronized (this) {
-				try {
-					while (!almostReady) {
-						this.wait();
-					}
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-				}
-			}
-
-		}
-
-	}
-
-	/**
-	 * A thread that tries to own a monitor.
-	 * 
-	 */
-	public class MonitorOwnerThread extends Thread {
-		private Object monitor;
-		private volatile boolean owned = false;
-
-		public MonitorOwnerThread(String name, Object monitor) {
-			super(name);
-			this.setDaemon(true); // Allow JVM to exit.
-			this.monitor = monitor;
-		}
-
-		public void run() {
-			synchronized (monitor) {
-				synchronized (this) {
-					owned = true;
-					this.notify();
-				}
-				while (true) {
-					// We have either entered, or are entering.
-
-					try {
-						sleep(10000);
-					} catch (InterruptedException e) {
-						// TODO Auto-generated catch block
-						e.printStackTrace();
-					}
-				}
-			}
-		}
-
-		public void start() {
-			super.start();
-			synchronized (this) {
-				try {
-					while (!owned) {
-						this.wait();
-					}
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-				}
-			}
-
-		}
-	}
-
-	/**
-	 * A thread that tries to enter a monitor.
-	 * 
-	 */
-	public class MonitorEnterThread extends Thread {
-		private Object monitor;
-		private volatile boolean owned = false;
-
-		public MonitorEnterThread(String name, Object monitor) {
-			super(name);
-			this.setDaemon(true); // Allow JVM to exit.
-			this.monitor = monitor;
-		}
-
-		public void run() {
-			synchronized (this) {
-				owned = true;
-				this.notify();
-			}
-			synchronized (monitor) {
-				// This code should never be reached.
-			}
-		}
-
-		public void start() {
-			super.start();
-	
-			synchronized (this) {
-	
-				try {
-					while (!owned) {
-						this.wait();
-					}
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-				}
-			}
-			try {
-				sleep(1000);
-			} catch (InterruptedException e1) {
-				e1.printStackTrace();
-			}
-		}
-	}
-
-	static private JavaRuntime runtime;
-
-	public void setUp() throws Exception {
-		JavaRuntime currentRuntime = getJavaRuntime();
-
-		if (runtime != null && currentRuntime.equals(runtime)) {
-			return;
-		}
-
-		runtime = getJavaRuntime();
-
-		findMonitors();
-	}
-
-	public void findMonitors() throws Exception {
-		JavaRuntime runtime = getJavaRuntime();
-
-		Iterator monitorIterator = runtime.getMonitors().iterator();
-
-		// Search through all monitors for this test's monitor.
-		while (monitorIterator.hasNext()) {
-			Object next = monitorIterator.next();
-
-			// Ignore corrupt data
-			if (next instanceof CorruptData) {
-				continue;
-			}
-
-			JavaMonitor monitorCandidate = (JavaMonitor) next;
-			
-			//System.out.println("Monitor candidate->"+monitorCandidate.getName());
-			JavaObject monitorObjectCandidate = monitorCandidate.getObject();
-
-			if (monitorObjectCandidate != null) {
-				JavaClass monitorClass = monitorObjectCandidate.getJavaClass();
-				if (!SetupJavaMonitor_ObjectMonitors.monitorClassName.equals(monitorClass.getName())) {
-					continue;
-				}
-
-				Iterator fields = monitorClass.getDeclaredFields().iterator();
-
-				while (fields.hasNext()) {
-					Object next2 = fields.next();
-
-					if (next2 instanceof CorruptData) {
-						continue;
-					}
-
-					JavaField field = (JavaField) next2;
-					String id = null;
-
-					if ("id".equals(field.getName())) {
-						id = field.getString(monitorObjectCandidate);
-					}
-
-					if (id != null) {
-
-						MonitorThreadConfig config = setup.findMonitorThreadConfig(id);
-
-						if (config != null) {
-							config.setMonitor(monitorCandidate);
-						}
-					}
-				}
-			}
-		}
-	}
-
-	public void testFindMonitor_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-
-		assertNotNull("Couldn't find 0-1-1", monitor);
-	}
-
-	public void testGetID_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 0-1-1 is null.", monitor.getID());
-	}
-
-	public void testGetName_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 0-1-1 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 0, count);
-	}
-
-	public void testCountEnters_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();
-			count++;
-		}
-
-		assertEquals("Enters count incorrect :" + count, 1, count);
-	}
-
-	public void testCountOwners_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNotNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			JavaThread next = (JavaThread) waiters.next();
-			assertEquals("Waiters name incorrect", generatePrefix(0, 1, 1)
-					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
-					.getName());
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 0, count);
-	}
-
-	public void testNameEnters_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			JavaThread next = (JavaThread) enters.next();
-			assertEquals("Enters name incorrect", generatePrefix(0, 1, 1) + "-"
-					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
-			count++;
-		}
-	}
-
-	public void testNameOwners_0_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertEquals("Owner name incorrect", generatePrefix(0, 1, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
-	}
-	
-	///////////////////////////////////////////
-
-	public void testFindMonitor_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-
-		assertNotNull("Couldn't find 0-1-1", monitor);
-	}
-
-	public void testGetID_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 0-1-1 is null.", monitor.getID());
-	}
-
-	public void testGetName_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 0-1-1 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 0, count);
-	}
-
-	public void testCountEnters_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();
-			count++;
-		}
-
-		assertEquals("Enters count incorrect :" + count, 0, count);
-	}
-
-	public void testCountOwners_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNotNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			JavaThread next = (JavaThread) waiters.next();
-			assertEquals("Waiters name incorrect", generatePrefix(0, 0, 1)
-					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
-					.getName());
-			count++;
-		}
-
-	}
-
-	public void testNameEnters_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			JavaThread next = (JavaThread) enters.next();
-			assertEquals("Enters name incorrect", generatePrefix(0, 0, 1) + "-"
-					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
-			count++;
-		}
-	}
-
-	public void testNameOwners_0_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertEquals("Owner name incorrect", generatePrefix(0, 0, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
-	}
-
-	///////////////////////////////////////////
-
-	public void testFindMonitor_1_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-
-		assertNotNull("Couldn't find monitor 1-0-0", monitor);
-	}
-
-	public void testGetID_1_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 1-0-0 is null.", monitor.getID());
-	}
-
-	public void testGetName_1_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 1-0-0 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_1_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 1, count);
-	}
-
-	public void testCountEnters_1_0_0() throws Exception {
-		JavaMonitor monitor =(JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();
-			count++;
-		}
-
-		assertEquals("Enters count incorrect :" + count, 0, count);
-	}
-
-	public void testCountOwners_1_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_1_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			JavaThread next = (JavaThread) waiters.next();
-			assertEquals("Waiters name incorrect", generatePrefix(1, 0, 0)
-					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
-					.getName());
-			count++;
-		}
-	}
-
-	public void testNameEnters_1_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			JavaThread next = (JavaThread) enters.next();
-			assertEquals("Enters name incorrect", generatePrefix(1, 0, 0) + "-"
-					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
-			count++;
-		}
-	}
-
-	///////////////////////////////////////////
-
-	public void testFindMonitor_1_1_1() throws Exception {
-		JavaMonitor monitor =(JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-
-		assertNotNull("Couldn't find monitor 1-1-1", monitor);
-	}
-
-	public void testGetID_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 1-1-1 is null.", monitor.getID());
-	}
-
-	public void testGetName_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 1-1-1 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 1, count);
-	}
-
-	public void testCountEnters_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-		enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();			 
-			count++;	
-		}
-
-		assertEquals("Enters count incorrect :" + count, 1, count);
-	}
-
-	public void testCountOwners_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNotNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		Iterator monitors = getJavaRuntime().getMonitors().iterator();
-		monitors = getJavaRuntime().getMonitors().iterator();
-
-
-		while (waiters.hasNext()) {
-			JavaThread next = (JavaThread) waiters.next();
-			assertEquals("Waiters name incorrect", generatePrefix(1, 1, 1)
-					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
-					.getName());
-			count++;
-		}
-	}
-
-	public void testNameEnters_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-		
-		while (enters.hasNext()) {
-			JavaThread next = (JavaThread) enters.next();		
-			assertEquals("Enters name incorrect", generatePrefix(1, 1, 1) + "-"
-					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
-			count++;
-		}
-	}
-
-	public void testNameOwners_1_1_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertEquals("Owner name incorrect", generatePrefix(1, 1, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
-	}
-	
-	//////////////////////////////////////////////
-	
-	public void testFindMonitor_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-
-		assertNotNull("Couldn't find monitor 2-0-0", monitor);
-	}
-
-	public void testGetID_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 2-0-0 is null.", monitor.getID());
-	}
-
-	public void testGetName_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 2-0-0 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 2, count);
-	}
-
-	public void testCountEnters_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();
-			count++;
-		}
-
-		assertEquals("Enters count incorrect :" + count, 0, count);
-	}
-
-	public void testCountOwners_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			JavaThread next = (JavaThread) waiters.next();
-			assertEquals("Waiters name incorrect", generatePrefix(2, 0, 0)
-					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
-					.getName());
-			count++;
-		}
-	}
-
-	public void testNameEnters_2_0_0() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			JavaThread next = (JavaThread) enters.next();
-			assertEquals("Enters name incorrect", generatePrefix(2, 0, 0) + "-"
-					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
-			count++;
-		}
-	}
-	///////////////////////////////////////////
-
-	public void testFindMonitor_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-
-		assertNotNull("Couldn't find monitor 1-0-1", monitor);
-	}
-
-	public void testGetID_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 1-0-1 is null.", monitor.getID());
-	}
-
-	public void testGetName_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 1-0-1 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 1, count);
-	}
-
-	public void testCountEnters_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();
-			count++;
-		}
-
-		assertEquals("Enters count incorrect :" + count, 0, count);
-	}
-
-	public void testCountOwners_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNotNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			JavaThread next = (JavaThread) waiters.next();
-			assertEquals("Waiters name incorrect", generatePrefix(1, 0, 1)
-					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
-					.getName());
-			count++;
-		}
-	}
-
-	public void testNameEnters_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			JavaThread next = (JavaThread) enters.next();
-			assertEquals("Enters name incorrect", generatePrefix(1, 0, 1) + "-"
-					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
-			count++;
-		}
-	}
-	
-	public void testNameOwners_1_0_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertEquals("Owner name incorrect", generatePrefix(1, 0, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
-	}
-	///////////////////////////////////////////
-
-	public void testFindMonitor_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-
-		assertNotNull("Couldn't find monitor 0-2-1", monitor);
-	}
-
-	public void testGetID_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 0-2-1 is null.", monitor.getID());
-	}
-
-	public void testGetName_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 0-2-1 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 0, count);
-	}
-
-	public void testCountEnters_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();
-			count++;
-		}
-
-		assertEquals("Enters count incorrect :" + count, 2, count);
-	}
-
-	public void testCountOwners_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNotNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			JavaThread next = (JavaThread) waiters.next();
-			assertEquals("Waiters name incorrect", generatePrefix(0, 2, 1)
-					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
-					.getName());
-			count++;
-		}
-	}
-
-	public void testNameEnters_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		String error = checkNames(enters, generatePrefix(0, 2, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName, 2);
-		
-		assertNull(error, error);
-	}
-	
-	public void testNameOwners_0_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertEquals("Owner name incorrect", generatePrefix(0, 2, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
-	}
-		
-	///////////////////////////////////////////
-
-	public void testFindMonitor_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
-
-		assertNotNull("Couldn't find monitor 2-2-1", monitor);
-	}
-
-	public void testGetID_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
-
-		assertNotNull("JavaMonitor.getID() for 2-2-1 is null.", monitor.getID());
-	}
-
-	public void testGetName_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
-		assertNotNull("JavaMonitor.getName() for 2-2-1 is null.", monitor
-				.getName());
-	}
-
-	public void testCountWaiters_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
-		int count = 0;
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			count++;
-		}
-
-		assertEquals("Waiters count incorrect :" + count, 2, count);
-	}
-
-	public void testCountEnters_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
-		int count = 0;
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		while (enters.hasNext()) {
-			Object next = enters.next();
-			count++;
-		}
-
-		assertEquals("Enters count incorrect :" + count, 2, count);
-	}
-
-	public void testCountOwners_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertNotNull("Owner count incorrect", owner);
-	}
-
-	public void testNameWaiters_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();		
-		Iterator waiters = monitor.getNotifyWaiters().iterator();
-
-		String error = checkNames(waiters, generatePrefix(2, 2, 1)
-				+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName , 2);
-		assertNull(error, error);
-	}
-
-	public void testNameEnters_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();		
-		Iterator enters = monitor.getEnterWaiters().iterator();
-
-		String error = checkNames(enters, generatePrefix(2, 2, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName, 2);
-		
-		assertNull(error, error);
-	}
-	
-	public void testNameOwners_2_2_1() throws Exception {
-		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
-		JavaThread owner = monitor.getOwner();
-
-		assertEquals("Owner name incorrect", generatePrefix(2, 2, 1) + "-"
-				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
-	}
-
-	////////////////////////////////////
-	
-	/**
-	 * Check  uniqueness of all the monitor ID's.
-	 * 
-	 */
-	public void testGetID() throws Exception {
-		Set foundSet = new HashSet(SetupJavaMonitor_ObjectMonitors.NUM_MONITORS);
-		
-		for (int i=0; i < SetupJavaMonitor_ObjectMonitors.NUM_MONITORS; i++){
-			JavaMonitor monitor=(JavaMonitor) setup.monitorConfigs[i].monitor;
-			ImagePointer id = monitor.getID();
-			
-			assertNotNull("Found null monitor id for " + setup.monitorConfigs[i].id, id);
-			
-			assertFalse("Found duplicate monitor id. " + setup.monitorConfigs[i].id, foundSet.contains(id));
-			
-			foundSet.add(id);
-		}
-	}
-	
-	////////////////////////////////////
-	
-	public void testGetName() throws Exception {
-		for (int i=0; i < SetupJavaMonitor_ObjectMonitors.NUM_MONITORS; i++){
-			JavaMonitor monitor=(JavaMonitor) setup.monitorConfigs[i].monitor;
-			String name = monitor.getName();
-			
-			assertNotNull("Found null monitor name for " + setup.monitorConfigs[i].id, name);
-		}
-	}
-	
-	public void testGetObject() throws Exception {
-		for (int i=0; i < SetupJavaMonitor_ObjectMonitors.NUM_MONITORS; i++){
-			JavaMonitor monitor=(JavaMonitor) setup.monitorConfigs[i].monitor;
-			JavaObject object = monitor.getObject();
-			
-			assertEquals("Monitor object class unexpected name.",setup.monitorClassName, object.getJavaClass().getName());
-			
-			JavaField idField = getJavaField(object, "id");
-			String idString = idField.getString(object);
-			
-			assertEquals("MonitorClass id strings didn't match.", setup.monitorConfigs[i].id, idString);
-		}
-	}
-	
-	public void testEqualsSelf()  throws Exception {
-		assertTrue(setup.monitorConfigs[0].monitor.equals(setup.monitorConfigs[0].monitor));
-	}
-	
-	public void testEqualsNull()  throws Exception {
-		assertFalse(setup.monitorConfigs[0].monitor.equals(null));
-	}
-	
-	public void testNotEqualsOther()  throws Exception {
-		assertFalse(setup.monitorConfigs[0].monitor.equals(setup.monitorConfigs[1].monitor));
-	}
-	
-	/**
-	 * Checks that the expected JavaThreads are within the iterator
-	 * of waiters passed, in no particular order.
-	 * Number of JavaThreads should be checked elsewhere.
-	 * 
-	 * @param waiters a set of a monitor's waiters.
-	 * @param prefix start of the thread name
-	 * @param count number of threads to look for. Used as suffix of thread name
-	 * @return null if ok or an error string if it is not ok
-	 * @throws CorruptDataException
-	 * 
-	 */
-	public String checkNames(Iterator waiters, String prefix, int count) throws CorruptDataException {
-		Set foundSet = new HashSet(count);		
-		
-		while (waiters.hasNext()) {
-			Object next = waiters.next();
-			
-			if (next instanceof JavaThread) {
-				JavaThread thread = (JavaThread) next;
-				foundSet.add(thread.getName());
-			}
-		}
-		
-		for(int i=0; i < count; i++) {
-			String threadName = prefix+"-"+i;
-						
-			if (!foundSet.contains(threadName)) {
-				return "Missing thread "+threadName;
-			}
-		}
-		
-		return null;
-	}
-
-	
-}
+/*******************************************************************************
+ * 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.kato.tck.tests.javaruntime;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaMonitor;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaMonitor_ObjectMonitors;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaMonitor_ObjectMonitors.MonitorThreadConfig;
+
+
+/**
+ * Tests that monitors work correctly.
+ * 
+ * Tests with variations on the number of notify waiters, enter waiters and owners,
+ * up to a maximum of 2 waiters of each type (there can be only one owner, of course).
+ * 
+ * TODO Add tests where threads own one monitor and wait on another.
+ * 
+ */
+public class TestJavaMonitor_ObjectMonitors extends TCKJavaRuntimeTestcase {
+	
+
+	public SetupJavaMonitor_ObjectMonitors setup=new SetupJavaMonitor_ObjectMonitors();
+
+	
+	/**
+	 * Not executed anywhere - for debugging
+	 */
+	private void printMonitors() {
+		System.out.println("JVM "+ System.getProperty("java.vm.name")+ ", "+System.getProperty("java.vm.vendor")+
+				System.getProperty("java.vm.version"));
+		
+		for (int i = 0; i < setup.monitorConfigs.length; i++) {
+			System.out.println("Printing out status of "+ setup.monitorConfigs[i].id);
+			System.out.println("==================================");
+			JavaMonitor monitor = (JavaMonitor) setup.monitorConfigs[i].getMonitor();
+			
+			if (monitor == null) {
+				System.out.println("monitor = null");
+				continue;
+			}
+			
+			try {
+				System.out.println("monitor.getName()"+ monitor.getName());
+			} catch (CorruptDataException e) {
+				assertNotNull(e.getCorruptData());
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			
+			System.out.println("\nmonitor.getEntersWaiters():");
+			
+			Iterator enters = monitor.getEnterWaiters().iterator();
+			
+			while (enters.hasNext()) {
+				Object next = enters.next();
+				
+				if (next instanceof CorruptData) {
+					System.out.println("enter waiter corrupt: "+ next);
+					continue;
+				}
+				
+				JavaThread thread = (JavaThread) next;
+				
+				try {
+					System.out.println("EnterWaiter: "+thread.getName());
+				} catch (CorruptDataException e) {
+					assertNotNull(e.getCorruptData());
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+								
+								
+			}
+			
+			System.out.println("\nmonitor.getNotifyWaiters():");
+			
+			Iterator notifiers = monitor.getNotifyWaiters().iterator();
+			
+			while (notifiers.hasNext()) {
+				Object next = notifiers.next();
+				
+				if (next instanceof CorruptData) {
+					System.out.println("notify waiter corrupt: "+ next);
+					continue;
+				}
+				
+				JavaThread thread = (JavaThread) next;
+				
+				try {
+					System.out.println("NotifyWaiter: "+thread.getName());
+				} catch (CorruptDataException e) {
+					assertNotNull(e.getCorruptData());
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}								
+			}
+			
+			JavaThread thread;
+			try {
+				thread = monitor.getOwner();
+				if (thread == null) {
+					System.out.println("Owner thread = null");
+				} else {
+					try {
+						System.out.println("Owner thread = "+thread.getName());
+					} catch (CorruptDataException e) {
+						assertNotNull(e.getCorruptData());
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+				}
+			} catch (CorruptDataException e1) {
+				assertNotNull(e1.getCorruptData());
+				// TODO Auto-generated catch block
+				e1.printStackTrace();
+			}			
+			
+			System.out.println("\n\n");
+		}
+	}
+	
+	
+
+	private static String generatePrefix(int waiters, int enters, int owners) {
+		return SetupJavaMonitor_ObjectMonitors.namePrefix + waiters + "-" + owners + "-" + enters;
+	}
+
+	
+
+	public class MonitorNotifyThread extends Thread {
+		private Object monitor;
+		private volatile boolean almostReady = false;
+
+		public MonitorNotifyThread(String name, Object monitor) {
+			super(name);
+			this.setDaemon(true); // Allow JVM to exit.
+			this.monitor = monitor;
+		}
+
+		public void run() {
+			synchronized (monitor) {
+				synchronized (this) {
+					almostReady = true;
+					this.notify();
+				}
+				while (true) {
+					try {
+						monitor.wait();
+					} catch (InterruptedException e) {
+						// Keep waiting...
+					}
+				}
+			}
+		}
+
+		/**
+		 * Start thread, and waits until the thread is about to release the
+		 * monitor.
+		 */
+		public void start() {
+			super.start();
+			synchronized (this) {
+				try {
+					while (!almostReady) {
+						this.wait();
+					}
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+			}
+
+		}
+
+	}
+
+	/**
+	 * A thread that tries to own a monitor.
+	 * 
+	 */
+	public class MonitorOwnerThread extends Thread {
+		private Object monitor;
+		private volatile boolean owned = false;
+
+		public MonitorOwnerThread(String name, Object monitor) {
+			super(name);
+			this.setDaemon(true); // Allow JVM to exit.
+			this.monitor = monitor;
+		}
+
+		public void run() {
+			synchronized (monitor) {
+				synchronized (this) {
+					owned = true;
+					this.notify();
+				}
+				while (true) {
+					// We have either entered, or are entering.
+
+					try {
+						sleep(10000);
+					} catch (InterruptedException e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+				}
+			}
+		}
+
+		public void start() {
+			super.start();
+			synchronized (this) {
+				try {
+					while (!owned) {
+						this.wait();
+					}
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+			}
+
+		}
+	}
+
+	/**
+	 * A thread that tries to enter a monitor.
+	 * 
+	 */
+	public class MonitorEnterThread extends Thread {
+		private Object monitor;
+		private volatile boolean owned = false;
+
+		public MonitorEnterThread(String name, Object monitor) {
+			super(name);
+			this.setDaemon(true); // Allow JVM to exit.
+			this.monitor = monitor;
+		}
+
+		public void run() {
+			synchronized (this) {
+				owned = true;
+				this.notify();
+			}
+			synchronized (monitor) {
+				// This code should never be reached.
+			}
+		}
+
+		public void start() {
+			super.start();
+	
+			synchronized (this) {
+	
+				try {
+					while (!owned) {
+						this.wait();
+					}
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+			}
+			try {
+				sleep(1000);
+			} catch (InterruptedException e1) {
+				e1.printStackTrace();
+			}
+		}
+	}
+
+	static private JavaRuntime runtime;
+
+	public void setUp() throws Exception {
+		JavaRuntime currentRuntime = getJavaRuntime();
+
+		if (runtime != null && currentRuntime.equals(runtime)) {
+			return;
+		}
+
+		runtime = getJavaRuntime();
+
+		findMonitors();
+	}
+
+	public void findMonitors() throws Exception {
+		JavaRuntime runtime = getJavaRuntime();
+
+		Iterator monitorIterator = runtime.getMonitors().iterator();
+
+		// Search through all monitors for this test's monitor.
+		while (monitorIterator.hasNext()) {
+			Object next = monitorIterator.next();
+
+			// Ignore corrupt data
+			if (next instanceof CorruptData) {
+				continue;
+			}
+
+			JavaMonitor monitorCandidate = (JavaMonitor) next;
+			
+			//System.out.println("Monitor candidate->"+monitorCandidate.getName());
+			JavaObject monitorObjectCandidate = monitorCandidate.getObject();
+
+			if (monitorObjectCandidate != null) {
+				JavaClass monitorClass = monitorObjectCandidate.getJavaClass();
+				if (!SetupJavaMonitor_ObjectMonitors.monitorClassName.equals(monitorClass.getName())) {
+					continue;
+				}
+
+				Iterator fields = monitorClass.getDeclaredFields().iterator();
+
+				while (fields.hasNext()) {
+					Object next2 = fields.next();
+
+					if (next2 instanceof CorruptData) {
+						continue;
+					}
+
+					JavaField field = (JavaField) next2;
+					String id = null;
+
+					if ("id".equals(field.getName())) {
+						id = field.getString(monitorObjectCandidate);
+					}
+
+					if (id != null) {
+
+						MonitorThreadConfig config = setup.findMonitorThreadConfig(id);
+
+						if (config != null) {
+							config.setMonitor(monitorCandidate);
+						}
+					}
+				}
+			}
+		}
+	}
+
+	public void testFindMonitor_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+
+		assertNotNull("Couldn't find 0-1-1", monitor);
+	}
+
+	public void testGetID_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 0-1-1 is null.", monitor.getID());
+	}
+
+	public void testGetName_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 0-1-1 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 0, count);
+	}
+
+	public void testCountEnters_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();
+			count++;
+		}
+
+		assertEquals("Enters count incorrect :" + count, 1, count);
+	}
+
+	public void testCountOwners_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNotNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			JavaThread next = (JavaThread) waiters.next();
+			assertEquals("Waiters name incorrect", generatePrefix(0, 1, 1)
+					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
+					.getName());
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 0, count);
+	}
+
+	public void testNameEnters_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			JavaThread next = (JavaThread) enters.next();
+			assertEquals("Enters name incorrect", generatePrefix(0, 1, 1) + "-"
+					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
+			count++;
+		}
+	}
+
+	public void testNameOwners_0_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 1, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertEquals("Owner name incorrect", generatePrefix(0, 1, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
+	}
+	
+	///////////////////////////////////////////
+
+	public void testFindMonitor_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor) setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+
+		assertNotNull("Couldn't find 0-1-1", monitor);
+	}
+
+	public void testGetID_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 0-1-1 is null.", monitor.getID());
+	}
+
+	public void testGetName_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 0-1-1 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 0, count);
+	}
+
+	public void testCountEnters_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();
+			count++;
+		}
+
+		assertEquals("Enters count incorrect :" + count, 0, count);
+	}
+
+	public void testCountOwners_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNotNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			JavaThread next = (JavaThread) waiters.next();
+			assertEquals("Waiters name incorrect", generatePrefix(0, 0, 1)
+					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
+					.getName());
+			count++;
+		}
+
+	}
+
+	public void testNameEnters_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			JavaThread next = (JavaThread) enters.next();
+			assertEquals("Enters name incorrect", generatePrefix(0, 0, 1) + "-"
+					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
+			count++;
+		}
+	}
+
+	public void testNameOwners_0_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 0, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertEquals("Owner name incorrect", generatePrefix(0, 0, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
+	}
+
+	///////////////////////////////////////////
+
+	public void testFindMonitor_1_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+
+		assertNotNull("Couldn't find monitor 1-0-0", monitor);
+	}
+
+	public void testGetID_1_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 1-0-0 is null.", monitor.getID());
+	}
+
+	public void testGetName_1_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 1-0-0 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_1_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 1, count);
+	}
+
+	public void testCountEnters_1_0_0() throws Exception {
+		JavaMonitor monitor =(JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();
+			count++;
+		}
+
+		assertEquals("Enters count incorrect :" + count, 0, count);
+	}
+
+	public void testCountOwners_1_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_1_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			JavaThread next = (JavaThread) waiters.next();
+			assertEquals("Waiters name incorrect", generatePrefix(1, 0, 0)
+					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
+					.getName());
+			count++;
+		}
+	}
+
+	public void testNameEnters_1_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 0).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			JavaThread next = (JavaThread) enters.next();
+			assertEquals("Enters name incorrect", generatePrefix(1, 0, 0) + "-"
+					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
+			count++;
+		}
+	}
+
+	///////////////////////////////////////////
+
+	public void testFindMonitor_1_1_1() throws Exception {
+		JavaMonitor monitor =(JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+
+		assertNotNull("Couldn't find monitor 1-1-1", monitor);
+	}
+
+	public void testGetID_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 1-1-1 is null.", monitor.getID());
+	}
+
+	public void testGetName_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 1-1-1 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 1, count);
+	}
+
+	public void testCountEnters_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+		enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();			 
+			count++;	
+		}
+
+		assertEquals("Enters count incorrect :" + count, 1, count);
+	}
+
+	public void testCountOwners_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNotNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		Iterator monitors = getJavaRuntime().getMonitors().iterator();
+		monitors = getJavaRuntime().getMonitors().iterator();
+
+
+		while (waiters.hasNext()) {
+			JavaThread next = (JavaThread) waiters.next();
+			assertEquals("Waiters name incorrect", generatePrefix(1, 1, 1)
+					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
+					.getName());
+			count++;
+		}
+	}
+
+	public void testNameEnters_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+		
+		while (enters.hasNext()) {
+			JavaThread next = (JavaThread) enters.next();		
+			assertEquals("Enters name incorrect", generatePrefix(1, 1, 1) + "-"
+					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
+			count++;
+		}
+	}
+
+	public void testNameOwners_1_1_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 1, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertEquals("Owner name incorrect", generatePrefix(1, 1, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
+	}
+	
+	//////////////////////////////////////////////
+	
+	public void testFindMonitor_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+
+		assertNotNull("Couldn't find monitor 2-0-0", monitor);
+	}
+
+	public void testGetID_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 2-0-0 is null.", monitor.getID());
+	}
+
+	public void testGetName_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 2-0-0 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 2, count);
+	}
+
+	public void testCountEnters_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();
+			count++;
+		}
+
+		assertEquals("Enters count incorrect :" + count, 0, count);
+	}
+
+	public void testCountOwners_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			JavaThread next = (JavaThread) waiters.next();
+			assertEquals("Waiters name incorrect", generatePrefix(2, 0, 0)
+					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
+					.getName());
+			count++;
+		}
+	}
+
+	public void testNameEnters_2_0_0() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 0, 0).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			JavaThread next = (JavaThread) enters.next();
+			assertEquals("Enters name incorrect", generatePrefix(2, 0, 0) + "-"
+					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
+			count++;
+		}
+	}
+	///////////////////////////////////////////
+
+	public void testFindMonitor_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+
+		assertNotNull("Couldn't find monitor 1-0-1", monitor);
+	}
+
+	public void testGetID_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 1-0-1 is null.", monitor.getID());
+	}
+
+	public void testGetName_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 1-0-1 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 1, count);
+	}
+
+	public void testCountEnters_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();
+			count++;
+		}
+
+		assertEquals("Enters count incorrect :" + count, 0, count);
+	}
+
+	public void testCountOwners_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNotNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			JavaThread next = (JavaThread) waiters.next();
+			assertEquals("Waiters name incorrect", generatePrefix(1, 0, 1)
+					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
+					.getName());
+			count++;
+		}
+	}
+
+	public void testNameEnters_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			JavaThread next = (JavaThread) enters.next();
+			assertEquals("Enters name incorrect", generatePrefix(1, 0, 1) + "-"
+					+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName + "-" + count, next.getName());
+			count++;
+		}
+	}
+	
+	public void testNameOwners_1_0_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(1, 0, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertEquals("Owner name incorrect", generatePrefix(1, 0, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
+	}
+	///////////////////////////////////////////
+
+	public void testFindMonitor_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+
+		assertNotNull("Couldn't find monitor 0-2-1", monitor);
+	}
+
+	public void testGetID_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 0-2-1 is null.", monitor.getID());
+	}
+
+	public void testGetName_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 0-2-1 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 0, count);
+	}
+
+	public void testCountEnters_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();
+			count++;
+		}
+
+		assertEquals("Enters count incorrect :" + count, 2, count);
+	}
+
+	public void testCountOwners_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNotNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			JavaThread next = (JavaThread) waiters.next();
+			assertEquals("Waiters name incorrect", generatePrefix(0, 2, 1)
+					+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName + "-" + count, next
+					.getName());
+			count++;
+		}
+	}
+
+	public void testNameEnters_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		String error = checkNames(enters, generatePrefix(0, 2, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName, 2);
+		
+		assertNull(error, error);
+	}
+	
+	public void testNameOwners_0_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(0, 2, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertEquals("Owner name incorrect", generatePrefix(0, 2, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
+	}
+		
+	///////////////////////////////////////////
+
+	public void testFindMonitor_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
+
+		assertNotNull("Couldn't find monitor 2-2-1", monitor);
+	}
+
+	public void testGetID_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
+
+		assertNotNull("JavaMonitor.getID() for 2-2-1 is null.", monitor.getID());
+	}
+
+	public void testGetName_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
+		assertNotNull("JavaMonitor.getName() for 2-2-1 is null.", monitor
+				.getName());
+	}
+
+	public void testCountWaiters_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
+		int count = 0;
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			count++;
+		}
+
+		assertEquals("Waiters count incorrect :" + count, 2, count);
+	}
+
+	public void testCountEnters_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
+		int count = 0;
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		while (enters.hasNext()) {
+			Object next = enters.next();
+			count++;
+		}
+
+		assertEquals("Enters count incorrect :" + count, 2, count);
+	}
+
+	public void testCountOwners_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertNotNull("Owner count incorrect", owner);
+	}
+
+	public void testNameWaiters_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();		
+		Iterator waiters = monitor.getNotifyWaiters().iterator();
+
+		String error = checkNames(waiters, generatePrefix(2, 2, 1)
+				+ "-" + SetupJavaMonitor_ObjectMonitors.monitorNotifyThreadName , 2);
+		assertNull(error, error);
+	}
+
+	public void testNameEnters_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();		
+		Iterator enters = monitor.getEnterWaiters().iterator();
+
+		String error = checkNames(enters, generatePrefix(2, 2, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorEnterThreadName, 2);
+		
+		assertNull(error, error);
+	}
+	
+	public void testNameOwners_2_2_1() throws Exception {
+		JavaMonitor monitor = (JavaMonitor)setup.findMonitorThreadConfig(2, 2, 1).getMonitor();
+		JavaThread owner = monitor.getOwner();
+
+		assertEquals("Owner name incorrect", generatePrefix(2, 2, 1) + "-"
+				+ SetupJavaMonitor_ObjectMonitors.monitorOwnerThreadName + "-0", owner.getName());
+	}
+
+	////////////////////////////////////
+	
+	/**
+	 * Check  uniqueness of all the monitor ID's.
+	 * 
+	 */
+	public void testGetID() throws Exception {
+		Set foundSet = new HashSet(SetupJavaMonitor_ObjectMonitors.NUM_MONITORS);
+		
+		for (int i=0; i < SetupJavaMonitor_ObjectMonitors.NUM_MONITORS; i++){
+			JavaMonitor monitor=(JavaMonitor) setup.monitorConfigs[i].monitor;
+			ImagePointer id = monitor.getID();
+			
+			assertNotNull("Found null monitor id for " + setup.monitorConfigs[i].id, id);
+			
+			assertFalse("Found duplicate monitor id. " + setup.monitorConfigs[i].id, foundSet.contains(id));
+			
+			foundSet.add(id);
+		}
+	}
+	
+	////////////////////////////////////
+	
+	public void testGetName() throws Exception {
+		for (int i=0; i < SetupJavaMonitor_ObjectMonitors.NUM_MONITORS; i++){
+			JavaMonitor monitor=(JavaMonitor) setup.monitorConfigs[i].monitor;
+			String name = monitor.getName();
+			
+			assertNotNull("Found null monitor name for " + setup.monitorConfigs[i].id, name);
+		}
+	}
+	
+	public void testGetObject() throws Exception {
+		for (int i=0; i < SetupJavaMonitor_ObjectMonitors.NUM_MONITORS; i++){
+			JavaMonitor monitor=(JavaMonitor) setup.monitorConfigs[i].monitor;
+			JavaObject object = monitor.getObject();
+			
+			assertEquals("Monitor object class unexpected name.",setup.monitorClassName, object.getJavaClass().getName());
+			
+			JavaField idField = getJavaField(object, "id");
+			String idString = idField.getString(object);
+			
+			assertEquals("MonitorClass id strings didn't match.", setup.monitorConfigs[i].id, idString);
+		}
+	}
+	
+	public void testEqualsSelf()  throws Exception {
+		assertTrue(setup.monitorConfigs[0].monitor.equals(setup.monitorConfigs[0].monitor));
+	}
+	
+	public void testEqualsNull()  throws Exception {
+		assertFalse(setup.monitorConfigs[0].monitor.equals(null));
+	}
+	
+	public void testNotEqualsOther()  throws Exception {
+		assertFalse(setup.monitorConfigs[0].monitor.equals(setup.monitorConfigs[1].monitor));
+	}
+	
+	/**
+	 * Checks that the expected JavaThreads are within the iterator
+	 * of waiters passed, in no particular order.
+	 * Number of JavaThreads should be checked elsewhere.
+	 * 
+	 * @param waiters a set of a monitor's waiters.
+	 * @param prefix start of the thread name
+	 * @param count number of threads to look for. Used as suffix of thread name
+	 * @return null if ok or an error string if it is not ok
+	 * @throws CorruptDataException
+	 * 
+	 */
+	public String checkNames(Iterator waiters, String prefix, int count) throws CorruptDataException {
+		Set foundSet = new HashSet(count);		
+		
+		while (waiters.hasNext()) {
+			Object next = waiters.next();
+			
+			if (next instanceof JavaThread) {
+				JavaThread thread = (JavaThread) next;
+				foundSet.add(thread.getName());
+			}
+		}
+		
+		for(int i=0; i < count; i++) {
+			String threadName = prefix+"-"+i;
+						
+			if (!foundSet.contains(threadName)) {
+				return "Missing thread "+threadName;
+			}
+		}
+		
+		return null;
+	}
+
+	
+}

Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaMonitor_ObjectMonitors.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message