incubator-kitty-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msa...@apache.org
Subject svn commit: r1146812 - in /incubator/kitty/trunk/src: main/java/org/apache/kitty/client/Client.groovy main/java/org/apache/kitty/client/rmi/RMIClient.groovy test/java/org/apache/kitty/client/ClientTest.groovy
Date Thu, 14 Jul 2011 17:25:37 GMT
Author: msacks
Date: Thu Jul 14 17:25:36 2011
New Revision: 1146812

URL: http://svn.apache.org/viewvc?rev=1146812&view=rev
Log:
Fixes ls invalid character issue https://issues.apache.org/jira/browse/KITTY-16

Removed:
    incubator/kitty/trunk/src/main/java/org/apache/kitty/client/rmi/RMIClient.groovy
Modified:
    incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy
    incubator/kitty/trunk/src/test/java/org/apache/kitty/client/ClientTest.groovy

Modified: incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy?rev=1146812&r1=1146811&r2=1146812&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy (original)
+++ incubator/kitty/trunk/src/main/java/org/apache/kitty/client/Client.groovy Thu Jul 14 17:25:36
2011
@@ -22,7 +22,6 @@ import java.io.IOException
 
 import javax.management.Attribute
 import javax.management.ObjectName
-import javax.management.remote.JMXConnector
 import javax.management.remote.JMXConnectorFactory
 import javax.management.remote.JMXServiceURL
 
