diff --git a/src/com/jmibanez/tools/jmeter/MethodCallRecord.java b/src/com/jmibanez/tools/jmeter/MethodCallRecord.java index d69231c..ccf1ae8 100644 --- a/src/com/jmibanez/tools/jmeter/MethodCallRecord.java +++ b/src/com/jmibanez/tools/jmeter/MethodCallRecord.java @@ -24,6 +24,8 @@ public class MethodCallRecord private Class[] argTypes; private Object[] args; private byte[] argsPacked; + private String mangledMethodName; + private String mangledArgs; private Object returnValue; private Throwable returnException; private boolean isException = false; @@ -39,7 +41,10 @@ public MethodCallRecord(final int index, final String target, final Method m, this.index = index; this.target = target; this.argTypes = m.getParameterTypes(); - this.method = constructMethodName(m.getName(), this.argTypes); + this.method = m.getName(); + String[] builtNames = constructMethodName(m.getName(), this.argTypes); + this.mangledMethodName = builtNames[0]; + this.mangledArgs = builtNames[1]; this.args = args; this.argsPacked = packArgs(this.args); } @@ -56,6 +61,14 @@ public String getMethod() { return method; } + public String getMangledMethodName() { + return mangledMethodName; + } + + public String getMangledArguments() { + return mangledArgs; + } + public Object[] recreateArguments() { this.args = unpackArgs(this.argsPacked); return args; @@ -111,24 +124,25 @@ public Map getRemotePathsInReturn() { return remotePathsInReturn; } - public static String constructMethodName(String methodName, Class[] argTypes) { - StringBuilder sb = new StringBuilder(); - sb.append(methodName); + public static String[] constructMethodName(String methodName, Class[] argTypes) { + StringBuilder full = new StringBuilder(); + StringBuilder args = new StringBuilder(); if(argTypes == null || argTypes.length == 0) { - sb.append(":"); - return sb.toString(); + return new String[] { methodName + ":", "" }; } - sb.append(":"); + full.append(methodName); + full.append(":"); for(Class c : argTypes) { - sb.append(c.getName()); - sb.append(","); + args.append(c.getName()); + args.append(","); } - sb.deleteCharAt(sb.length() - 1); + args.deleteCharAt(args.length() - 1); - return sb.toString(); + full.append(args); + return new String[] { full.toString(), args.toString() }; } private void writeObject(ObjectOutputStream out) diff --git a/src/com/jmibanez/tools/jmeter/RMISampleResult.java b/src/com/jmibanez/tools/jmeter/RMISampleResult.java index dfda405..255a582 100644 --- a/src/com/jmibanez/tools/jmeter/RMISampleResult.java +++ b/src/com/jmibanez/tools/jmeter/RMISampleResult.java @@ -142,7 +142,9 @@ private void writeObject(ObjectOutputStream out) if(method != null) { out.writeUTF(method.getClass().getCanonicalName()); out.writeUTF("\nM:"); - out.writeUTF(MethodCallRecord.constructMethodName(method.getName(), method.getParameterTypes())); + String[] builtNames = MethodCallRecord.constructMethodName(method.getName(), + method.getParameterTypes()); + out.writeUTF(builtNames[0]); } else { out.writeUTF(classOwnerName); diff --git a/src/com/jmibanez/tools/jmeter/gui/NativeRmiProxyControllerGui.java b/src/com/jmibanez/tools/jmeter/gui/NativeRmiProxyControllerGui.java index 83924dd..55555f4 100644 --- a/src/com/jmibanez/tools/jmeter/gui/NativeRmiProxyControllerGui.java +++ b/src/com/jmibanez/tools/jmeter/gui/NativeRmiProxyControllerGui.java @@ -302,10 +302,10 @@ private void init() { JLabel portLabel = new JLabel("Proxy Port"); portLabel.setLabelFor(proxyPort); - samplerNameFormat = new JTextField("[%1$s] %2$d - %3$s", 100); + samplerNameFormat = new JTextField("[%1$s] %2$d - %3$s:%4$s", 100); samplerNameFormat.setName(SAMPLERNAMEFORMAT_FIELD); - JLabel samplerNameFormatLabel = new JLabel("Sampler Name Format"); + JLabel samplerNameFormatLabel = new JLabel("Sampler Name Format [1: Target; 2: Call Index; 3: Method; 4: Args]"); samplerNameFormatLabel.setLabelFor(samplerNameFormat); JPanel configBox = new HorizontalPanel(); diff --git a/src/com/jmibanez/tools/jmeter/impl/RmiSamplerGeneratorMethodRecorder.java b/src/com/jmibanez/tools/jmeter/impl/RmiSamplerGeneratorMethodRecorder.java index b9f2aef..d695d57 100644 --- a/src/com/jmibanez/tools/jmeter/impl/RmiSamplerGeneratorMethodRecorder.java +++ b/src/com/jmibanez/tools/jmeter/impl/RmiSamplerGeneratorMethodRecorder.java @@ -36,7 +36,7 @@ public class RmiSamplerGeneratorMethodRecorder implements MethodRecorder { - public static final String DEFAULT_SAMPLER_NAME_FORMAT = "[%1$s] %2$d - %3$s"; + public static final String DEFAULT_SAMPLER_NAME_FORMAT = "[%1$s] %2$d - %3$s:%4$s"; private static Log log = LogFactory.getLog(RmiSamplerGeneratorMethodRecorder.class); @@ -161,28 +161,31 @@ public void recordCall(final MethodCallRecord r) BeanShellPostProcessor retValProc = null; sampler.setProperty(TestElement.TEST_CLASS, RMISampler.class.getName()); sampler.setProperty(TestElement.GUI_CLASS, RMISamplerGUI.class.getName()); - sampler.setTargetName(r.getTarget()); + sampler.setMethodName(r.getMangledMethodName()); String instanceName = r.getTarget(); + sampler.setTargetName(instanceName); if (instanceName == null) { instanceName = ""; } int index = r.getIndex(); String method = r.getMethod(); - sampler.setMethodName(method); + String mangledArgs = r.getMangledArguments(); + String samplerName = ""; + try { samplerName = String.format(samplerNameFormat, instanceName, index, - method); + method, mangledArgs); } catch(Exception e) { // use default format log.warn("Invalid sampler name format", e); samplerName = String.format(DEFAULT_SAMPLER_NAME_FORMAT, instanceName, index, - method); + method, mangledArgs); } sampler.setName(samplerName); diff --git a/test/com/jmibanez/tools/jmeter/MethodCallRecordTest.java b/test/com/jmibanez/tools/jmeter/MethodCallRecordTest.java new file mode 100644 index 0000000..2083d84 --- /dev/null +++ b/test/com/jmibanez/tools/jmeter/MethodCallRecordTest.java @@ -0,0 +1,28 @@ +package com.jmibanez.tools.jmeter; + +import java.util.List; +import java.util.Map; +import junit.framework.TestCase; + +public class MethodCallRecordTest extends TestCase { + + public void testConstructSimpleMethodName() { + String[] builtNames = MethodCallRecord.constructMethodName("foo", null); + assertEquals("foo:", builtNames[0]); + assertEquals("", builtNames[1]); + } + + public void testConstructMethodNameWithOneArg() { + String[] builtNames = MethodCallRecord + .constructMethodName("foo", new Class[] { String.class }); + assertEquals("foo:java.lang.String", builtNames[0]); + assertEquals("java.lang.String", builtNames[1]); + } + + public void testConstructMethodNameWithSeveralArgs() { + String[] builtNames = MethodCallRecord + .constructMethodName("foo", new Class[] { String.class, Class.class }); + assertEquals("foo:java.lang.String,java.lang.Class", builtNames[0]); + assertEquals("java.lang.String,java.lang.Class", builtNames[1]); + } +}