diff --git a/pom.xml b/pom.xml index cd45f58..87f68b7 100644 --- a/pom.xml +++ b/pom.xml @@ -41,14 +41,21 @@ UTF-8 - 1.4 - 1.0.1 + 1.5 + 1.5 + + kg.apc + jmeter-plugins-emulators + 0.3 + test + + kg.apc cmdrunner - ${cmdrunner-version} + 1.0.2 @@ -110,70 +117,6 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9 - - - package - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - package - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.4 - - - - org.apache.maven.plugins - maven-deploy-plugin - 2.7 - - - deploy - - deploy - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - ${java-version} - ${java-version} - - org.apache.maven.plugins maven-dependency-plugin diff --git a/src/kg/apc/perfmon/PerfMonMetricGetter.java b/src/kg/apc/perfmon/PerfMonMetricGetter.java index a2a2345..90da6f2 100644 --- a/src/kg/apc/perfmon/PerfMonMetricGetter.java +++ b/src/kg/apc/perfmon/PerfMonMetricGetter.java @@ -14,9 +14,6 @@ import java.nio.channels.SocketChannel; import java.nio.channels.WritableByteChannel; -/** - * @author undera - */ public class PerfMonMetricGetter { public static final String TAB = "\t"; @@ -46,7 +43,7 @@ private void processCommand(String command) throws IOException { String cmdType = command.trim(); String params = ""; - if (command.indexOf(DVOETOCHIE) >= 0) { + if (command.contains(DVOETOCHIE)) { cmdType = command.substring(0, command.indexOf(DVOETOCHIE)).trim(); params = command.substring(command.indexOf(DVOETOCHIE) + 1).trim(); } @@ -96,7 +93,7 @@ public void addCommandString(String byteBufferToString) { public boolean processNextCommand() throws IOException { log.debug("Command line is: " + commandString); - if (commandString.indexOf(NEWLINE) >= 0) { + if (commandString.contains(NEWLINE)) { int pos = commandString.indexOf(NEWLINE); String cmd = commandString.substring(0, pos); commandString = commandString.substring(pos + 1); @@ -111,9 +108,9 @@ public ByteBuffer getMetricsLine() throws IOException { log.debug("Building metrics"); StringBuffer res = new StringBuffer(); synchronized (channel) { - for (int n = 0; n < metrics.length; n++) { + for (AbstractPerfMonMetric metric : metrics) { try { - metrics[n].getValue(res); + metric.getValue(res); } catch (Exception ex) { log.error("Error getting metric", ex); } @@ -132,7 +129,7 @@ private void setUpMetrics(String[] params) throws IOException { for (int n = 0; n < params.length; n++) { String metricParams = ""; String metricType = params[n]; - if (metricType.indexOf(DVOETOCHIE) >= 0) { + if (DVOETOCHIE.contains(metricType)) { metricParams = metricType.substring(metricType.indexOf(DVOETOCHIE) + 1).trim(); metricType = metricType.substring(0, metricType.indexOf(DVOETOCHIE)).trim(); } @@ -149,13 +146,13 @@ public boolean isStarted() { // FIXME: some kind of tokenizer would go better private void setUpTransmitter(String params) throws IOException { log.info("Starting UDP transmitter for: " + params); - if (params.indexOf(DVOETOCHIE) < 0) { + if (!params.contains(DVOETOCHIE)) { throw new IllegalArgumentException("Wrong syntax for udp-transmitter command: " + params); } String transmitToAddr = params.substring(0, params.indexOf(DVOETOCHIE)).trim(); params = params.substring(params.indexOf(DVOETOCHIE) + 1).trim(); - if (params.indexOf(DVOETOCHIE) < 0) { + if (!params.contains(DVOETOCHIE)) { throw new IllegalArgumentException("Wrong syntax for udp-transmitter command: " + params); } int transmitToPort = Integer.parseInt(params.substring(0, params.indexOf(DVOETOCHIE)).trim()); diff --git a/src/kg/apc/perfmon/PerfMonWorker.java b/src/kg/apc/perfmon/PerfMonWorker.java index b859a64..3d60fbf 100644 --- a/src/kg/apc/perfmon/PerfMonWorker.java +++ b/src/kg/apc/perfmon/PerfMonWorker.java @@ -18,22 +18,18 @@ import java.util.LinkedList; import java.util.Properties; -/** - * @author undera - */ public class PerfMonWorker implements Runnable { private static final Logger log = LoggingManager.getLoggerForClass(); private int tcpPort = 4444; private int udpPort = 4444; - private int exitCode = -1; private boolean isFinished = true; private final Selector acceptSelector; private ServerSocketChannel tcpServer; private final Thread writerThread; private final Selector sendSelector; private DatagramChannel udpServer; - private final LinkedList tcpConnections = new LinkedList(); + private final LinkedList tcpConnections = new LinkedList(); private final Hashtable udpConnections = new Hashtable(); private long interval = 1000; private final SigarProxy sigar; @@ -98,7 +94,7 @@ public void processCommands() throws IOException { } public int getExitCode() { - return exitCode; + return -1; } public void startAcceptingCommands() { @@ -292,9 +288,8 @@ private void processSenders() throws IOException { private void sendToUDP(SelectionKey key) throws IOException { synchronized (udpConnections) { - Iterator it = udpConnections.keySet().iterator(); - while (it.hasNext()) { - SocketAddress addr = (SocketAddress) it.next(); + for (Object o : udpConnections.keySet()) { + SocketAddress addr = (SocketAddress) o; PerfMonMetricGetter getter = (PerfMonMetricGetter) udpConnections.get(addr); if (getter.isStarted()) { ByteBuffer metrics = getter.getMetricsLine(); @@ -344,9 +339,8 @@ public void sendToClient(SelectableChannel channel, ByteBuffer buf) throws IOExc if (channel instanceof DatagramChannel) { synchronized (udpConnections) { DatagramChannel udpChannel = (DatagramChannel) channel; - Iterator it = udpConnections.keySet().iterator(); - while (it.hasNext()) { - SocketAddress addr = (SocketAddress) it.next(); + for (Object o : udpConnections.keySet()) { + SocketAddress addr = (SocketAddress) o; if (udpConnections.get(addr) == udpChannel) { udpChannel.send(buf, addr); } diff --git a/test/kg/apc/emulators/BinaryTools.java b/test/kg/apc/emulators/BinaryTools.java deleted file mode 100644 index 1938300..0000000 --- a/test/kg/apc/emulators/BinaryTools.java +++ /dev/null @@ -1,29 +0,0 @@ -package kg.apc.emulators; - -/** - * @author undera - */ -public class BinaryTools { - - public static byte[] hexStringToByteArray(String hexEncodedBinary) { - if (hexEncodedBinary.length() % 2 == 0) { - char[] sc = hexEncodedBinary.toCharArray(); - byte[] ba = new byte[sc.length / 2]; - - for (int i = 0; i < ba.length; i++) { - int nibble0 = Character.digit(sc[i * 2], 16); - int nibble1 = Character.digit(sc[i * 2 + 1], 16); - if (nibble0 == -1 || nibble1 == -1) { - throw new IllegalArgumentException( - "Hex-encoded binary string contains an invalid hex digit in '" + sc[i * 2] + sc[i * 2 + 1] + "'"); - } - ba[i] = (byte) ((nibble0 << 4) | (nibble1)); - } - - return ba; - } else { - throw new IllegalArgumentException( - "Hex-encoded binary string contains an uneven no. of digits"); - } - } -} diff --git a/test/kg/apc/emulators/DatagramChannelEmul.java b/test/kg/apc/emulators/DatagramChannelEmul.java deleted file mode 100644 index 73be8d4..0000000 --- a/test/kg/apc/emulators/DatagramChannelEmul.java +++ /dev/null @@ -1,122 +0,0 @@ -package kg.apc.emulators; - -import org.apache.jorphan.logging.LoggingManager; -import org.apache.log.Logger; - -import java.io.IOException; -import java.net.DatagramSocket; -import java.net.SocketAddress; -import java.net.SocketException; -import java.nio.ByteBuffer; -import java.nio.channels.DatagramChannel; -import java.util.logging.Level; - -/** - * @author undera - */ -public class DatagramChannelEmul extends DatagramChannel { - - private ByteBuffer writtenBytes; - private ByteBuffer bytesToRead; - private static final Logger log = LoggingManager.getLoggerForClass(); - private DatagramSocket socket; - - public DatagramChannelEmul() { - super(null); - try { - socket = new DatagramSocketEmulator(); - } catch (SocketException ex) { - java.util.logging.Logger.getLogger(DatagramChannelEmul.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public static DatagramChannel open() throws IOException { - return new DatagramChannelEmul(); - } - - public DatagramSocket socket() { - return socket; - } - - public boolean isConnected() { - return true; - } - - public int read(ByteBuffer dst) throws IOException { - if (bytesToRead == null || bytesToRead.remaining() == 0) { - log.debug("No more data to read"); - return -1; - } - int cnt = dst.capacity() < bytesToRead.capacity() ? dst.capacity() : bytesToRead.capacity(); - ByteBuffer chunk = bytesToRead.duplicate(); - if (cnt < chunk.capacity()) { - log.debug("Setting limit to " + cnt); - chunk.limit(cnt); - } - log.debug("Emulating read: " + getString(chunk)); - chunk.rewind(); - dst.put(chunk); - bytesToRead = null; - return cnt; - } - - public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int write(ByteBuffer src) throws IOException { - log.debug("Emulating write: " + getString(src)); - writtenBytes = src; - return src.capacity(); - } - - public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); - } - - protected void implCloseSelectableChannel() throws IOException { - log.debug("Close selectable channel"); - } - - protected void implConfigureBlocking(boolean block) throws IOException { - log.debug("Configure blocking: " + block); - } - - /** - * @return the writtenBytes - */ - public ByteBuffer getWrittenBytes() { - ByteBuffer res = writtenBytes; - writtenBytes = null; - return res; - } - - public void setBytesToRead(ByteBuffer wrap) { - log.debug("Set bytes to read: " + getString(wrap)); - bytesToRead = wrap; - } - - private String getString(ByteBuffer src) { - if (src == null) { - log.error("Null buffer!"); - return ""; - } - return src.toString(); - } - - public DatagramChannel connect(SocketAddress remote) throws IOException { - return this; - } - - public DatagramChannel disconnect() throws IOException { - return this; - } - - public SocketAddress receive(ByteBuffer dst) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); - } - - public int send(ByteBuffer src, SocketAddress target) throws IOException { - return write(src); - } -} diff --git a/test/kg/apc/emulators/DatagramSocketEmulator.java b/test/kg/apc/emulators/DatagramSocketEmulator.java deleted file mode 100644 index 9be1719..0000000 --- a/test/kg/apc/emulators/DatagramSocketEmulator.java +++ /dev/null @@ -1,43 +0,0 @@ -package kg.apc.emulators; - -import org.apache.jorphan.logging.LoggingManager; -import org.apache.log.Logger; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.SocketException; - -/** - * @author APC - */ -public class DatagramSocketEmulator - extends DatagramSocket { - - private static final Logger log = LoggingManager.getLoggerForClass(); - private DatagramPacket toRead; - - public DatagramSocketEmulator() throws SocketException { - log.debug("Created emulator"); - } - - public synchronized void receive(DatagramPacket p) throws IOException { - log.debug("Emulate receive: " + p); - if (toRead == null) { - throw new SocketException(); - } - - p.setData(toRead.getData()); - p.setAddress(toRead.getAddress()); - //p.setSocketAddress(toRead.getSocketAddress()); - toRead = null; - } - - public void send(DatagramPacket p) throws IOException { - log.debug("Emulate send: " + p); - } - - public void setDatagramToReceive(DatagramPacket datagramPacket) { - toRead = datagramPacket; - } -} diff --git a/test/kg/apc/emulators/ServerSocketEmulator.java b/test/kg/apc/emulators/ServerSocketEmulator.java deleted file mode 100644 index ef2c42a..0000000 --- a/test/kg/apc/emulators/ServerSocketEmulator.java +++ /dev/null @@ -1,18 +0,0 @@ -package kg.apc.emulators; - -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; - -/** - * @author undera - */ -public class ServerSocketEmulator extends ServerSocket { - - public ServerSocketEmulator() throws IOException { - } - - public Socket accept() throws IOException { - return new SocketEmulator(); - } -} diff --git a/test/kg/apc/emulators/SocketEmulator.java b/test/kg/apc/emulators/SocketEmulator.java deleted file mode 100644 index d2c38c6..0000000 --- a/test/kg/apc/emulators/SocketEmulator.java +++ /dev/null @@ -1,28 +0,0 @@ -package kg.apc.emulators; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.Socket; - -/** - * @author APC - */ -public class SocketEmulator - extends Socket { - private final SocketEmulatorOutputStream os; - private final SocketEmulatorInputStream is; - - public SocketEmulator() { - os = new SocketEmulatorOutputStream(); - is = new SocketEmulatorInputStream(); - } - - public OutputStream getOutputStream() throws IOException { - return os; - } - - public InputStream getInputStream() throws IOException { - return is; - } -} diff --git a/test/kg/apc/emulators/SocketEmulatorInputStream.java b/test/kg/apc/emulators/SocketEmulatorInputStream.java deleted file mode 100644 index 99a8274..0000000 --- a/test/kg/apc/emulators/SocketEmulatorInputStream.java +++ /dev/null @@ -1,66 +0,0 @@ -package kg.apc.emulators; - -import org.apache.jorphan.logging.LoggingManager; -import org.apache.log.Logger; - -import java.io.IOException; -import java.io.InputStream; - -/** - * @author apc - */ -public class SocketEmulatorInputStream - extends InputStream { - private static final Logger log = LoggingManager.getLoggerForClass(); - private byte[] bytes; - private int pos = 0; - - /** - * @param hexStringToByteArray - */ - public SocketEmulatorInputStream(byte[] hexStringToByteArray) { - this(); - setBytesToRead(hexStringToByteArray); - } - - /** - * - */ - public SocketEmulatorInputStream() { - bytes = null; - pos = 0; - log.info("Created input stream emulator"); - } - - /** - * @param hexStringToByteArray - */ - public final void setBytesToRead(byte[] hexStringToByteArray) { - log.debug("Set bytes to read: " + Integer.toString(hexStringToByteArray.length)); - bytes = hexStringToByteArray; - } - - public final void setBytesToRead(String str) { - setBytesToRead(str.getBytes()); - } - - public int read() - throws IOException { - if (bytes == null) { - log.debug("Expected emulator data was not set"); - return -1; - } - - if (pos >= bytes.length) { - log.debug("End of data reached, resetting buffer"); - bytes = null; - pos = 0; - return -1; - } else { - final byte byteToret = bytes[pos]; - pos++; - //log.debug("Byte: #"+Integer.toString(pos)+" "+Byte.toString(byteToret)); - return byteToret; - } - } -} diff --git a/test/kg/apc/emulators/SocketEmulatorOutputStream.java b/test/kg/apc/emulators/SocketEmulatorOutputStream.java deleted file mode 100644 index e496e34..0000000 --- a/test/kg/apc/emulators/SocketEmulatorOutputStream.java +++ /dev/null @@ -1,39 +0,0 @@ -package kg.apc.emulators; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * @author apc - */ -public class SocketEmulatorOutputStream - extends OutputStream { - - private StringBuffer buffer; - - /** - * - */ - public SocketEmulatorOutputStream() { - buffer = new StringBuffer(); - } - - public void write(int b) - throws IOException { - buffer.append(b > 10 ? "" : "0").append(Integer.toHexString(b)); - } - - /** - * @return - */ - public String getWrittenBytesAsHexString() { - final String toString = buffer.toString(); - buffer.setLength(0); - return toString; - } - - public String getWrittenBytesAsString() { - byte[] res = BinaryTools.hexStringToByteArray(getWrittenBytesAsHexString()); - return res.toString(); - } -} diff --git a/test/kg/apc/perfmon/client/NIOTransportTest.java b/test/kg/apc/perfmon/client/NIOTransportTest.java index da4c892..a9fae9e 100644 --- a/test/kg/apc/perfmon/client/NIOTransportTest.java +++ b/test/kg/apc/perfmon/client/NIOTransportTest.java @@ -6,30 +6,23 @@ import kg.apc.emulators.DatagramChannelEmul; import java.io.IOException; -import java.nio.channels.ReadableByteChannel; -import java.nio.channels.WritableByteChannel; -/** - * @author undera - */ public class NIOTransportTest extends TestCase { private NIOTransport instance; - private DatagramChannelEmul channel; public NIOTransportTest(String testName) { super(testName); } public static Test suite() { - TestSuite suite = new TestSuite(NIOTransportTest.class); - return suite; + return new TestSuite(NIOTransportTest.class); } protected void setUp() throws Exception { super.setUp(); instance = new NIOTransport(); - channel = (DatagramChannelEmul) DatagramChannelEmul.open(); + DatagramChannelEmul channel = (DatagramChannelEmul) DatagramChannelEmul.open(); instance.setChannels(channel, channel); } @@ -61,9 +54,7 @@ public void testReadln_0args() { */ public void testSetChannels() throws IOException { System.out.println("setChannels"); - ReadableByteChannel reader = null; - WritableByteChannel writer = null; - instance.setChannels(reader, writer); + instance.setChannels(null, null); } /** diff --git a/test/kg/apc/perfmon/metrics/jmx/ClassesDataProviderTest.java b/test/kg/apc/perfmon/metrics/jmx/ClassesDataProviderTest.java index f38d38f..c8f288c 100644 --- a/test/kg/apc/perfmon/metrics/jmx/ClassesDataProviderTest.java +++ b/test/kg/apc/perfmon/metrics/jmx/ClassesDataProviderTest.java @@ -4,6 +4,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import javax.management.ObjectName; import java.lang.management.ClassLoadingMXBean; /** @@ -81,5 +82,9 @@ public boolean isVerbose() { public void setVerbose(boolean bln) { throw new UnsupportedOperationException("Not supported yet."); } + + public ObjectName getObjectName() { + return null; + } } } diff --git a/test/kg/apc/perfmon/metrics/jmx/CompilerDataProviderTest.java b/test/kg/apc/perfmon/metrics/jmx/CompilerDataProviderTest.java index 03839c6..c806717 100644 --- a/test/kg/apc/perfmon/metrics/jmx/CompilerDataProviderTest.java +++ b/test/kg/apc/perfmon/metrics/jmx/CompilerDataProviderTest.java @@ -4,6 +4,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import javax.management.ObjectName; import java.lang.management.CompilationMXBean; import java.lang.management.ManagementFactory; @@ -76,5 +77,9 @@ public boolean isCompilationTimeMonitoringSupported() { public long getTotalCompilationTime() { return 123; } + + public ObjectName getObjectName() { + return null; + } } } diff --git a/test/kg/apc/perfmon/metrics/jmx/GCDataProviderTest.java b/test/kg/apc/perfmon/metrics/jmx/GCDataProviderTest.java index 49a3452..33d466f 100644 --- a/test/kg/apc/perfmon/metrics/jmx/GCDataProviderTest.java +++ b/test/kg/apc/perfmon/metrics/jmx/GCDataProviderTest.java @@ -4,6 +4,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import javax.management.ObjectName; import java.lang.management.GarbageCollectorMXBean; /** @@ -81,5 +82,9 @@ public boolean isValid() { public String[] getMemoryPoolNames() { throw new UnsupportedOperationException("Not supported yet."); } + + public ObjectName getObjectName() { + return null; + } } } diff --git a/test/kg/apc/perfmon/metrics/jmx/MemoryDataProviderTest.java b/test/kg/apc/perfmon/metrics/jmx/MemoryDataProviderTest.java index 248bd2c..7f25fe4 100644 --- a/test/kg/apc/perfmon/metrics/jmx/MemoryDataProviderTest.java +++ b/test/kg/apc/perfmon/metrics/jmx/MemoryDataProviderTest.java @@ -4,6 +4,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import javax.management.ObjectName; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryUsage; @@ -89,5 +90,9 @@ public void setVerbose(boolean bln) { public void gc() { throw new UnsupportedOperationException("Not supported yet."); } + + public ObjectName getObjectName() { + return null; + } } } diff --git a/test/kg/apc/perfmon/metrics/jmx/MemoryPoolDataProviderTest.java b/test/kg/apc/perfmon/metrics/jmx/MemoryPoolDataProviderTest.java index 48b5098..cd24dc1 100644 --- a/test/kg/apc/perfmon/metrics/jmx/MemoryPoolDataProviderTest.java +++ b/test/kg/apc/perfmon/metrics/jmx/MemoryPoolDataProviderTest.java @@ -4,6 +4,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; +import javax.management.ObjectName; import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryType; @@ -139,5 +140,9 @@ public MemoryUsage getCollectionUsage() { public boolean isCollectionUsageThresholdSupported() { throw new UnsupportedOperationException("Not supported yet."); } + + public ObjectName getObjectName() { + return null; + } } } diff --git a/zip.xml b/zip.xml index 0466d76..64f7c75 100644 --- a/zip.xml +++ b/zip.xml @@ -14,7 +14,7 @@ CMDRunner.jar - ${project.build.directory}/lib/cmdrunner-${cmdrunner-version}.jar + ${project.build.directory}/lib/cmdrunner-1.0.2.jar LICENSE