@@ -57,24 +56,24 @@ class Client {
 	public connect(def _host, def _port) {
 		connect(_host, _port, null, null)
 	}
-		
+
 	public connect(def _host, def _port, def _username, def _password) {
 
 		def serviceURL
 		def properties = new HashMap()
-		
+
 		if (remote != null) {
 			disconnect()
 		}
-		
+
 		if ((_username != null) && (_password != null)) {
 			properties.put JMXConnector.CREDENTIALS, [_username, _password] as String[]
 		}
 
 		try {
-			serviceURL = "service:jmx:rmi:///jndi/rmi://$_host:$_port/jmxrmi"			
+			serviceURL = "service:jmx:rmi:///jndi/rmi://$_host:$_port/jmxrmi"
 			this.url = new JMXServiceURL(serviceURL)
-			
+
 			// TODO add auth & credentials to properties
 			this.connector = JMXConnectorFactory.connect(this.url, properties)
 			this.remote = this.connector.getMBeanServerConnection()
@@ -142,7 +141,6 @@ class Client {
 				if (it.equals(_domain)) {
 					this.domain = _domain
 					this.mBeansPath = []
-                    println "The domain is set to $domain"
 					return
 				}
 			}
@@ -157,7 +155,7 @@ class Client {
 	 * @return
 	 */
 	public ls() {
-		
+
 		if (!this.remote) {
 			println "No remote is set!"
 			return
@@ -171,10 +169,9 @@ class Client {
 		if (this.remote) {
 			if (this.domain) {
 				def objectName = this.domain + ":"
-				
 				def objectName2
-				if (objectName.length() > 0) {
-					objectName += ",".concat(this.mBeansPath.join())  // make sure mBeansPath is a list,
otherwise remove the .join() command
+				if (mBeansPath.size() > 0) {
+					objectName += this.mBeansPath.join(',')  // make sure mBeansPath is a list, otherwise
remove the .join() command
 					objectName2 = objectName + ","
 				}
 				else {
@@ -183,18 +180,20 @@ class Client {
 
 				println "objectName: " + objectName
 				println "objectName2: " + objectName2
-				
+
 				def pool = new ObjectName(objectName2 + "*")
-				def paths = {}
+				def paths = [:]
 				println objectName
 				println "-----"
+
+                // List the MBeans names
 				def qNames = this.remote.queryNames(pool, null)
 				try {
 					qNames.each { mbean ->
 						def p = mbean.toString().split(objectName2)[1].split(',')[0]
 						paths[p] = p
 					}
-					paths.each { p ->  println  "M " + p }
+					paths.each { p, dummy ->  println  "M " + p }
 				}
 				catch(Exception e) {
 					throw new DomainIsNoneException()
@@ -231,7 +230,7 @@ class Client {
 					}
 				}
 				catch(Exception e) {
-					//
+                    // ObjectName not found
 				}
 
 				try {
@@ -245,7 +244,7 @@ class Client {
 					}
 				}
 				catch(Exception e) {
-					throw new DomainIsNoneException()
+                    // ObjectName not found
 				}
 			}
 		}
@@ -259,13 +258,13 @@ class Client {
 		if (this.remote) {
 			if (this.domain) {
 				if (path == "..") {
-					if (this.mBeansPath.size()) {
+					if (this.mBeansPath.length()) {
 						this.mBeansPath.pop()
 					}
 				}
 				else {
 					for (p in path.split(',')) {
-						this.mBeansPath.append(p)
+						this.mBeansPath << p
 					}
 				}
 			}
@@ -342,7 +341,7 @@ class Client {
 				def objectName = this.domain + ":"
 				def attr
 
-				if (this.mBeansPath.size() > 0) {
+				if (this.mBeansPath.length() > 0) {
 					objectName = objectName + ','.concat(this.mBeansPath.join())
 				}
 				try {
@@ -386,7 +385,7 @@ class Client {
 		if (this.remote) {
 			if (this.domain) {
 				def objectName = this.domain + ":"
-				if (this.mBeansPath.size()) {
+				if (this.mBeansPath.length()) {
 					objectName = objectName + ','.concat(this.mBeansPath.join())
 				}
 				try{
@@ -423,7 +422,7 @@ class Client {
 	public pwd() {
 		def name
 		if (this.domain) {
-			name = this.domain + ":" + ",".concat(this.mBeansPath.join())  // may need to change this
+			name = this.domain + ":" + this.mBeansPath.join(',')
 		}
 
 		return name

Modified: incubator/kitty/trunk/src/test/java/org/apache/kitty/client/ClientTest.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/test/java/org/apache/kitty/client/ClientTest.groovy?rev=1146812&r1=1146811&r2=1146812&view=diff
==============================================================================
--- incubator/kitty/trunk/src/test/java/org/apache/kitty/client/ClientTest.groovy (original)
+++ incubator/kitty/trunk/src/test/java/org/apache/kitty/client/ClientTest.groovy Thu Jul
14 17:25:36 2011
@@ -20,7 +20,10 @@ package org.apache.kitty.client;
 import static org.junit.Assert.*;
 import org.apache.kitty.client.Client
 import javax.management.MBeanServerConnection
-import org.junit.Test;
+import org.junit.Test
+import groovy.mock.interceptor.MockFor
+import javax.management.ObjectName
+import org.apache.kitty.exceptions.DomainIsNoneException;
 
 class ClientTest {
 
@@ -55,4 +58,40 @@ class ClientTest {
 
         assert client.domain == 'a'
     }
+
+    @Test
+    public void should_list_names_for_domain() throws Exception {
+       Client client = new Client()
+
+       // Mock the remote connection
+       def mockForRemote = new MockFor(MBeanServerConnection)
+       mockForRemote.ignore.asBoolean {
+            true
+       }
+       mockForRemote.ignore.getDomains {
+           ['a_domain']
+       }
+
+       // Prepare the names list
+       mockForRemote.ignore.queryNames { a,b ->
+           def set = new HashSet()
+           set.add(new ObjectName("a_domain", "test1", "1"))
+           set.add(new ObjectName("a_domain", "test2", "2"))
+           set.add(new ObjectName("a_domain", "test3", "3"))
+           return set
+       }
+
+       def theProxyInstance = mockForRemote.proxyInstance()
+
+       // Verify "ls" is working
+       mockForRemote.use {
+           client.remote = theProxyInstance
+           client.setDomain('a_domain')
+           try {
+             client.ls()
+           } catch(DomainIsNoneException dine) {
+             fail("DomainIsNoneException thrown")
+           }
+       }
+    }
 }



Mime
View raw message