diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2010-06-22 13:41:42 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2010-06-22 13:41:42 +0000 |
| commit | dda1716edbe942300d0e1190ec215d2bce9b9cbb (patch) | |
| tree | 53f5100bd45c81210e947dc49bdc13e0793ca1aa /java/broker-plugins | |
| parent | 5951dfafe74a4115ef22dbb5d5d9b8c455bde0f5 (diff) | |
| download | qpid-python-dda1716edbe942300d0e1190ec215d2bce9b9cbb.tar.gz | |
QPID-2555 : Info-Plugin systest fixes
Patch provided by Sorin Suciu
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@956889 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker-plugins')
3 files changed, 253 insertions, 4 deletions
diff --git a/java/broker-plugins/experimental/info/build.xml b/java/broker-plugins/experimental/info/build.xml index bc7dd19410..caf4b138a4 100644 --- a/java/broker-plugins/experimental/info/build.xml +++ b/java/broker-plugins/experimental/info/build.xml @@ -18,10 +18,10 @@ nn - or more contributor license agreements. See the NOTICE file - under the License. - --> -<project name="AMQ Broker-Plugins" default="build"> +<project name="AMQ Broker Info Plugin" default="build"> - <property name="module.depends" value="common management/common broker broker-plugins"/> - <property name="module.test.depends" value="test broker/test"/> + <property name="module.depends" value="common broker broker-plugins"/> + <property name="module.test.depends" value="test broker/test management/common client systests"/> <property name="module.manifest" value="MANIFEST.MF"/> <property name="module.plugin" value="true"/> diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java new file mode 100644 index 0000000000..bcaf2328a6 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java @@ -0,0 +1,249 @@ +package org.apache.qpid.info; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.apache.qpid.test.utils.QpidBrokerTestCase; + +public class InfoPluginTest extends QpidBrokerTestCase +{ + private String QPID_HOME = null; + + private ServerSocket server = null; + + private final int port = 9000; + + private static final String CR = System.getProperty("line.separator"); + + private static final String FS = File.separator; + + private final String cfgRelPath = "etc" + FS + "qpidinfo.properties"; + + private File tmpCfgFile; + + private final String soapEnvelopeHead = "<?xml version=\"1.0\"?><soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\" soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">"; + + private final String soapEnvelopeTail = "</soap:Envelope>"; + + private String soapMessage1 = "@ACTION" + "-" + "@VERSION"; + + private String soapMessage2 = "@VERSION" + "-" + "@ACTION"; + + private CountDownLatch latch = new CountDownLatch(2); + + final List<List<String>> recv = new ArrayList<List<String>>(); + + Thread socketAcceptor; + + public void setUp() throws Exception + { + QPID_HOME = System.getProperty("QPID_HOME"); + if (QPID_HOME != null) + { + System.out.println("QPID_HOME=" + QPID_HOME); + } else + { + fail("QPID_HOME not set"); + } + createConfigFile(); + startSoapServer(port); + } + + public void tearDown() throws Exception + { + System.out.println("*** Deleting the config file..."); + if (tmpCfgFile.isFile()) + tmpCfgFile.delete(); + super.tearDown(); + } + + private void createConfigFile() + { + try + { + tmpCfgFile = new File(QPID_HOME + FS + cfgRelPath); + if (tmpCfgFile.isFile()) + tmpCfgFile.delete(); + tmpCfgFile.createNewFile(); + assertTrue(tmpCfgFile.isFile()); + FileWriter fwriter = new FileWriter(tmpCfgFile); + BufferedWriter writer = new BufferedWriter(fwriter); + writer.write("protocol=soap"); + writer.write(CR); + writer.write("soap.hostname=localhost"); + writer.write(CR); + writer.write("soap.port=" + port); + writer.write(CR); + writer.write(CR); + writer.write("[MSG1]"); + writer.write(CR); + writer.write("soap.path=/info1"); + writer.write(CR); + writer.write("soap.action=submitinfo1"); + writer.write(CR); + writer.write("soap.envelope=" + soapEnvelopeHead + soapMessage1 + + soapEnvelopeTail); + writer.write(CR); + writer.write(CR); + writer.write("[MSG2]"); + writer.write(CR); + writer.write("soap.path=/info2"); + writer.write(CR); + writer.write("soap.action=submitinfo2"); + writer.write(CR); + writer.write("soap.envelope=" + soapEnvelopeHead + soapMessage2 + + soapEnvelopeTail); + writer.write(CR); + writer.write(CR); + writer.close(); + assertTrue("Config file size is zero", tmpCfgFile.length() > 0); + } catch (IOException e) + { + fail("Unable to create the qpidinfo.properties due to: " + + e.getMessage()); + } + } + + private void startSoapServer(int port) throws Exception + { + assertTrue("Port a negative number", port > 0); + assertTrue("Port higher than 65535", port < 65535); + + try + { + server = new ServerSocket(port); + assertNotNull("SocketServer is null", server); + } catch (Exception ex) + { + fail("Unable to start the socket server due to: " + ex.getMessage()); + } + + socketAcceptor = new Thread() + { + public void run() + { + while (true) + { + try + { + Socket socket = server.accept(); + new ConnectionHandler(socket); + } catch (IOException e) + { + fail("Error opening the socket in accept mode"); + } + } + } + }; + socketAcceptor.start(); + System.out.println("*** Socket server started..."); + } + + class ConnectionHandler implements Runnable + { + private Socket socket; + + public ConnectionHandler(Socket socket) + { + this.socket = socket; + Thread t = new Thread(this); + t.start(); + } + + public void run() + { + System.out.println("*** Connection handler running..."); + List<String> buf = new ArrayList<String>(); + String line; + try + { + BufferedReader br = new BufferedReader(new InputStreamReader( + socket.getInputStream())); + assertNotNull(br); + while ((line = br.readLine()) != null) + { + buf.add(line); + } + br.close(); + System.out.println("*** Received buffer: " + buf); + System.out.println("*** Latch countdown"); + latch.countDown(); + synchronized (recv) + { + recv.add(buf); + } + } catch (Exception ex) + { + ex.printStackTrace(); + fail("Exception while reading from the socket"); + } + + } + + } + + public void testInfoPlugin() throws Exception + { + super.setUp(); + if (!latch.await(10, TimeUnit.SECONDS)) + { + fail("Timeout awaiting for the latch, upon startup"); + } + + assertTrue("Received less than 2 messages", recv.size() > 1); + //Message 1 + assertTrue("Message has 0 size", recv.get(0).size()>0); + assertEquals("Message does not have 8 fields", recv.get(0).size(), 8); + assertTrue("Message does not contain Host: localhost:9000",recv.get(0).contains("Host: localhost:9000")); + assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(0).contains("User-Agent: Axis2")); + assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(0).get(4).startsWith("SOAPAction: \"urn:submitinfo")); + assertTrue("Message does not contain STARTUP in the soap envelope", recv.get(0).get(7).contains("STARTUP")); + + //Message 2 + assertTrue("Message has 0 size", recv.get(1).size()>0); + assertEquals("Message does not have 8 fields", recv.get(1).size(), 8); + assertTrue("Message does not contain Host: localhost:9000",recv.get(1).contains("Host: localhost:9000")); + assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(1).contains("User-Agent: Axis2")); + assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(1).get(4).startsWith("SOAPAction: \"urn:submitinfo")); + assertTrue("Message does not contain STARTUP in the soap envelope", recv.get(0).get(7).contains("STARTUP")); + + recv.clear(); + latch = new CountDownLatch(2); + + stopBroker(); + + if (!latch.await(10, TimeUnit.SECONDS)) + { + fail("Timeout awaiting for the latch, upon shutdown"); + } + + + assertTrue("Received less than 2 messages", recv.size() > 1); + + // Message 1 + assertTrue("Message does not contain Host: localhost:9000",recv.get(0).contains("Host: localhost:9000")); + assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(0).contains("User-Agent: Axis2")); + assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(0).get(4).startsWith("SOAPAction: \"urn:submitinfo")); + assertTrue("Message does not contain SHUTDOWN in the soap envelope", recv.get(0).get(7).contains("SHUTDOWN")); + + // Message 2 + assertTrue("Message does not contain Host: localhost:9000",recv.get(1).contains("Host: localhost:9000")); + assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(1).contains("User-Agent: Axis2")); + assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(1).get(4).startsWith("SOAPAction: \"urn:submitinfo")); + assertTrue("Message does not contain SHUTDOWN in the soap envelope", recv.get(0).get(7).contains("SHUTDOWN")); + + System.out.println("*** Stopping socket server..."); + socketAcceptor.join(2000); + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java index 5c7276456c..4f977e1f99 100644 --- a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java @@ -38,7 +38,7 @@ import org.apache.qpid.info.util.SoapClient; public class SoapClientTest extends TestCase { - private final int port = 9000; + private final int port = 9900; private final String hostName = "localhost"; |
