perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6444 - in trunk/perfsonar-base/messaging/src: main/java/net/geant/perfsonar/messaging test/java/net/geant/perfsonar/messaging
Subject: perfsonar development work
List archive
[pS-dev] [GEANT/SA2/ps-java-services] r6444 - in trunk/perfsonar-base/messaging/src: main/java/net/geant/perfsonar/messaging test/java/net/geant/perfsonar/messaging
Chronological Thread
- From:
- To:
- Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6444 - in trunk/perfsonar-base/messaging/src: main/java/net/geant/perfsonar/messaging test/java/net/geant/perfsonar/messaging
- Date: Fri, 5 Jul 2013 16:50:44 +0100 (BST)
- Authentication-results: sfpop-ironport05.merit.edu; dkim=neutral (message not signed) header.i=none
Author: psnc.pietrzak
Date: 2013-07-05 16:50:43 +0100 (Fri, 05 Jul 2013)
New Revision: 6444
Added:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java
Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodThrowsExceptionTest.java
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java
Log:
debugging improvements and bug fixes.
Added:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -0,0 +1,71 @@
+package net.geant.perfsonar.messaging;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Aggregate exception for exceptions that are thrown when deserializing
+ * objects.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
+public class DeserializationException extends Exception implements
Iterable<Throwable> {
+ private static final long serialVersionUID = 2627705969628394226L;
+ private List<Throwable> exceptions = new ArrayList<Throwable>();
+
+ public DeserializationException(List<Throwable> exceptions) {
+ super(toString(exceptions));
+ this.exceptions.addAll(exceptions);
+ }
+
+ public DeserializationException(Throwable... ex) {
+ super(toString(ex));
+ for (Throwable t : ex) {
+ exceptions.add(t);
+ }
+ }
+
+ private static String toString(Throwable[] ex) {
+ final StringBuffer text = new StringBuffer();
+ boolean firstTime = true;
+ for (Throwable t : ex) {
+ if (firstTime) {
+ firstTime = false;
+ } else {
+ text.append("\n");
+ }
+ toString(text, t);
+ }
+ return text.toString();
+ }
+
+ private static void toString(StringBuffer text, Throwable t) {
+ text.append(t.getMessage());
+ text.append("\n");
+ StringWriter out = new StringWriter();
+ t.printStackTrace(new PrintWriter(out));
+ text.append(out.toString());
+ }
+
+ private static String toString(List<Throwable> exceptions) {
+ final StringBuffer text = new StringBuffer();
+ boolean firstTime = true;
+ for (Throwable ex : exceptions) {
+ if (firstTime) {
+ firstTime = false;
+ } else {
+ text.append("\n");
+ }
+ toString(text, ex);
+ }
+ return text.toString();
+ }
+
+ @Override
+ public Iterator<Throwable> iterator() {
+ return exceptions.iterator();
+ }
+}
Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -1,36 +1,34 @@
package net.geant.perfsonar.messaging;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import net.geant.perfsonar.PerfSONARException;
+import javax.xml.xpath.XPathException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import jlibs.xml.sax.dog.NodeItem;
import jlibs.xml.sax.dog.expr.Expression;
import jlibs.xml.sax.dog.expr.InstantEvaluationListener;
/**
- * Collects objects created from XPath events and stores them in memory.
+ * Creates objects from XPath events and stores them in memory.
*
* @author <a
href="mailto:">Blazej
Pietrzak</a>
*/
public class InMemoryInstancesListener extends InstantEvaluationListener {
- protected Logger logger = LoggerFactory.getLogger(getClass());
- private int exceptionsCount = 0;
-
- // Hash containing objects instances created when parsing the XML stream
- // FIXME: do we need ConcurrentHashMap or a regular Hashmap would be ok?
private final Map<Class<?>, List<Object>> instances = new
ConcurrentHashMap<Class<?>, List<Object>>();
+ private final List<Throwable> exceptions = new ArrayList<Throwable>();
@Override
public void onNodeHit(Expression expression, NodeItem nodeItem) {
final Method method =
XPathDeserializer.getXPathMethod(expression.getXPath());
- executeMethod(method, nodeItem.value, expression);
+ if (method == null) {
+ exceptions.add(new XPathException("No method for XPath
expression: " + expression.getXPath()));
+ return;
+ }
+ executeMethod(method, nodeItem.value, instances, expression);
}
@Override
@@ -41,12 +39,13 @@
@Override
public void onResult(Expression expression, Object result) {
final Method method =
XPathDeserializer.getXPathMethod(expression.getXPath());
- executeMethod(method, (String) result.toString(), expression);
+ if (method == null) {
+ exceptions.add(new XPathException("No method for XPath
expression: " + expression.getXPath()));
+ return;
+ }
+ executeMethod(method, (String) result.toString(), instances,
expression);
}
- /**
- * Return all the objects created
- */
public List<?> getObjects() {
final List<Object> result = new ArrayList<Object>();
for (List<Object> temp : instances.values()) {
@@ -55,24 +54,20 @@
return result;
}
- /**
- * Wrapper around Method.execute
- */
- private void executeMethod(final Method method, String arg, Expression
expr) {
- if (arg == null) {
- exceptionsCount++;
- logger.warn("XPath({}) returned null, no arg to pass to method
[{}].", expr.getXPath(), method.toString());
+ private void executeMethod(final Method method, String value, final
Map<Class<?>, List<Object>> instances,
+ Expression expr) {
+ if (value == null) {
+ exceptions.add(new XPathException("XPath(" + expr.getXPath() +
") returned null."));
+ return;
}
try {
- method.execute(arg, instances, logger);
- } catch (PerfSONARException e) {
- exceptionsCount++;
- logger.warn("Error when trying to execute method({}) from
XPath({}) on {}", method.toString(), expr.getXPath(), arg);
+ method.execute(value, instances);
+ } catch (Throwable ex) {
+ exceptions.add(ex);
}
}
- public int getExceptionsCount() {
- return exceptionsCount;
+ public List<Throwable> getExceptions() {
+ return Collections.unmodifiableList(exceptions);
}
-
}
Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -6,10 +6,6 @@
import java.util.List;
import java.util.Map;
-import org.slf4j.Logger;
-
-import net.geant.perfsonar.PerfSONARException;
-
/**
* This class uses reflection to instantiate object and execute methods
* whenever a given XPath is evaluated successfully.
@@ -85,52 +81,34 @@
* parameter type is not a string)
* @param instances
* list of instances of method's declaring class (execution
may add new object to this list)
- * @param logger
- * the logger to use if anything needs to be written to log
*/
- public synchronized void execute(String arg, Map<Class<?>, List<Object>>
instances, Logger logger) throws PerfSONARException {
+ public synchronized void execute(String arg, Map<Class<?>, List<Object>>
instances) throws Exception {
final Object instance;
- try {
- if (object != null) {
- // If object is assigned, we use it
- instance = object;
- } else if (instances.get(method.getDeclaringClass()) != null
- && instances.get(method.getDeclaringClass()).size() >
count) {
- // If instances contains more objects than have been
executed, we return the next object to be used
- instance =
instances.get(method.getDeclaringClass()).get(count);
- } else {
- // Otherwise, we create a new instance of the method's
declaring class FIXME: Why???
- try {
- instance = method.getDeclaringClass().newInstance();
- } catch (InstantiationException e) {
- throw new PerfSONARException(logger, "Cannot instanciate
object of method [" + method.toString() + "].", e);
- } catch (IllegalAccessException e) {
- throw new PerfSONARException(logger, "Illegal access to
class of method [" + method.toString() + "]", e);
- }
- }
+
+ if (object != null) {
+ // If object is assigned, we use it
+ instance = object;
+ } else if (instances.get(method.getDeclaringClass()) != null
+ && instances.get(method.getDeclaringClass()).size() > count)
{
+ // If instances contains more objects than have been executed,
we return the next object to be used
+ instance = instances.get(method.getDeclaringClass()).get(count);
+ } else {
+ // Otherwise, we create a new instance of the method's declaring
class FIXME: Why???
+ instance = method.getDeclaringClass().newInstance();
+ }
- if (getParameterType().equals(String.class)) {
- // If the method parameter type is a String it means the arg
we've been given should
- // be fed as such to the invoked method
- logger.trace("Trying to invoke {} for {}", method, instance);
- method.invoke(instance, arg);
- } else {
- // Otherwise, the arg is just the name of the object
reference
- // We need to get the actual object before invoking the
method
- final Object reference = getReference(instances, arg);
- if (reference == null) {
- logger.warn("Reference to instance object not found,
cannot invoke.");
- return;
- }
- logger.trace("Trying to invoke {} for {}", method, instance);
- method.invoke(instance, reference);
+ if (getParameterType().equals(String.class)) {
+ // If the method parameter type is a String it means the arg
we've been given should
+ // be fed as such to the invoked method
+ method.invoke(instance, arg);
+ } else {
+ // Otherwise, the arg is just the name of the object reference
+ // We need to get the actual object before invoking the method
+ final Object reference = getReference(instances, arg);
+ if (reference == null) {
+ return;
}
- } catch (IllegalAccessException e) {
- throw new PerfSONARException(logger, "Illegal access to method:
" + method.toString(), e);
- } catch (IllegalArgumentException e) {
- throw new PerfSONARException(logger, "Illegal arguments passed
to method: " + method.toString(), e);
- } catch (InvocationTargetException e) {
- throw new PerfSONARException(logger, "Error when invoking
method: " + method.toString(), (Exception) e.getTargetException());
+ method.invoke(instance, reference);
}
// After method has been invoked, we store it in the instances Hash
Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -13,13 +13,10 @@
import jlibs.xml.sax.dog.XMLDog;
import jlibs.xml.sax.dog.sniff.DOMBuilder;
import jlibs.xml.sax.dog.sniff.Event;
-import net.geant.perfsonar.PerfSONARException;
import net.sf.cglib.proxy.Enhancer;
import org.jaxen.saxpath.SAXPathException;
import org.jaxen.saxpath.XPathSyntaxException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
/**
@@ -96,8 +93,6 @@
* @author <a
href="mailto:">Blazej
Pietrzak</a>
*/
public class XPathDeserializer {
- protected Logger logger = LoggerFactory.getLogger(getClass());
-
private static final DefaultNamespaceContext CONTEXT = new
DefaultNamespaceContext();
private static final Map<String, Method> XPATHS = new
ConcurrentHashMap<String, Method>();
private static final Map<Class<?>, java.lang.reflect.Method> IDENTIFIERS
= new ConcurrentHashMap<Class<?>, java.lang.reflect.Method>();
@@ -131,7 +126,6 @@
XPATHS.put(xpath, new Method(method,
IDENTIFIERS.get(method.getParameterTypes()[0]), object));
}
- //FIXME: why is this one synchronized and other methods not?
public static synchronized void putXPath(String xpath,
java.lang.reflect.Method method) {
XPATHS.put(xpath, new Method(method,
IDENTIFIERS.get(method.getParameterTypes()[0])));
}
@@ -159,60 +153,67 @@
public XPathDeserializer() {
}
+ public static String validate(String xpath) {
+ final XMLDog dog = new XMLDog(CONTEXT);
+ try {
+ dog.addXPath(xpath);
+ } catch (XPathSyntaxException ex) {
+ return "Invalid XPath: " + ex.getMultilineMessage();
+ } catch (SAXPathException ex) {
+ return "Invalid XPath: " + ex.getMessage();
+ }
+
+ return null;
+ }
+
/**
- * Deserializes objects from XML stream using streaming XPath
expressions.
+ * Deserializes objects from xml stream using streaming XPath
expressions.
*
- * @throws PerfSONARException
+ * @throws DeserializationException
+ * list of exceptions thrown while deserializing
*/
- public List<?> deserialize(InputSource reader) throws PerfSONARException
{
+ public List<?> deserialize(InputSource reader) throws
DeserializationException {
final XMLDog dog = new XMLDog(CONTEXT);
- int exceptions = 0;
-
- // First we add all XPaths we know about
- logger.trace("First we add all XPaths we know about.");
+ final List<Throwable> exceptions = new ArrayList<Throwable>();
for (Iterator<String> iter =
XPathDeserializer.getXPaths().iterator(); iter.hasNext();) {
try {
dog.addXPath(iter.next());
} catch (XPathSyntaxException ex) {
- exceptions++;
- logger.warn("Invalid XPath: {}", ex.getMultilineMessage());
+ exceptions.add(new XPathException("Invalid XPath: " +
ex.getMultilineMessage()));
} catch (SAXPathException ex) {
- exceptions++;
- logger.warn("Invalid XPath: {}", ex.getMessage());
+ exceptions.add(new XPathException("Invalid XPath: " +
ex.getMessage()));
}
}
- if (exceptions > 0) {
- throw new PerfSONARException(logger, "XPath errors (" +
exceptions + ") during deserialization, see warnings above.");
+ if (exceptions.size() > 0) {
+ throw new DeserializationException(exceptions);
}
- // Then setup the event listener to collect the objects created when
parsing
- final Event event = dog.createEvent(); // must be after all
expressions are added.
+ final Event event = dog.createEvent(); // must be after all
expressions
+ // are added.
event.setXMLBuilder(new DOMBuilder());
+
final InMemoryInstancesListener listener = new
InMemoryInstancesListener();
+
event.setListener(listener);
- // Parse the incoming XML stream
- logger.trace("Then we parse the incoming XML stream with XMLDog.");
try {
dog.sniff(event, reader, false/* useSTAX */);
} catch (XPathException ex) {
- throw new PerfSONARException(logger, "XPath error during parsing
of input.", ex);
+ throw new DeserializationException(ex);
} finally {
- final Iterator<Method> iter = XPATHS.values().iterator();
- while (iter.hasNext()) {
- Method method = iter.next();
+ final Iterator<Method> iter = XPATHS.values().iterator();
+ while (iter.hasNext()) {
+ Method method = iter.next();
method.resetCount();
}
}
- if (listener.getExceptionsCount() > 0) {
- throw new PerfSONARException(logger, "Multiple errors (" +
listener.getExceptionsCount() + ") when parsing the incoming stream.");
+ if (listener.getExceptions().size() > 0) {
+ throw new DeserializationException(listener.getExceptions());
}
- final List<?> objects = listener.getObjects();
- logger.trace("And finnaly we return the generated objects ({}).",
objects.size());
- return objects;
+ return listener.getObjects();
}
@SuppressWarnings("unchecked")
Modified:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -3,11 +3,16 @@
import static net.geant.perfsonar.messaging.XPathDeserializer.any;
import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.io.Reader;
import java.net.InetAddress;
+import java.util.Iterator;
+import javax.xml.xpath.XPathException;
+
import net.geant.perfsonar.PerfSONARException;
import net.geant.perfsonar.mp.sshtelnet.Command;
import net.geant.perfsonar.mp.sshtelnet.Router;
@@ -55,9 +60,11 @@
try {
deserializer.deserialize(new InputSource(reader));
fail("PerfSONARException was not thrown");
- } catch (PerfSONARException ex) {
- // TODO: Check that we actually got 2 warnings
- logger.warn("•• Invalid XPath test passed: exception correctly
thrown, we should have at least 2 warnings above.");
+ } catch (DeserializationException ex) {
+ Iterator<Throwable> iter = ex.iterator();
+ assertEquals(XPathException.class, iter.next().getClass());
+ assertEquals(XPathException.class,
iter.next().getClass());
+ assertFalse(iter.hasNext());
}
}
@@ -68,9 +75,11 @@
try {
deserializer.deserialize(new InputSource(reader));
- fail("PerfSONARException was not thrown");
- } catch (PerfSONARException ex) {
- logger.warn("•• Null XPath test passed: exception correctly
thrown, we should have at least 1 warning above.");
+ fail("DeserializationException was not thrown");
+ } catch (DeserializationException ex) {
+ final Iterator<Throwable> iter = ex.iterator();
+ assertEquals(XPathException.class,
iter.next().getClass());
+ assertFalse(iter.hasNext());
}
}
@@ -81,9 +90,11 @@
try {
deserializer.deserialize(new InputSource(reader));
- fail("PerfSONARException was not thrown");
- } catch (PerfSONARException ex) {
- logger.warn("•• Undeclared prefix test passed: exception
correctly thrown, we should have at least 1 warning above.");
+ fail("DeserializationException was not thrown");
+ } catch (DeserializationException ex) {
+ final Iterator<Throwable> iter = ex.iterator();
+ assertEquals(XPathException.class,
iter.next().getClass());
+ assertFalse(iter.hasNext());
}
}
}
Modified:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -75,9 +75,9 @@
* Executes the method and test the object is correctly
instanciated/reflected.
*/
@Test
- public void shouldReturnObject() throws PerfSONARException {
+ public void shouldReturnObject() throws Exception {
assertTrue(instances.isEmpty());
- method.execute(OBJECT_NEW_NAME, instances, logger);
+ method.execute(OBJECT_NEW_NAME, instances);
assertEquals(expectedObject, (Command)
instances.get(Command.class).get(0));
}
@@ -85,9 +85,9 @@
* Executes the method and check its effect on the object
*/
@Test
- public void shouldExecute() throws PerfSONARException,
NoSuchMethodException {
+ public void shouldExecute() throws Exception {
assertEquals(OBJECT_NAME, expectedObject.getName());
- method.execute(OBJECT_NEW_NAME, instances, logger);
+ method.execute(OBJECT_NEW_NAME, instances);
assertEquals(OBJECT_NEW_NAME, expectedObject.getName());
}
@@ -95,9 +95,9 @@
* Execute the method and test its counter.
*/
@Test
- public void shouldExecuteMethodOnce() throws PerfSONARException,
NoSuchMethodException {
+ public void shouldExecuteMethodOnce() throws Exception {
assertTrue(instances.isEmpty());
- method.execute(OBJECT_NEW_NAME, instances, logger);
+ method.execute(OBJECT_NEW_NAME, instances);
assertEquals(1, method.getCount());
assertFalse(instances.isEmpty());
}
@@ -106,10 +106,10 @@
* Executes the method twice, but object should only be instanciated
once.
*/
@Test
- public void shouldReturnOneObject() throws PerfSONARException {
+ public void shouldReturnOneObject() throws Exception {
assertTrue(instances.isEmpty());
- method.execute(OBJECT_NEW_NAME, instances, logger);
- method.execute(OBJECT_NAME, instances, logger);
+ method.execute(OBJECT_NEW_NAME, instances);
+ method.execute(OBJECT_NAME, instances);
assertEquals(2, method.getCount());
assertEquals(1, instances.size());
}
@@ -118,10 +118,10 @@
* Initialised without object
*/
@Test
- public void shouldExecuteAndInstanciate() throws NoSuchMethodException,
PerfSONARException {
+ public void shouldExecuteAndInstanciate() throws Exception {
final Method myMethod = new
Method(Command.class.getMethod("setName", String.class));
assertTrue(instances.isEmpty());
- myMethod.execute(OBJECT_NAME, instances, logger);
+ myMethod.execute(OBJECT_NAME, instances);
assertFalse(instances.isEmpty());
assertEquals(1, myMethod.getCount());
assertEquals(1, instances.size());
@@ -131,18 +131,18 @@
* Executes the method multiple times and play with the execution counter
*/
@Test
- public void testExecutionCounter() throws PerfSONARException,
NoSuchMethodException {
+ public void testExecutionCounter() throws Exception {
assertTrue(instances.isEmpty());
for (int i = 0; i < LOOP_COUNT; i++) {
- method.execute(OBJECT_NAME, instances, logger);
+ method.execute(OBJECT_NAME, instances);
}
assertEquals(1, instances.size());
assertEquals(LOOP_COUNT, method.getCount());
logger.debug("Method correctly executed {} times: {}", count.get(),
method.toString());
method.resetCount();
assertEquals(0, method.getCount());
- method.execute(OBJECT_NEW_NAME, instances, logger);
+ method.execute(OBJECT_NEW_NAME, instances);
assertEquals(1, method.getCount());
assertEquals(1, instances.size());
logger.debug("Method correctly executed and counter reseted: {}",
method.toString());
@@ -183,7 +183,7 @@
* Execute a non String parameter method along with 2 different Objects
in the instances map
*/
@Test
- public void shouldExecuteNotStringArg() throws NoSuchMethodException,
PerfSONARException {
+ public void shouldExecuteNotStringArg() throws Exception {
method = newCommandRouterMethod();
// We add a Router object it to the instances List
@@ -193,7 +193,7 @@
assertEquals(2, instances.size());
// We invoke the setRouter method on a non existing Router
- method.execute("a wrong id", instances, logger);
+ method.execute("a wrong id", instances);
logger.warn("• Partial test passed: a warning about instance not
found should have printed above");
// The instances Map still got 2 entries
assertEquals(2, instances.size());
@@ -207,7 +207,7 @@
assertEquals(new ArrayList<Object>(), ((Router)
instances.get(Router.class).get(0)).getCommands());
// We invoke the setRouter method on the myRouterId Router
- method.execute("myRouterId", instances, logger);
+ method.execute("myRouterId", instances);
// Instances size and content has not changed
assertEquals(2, instances.size());
assertEquals(1, instances.get(Command.class).size());
@@ -221,7 +221,7 @@
assertEquals("My Router Name", ((Router)
instances.get(Router.class).get(0)).getName());
// If we execute once more, the instances shouldn't change
- method.execute("myRouterId", instances, logger);
+ method.execute("myRouterId", instances);
assertEquals(2, instances.size());
// FIXME: or should it? Why do I get 2 instances of the Command
class now?
// assertEquals(1, instances.get(Command.class).size());
@@ -236,7 +236,7 @@
* Call execute with existing objects in the instances Map
*/
@Test
- public void shouldExecuteOnObjects() throws PerfSONARException,
NoSuchMethodException {
+ public void shouldExecuteOnObjects() throws Exception {
final Method myMethod = new
Method(Command.class.getMethod("setName", String.class));
anObject = new Command();
anObject.setName("First command");
@@ -252,22 +252,22 @@
instances.put(Command.class, aListOfObjects);
assertEquals(1, instances.size());
- myMethod.execute(OBJECT_NEW_NAME, instances, logger);
+ myMethod.execute(OBJECT_NEW_NAME, instances);
assertEquals(1, myMethod.getCount());
assertEquals(3, aListOfObjects.size());
assertEquals(1, instances.size());
- myMethod.execute(OBJECT_NAME, instances, logger);
+ myMethod.execute(OBJECT_NAME, instances);
assertEquals(2, myMethod.getCount());
assertEquals(3, aListOfObjects.size());
assertEquals(1, instances.size());
- myMethod.execute(OBJECT_NEW_NAME, instances, logger);
+ myMethod.execute(OBJECT_NEW_NAME, instances);
assertEquals(3, myMethod.getCount());
assertEquals(3, aListOfObjects.size());
assertEquals(1, instances.size());
- myMethod.execute(OBJECT_NAME, instances, logger);
+ myMethod.execute(OBJECT_NAME, instances);
assertEquals(4, myMethod.getCount());
assertEquals(4, aListOfObjects.size());
assertEquals(1, instances.size());
@@ -290,12 +290,12 @@
int last = method.getCount();
try {
for (int i = 0; i < LOOP_COUNT; i++) {
- method.execute(OBJECT_NEW_NAME, instances,
logger);
+ method.execute(OBJECT_NEW_NAME, instances);
final int current = method.getCount();
assertTrue(current > last);
last = current;
}
- } catch (PerfSONARException e) {
+ } catch (Exception e) {
logger.error("Error when executing {}",
method.toString());
}
@@ -347,8 +347,8 @@
// assertEquals(1,
instances.get(Command.class).size());
try {
- method.execute(currentId, instances, logger);
- } catch (PerfSONARException e) {
+ method.execute(currentId, instances);
+ } catch (Exception e) {
logger.error("Error when executing {} {}",
method.toString(), currentId);
}
}
Modified:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -34,7 +34,7 @@
private final Map<Class<?>, List<Object>> expected = new
Hashtable<Class<?>, List<Object>>();
@Before
- public void givenMethods() throws PerfSONARException,
NoSuchMethodException {
+ public void givenMethods() throws Exception {
new Command();
eventTypeMethod = createCommandMethod("setEventType", String.class);
commandNameMethod = createCommandMethod("setName", String.class);
@@ -77,20 +77,20 @@
return new Method(Command.class.getMethod(methodName, params),
Command.class.getMethod("getId"));
}
- private void whenExecutingMethods(final Map<Class<?>, List<Object>>
instances) throws PerfSONARException {
+ private void whenExecutingMethods(final Map<Class<?>, List<Object>>
instances) throws Exception {
// We call router.setId("router2");
- routerIdMethod.execute("router2", instances, logger);
+ routerIdMethod.execute("router2", instances);
// We call router.setName("router");
- routerNameMethod.execute("router", instances, logger);
+ routerNameMethod.execute("router", instances);
// We call setCurrentRouter(getReference("router2"));
- currentRouterMethod.execute("router2", instances, logger);
+ currentRouterMethod.execute("router2", instances);
// We call command1.setEventType("testing1");
- eventTypeMethod.execute("testing1", instances, logger);
+ eventTypeMethod.execute("testing1", instances);
// We call command1.setName("test1");
- commandNameMethod.execute("test1", instances, logger);
+ commandNameMethod.execute("test1", instances);
// We call command2.setName("test2");
- commandNameMethod.execute("test2", instances, logger);
+ commandNameMethod.execute("test2", instances);
// We call command2.setEventType("testing2");
- eventTypeMethod.execute("testing2", instances, logger);
+ eventTypeMethod.execute("testing2", instances);
}
}
Modified:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodThrowsExceptionTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodThrowsExceptionTest.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodThrowsExceptionTest.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -31,10 +31,9 @@
public void whenMethodThrowsException() throws NoSuchMethodException {
method = new Method(getClass().getMethod("throwException",
String.class));
try {
- method.execute("argument", instances, logger);
+ method.execute("argument", instances);
fail("Exception was not thrown.");
- } catch (PerfSONARException ex) {
- logger.warn("• Test passed with a PerfSONARException thrown, see
above warning");
+ } catch (Exception ex) {
}
}
Modified:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java
2013-07-05 13:34:38 UTC (rev 6443)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java
2013-07-05 15:50:43 UTC (rev 6444)
@@ -87,7 +87,7 @@
@SuppressWarnings("unchecked")
@Test
- public void shouldReturnRouters() throws PerfSONARException,
UnknownHostException {
+ public void shouldReturnRouters() throws Exception {
final List<Object> actual = (List<Object>)
deserializer.deserialize(new InputSource(reader));
assertEquals(Arrays.asList(Command.PING_IPV6,
Command.SHOW_ENVIRONMENT),
- [pS-dev] [GEANT/SA2/ps-java-services] r6444 - in trunk/perfsonar-base/messaging/src: main/java/net/geant/perfsonar/messaging test/java/net/geant/perfsonar/messaging, svn-noreply, 07/05/2013
Archive powered by MHonArc 2.6.16.