incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r818876 - in /incubator/kato/branches/experimental/kato.javaview: ./ .settings/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/kato/ src/main/java/org/apache/kato/javaview/ src/main/resou...
Date Fri, 25 Sep 2009 15:16:58 GMT
Author: spoole
Date: Fri Sep 25 15:16:54 2009
New Revision: 818876

URL: http://svn.apache.org/viewvc?rev=818876&view=rev
Log:
upload of experimental code for java app view 

Added:
    incubator/kato/branches/experimental/kato.javaview/.classpath
    incubator/kato/branches/experimental/kato.javaview/.project
    incubator/kato/branches/experimental/kato.javaview/.settings/
    incubator/kato/branches/experimental/kato.javaview/.settings/org.eclipse.jdt.core.prefs
    incubator/kato/branches/experimental/kato.javaview/.settings/org.maven.ide.eclipse.prefs
    incubator/kato/branches/experimental/kato.javaview/pom.xml
    incubator/kato/branches/experimental/kato.javaview/src/
    incubator/kato/branches/experimental/kato.javaview/src/main/
    incubator/kato/branches/experimental/kato.javaview/src/main/java/
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchy.java
    incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchyBuilder.java
    incubator/kato/branches/experimental/kato.javaview/src/main/resources/
    incubator/kato/branches/experimental/kato.javaview/src/test/
    incubator/kato/branches/experimental/kato.javaview/src/test/java/
    incubator/kato/branches/experimental/kato.javaview/src/test/java/test/
    incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/
    incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/kato/
    incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/kato/javaview/
    incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/kato/javaview/TestJavaClassLoaderHierarchyBuilder.java
    incubator/kato/branches/experimental/kato.javaview/src/test/resources/

Added: incubator/kato/branches/experimental/kato.javaview/.classpath
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/.classpath?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/.classpath (added)
+++ incubator/kato/branches/experimental/kato.javaview/.classpath Fri Sep 25 15:16:54 2009
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: incubator/kato/branches/experimental/kato.javaview/.project
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/.project?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/.project (added)
+++ incubator/kato/branches/experimental/kato.javaview/.project Fri Sep 25 15:16:54 2009
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>kato.javaview</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

Added: incubator/kato/branches/experimental/kato.javaview/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/.settings/org.eclipse.jdt.core.prefs?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/.settings/org.eclipse.jdt.core.prefs
(added)
+++ incubator/kato/branches/experimental/kato.javaview/.settings/org.eclipse.jdt.core.prefs
Fri Sep 25 15:16:54 2009
@@ -0,0 +1,5 @@
+#Thu Sep 24 21:23:29 BST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.source=1.6

Added: incubator/kato/branches/experimental/kato.javaview/.settings/org.maven.ide.eclipse.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/.settings/org.maven.ide.eclipse.prefs?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/.settings/org.maven.ide.eclipse.prefs
(added)
+++ incubator/kato/branches/experimental/kato.javaview/.settings/org.maven.ide.eclipse.prefs
Fri Sep 25 15:16:54 2009
@@ -0,0 +1,9 @@
+#Thu Sep 24 21:23:28 BST 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1

