issue with exception handling in java code
JJ <[email protected]>
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <[email protected]> |
Hello i am not familiar with jython concept and Grinder so this may be a
newbee issue, however the issue i am facing regarding exception handling
is weird to me.
I am using grinder to test load an udp server. This server, to make
it simple, act almost like an http server (but in private udp
protocol).
i have written a java client code that work fine ; create udp request,
and listen for udp response and use this class from ultra basic jython
script that i copied from other source.
Now it happens that the udp socket timeout when getting the expected
response (i know UDP is not reliable , the point is not there) and this
create an exception.
My problem is this exception should be caught & processed at the java
level, there are all needed try catch . but it does not appear to be the
case and the exception is only visible in the Log of grinder. ( and I do
not print the shown stacktrace ).
Is it due to some instrumentation that the exception bubbles up ?
What could I be doing wrong ? ( again the exception is not abnormal, it
only its processing that look abnormal to me )
below are code snipets
Thanks for your help.
JJ
--- full jython script code ------
# -*- coding:utf-8 -*-
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from aaaa.bbbb import UdpClient
from java.lang import String
import time
test1 = Test(1, "")
client1 = UdpClient()
test1.record(client1)
class TestRunner:
def __init__(self):
grinder.statistics.delayReports = True
pass
def __call__(self):
# this method should never throw an exception
result = client1.createLegacyRequest("someparam" ... )
if result == -1:
grinder.statistics.forLastTest.success = 0
elif result == 0:
# this log is actually never shown - but should in the
expected error case
grinder.logger.warn("error missing more than 1 packet")
grinder.statistics.forLastTest.success = 0
else:
grinder.statistics.forLastTest.success = 1
--- full jython script code ------
--- java code snippet ------
(...)
public class UdpClient
{
/* this does not
declare any throw */
public int createLegacyRequest( ... some param )
{
int nb = -1;
DatagramSocket socket = null;
try
{
(...)
socket = new DatagramSocket();
(...)
socket.send(packet);
nb = 0;
for (int i= 0; i < expected ; i++)
{
socket.receive(rcvPacket);
nb++;
}
return nb;
}catch(SocketTimeoutException ste)
{
logMe(" this is a throwable caught ", ste);
if (nb <= 0) return -1; // nothing received
if (nb < expected - 1) return 0; // we lost more than 1
return nb;
} catch (Throwable e)
{
logMe(": this is a throwable caught ", e);
if (nb <= 0) return -1; // nothing received
if (nb < expected - 1) return 0; // we lost more than 1
return nb;
}
finally
{
if (socket!= null)
{
try
{
socket.close();
} catch (Throwable e)
{
}
}
}
}
--- end java code snippet ------
---- grinder logs -------------
(...)
2014-02-12 14:19:34,357 INFO The Grinder version 3.9.1
2014-02-12 14:19:34,361 INFO Java(TM) SE Runtime Environment
1.7.0_25-b15: Java HotSpot(TM) 64-Bit Server VM (23.25-b01, mixed mode)
on Linux
2014-02-12 14:19:34,568 INFO worker process 0 of agent number 0
2014-02-12 14:19:34,855 INFO instrumentation agents: byte code
transforming instrumenter for Jython 2.5; byte code transforming
instrumenter for Java
2014-02-12 14:19:39,460 INFO running "udp.py" using Jython 2.5.3
(2.5:c56500f08d34+, Aug 13 2012, 14:54:35)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)]
2014-02-12 14:19:39,507 INFO starting, will run forever
2014-02-12 14:19:39,508 INFO starting, will run forever
2014-02-12 14:19:39,508 INFO starting, will run forever
2014-02-12 14:19:39,508 INFO starting, will run forever
2014-02-12 14:19:39,508 INFO starting, will run forever
2014-02-12 14:19:39,509 INFO starting, will run forever
2014-02-12 14:19:39,509 INFO starting, will run forever
2014-02-12 14:19:39,509 INFO starting, will run forever
2014-02-12 14:19:39,509 INFO starting, will run forever
2014-02-12 14:19:39,509 INFO starting, will run forever
2014-02-12 14:19:39,509 INFO starting, will run forever
2014-02-12 14:19:39,510 INFO start time is 1392211179509 ms since Epoch
2014-02-12 14:19:48,671 ERROR Aborted run: Java exception calling
TestRunner
net.grinder.scriptengine.jython.JythonScriptExecutionException: Java
exception calling TestRunner
result = client1.createLegacyRequest( some param ... )
File "(...) udp.py", line 28, in __call__
java.net.SocketTimeoutException: Receive timed out
at java.net.PlainDatagramSocketImpl.receive0(Native Method)
~[na:1.7.0_25]
at
java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:145)
~[na:1.7.0_25]
at java.net.DatagramSocket.receive(DatagramSocket.java:786)
~[na:1.7.0_25]
at aaaa.bbbb.UdpClient.createLegacyRequest(Unknown Source)
~[udpgrinder.jar:na]
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source) ~[na:na]
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyObject.__call__(PyObject.java:345)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:220)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyMethod.__call__(PyMethod.java:211)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyMethod.__call__(PyMethod.java:201)
~[jython-standalone-2.5.3.jar:na]
at org.python.pycode._pyx1.__call__$3((..)/udp.py:36) ~[na:na]
at org.python.pycode._pyx1.call_function((...)/udp.py) ~[na:na]
at org.python.core.PyTableCode.call(PyTableCode.java:165)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyBaseCode.call(PyBaseCode.java:194)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyFunction.__call__(PyFunction.java:387)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:220)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyMethod.__call__(PyMethod.java:211)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyMethod.__call__(PyMethod.java:206)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyObject.invoke(PyObject.java:3555)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyInstance.instance___call__(PyInstance.java:351)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyInstance.__call__(PyInstance.java:342)
~[jython-standalone-2.5.3.jar:na]
at org.python.core.PyObject.__call__(PyObject.java:371)
~[jython-standalone-2.5.3.jar:na]
at
net.grinder.scriptengine.jython.JythonScriptEngine$JythonWorkerRunnable.run(JythonScriptEngine.java:250)
~[grinder-core-3.9.1.jar:na]
at net.grinder.engine.process.GrinderThread.run(GrinderThread.java:118)
~[grinder-core-3.9.1.jar:na]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
(...)
------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience. Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk