brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grk...@apache.org
Subject [12/14] git commit: Updated Qpid integration test to use the correct map for runtime files and clarified when resource copying takes place
Date Mon, 06 Oct 2014 11:56:44 GMT
Updated Qpid integration test to use the correct map for runtime files and clarified when resource
copying takes place


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ae4db42d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ae4db42d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ae4db42d

Branch: refs/heads/master
Commit: ae4db42df9894522946c3e7680410669f510b64b
Parents: 2cfbe40
Author: Andrew Kennedy <grkvlt@apache.org>
Authored: Sun Oct 5 18:17:58 2014 +0100
Committer: Andrew Kennedy <grkvlt@apache.org>
Committed: Sun Oct 5 23:47:00 2014 +0100

----------------------------------------------------------------------
 .../basic/AbstractSoftwareProcessDriver.java    |  10 +-
 .../basic/AbstractSoftwareProcessSshDriver.java |   9 +-
 .../brooklyn/entity/basic/SoftwareProcess.java  |   8 +-
 .../messaging/qpid/QpidIntegrationTest.groovy   | 250 ------------------
 .../messaging/qpid/QpidIntegrationTest.java     | 251 +++++++++++++++++++
 5 files changed, 269 insertions(+), 259 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ae4db42d/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
index 421522c..dd3e663 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
@@ -113,16 +113,16 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
             }});
         };
 
-        DynamicTasks.queue("copy-runtime-resources", new Runnable() { public void run() {
-            waitForConfigKey(BrooklynConfigKeys.RUNTIME_RESOURCES_LATCH);
-            copyRuntimeResources();
-        }});
-
         DynamicTasks.queue("customize", new Runnable() { public void run() {
             waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH);
             customize();
         }});
 