Added: incubator/kato/branches/experimental/kato.javaview/pom.xml
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/pom.xml?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/pom.xml (added)
+++ incubator/kato/branches/experimental/kato.javaview/pom.xml Fri Sep 25 15:16:54 2009
@@ -0,0 +1,30 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>kato</artifactId>
+    <groupId>org.apache.kato</groupId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.kato</groupId>
+  <artifactId>kato.javaview</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <description>		</description>
+  <dependencies>
+  	<dependency>
+  		<groupId>org.apache.kato</groupId>
+  		<artifactId>kato.api</artifactId>
+  		<version>0.0.1-SNAPSHOT</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>org.apache.kato</groupId>
+  		<artifactId>kato.hprof.api</artifactId>
+  		<version>0.0.1-SNAPSHOT</version>
+  	</dependency>
+  	<dependency>
+		<groupId>junit</groupId>
+		<artifactId>junit</artifactId>
+		<version>3.8.1</version>
+		<scope>test</scope>
+	</dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchy.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchy.java?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchy.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchy.java
Fri Sep 25 15:16:54 2009
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.javaview;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.kato.javaview.JavaClassLoaderHierarchyBuilder.Loader;
+
+/**
+ * Inferred class loader hierarchy determined by the Hierarchy Builder
+ *   
+ */
+public class JavaClassLoaderHierarchy {
+	List<Loader> loaderMap=new LinkedList<Loader>();
+
+	public void add(Loader loader) {
+		loaderMap.add(loader);
+		
+	}
+
+	public List<Loader> getAllLoaders() {
+		
+		return loaderMap;
+	}
+
+	public int size() {
+		return loaderMap.size();
+	}
+
+	public List<Loader> getLeafLoaders() {
+		
+		List<Loader> loaders=new LinkedList<Loader>();
+		for(Loader loader:loaderMap) {
+			
+			if(loader.hasChildren()==false)  {
+				loaders.add(loader);
+			}
+			
+		}
+		return loaders;
+	}
+
+	public List<Loader> getRootLoaders() {
+		List<Loader> loaders=new LinkedList<Loader>();
+		for(Loader loader:loaderMap) {
+			
+			if(loader.hasParents()==false)  {
+				loaders.add(loader);
+			}
+			
+		}
+		return loaders;
+	}
+}

Added: incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchyBuilder.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchyBuilder.java?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchyBuilder.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/main/java/org/apache/kato/javaview/JavaClassLoaderHierarchyBuilder.java
Fri Sep 25 15:16:54 2009
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * 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.javaview;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.tools.diagnostics.image.DiagnosticException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+
+import org.apache.xerces.impl.dtd.models.DFAContentModel;
+
+
+
+/**
+ * Class to construct an inferred relationship graph between multiple class loaders
+ * 
+ * Logic
+ * 
+ * We build a child / parent graph between all java class loaders
+ * by first determining the first order close relationship of class loaders whose list of
+ * inherited classes are fully satisfied by the defined list of another.
+ * 
+ * Remaining classes are joined based on the child classes inheritance being fully satisfied
by
+ * another class loaders cached list
+ *
+ */
+public class JavaClassLoaderHierarchyBuilder {
+
+	 
+	public  JavaClassLoaderHierarchy buildHierarchy(List<JavaClassLoader> runtime) throws
DiagnosticException {
+	
+		JavaClassLoaderHierarchy loaderMap=new JavaClassLoaderHierarchy();
+		
+		
+		
+		
+		
+		// visit all class loaders and create the loader map
+		
+		for(JavaClassLoader loader:runtime) {
+				loaderMap.add(new Loader(loader));
+		}
+		
+		// create initial hard links where all of child inheritence comes from parents defined
set
+		//System.out.println("\nFirst Parents");
+		for(Loader parent:loaderMap.getAllLoaders()) {
+			
+			for(Loader child:loaderMap.getAllLoaders()) {
+				if(child==parent) continue;
+				//System.out.println("\nchecking p="+parent+" child="+child);
+				if(parent.isFullParentOf(child)) {
+					parent.addChild(child);
+				}
+				
+			}
+		}
+		
+		//System.out.println("\n2nd Parents");
+		// step two - for all non parented class loaders which inherit - find a parent who cached
list contains all of the inherited and none of the childs defines
+			for(Loader parent:loaderMap.getAllLoaders()) {
+			
+			
+			for(Loader child:loaderMap.getAllLoaders()) {
+				if(child==parent) continue;
+				if(child.hasParents()) continue;
+				if(child.inheritedClasses.size()==0) continue;
+				
+				if(parent.is2ndParentOf(child)) {
+					parent.addChild(child);
+				}
+				
+			}
+		}
+		
+		 
+		return loaderMap;
+		
+	}
+
+	
+
+	public class Loader {
+
+		private JavaClassLoader definingLoader=null;
+		private Set<JavaClass> inheritedClasses=new HashSet<JavaClass>();
+		private Set<Loader> kids=new HashSet<Loader>();
+		private Set<Loader> parents=new HashSet<Loader>();
+		
+		
+		public String toString() {
+			return "LD"+definingLoader.toString()+",I"+inheritedClasses;
+		}
+		public boolean is2ndParentOf(Loader child) {
+			
+			// is childs inheritent coverd by your cache?
+			if(definingLoader.getCachedClasses().containsAll(child.inheritedClasses)==false) return
false;
+			// do you have any inherited classes that the child defines?
+			List<JavaClass> defined=definingLoader.getDefinedClasses();
+			
+			for(JavaClass clazz: child.definingLoader.getDefinedClasses()) {
+				if(defined.contains(clazz)) return false;
+			}
+			return true;
+		}
+		public boolean isFullParentOf(Loader child) {
+			
+			Set<JavaClass> childInheritedSet=child.inheritedClasses;
+			if(childInheritedSet.isEmpty()) return false;
+			
+			// you are a full parent of a class loader if all
+			// of its inheritance are provided by your defined list
+			
+			List<JavaClass> myDefinedList=definingLoader.getDefinedClasses();
+			if(myDefinedList.isEmpty()) return false;
+			
+			
+			return myDefinedList.containsAll(childInheritedSet);
+			
+		}
+		public Loader(JavaClassLoader definingloader) {
+			this.definingLoader=definingloader;
+			inheritedClasses.addAll(definingloader.getCachedClasses());
+			if(inheritedClasses.isEmpty()==false) 	inheritedClasses.removeAll(definingloader.getDefinedClasses());
+		}
+
+		
+
+		
+		public Set<Loader> getParents() {
+			
+			return parents;
+		}
+
+		public boolean hasParents() {
+			return parents.isEmpty()==false;
+		}
+		public void addChild(Loader child) {
+			//System.out.println("making "+child+" child of "+this);
+			kids.add(child);
+			child.parents.add(this);
+		}
+
+		public boolean hasChildren() {
+			return kids.isEmpty()==false;
+		}
+		public JavaClassLoader getDefiningLoader() {
+			return definingLoader;
+		}
+		
+		
+	}
+	
+}

