activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1306555 - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/jetty/ apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/ apollo-broker/src/test/scala/ apollo-openwire/src/test/...
Date Wed, 28 Mar 2012 19:40:34 GMT
Author: chirino
Date: Wed Mar 28 19:40:33 2012
New Revision: 1306555

URL: http://svn.apache.org/viewvc?rev=1306555&view=rev
Log:
Refactor common test support bits that start a and help access a broker.

Added:
    activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala
Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/jetty/JettyWebServer.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala
    activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompTest.scala
    activemq/activemq-apollo/trunk/apollo-web/pom.xml
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/jetty/JettyWebServer.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/jetty/JettyWebServer.scala?rev=1306555&r1=1306554&r2=1306555&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/jetty/JettyWebServer.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/jetty/JettyWebServer.scala
Wed Mar 28 19:40:33 2012
@@ -138,6 +138,7 @@ class JettyWebServer(val broker:Broker) 
 
   val dispatch_queue = createQueue()
   var web_admins = List[WebAdminDTO]()
+  var uri_addresses = List[URI]()
 
   protected def _start(on_completed: Task) = Broker.BLOCKABLE_THREAD_POOL {
     this.synchronized {
@@ -250,8 +251,9 @@ class JettyWebServer(val broker:Broker) 
             case _ => "http"
           }
 
-          def url = new URI(scheme, null, connector.getHost, localPort, prefix, null, null).toString
-          broker.console_log.info("Administration interface available at: "+url)
+          val uri:URI = new URI(scheme, null, connector.getHost, localPort, prefix, null,
null)
+          broker.console_log.info("Administration interface available at: %s", uri)
+          uri_addresses ::= uri
         }
 
       }
@@ -265,11 +267,14 @@ class JettyWebServer(val broker:Broker) 
       if( server!=null ) {
         server.stop
         server = null
+        uri_addresses = Nil
       }
       on_completed.run
     }
   }
 
