You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2010/11/12 14:06:08 UTC

svn commit: r1034386 - in /activemq/activemq-apollo/trunk: apollo-cassandra/src/test/scala/org/apache/activemq/apollo/store/cassandra/ apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/ apollo-stomp/src/test/scala/org/apache/activemq/apollo/...

Author: chirino
Date: Fri Nov 12 13:06:07 2010
New Revision: 1034386

URL: http://svn.apache.org/viewvc?rev=1034386&view=rev
Log:
basedir is now set more intelligently.

Modified:
    activemq/activemq-apollo/trunk/apollo-cassandra/src/test/scala/org/apache/activemq/apollo/store/cassandra/CassandraServerMixin.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/StompTest.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala
    activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FileSupportTest.scala
    activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala

Modified: activemq/activemq-apollo/trunk/apollo-cassandra/src/test/scala/org/apache/activemq/apollo/store/cassandra/CassandraServerMixin.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cassandra/src/test/scala/org/apache/activemq/apollo/store/cassandra/CassandraServerMixin.scala?rev=1034386&r1=1034385&r2=1034386&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cassandra/src/test/scala/org/apache/activemq/apollo/store/cassandra/CassandraServerMixin.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-cassandra/src/test/scala/org/apache/activemq/apollo/store/cassandra/CassandraServerMixin.scala Fri Nov 12 13:06:07 2010
@@ -25,57 +25,53 @@ import org.apache.thrift.transport.{TTra
 import com.shorrockin.cascal.session._
 import com.shorrockin.cascal.utils.{Utils, Logging}
 import org.scalatest.{Suite, BeforeAndAfterAll}
+import org.apache.activemq.apollo.util.{FileSupport, FunSuiteSupport}
+import FileSupport._
 
 /**
  * trait which mixes in the functionality necessary to embed
  * cassandra into a unit test
  */
-trait CassandraServerMixin extends BeforeAndAfterAll {
+trait CassandraServerMixin extends FunSuiteSupport with BeforeAndAfterAll {
 this: Suite =>
 
-  private var basedir = "target"
-
   override protected def beforeAll(configMap: Map[String, Any]): Unit = {
-    configMap.get("basedir") match {
-      case Some(x) => basedir = x.toString
-      case _ =>
-    }
-    startCassandra
+    start_cassandra
     super.beforeAll(configMap)
   }
 
   override protected def afterAll(configMap: Map[String, Any]) = {
     super.afterAll(configMap)
-    stopCassandra
+    stop_cassandra
   }
 
 
   import Utils._
 
-  protected def cassandraHomeDirectory = new File(new File(basedir),"cassandra.home.unit-tests")
+  protected def cassandra_home = test_data_dir / "cassandra-data"
   protected def resource(str:String) = getClass.getResourceAsStream(str)
 
   private var daemon:CassandraDaemon = null
   var pool:SessionPool = null
-  var daemonThread:Thread = null
+  var daemon_thread:Thread = null
 
-  private def startCassandra = synchronized {
+  private def start_cassandra = synchronized {
     val hosts  = Host("localhost", 9160, 250) :: Nil
     val params = new PoolParams(10, ExhaustionPolicy.Fail, 500L, 6, 2)
     pool = new SessionPool(hosts, params, Consistency.One)
 
-    val home = cassandraHomeDirectory
+    val home = cassandra_home
     delete(home)
     home.mkdirs
 
-    val fileSep     = System.getProperty("file.separator")
-    val storageFile = new File(cassandraHomeDirectory, "storage-conf.xml")
-    val logFile     = new File(cassandraHomeDirectory, "log4j.properties")
+    val file_sep     = System.getProperty("file.separator")
+    val storage_file = new File(cassandra_home, "storage-conf.xml")
+    val log_file     = new File(cassandra_home, "log4j.properties")
 
-    replace(copy(resource("storage-conf.xml"), storageFile), ("%temp-dir%" -> (cassandraHomeDirectory.getCanonicalPath + fileSep)))
-    copy(resource("log4j.properties"), logFile)
+    replace(copy(resource("storage-conf.xml"), storage_file), ("%temp-dir%" -> (cassandra_home.getCanonicalPath + file_sep)))
+    copy(resource("log4j.properties"), log_file)
 
-    System.setProperty("storage-config", cassandraHomeDirectory.getCanonicalPath)
+    System.setProperty("storage-config", cassandra_home.getCanonicalPath)
 
     try {
       DatabaseDescriptor.getAllDataFileLocations.foreach {
@@ -86,12 +82,12 @@ this: Suite =>
       daemon = new CassandraDaemon
       daemon.init(new Array[String](0))
 
-      daemonThread = new Thread("Cassandra Daemon") {
+      daemon_thread = new Thread("Cassandra Daemon") {
         override def run = {
           daemon.start
         }
       }
-      daemonThread.start
+      daemon_thread.start
       
     } catch {
       case e:Throwable =>
@@ -115,11 +111,11 @@ this: Suite =>
     }
   }
 
-  private def stopCassandra() = {
+  private def stop_cassandra() = {
     pool.close
     daemon.stop
-    daemonThread.join
-    daemonThread = null
+    daemon_thread.join
+    daemon_thread = null
 
     daemon.destroy
     daemon = null

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=1034386&r1=1034385&r2=1034386&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 Fri Nov 12 13:06:07 2010
@@ -409,7 +409,7 @@ class StompSslDestinationTest extends St
   override val broker_config_uri: String = "xml:classpath:apollo-stomp-ssl.xml"
 
   client.key_storeage = new KeyStorage
-  client.key_storeage.config.file = baseDir/"src"/"test"/"resources"/"client.ks"
+  client.key_storeage.config.file = basedir/"src"/"test"/"resources"/"client.ks"
   client.key_storeage.config.password = "password"
 
 }

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala?rev=1034386&r1=1034385&r2=1034386&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/perf/StompBrokerPerfTest.scala Fri Nov 12 13:06:07 2010
@@ -54,7 +54,7 @@ trait HawtDBScenario extends PersistentS
   override def createBrokerConfig(name: String, bindURI: String, connectUri: String): BrokerDTO = {
     val rc = super.createBrokerConfig(name, bindURI, connectUri)
     val store = new HawtDBStoreDTO
-    storeDirectory = new File(new File(testDataDir, getClass.getName), name)
+    storeDirectory = new File(new File(test_data_dir, getClass.getName), name)
     store.directory = storeDirectory
     rc.virtual_hosts.get(0).store = store
     rc
@@ -65,7 +65,7 @@ trait BDBScenario extends PersistentScen
   override def createBrokerConfig(name: String, bindURI: String, connectUri: String): BrokerDTO = {
     val rc = super.createBrokerConfig(name, bindURI, connectUri)
     val store = new BDBStoreDTO
-    storeDirectory = new File(new File(testDataDir, getClass.getName), name)
+    storeDirectory = new File(new File(test_data_dir, getClass.getName), name)
     store.directory = storeDirectory
     rc.virtual_hosts.get(0).store = store
     rc

Modified: activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FileSupportTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FileSupportTest.scala?rev=1034386&r1=1034385&r2=1034386&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FileSupportTest.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FileSupportTest.scala Fri Nov 12 13:06:07 2010
@@ -25,7 +25,7 @@ class FileSupportTest extends FunSuiteSu
 
   test("recursive file copy test") {
 
-    val base = new Directory(baseDir)
+    val base = new Directory(basedir)
     var target = base / FileSupport.toDirectory("target")
 
     val sourceDir: Directory = target / FileSupport.toDirectory("sourceDir")
@@ -55,9 +55,9 @@ class FileSupportTest extends FunSuiteSu
 
 
     
-    var expected = (new File(baseDir)/"target"/"targetDir"/"subDir").normalize.toString
+    var expected = (new File(basedir)/"target"/"targetDir"/"subDir").normalize.toString
     listing should contain( expected )
-    expected = (new File(baseDir)/"target"/"targetDir"/"subDir"/"someFile").normalize.toString
+    expected = (new File(basedir)/"target"/"targetDir"/"subDir"/"someFile").normalize.toString
     listing should contain(expected)
 
   }

Modified: activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala?rev=1034386&r1=1034385&r2=1034386&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-util/src/test/scala/org/apache/activemq/apollo/util/FunSuiteSupport.scala Fri Nov 12 13:06:07 2010
@@ -23,36 +23,48 @@ import java.io.File
 import java.lang.String
 import collection.immutable.Map
 import org.scalatest._
+import FileSupport._
 
 /**
  * @version $Revision : 1.1 $
  */
 @RunWith(classOf[JUnitRunner])
 abstract class FunSuiteSupport extends FunSuite with Logging with BeforeAndAfterAll {
-  protected var _basedir = "."
-
+  protected var _basedir = try {
+    var file = new File(getClass.getProtectionDomain.getCodeSource.getLocation.getFile)
+    file = (file / ".." / "..").getCanonicalFile
+    if( file.isDirectory ) {
+      file.getPath
+    } else {
+      "."
+    }
+  } catch {
+    case x=>
+      "."
+  }
 
   /**
    * Returns the base directory of the current project
    */
-  def baseDir = {
+  def basedir = {
     new File(_basedir).getCanonicalFile
   }
 
   /**
    * Returns ${basedir}/target/test-data
    */
-  def testDataDir = {
+  def test_data_dir = {
     new File(new File(_basedir, "target"), "test-data")
   }
 
   override protected def beforeAll(map: Map[String, Any]): Unit = {
     _basedir = map.get("basedir") match {
-      case Some(basedir) => basedir.toString
-      case _ => System.getProperty("basedir", ".")
+      case Some(basedir) =>
+        basedir.toString
+      case _ =>
+        System.getProperty("basedir", _basedir)
     }
     System.setProperty("basedir", _basedir)
-    debug("using basedir: " + _basedir)
     super.beforeAll(map)
   }