Added: incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/kato/javaview/TestJavaClassLoaderHierarchyBuilder.java
URL: http://svn.apache.org/viewvc/incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/kato/javaview/TestJavaClassLoaderHierarchyBuilder.java?rev=818876&view=auto
==============================================================================
--- incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/kato/javaview/TestJavaClassLoaderHierarchyBuilder.java
(added)
+++ incubator/kato/branches/experimental/kato.javaview/src/test/java/test/apache/kato/javaview/TestJavaClassLoaderHierarchyBuilder.java
Fri Sep 25 15:16:54 2009
@@ -0,0 +1,328 @@
+package test.apache.kato.javaview;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DiagnosticException;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
+
+import junit.framework.TestCase;
+
+import org.apache.kato.javaview.JavaClassLoaderHierarchy;
+import org.apache.kato.javaview.JavaClassLoaderHierarchyBuilder;
+import org.apache.kato.javaview.JavaClassLoaderHierarchyBuilder.Loader;
+
+
+public class TestJavaClassLoaderHierarchyBuilder extends TestCase {
+
+	 private final class MockJavaClass implements JavaClass {
+
+		 	private int id=0;
+		 	public MockJavaClass(int i) {
+			this.id=i;
+		}
+			public String toString() {
+		 		return ""+id;
+		 	}
+			@Override
+			public JavaClassLoader getClassLoader() throws CorruptDataException {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public JavaClass getComponentType() throws CorruptDataException {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public List<JavaObject> getConstantPoolReferences() {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public List<JavaField> getDeclaredFields() {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public List<JavaMethod> getDeclaredMethods() {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public ImagePointer getID() {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public List<String> getInterfaces() {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public int getModifiers() throws CorruptDataException {
+				// TODO Auto-generated method stub
+				return 0;
+			}
+
+			@Override
+			public String getName() throws CorruptDataException {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public JavaObject getObject() throws CorruptDataException {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public List<JavaReference> getReferences() {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public JavaClass getSuperclass() throws CorruptDataException {
+				// TODO Auto-generated method stub
+				return null;
+			}
+
+			@Override
+			public boolean isArray() throws CorruptDataException {
+				// TODO Auto-generated method stub
+				return false;
+			}
+
+		}
+
+	
+	private final class MockJavaClassLoader implements JavaClassLoader {
+		
+		private List<JavaClass> defined=null;
+		private List<JavaClass> cached=null;
+		private int id=0;
+		public MockJavaClassLoader(int id,List<JavaClass> defined, List<JavaClass>
inherited) {
+			this.defined=new LinkedList<JavaClass>();
+			this.defined.addAll(defined);
+			this.cached=new LinkedList<JavaClass>();
+			this.cached.addAll(defined);
+			this.cached.addAll(inherited);
+			this.id=id;
+		}
+		public MockJavaClassLoader(MockJavaClass definedClass, int id,MockJavaClass ... inhertiedClass)
{
+			this.defined=new LinkedList<JavaClass>();
+			if(definedClass!=null) this.defined.add(definedClass);
+			this.cached=new LinkedList<JavaClass>();
+			if(definedClass!=null) this.cached.add(definedClass);
+			if(inhertiedClass!=null) {
+				for(MockJavaClass m:inhertiedClass) {
+					this.cached.add(m);
+				}
+			}
+			this.id=id;
+		}
+		@Override
+		public JavaClass findClass(String name) throws CorruptDataException {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public List<JavaClass> getCachedClasses() {
+			
+			return cached;
+		}
+
+		public String toString() {
+			return "CL:"+id+":D"+defined+",C"+cached;
+		}
+		@Override
+		public List<JavaClass> getDefinedClasses() {
+
+			return defined;
+		}
+
+		@Override
+		public JavaObject getObject() throws CorruptDataException {
+			// TODO Auto-generated method stub
+			return null;
+		}
+	}
+
+	public void testConstructor() {
+		JavaClassLoaderHierarchyBuilder builder=new JavaClassLoaderHierarchyBuilder();
+	}
+	
+	public void testOneEmptyClassLoader() throws DiagnosticException {
+
+		List<JavaClass> d=new LinkedList<JavaClass>();
+		List<JavaClass> i=new LinkedList<JavaClass>();
+		JavaClassLoader l1=new MockJavaClassLoader(1,d, i);
+		List<JavaClassLoader> list=new LinkedList<JavaClassLoader>();
+		list.add(l1);
+		JavaClassLoaderHierarchyBuilder builder=new JavaClassLoaderHierarchyBuilder();
+		JavaClassLoaderHierarchy h=builder.buildHierarchy(list);
+		assertNotNull(h);
+		
+	}
+	public void testTwoEmptyClassLoaders() throws DiagnosticException {
+
+		List<JavaClass> d=new LinkedList<JavaClass>();
+		List<JavaClass> i=new LinkedList<JavaClass>();
+		JavaClassLoader l1=new MockJavaClassLoader(1,d, i);
+		JavaClassLoader l2=new MockJavaClassLoader(2,d,i); 
+		List<JavaClassLoader> list=new LinkedList<JavaClassLoader>();
+		list.add(l1);
+		list.add(l2);
+		JavaClassLoaderHierarchyBuilder builder=new JavaClassLoaderHierarchyBuilder();
+		JavaClassLoaderHierarchy h=builder.buildHierarchy(list);
+		assertEquals(2,h.size());
+		
+	}
+	
+	public void testSimpleRelationship() throws DiagnosticException {
+
+		MockJavaClass c1=new MockJavaClass(1);
+		
+		// defining class loader
+		JavaClassLoader l1=new MockJavaClassLoader(c1,1,null);
+		// inheriting class loader
+		JavaClassLoader l2=new MockJavaClassLoader(null,2, c1);
+		
+		
+		List<JavaClassLoader> list=new LinkedList<JavaClassLoader>();
+		list.add(l1);
+		list.add(l2);
+		JavaClassLoaderHierarchyBuilder builder=new JavaClassLoaderHierarchyBuilder();
+		
+		JavaClassLoaderHierarchy h=builder.buildHierarchy(list);
+		
+		List<Loader> loaders=h.getLeafLoaders();
+		
+		assertEquals(1,loaders.size());
+		assertEquals(l2,loaders.get(0).getDefiningLoader());
+		
+		
+	}
+	public void testThreeWayRelationship() throws DiagnosticException {
+
+		MockJavaClass c1=new MockJavaClass(1);
+		MockJavaClass c2=new MockJavaClass(2);
+		MockJavaClass c3=new MockJavaClass(3);
+		
+		// defining class loader for C1 and C2
+		List<JavaClass> d1=new LinkedList<JavaClass>();
+		List<JavaClass> i1=new LinkedList<JavaClass>();
+		d1.add(c1);
+		d1.add(c2);
+		JavaClassLoader l1=new MockJavaClassLoader(1,d1, i1);
+		
+		// inheriting and defining class loader 
+		List<JavaClass> d2=new LinkedList<JavaClass>();
+		List<JavaClass> i2=new LinkedList<JavaClass>();
+		i2.add(c1);
+		i2.add(c2);
+		d2.add(c3);
+		JavaClassLoader l2=new MockJavaClassLoader(2,d2, i2);
+		
+		// inheriting class loader 
+		List<JavaClass> d3=new LinkedList<JavaClass>();
+		List<JavaClass> i3=new LinkedList<JavaClass>();
+		i3.add(c1);
+		i3.add(c2);
+		i3.add(c3);
+		JavaClassLoader l3=new MockJavaClassLoader(3,d3,i3);
+		
+		List<JavaClassLoader> list=new LinkedList<JavaClassLoader>();
+		list.add(l1);
+		list.add(l2);
+		list.add(l3);
+		
+		JavaClassLoaderHierarchyBuilder builder=new JavaClassLoaderHierarchyBuilder();
+		
+		JavaClassLoaderHierarchy h=builder.buildHierarchy(list);
+		
+		List<Loader> loaders=h.getLeafLoaders();
+		
+		assertEquals(1,loaders.size());
+		
+		
+		
+	}
+	
+	public void testSimpleTreeLeafNodesCount() throws DiagnosticException {
+		
+		JavaClassLoaderHierarchy h = buildSimpleTreeScenerio();
+		
+		List<Loader> loaders=h.getLeafLoaders();
+		
+		assertEquals(3,loaders.size());
+		
+	}
+public void testSimpleTreeLeafNodeEntries() throws DiagnosticException {
+		
+		JavaClassLoaderHierarchy h = buildSimpleTreeScenerio();
+		
+		List<Loader> loaders=h.getLeafLoaders();
+		
+		Loader l1=loaders.get(0);
+		MockJavaClassLoader cl1=(MockJavaClassLoader) l1.getDefiningLoader();
+		assertEquals(3,cl1.id);
+		
+		Loader l2=loaders.get(1);
+		MockJavaClassLoader cl2=(MockJavaClassLoader) l2.getDefiningLoader();
+		assertEquals(5,cl2.id);
+		
+		Loader l3=loaders.get(2);
+		MockJavaClassLoader cl3=(MockJavaClassLoader) l3.getDefiningLoader();
+		assertEquals(6,cl3.id);
+		
+		
+	}
+
+	private JavaClassLoaderHierarchy buildSimpleTreeScenerio()
+			throws DiagnosticException {
+		MockJavaClass c1=new MockJavaClass(1);
+		MockJavaClass c2=new MockJavaClass(2);
+		MockJavaClass c3=new MockJavaClass(3);
+		MockJavaClass c4=new MockJavaClass(4);
+		MockJavaClass c5=new MockJavaClass(5);
+		MockJavaClass c6=new MockJavaClass(6);
+		
+		MockJavaClassLoader l1=new MockJavaClassLoader(c1,1,null);
+		MockJavaClassLoader l2=new MockJavaClassLoader(c2,2,c1);
+		MockJavaClassLoader l3=new MockJavaClassLoader(c3,3,c1,c2);
+		MockJavaClassLoader l4=new MockJavaClassLoader(c4,4,c1);
+		MockJavaClassLoader l5=new MockJavaClassLoader(c5,5,c1,c4);
+		MockJavaClassLoader l6=new MockJavaClassLoader(c6,6,c4);
+		
+		List<JavaClassLoader> list=new LinkedList<JavaClassLoader>();
+		list.add(l1);
+		list.add(l2);
+		list.add(l3);
+		list.add(l4);
+		list.add(l5);
+		list.add(l6);
+		
+		JavaClassLoaderHierarchyBuilder builder=new JavaClassLoaderHierarchyBuilder();
+		
+		JavaClassLoaderHierarchy h=builder.buildHierarchy(list);
+		return h;
+	}
+}



Mime
View raw message