+  def uris() = uri_addresses.toArray
+
   def update(on_complete: Task) = dispatch_queue {
     import collection.JavaConversions._
     val new_list = broker.config.web_admins.toList

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala?rev=1306555&r1=1306554&r2=1306555&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala
Wed Mar 28 19:40:33 2012
@@ -19,6 +19,7 @@ package org.apache.activemq.apollo.broke
 import org.apache.activemq.apollo.util._
 import org.apache.activemq.apollo.broker.Broker
 import org.fusesource.hawtdispatch.Task
+import java.net.URI
 
 /**
  * <p>
@@ -28,6 +29,7 @@ import org.fusesource.hawtdispatch.Task
  */
 trait WebServer extends Service {
   def update(on_complete:Task):Unit
+  def uris():Array[URI]
 }
 
 trait WebServerFactory {

Added: activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala?rev=1306555&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/BrokerFunSuiteSupport.scala
Wed Mar 28 19:40:33 2012
@@ -0,0 +1,109 @@
+/**
+ * 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 org.apache.activemq.apollo.broker
+
+import org.apache.activemq.apollo.util.{ServiceControl, Logging, FunSuiteSupport}
+import java.net.InetSocketAddress
+import org.apache.activemq.apollo.dto.{QueueStatusDTO, TopicStatusDTO}
+import org.apache.activemq.apollo.util._
+import FileSupport._
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+class BrokerFunSuiteSupport extends FunSuiteSupport with Logging { // with ShouldMatchers
with BeforeAndAfterEach with Logging {
+  var broker: Broker = null
+  var port = 0
+
+  def broker_config_uri = "xml:classpath:apollo.xml"
+
+  def createBroker: Broker = {
+    info("Loading broker configuration from the classpath with URI: " + broker_config_uri)
+    var broker = BrokerFactory.createBroker(broker_config_uri)
+    broker.setTmp(basedir / "target" / "tmp")
+    broker.getTmp().mkdirs()
+    broker
+  }
+
+  override protected def beforeAll() = {
+    super.beforeAll()
+    try {
+      broker = createBroker
+      ServiceControl.start(broker)
+      port = broker.get_socket_address.asInstanceOf[InetSocketAddress].getPort
+    } catch {
+      case e: Throwable => e.printStackTrace
+    }
+  }
+
+  override protected def afterAll() = {
+    ServiceControl.stop(broker)
+    super.afterAll()
+  }
+
+  def connector_port(connector: String): Option[Int] = Option(connector).map {
+    id => broker.connectors.get(id).map(_.socket_address.asInstanceOf[InetSocketAddress].getPort).getOrElse(port)
+  }
+
+  def queue_exists(name: String): Boolean = {
+    val host = broker.default_virtual_host
+    host.dispatch_queue.future {
+      val router = host.router.asInstanceOf[LocalRouter]
+      router.local_queue_domain.destination_by_id.get(name).isDefined
+    }.await()
+  }
+
+  def topic_exists(name: String): Boolean = {
+    val host = broker.default_virtual_host
+    host.dispatch_queue.future {
+      val router = host.router.asInstanceOf[LocalRouter]
+      router.local_topic_domain.destination_by_id.get(name).isDefined
+    }.await()
+  }
+
+  def topic_status(name: String): TopicStatusDTO = {
+    val host = broker.default_virtual_host
+    sync(host) {
+      val router = host.router.asInstanceOf[LocalRouter]
+      router.local_topic_domain.destination_by_id.get(name).get.status
+    }
+  }
+
+  def queue_status(name: String): QueueStatusDTO = {
+    val host = broker.default_virtual_host
+    sync(host) {
+      val router = host.router.asInstanceOf[LocalRouter]
+      router.local_queue_domain.destination_by_id.get(name).get.status(false)
+    }
+  }
+
+  def dsub_status(name: String): QueueStatusDTO = {
+    val host = broker.default_virtual_host
+    sync(host) {
+      val router = host.router.asInstanceOf[LocalRouter]
+      router.local_dsub_domain.destination_by_id.get(name).get.status(false)
+    }
+  }
+
+  def webadmin_uri(scheme:String = "http") = {
+    Option(broker.web_server).flatMap(_.uris().find(_.getScheme == scheme)).get
+  }
+
+}

Modified: activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala?rev=1306555&r1=1306554&r2=1306555&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-openwire/src/test/scala/org/apache/activemq/apollo/openwire/OpenwireTestSupport.scala
Wed Mar 28 19:40:33 2012
@@ -20,35 +20,20 @@ package org.apache.activemq.apollo.openw
 import org.scalatest.matchers.ShouldMatchers
 import org.scalatest.BeforeAndAfterEach
 import java.lang.String
-import org.apache.activemq.apollo.broker.{Broker, BrokerFactory}
-import org.apache.activemq.apollo.util.{Logging, FunSuiteSupport, ServiceControl}
 import javax.jms.Connection
 import org.apache.activemq.ActiveMQConnectionFactory
 import org.apache.activemq.command.{ActiveMQTopic, ActiveMQQueue}
-import java.net.InetSocketAddress
+import org.apache.activemq.apollo.broker.BrokerFunSuiteSupport
 
-class OpenwireTestSupport extends FunSuiteSupport with ShouldMatchers with BeforeAndAfterEach
with Logging {
-  var broker: Broker = null
-  var port = 0
+class OpenwireTestSupport extends BrokerFunSuiteSupport with ShouldMatchers with BeforeAndAfterEach
{
 
-  def broker_config_uri = "xml:classpath:apollo-openwire.xml"
+  override def broker_config_uri = "xml:classpath:apollo-openwire.xml"
   val transport_scheme = "tcp"
   val transport_host = "localhost"
 
-  override protected def beforeAll() {
-    info("Loading broker configuration from the classpath with URI: " + broker_config_uri)
-    broker = BrokerFactory.createBroker(broker_config_uri)
-    ServiceControl.start(broker, "Starting broker")
-    port = broker.get_socket_address.asInstanceOf[InetSocketAddress].getPort
-  }
-
   var default_connection:Connection = _
   var connections = List[Connection]()
 
-  override protected def afterAll() {
-    ServiceControl.stop(broker)
-  }
-
   override protected def afterEach() {
     super.afterEach()
     connections.foreach(_.close())

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompTest.scala?rev=1306555&r1=1306554&r2=1306555&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompTest.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompTest.scala
Wed Mar 28 19:40:33 2012
@@ -19,52 +19,29 @@ package org.apache.activemq.apollo.stomp
 import org.scalatest.matchers.ShouldMatchers
 import org.scalatest.BeforeAndAfterEach
 import java.lang.String
-import org.fusesource.hawtdispatch._
-import org.apache.activemq.apollo.broker.{LocalRouter, KeyStorage, Broker, BrokerFactory}
 import java.util.concurrent.TimeUnit._
 import org.apache.activemq.apollo.util._
-import org.apache.activemq.apollo.dto.{QueueStatusDTO, TopicStatusDTO, KeyStorageDTO}
+import org.apache.activemq.apollo.dto.KeyStorageDTO
 import java.util.concurrent.atomic.AtomicLong
 import FileSupport._
-import java.net.{DatagramSocket, InetSocketAddress}
+import java.net.InetSocketAddress
 import java.nio.channels.DatagramChannel
 import org.fusesource.hawtbuf.AsciiBuffer
+import org.apache.activemq.apollo.broker._
 
-class StompTestSupport extends FunSuiteSupport with ShouldMatchers with BeforeAndAfterEach
with Logging {
-  var broker: Broker = null
-  var port = 0
+class StompTestSupport extends BrokerFunSuiteSupport with ShouldMatchers with BeforeAndAfterEach
{
 
-  val broker_config_uri = "xml:classpath:apollo-stomp.xml"
-
-  override protected def beforeAll() = {
-    try {
-      info("Loading broker configuration from the classpath with URI: " + broker_config_uri)
-      broker = BrokerFactory.createBroker(broker_config_uri)
-      ServiceControl.start(broker, "Starting broker")
-      port = broker.get_socket_address.asInstanceOf[InetSocketAddress].getPort
-    }
-    catch {
-      case e:Throwable => e.printStackTrace
-    }
-  }
+  override val broker_config_uri = "xml:classpath:apollo-stomp.xml"
 
   var client = new StompClient
   var clients = List[StompClient]()
 
-  override protected def afterAll() = {
-    ServiceControl.stop(broker, "Stopping broker")
-  }
-
   override protected def afterEach() = {
     super.afterEach
     clients.foreach(_.close)
     clients = Nil
   }
 
-  def connector_port(connector:String):Option[Int] = Option(connector).map { id =>
-    broker.connectors.get(id).map(_.socket_address.asInstanceOf[InetSocketAddress].getPort).getOrElse(port)
-  }
-  
   def connect_request(version:String, c: StompClient, headers:String="", connector:String=null)
= {
     val p = connector_port(connector).getOrElse(port)
     c.open("localhost", p)
@@ -173,47 +150,6 @@ class StompTestSupport extends FunSuiteS
     frame should startWith("RECEIPT\n")
     frame should include("receipt-id:"+id+"\n")
   }
-
-  def queue_exists(name:String):Boolean = {
-    val host = broker.default_virtual_host
-    host.dispatch_queue.future {
-      val router = host.router.asInstanceOf[LocalRouter]
-      router.local_queue_domain.destination_by_id.get(name).isDefined
-    }.await()
-  }
-
-  def topic_exists(name:String):Boolean = {
-    val host = broker.default_virtual_host
-    host.dispatch_queue.future {
-      val router = host.router.asInstanceOf[LocalRouter]
-      router.local_topic_domain.destination_by_id.get(name).isDefined
-    }.await()
-  }
-
-  def topic_status(name:String):TopicStatusDTO = {
-    val host = broker.default_virtual_host
-    sync(host) {
-      val router = host.router.asInstanceOf[LocalRouter]
-      router.local_topic_domain.destination_by_id.get(name).get.status
-    }
-  }
-
-  def queue_status(name:String):QueueStatusDTO = {
-    val host = broker.default_virtual_host
-    sync(host) {
-      val router = host.router.asInstanceOf[LocalRouter]
-      router.local_queue_domain.destination_by_id.get(name).get.status(false)
-    }
-  }
-
-  def dsub_status(name:String):QueueStatusDTO = {
-    val host = broker.default_virtual_host
-    sync(host) {
-      val router = host.router.asInstanceOf[LocalRouter]
-      router.local_dsub_domain.destination_by_id.get(name).get.status(false)
-    }
-  }
-
 }
 
 /**

Modified: activemq/activemq-apollo/trunk/apollo-web/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/pom.xml?rev=1306555&r1=1306554&r2=1306555&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/pom.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-web/pom.xml Wed Mar 28 19:40:33 2012
@@ -131,6 +131,13 @@
     </dependency>
     <dependency>
       <groupId>org.apache.activemq</groupId>
+      <artifactId>apollo-broker</artifactId>
+      <version>99-trunk-SNAPSHOT</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
       <artifactId>apollo-util</artifactId>
       <version>99-trunk-SNAPSHOT</version>
       <type>test-jar</type>

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala?rev=1306555&r1=1306554&r2=1306555&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
Wed Mar 28 19:40:33 2012
@@ -70,12 +70,12 @@ class BrokerResource() extends Resource 
     rc
   }
 
-  @Deprecated("The session resource should be used instead.")
+  @Deprecated()
   @GET
   @Path("/whoami")
   def whoami() = SessionResource().whoami()
 
-  @Deprecated("The session resource should be used instead.")
+  @Deprecated()
   @Produces(Array("text/html;qs=5"))
   @GET
   @Path("/signin")
@@ -85,19 +85,19 @@ class BrokerResource() extends Resource 
                       @QueryParam("target") target:String
                              ): ErrorDTO = SessionResource().get_signin_html(response, username,
password, target)
 
-  @Deprecated("The session resource should be used instead.")
+  @Deprecated()
   @POST
   @Path("/signin")
   def post_signin(@Context response:HttpServletResponse,
                   @FormParam("username") username:String,
-                  @FormParam("password") password:String):Boolean = SessionResource().post_signin(response,
username, password, target)
+                  @FormParam("password") password:String):Boolean = SessionResource().post_signin(response,
username, password)
 
-  @Deprecated("The session resource should be used instead.")
+  @Deprecated()
   @Produces(Array("text/html"))
   @GET @Path("/signout")
   def signout_html():String = SessionResource().signout_html()
 
-  @Deprecated("The session resource should be used instead.")
+  @Deprecated()
   @Produces(Array(APPLICATION_JSON, APPLICATION_XML, TEXT_XML))
   @GET @Path("/signout")
   def signout():String = SessionResource().signout()



Mime
View raw message