use dynamic port for cassandra testing
authorOlivier Lamy <olamy@apache.org>
Mon, 10 Jun 2013 10:44:06 +0000 (10:44 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 10 Jun 2013 10:44:06 +0000 (10:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/sandbox/trunk@1491404 13f79535-47bb-0310-9956-ffa450edef68

metadata-store-cassandra/pom.xml
metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java

index 3390b03..80028d5 100644 (file)
           </instructions>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>reserve-ports</id>
+            <phase>process-test-resources</phase>
+            <goals>
+              <goal>reserve-network-port</goal>
+            </goals>
+            <configuration>
+              <portNames>
+                <portName>cassandraPort</portName>
+              </portNames>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
       <!-- TODO use dynamic port -->
 
       <plugin>
             <goals>
               <goal>start</goal>
             </goals>
+            <configuration>
+              <rpcPort>${cassandraPort}</rpcPort>
+            </configuration>
           </execution>
           <execution>
             <id>stop-cassandra</id>
         </dependencies>
       </plugin>
     </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <configuration>
+            <systemPropertyVariables>
+              <cassandraPort>${cassandraPort}</cassandraPort>
+            </systemPropertyVariables>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
   </build>
 
   <repositories>
index faadc15..2f4f6ac 100644 (file)
@@ -60,14 +60,14 @@ public class DefaultCassandraEntityManagerFactory
     public void initialize()
         throws ConnectionException
     {
-
+        String cassandraPort = System.getProperty( "cassandraPort" );
         keyspaceContext = new AstyanaxContext.Builder().forCluster( CLUSTER_NAME ).forKeyspace(
             KEYSPACE_NAME ).withAstyanaxConfiguration(
             new AstyanaxConfigurationImpl().setDiscoveryType( NodeDiscoveryType.RING_DESCRIBE ).setConnectionPoolType(
                 ConnectionPoolType.TOKEN_AWARE ) ).withConnectionPoolConfiguration(
             new ConnectionPoolConfigurationImpl( CLUSTER_NAME + "_" + KEYSPACE_NAME ).setSocketTimeout(
                 30000 ).setMaxTimeoutWhenExhausted( 2000 ).setMaxConnsPerHost( 20 ).setInitConnsPerHost( 10 ).setSeeds(
-                "localhost:9160" ) ).withConnectionPoolMonitor( new CountingConnectionPoolMonitor() ).buildKeyspace(
+                "localhost:"+ cassandraPort ) ).withConnectionPoolMonitor( new CountingConnectionPoolMonitor() ).buildKeyspace(
             ThriftFamilyFactory.getInstance() );
 
         keyspaceContext.start();