+        DynamicTasks.queue("copy-runtime-resources", new Runnable() { public void run() {
+            waitForConfigKey(BrooklynConfigKeys.RUNTIME_RESOURCES_LATCH);
+            copyRuntimeResources();
+        }});
+
         if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND)))
{
             DynamicTasks.queue("pre-launch-command", new Runnable() { public void run() {
                 runPreLaunchCommand(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ae4db42d/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
index 24dfa11..c1d7d94 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
@@ -294,12 +294,14 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
     }
 
     /**
-     * Files and templates to be copied to the server before install.
+     * Files and templates to be copied to the server <em>before</em> installation.
This allows the {@link #install()}
+     * process to have access to all required resources. 
      * <p>
      * Will be prefixed with the entity's {@link #getInstallDir() install directory} if relative.
      *
      * @see SoftwareProcess#INSTALL_FILES
      * @see SoftwareProcess#INSTALL_TEMPLATES
+     * @see #copyRuntimeResources()
      */
     @Override
     public void copyInstallResources() {
@@ -333,12 +335,15 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
     }
 
     /**
-     * Files and templates to be copied to the server before customisation.
+     * Files and templates to be copied to the server <em>after</em> customisation.
This allows overwriting of
+     * existing files such as entity configuration which may be copied from the installation
directory
+     * during the {@link #customize()} process.
      * <p>
      * Will be prefixed with the entity's {@link #getRunDir() run directory} if relative.
      *
      * @see SoftwareProcess#RUNTIME_FILES
      * @see SoftwareProcess#RUNTIME_TEMPLATES
+     * @see #copyInstallResources()
      */
     @Override
     public void copyRuntimeResources() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ae4db42d/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
index e8819b2..eeb1a23 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java
@@ -111,6 +111,8 @@ public interface SoftwareProcess extends Entity, Startable {
      * <p>
      * Map of {@code classpath://foo/file.txt} (or other url) source to destination path,
      * as {@code subdir/file} relative to installation directory or {@code /absolute/path/to/file}.
+     *
+     * @see #INSTALL_TEMPLATES
      */
     @Beta
     @SuppressWarnings("serial")
@@ -130,10 +132,12 @@ public interface SoftwareProcess extends Entity, Startable {
             "templates.install", "Mapping of templates, to be filled in and copied before
install, to destination name relative to installDir");
 
     /**
-     * Files to be copied to the server before customisation.
+     * Files to be copied to the server after customisation.
      * <p>
      * Map of {@code classpath://foo/file.txt} (or other url) source to destination path,
      * as {@code subdir/file} relative to runtime directory or {@code /absolute/path/to/file}.
+     *
+     * @see #RUNTIME_TEMPLATES
      */
     @Beta
     @SuppressWarnings("serial")
@@ -142,7 +146,7 @@ public interface SoftwareProcess extends Entity, Startable {
             "files.runtime", "Mapping of files, to be copied before customisation, to destination
name relative to runDir");
 
     /**
-     * Templates to be filled in and then copied to the server before customisation.
+     * Templates to be filled in and then copied to the server after customisation.
      *
      * @see #RUNTIME_FILES
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ae4db42d/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.groovy
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.groovy
b/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.groovy
deleted file mode 100644
index fb66db5..0000000
--- a/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.groovy
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package brooklyn.entity.messaging.qpid;
-
-import static brooklyn.test.TestUtils.*
-import static java.util.concurrent.TimeUnit.*
-import static org.testng.Assert.*
-
-import javax.jms.Connection
-import javax.jms.MessageConsumer
-import javax.jms.MessageProducer
-import javax.jms.Queue
-import javax.jms.Session
-import javax.jms.TextMessage
-
-import org.apache.qpid.client.AMQConnectionFactory
-import org.apache.qpid.configuration.ClientProperties
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-import org.testng.annotations.AfterMethod
-import org.testng.annotations.BeforeMethod
-import org.testng.annotations.Test
-
-import brooklyn.entity.basic.ApplicationBuilder
-import brooklyn.entity.basic.Attributes
-import brooklyn.entity.basic.Entities
-import brooklyn.entity.proxying.EntitySpec
-import brooklyn.entity.trait.Startable
-import brooklyn.location.Location
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation
-import brooklyn.test.entity.TestApplication
-import brooklyn.util.internal.TimeExtras
-
-/**
- * Test the operation of the {@link QpidBroker} class.
- */
-public class QpidIntegrationTest {
-    private static final Logger log = LoggerFactory.getLogger(QpidIntegrationTest.class)
-
-    static { TimeExtras.init() }
-
-    private TestApplication app
-    private Location testLocation
-    private QpidBroker qpid
-
-    @BeforeMethod(groups = "Integration")
-    public void setup() {
-        String workingDir = System.getProperty("user.dir");
-        println workingDir
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
-        testLocation = app.newLocalhostProvisioningLocation()
-    }
-
-    @AfterMethod(alwaysRun=true)
-    public void shutdown() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
-    /**
-     * Test that the broker starts up with JMX and RMI ports configured, and sets SERVICE_UP
correctly.
-     */
-    @Test(groups = "Integration")
-    public void canStartupAndShutdown() {
-        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
-                .configure("jmxPort", "9909+")
-                .configure("rmiRegistryPort", "9910+"));
-        qpid.start([ testLocation ])
-        executeUntilSucceedsWithShutdown(qpid) {
-            assertTrue qpid.getAttribute(Startable.SERVICE_UP)
-        }
-        assertFalse qpid.getAttribute(Startable.SERVICE_UP)
-    }
-
-    /**
-     * Test that the broker starts up with HTTP management enabled, and we can connect to
the URL.
-     */
-    @Test(groups = "Integration")
-    public void canStartupAndShutdownWithHttpManagement() {
-        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
-                .configure("httpManagementPort", "8888"));
-        qpid.start([ testLocation ])
-        executeUntilSucceedsWithShutdown(qpid) {
-            assertTrue qpid.getAttribute(Startable.SERVICE_UP)
-            URI.create("http://localhost:8888/").toURL().openConnection().connect()
-            // TODO check actual REST output
-        }
-        assertFalse qpid.getAttribute(Startable.SERVICE_UP)
-    }
-
-    /**
-     * Test that the broker starts up and sets SERVICE_UP correctly when plugins are configured.
-     * 
-     * FIXME the custom plugin was written against qpid 0.14, so that's the version we need
to run
-     * this test against. However, v0.14 is no longer available from the download site.
-     * We should update this plugin so it works with the latest qpid.
-     */
-    @Test(enabled=false, groups = "Integration")
-    public void canStartupAndShutdownWithPlugin() {
-        Map qpidRuntimeFiles;
-        String pluginjar = "src/test/resources/qpid-test-plugin.jar";
-        String configfile = "src/test/resources/qpid-test-config.xml";
-        if (new File(pluginjar).isFile()) {
-           qpidRuntimeFiles = [
-                   ('lib/plugins/sample-plugin.jar'):new File(pluginjar),
-                    ('etc/config.xml'):new File(configfile) ]
-        } else {
-           qpidRuntimeFiles = [
-                   ('lib/plugins/sample-plugin.jar'):new File('software/messaging/'+pluginjar),
-                   ('etc/config.xml'):new File('software/messaging/'+configfile) ]
-        }
-        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
-                .configure("runtimeFiles", qpidRuntimeFiles)
-                .configure(QpidBroker.SUGGESTED_VERSION, "0.14"));
-
-        qpid.start([ testLocation ])
-        //TODO assert the files/plugins were installed?
-        executeUntilSucceedsWithShutdown(qpid) {
-            assertTrue qpid.getAttribute(Startable.SERVICE_UP)
-        }
-        assertFalse qpid.getAttribute(Startable.SERVICE_UP)
-    }
-
-    /**
-     * Test that setting the 'queue' property causes a named queue to be created.
-     *
-     * This test is disabled, pending further investigation. Issue with AMQP 0-10 queue names.
-     * 
-     * FIXME disabled becausing failing in jenkins CI (in QpidIntegrationTest.getQpidConnection()).
-     *     url=amqp://admin:********@brooklyn/localhost?brokerlist='tcp://localhost:5672'
-     * Was previously enabled, dispite comment above about "test is disabled".	
-     */
-    @Test(groups = ["Integration", "WIP"])
-    public void testCreatingQueues() {
-        String queueName = "testQueue"
-        int number = 20
-        String content = "01234567890123456789012345678901"
-
-        // Start broker with a configured queue
-        // FIXME Can't use app.createAndManageChild, because of QpidDestination reffing impl
directly
-        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
-                .configure("queue", queueName));
-        
-        qpid.start([ testLocation ])
-        executeUntilSucceeds {
-            assertTrue qpid.getAttribute(Startable.SERVICE_UP)
-        }
-
-        try {
-            // Check queue created
-            assertFalse qpid.queueNames.isEmpty()
-            assertEquals qpid.queueNames.size(), 1
-            assertTrue qpid.queueNames.contains(queueName)
-            assertEquals qpid.children.size(), 1
-            assertFalse qpid.queues.isEmpty()
-            assertEquals qpid.queues.size(), 1
-
-            // Get the named queue entity
-            QpidQueue queue = qpid.queues[queueName]
-            assertNotNull queue
-
-            // Connect to broker using JMS and send messages
-            Connection connection = getQpidConnection(qpid)
-            clearQueue(connection, queue.queueName)
-            executeUntilSucceeds { assertEquals queue.getAttribute(QpidQueue.QUEUE_DEPTH_MESSAGES),
0 }
-            sendMessages(connection, number, queue.queueName, content)
-
-            // Check messages arrived
-            executeUntilSucceeds { 
-                assertEquals queue.getAttribute(QpidQueue.QUEUE_DEPTH_MESSAGES), number
-                assertEquals queue.getAttribute(QpidQueue.QUEUE_DEPTH_BYTES), number * content.length()
-            }
-
-            //TODO clearing the queue currently returns 0
-//            // Clear the messages -- should get 20
-//            assertEquals clearQueue(connection, queue.queueName), 20
-//
-//            // Check messages cleared
-//            executeUntilSucceeds {
-//                assertEquals queue.getAttribute(QpidQueue.QUEUE_DEPTH_MESSAGES), 0
-//                assertEquals queue.getAttribute(QpidQueue.QUEUE_DEPTH_BYTES), 0
-//            }
-            
-	        connection.close()
-
-            // Close the JMS connection
-        } finally {
-            // Stop broker
-	        qpid.stop()
-            qpid = null;
-            app = null;
-        }
-    }
-
-    private Connection getQpidConnection(QpidBroker qpid) {
-        int port = qpid.getAttribute(Attributes.AMQP_PORT)
-        System.setProperty(ClientProperties.AMQP_VERSION, "0-10");
-        System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR");
-        AMQConnectionFactory factory = new AMQConnectionFactory("amqp://admin:admin@brooklyn/localhost?brokerlist='tcp://localhost:${port}'")
-        try {
-            Connection connection = factory.createConnection();
-            connection.start();
-            return connection
-        } catch (Exception e) {
-            log.error("Error connecting to qpid: url="+factory.getConnectionURLString(),
e);
-            throw e;
-        }
-    }
-
-    private void sendMessages(Connection connection, int count, String queueName, String
content="") {
-        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
-        Queue destination = session.createQueue(queueName)
-        MessageProducer messageProducer = session.createProducer(destination)
-
-        count.times {
-            TextMessage message = session.createTextMessage(content)
-            messageProducer.send(message);
-        }
-
-        session.close()
-    }
-
-    private int clearQueue(Connection connection, String queueName) {
-        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
-        Queue destination = session.createQueue(queueName)
-        MessageConsumer messageConsumer = session.createConsumer(destination)
-
-        int received = 0
-        while (messageConsumer.receive(500) != null) received++
-
-        session.close()
-        
-        received
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ae4db42d/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
b/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
new file mode 100644
index 0000000..d4a3a57
--- /dev/null
+++ b/software/messaging/src/test/java/brooklyn/entity/messaging/qpid/QpidIntegrationTest.java
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.entity.messaging.qpid;
+
+import static org.testng.Assert.*;
+
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.configuration.ClientProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.trait.Startable;
+import brooklyn.location.Location;
+import brooklyn.test.Asserts;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.HttpTestUtils;
+import brooklyn.test.entity.TestApplication;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.exceptions.Exceptions;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Test the operation of the {@link QpidBroker} class.
+ */
+public class QpidIntegrationTest {
+    private static final Logger log = LoggerFactory.getLogger(QpidIntegrationTest.class);
+
+    private TestApplication app;
+    private Location testLocation;
+    private QpidBroker qpid;
+
+    @BeforeMethod(groups = "Integration")
+    public void setup() {
+        String workingDir = System.getProperty("user.dir");
+        log.info("Qpid working dir: {}", workingDir);
+        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        testLocation = app.newLocalhostProvisioningLocation();
+    }
+
+    @AfterMethod(alwaysRun=true)
+    public void shutdown() {
+        if (app != null) Entities.destroyAll(app.getManagementContext());
+    }
+
+    /**
+     * Test that the broker starts up with JMX and RMI ports configured, and sets SERVICE_UP
correctly.
+     */
+    @Test(groups = "Integration")
+    public void canStartupAndShutdown() {
+        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
+                .configure("jmxPort", "9909+")
+                .configure("rmiRegistryPort", "9910+"));
+        qpid.start(ImmutableList.of(testLocation));
+        EntityTestUtils.assertAttributeEqualsEventually(qpid, Startable.SERVICE_UP, true);
+        qpid.stop();
+        assertFalse(qpid.getAttribute(Startable.SERVICE_UP));
+    }
+
+    /**
+     * Test that the broker starts up with HTTP management enabled, and we can connect to
the URL.
+     */
+    @Test(groups = "Integration")
+    public void canStartupAndShutdownWithHttpManagement() {
+        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
+                .configure("httpManagementPort", "8888"));
+        qpid.start(ImmutableList.of(testLocation));
+        EntityTestUtils.assertAttributeEqualsEventually(qpid, Startable.SERVICE_UP, true);
+        String httpUrl = "http://"+qpid.getAttribute(QpidBroker.HOSTNAME)+":"+qpid.getAttribute(QpidBroker.HTTP_MANAGEMENT_PORT)+"/";
+        HttpTestUtils.assertHttpStatusCodeEventuallyEquals(httpUrl, 200);
+        // TODO check actual REST output
+        qpid.stop();
+        assertFalse(qpid.getAttribute(Startable.SERVICE_UP));
+    }
+
+    /**
+     * Test that the broker starts up and sets SERVICE_UP correctly when plugins are configured.
+     * 
+     * FIXME the custom plugin was written against qpid 0.14, so that's the version we need
to run
+     * this test against. However, v0.14 is no longer available from the download site.
+     * We should update this plugin so it works with the latest qpid.
+     */
+    @Test(enabled = false, groups = "Integration")
+    public void canStartupAndShutdownWithPlugin() {
+        Map<String,String> qpidRuntimeFiles = MutableMap.<String,String>builder()
+                .put("classpath://qpid-test-config.xml", "etc/config.xml")
+                .put("classpath://qpid-test-plugin.jar", "lib/plugins/sample-plugin.jar")
+                .build();
+        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
+                .configure(SoftwareProcess.RUNTIME_FILES, qpidRuntimeFiles)
+                .configure(QpidBroker.SUGGESTED_VERSION, "0.14"));
+        qpid.start(ImmutableList.of(testLocation));
+        EntityTestUtils.assertAttributeEqualsEventually(qpid, Startable.SERVICE_UP, true);
+        qpid.stop();
+        assertFalse(qpid.getAttribute(Startable.SERVICE_UP));
+    }
+
+    /**
+     * Test that setting the 'queue' property causes a named queue to be created.
+     *
+     * This test is disabled, pending further investigation. Issue with AMQP 0-10 queue names.
+     * 
+     * FIXME disabled becausing failing in jenkins CI (in QpidIntegrationTest.getQpidConnection()).
+     *     url=amqp://admin:********@brooklyn/localhost?brokerlist='tcp://localhost:5672'
+     * Was previously enabled, dispite comment above about "test is disabled".	
+     */
+    @Test(enabled = false, groups = { "Integration", "WIP" })
+    public void testCreatingQueues() {
+        final String queueName = "testQueue";
+        final int number = 20;
+        final String content = "01234567890123456789012345678901";
+
+        // Start broker with a configured queue
+        // FIXME Can't use app.createAndManageChild, because of QpidDestination reffing impl
directly
+        qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
+                .configure("queue", queueName));
+        qpid.start(ImmutableList.of(testLocation));
+        EntityTestUtils.assertAttributeEqualsEventually(qpid, Startable.SERVICE_UP, true);
+
+        try {
+            // Check queue created
+            assertFalse(qpid.getQueueNames().isEmpty());
+            assertEquals(qpid.getQueueNames().size(), 1);
+            assertTrue(qpid.getQueueNames().contains(queueName));
+            assertEquals(qpid.getChildren().size(), 1);
+            assertFalse(qpid.getQueues().isEmpty());
+            assertEquals(qpid.getQueues().size(), 1);
+
+            // Get the named queue entity
+            final QpidQueue queue = qpid.getQueues().get(queueName);
+            assertNotNull(queue);
+
+            // Connect to broker using JMS and send messages
+            Connection connection = getQpidConnection(qpid);
+            clearQueue(connection, queue.getQueueName());
+            Asserts.succeedsEventually(new Runnable() {
+                @Override
+                public void run() {
+                    assertEquals(queue.getAttribute(QpidQueue.QUEUE_DEPTH_MESSAGES), Integer.valueOf(0));
+                }
+            });
+            sendMessages(connection, number, queue.getQueueName(), content);
+
+            // Check messages arrived
+            Asserts.succeedsEventually(new Runnable() {
+                @Override
+                public void run() {
+                    assertEquals(queue.getAttribute(QpidQueue.QUEUE_DEPTH_MESSAGES), Integer.valueOf(number));
+                    assertEquals(queue.getAttribute(QpidQueue.QUEUE_DEPTH_BYTES), Integer.valueOf(number
* content.length()));
+                }
+            });
+
+            //TODO clearing the queue currently returns 0
+//            // Clear the messages -- should get 20
+//            assertEquals clearQueue(connection, queue.queueName), 20
+//
+//            // Check messages cleared
+//            executeUntilSucceeds {
+//                assertEquals queue.getAttribute(QpidQueue.QUEUE_DEPTH_MESSAGES), 0
+//                assertEquals queue.getAttribute(QpidQueue.QUEUE_DEPTH_BYTES), 0
+//            }
+
+            // Close the JMS connection
+            connection.close();
+        } catch (JMSException jmse) {
+            log.warn("JMS exception caught", jmse);
+            throw Exceptions.propagate(jmse);
+        } finally {
+            // Stop broker
+            qpid.stop();
+            qpid = null;
+            app = null;
+        }
+    }
+
+    private Connection getQpidConnection(QpidBroker qpid) {
+        int port = qpid.getAttribute(Attributes.AMQP_PORT);
+        System.setProperty(ClientProperties.AMQP_VERSION, "0-10");
+        System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR");
+        String connectionUrl = String.format("amqp://admin:admin@brooklyn/localhost?brokerlist='tcp://localhost:%d'",
port);
+        try {
+            AMQConnectionFactory factory = new AMQConnectionFactory(connectionUrl);
+            Connection connection = factory.createConnection();
+            connection.start();
+            return connection;
+        } catch (Exception e) {
+            log.error(String.format("Error connecting to qpid: %s", connectionUrl), e);
+            throw Exceptions.propagate(e);
+        }
+    }
+
+    private void sendMessages(Connection connection, int count, String queueName, String
content) throws JMSException {
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue destination = session.createQueue(queueName);
+        MessageProducer messageProducer = session.createProducer(destination);
+
+        for (int i = 0; i < count; i++) {
+            TextMessage message = session.createTextMessage(content);
+            messageProducer.send(message);
+        }
+
+        session.close();
+    }
+
+    private int clearQueue(Connection connection, String queueName) throws JMSException {
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Queue destination = session.createQueue(queueName);
+        MessageConsumer messageConsumer = session.createConsumer(destination);
+
+        int received = 0;
+        while (messageConsumer.receive(500) != null) received++;
+
+        session.close();
+
+        return received;
+    }
+}


Mime
View raw message