DATACASS-73 - no longer assuming any port numbers are available

This commit is contained in:
Matthew Adams
2014-01-22 09:46:50 -06:00
parent ad40ac1c08
commit 03600bf451
18 changed files with 143 additions and 28 deletions

48
pom.xml
View File

@@ -230,6 +230,28 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>cassandra.native_transport_port</portName>
<portName>cassandra.rpc_port</portName>
<portName>cassandra.storage_port</portName>
<portName>cassandra.ssl_storage_port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
@@ -285,5 +307,31 @@
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</testResource>
<testResource>
<directory>../shared/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
</build>
</project>

View File

@@ -0,0 +1,2 @@
cassandra.native_transport_port=@cassandra.native_transport_port@
cassandra.rpc_port=@cassandra.rpc_port@

View File

@@ -8,6 +8,7 @@ import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cassandra.test.integration.support.BuildProperties;
import org.springframework.cassandra.test.unit.support.Utils;
import com.datastax.driver.core.Cluster;
@@ -22,9 +23,11 @@ public class AbstractEmbeddedCassandraIntegrationTest {
static Logger log = LoggerFactory.getLogger(AbstractEmbeddedCassandraIntegrationTest.class);
protected static final BuildProperties PROPS = new BuildProperties("/build.properties");
protected static final String CASSANDRA_CONFIG = "spring-cassandra.yaml";
protected static final String CASSANDRA_HOST = "localhost";
protected static final int CASSANDRA_NATIVE_PORT = 9042;
protected static final int CASSANDRA_NATIVE_PORT = PROPS.getInt("cassandra.native_transport_port");
/**
* The session connected to the system keyspace.

View File

@@ -1,10 +1,10 @@
package org.springframework.cassandra.test.integration.config.java;
import org.springframework.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.cassandra.test.integration.support.AbstractTestJavaConfig;
@Configuration
public class Config extends AbstractCassandraConfiguration {
public class Config extends AbstractTestJavaConfig {
@Override
protected String getKeyspaceName() {

View File

@@ -4,13 +4,13 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.cassandra.config.KeyspaceAttributes;
import org.springframework.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.KeyspaceOption;
import org.springframework.cassandra.test.integration.support.AbstractTestJavaConfig;
import org.springframework.context.annotation.Configuration;
@Configuration
public class KeyspaceCreatingJavaConfig extends AbstractCassandraConfiguration {
public class KeyspaceCreatingJavaConfig extends AbstractTestJavaConfig {
public static final String KEYSPACE_NAME = "foo";

View File

@@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.datastax.driver.core.Session;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@ContextConfiguration(locations = "classpath:/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest-context.xml")
public class XmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest {
public static final String KEYSPACE = "xmlconfigtest";

View File

@@ -0,0 +1,16 @@
package org.springframework.cassandra.test.integration.support;
import org.springframework.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.context.annotation.Configuration;
@Configuration
public abstract class AbstractTestJavaConfig extends AbstractCassandraConfiguration {
public static BuildProperties PROPS = new BuildProperties("/build.properties");
public static final int PORT = PROPS.getInt("cassandra.native_transport_port");
@Override
protected int getPort() {
return PORT;
}
}

View File

@@ -0,0 +1,45 @@
package org.springframework.cassandra.test.integration.support;
import java.io.InputStream;
import java.util.Properties;
@SuppressWarnings("serial")
public class BuildProperties extends Properties {
public BuildProperties() {
this("build.properties");
}
public BuildProperties(String resourceName) {
InputStream in = null;
try {
in = getClass().getResourceAsStream(resourceName);
if (in == null) {
return;
}
load(in);
} catch (Exception x) {
throw new RuntimeException(x);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
// gulp
}
}
}
}
public int getInt(String key) {
String property = getProperty(key);
return Integer.parseInt(property);
}
public boolean getBoolean(String key) {
return Boolean.parseBoolean(getProperty(key));
}
}

View File

@@ -9,7 +9,7 @@
</encoder>
</appender>
<logger name="org.springframework.context" level="info" />
<logger name="org.springframework.context" level="debug" />
<logger name="org.springframework.cassandra" level="info" />
<logger name="org.springframework.data.cassandra" level="info" />
<logger name="com.datastax" level="info" />

View File

@@ -8,9 +8,9 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.properties" />
location="classpath:build.properties,classpath:/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigTest.properties" />
<cass:cluster>
<cass:cluster port="${cassandra.native_transport_port}">
<cass:keyspace action="CREATE-DROP" durable-writes="true"
name="full1">
<cass:replication class="SimpleStrategy"

View File

@@ -7,7 +7,10 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<cass:cluster>
<context:property-placeholder
location="classpath:build.properties" />
<cass:cluster port="${cassandra.native_transport_port}">
<cass:keyspace action="CREATE-DROP" name="minimal" />
</cass:cluster>

View File

@@ -6,7 +6,10 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<cassandra:cluster port="9042" />
<context:property-placeholder
location="classpath:build.properties" />
<cassandra:cluster port="${cassandra.native_transport_port}" />
<cassandra:session keyspace-name="minimalxmlconfigtest" />

View File

@@ -6,8 +6,11 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder
location="classpath:build.properties" />
<cassandra:cluster id="cassandra-cluster"
contactPoints="localhost" port="9042">
contactPoints="localhost" port="${cassandra.native_transport_port}">
<cassandra:local-pooling-options
min-simultaneous-requests="25" max-simultaneous-requests="100"
core-connections="2" max-connections="8" />

View File

@@ -303,11 +303,11 @@ trickle_fsync: false
trickle_fsync_interval_in_kb: 10240
# TCP port, for commands and data
storage_port: 7000
storage_port: ${cassandra.storage_port}
# SSL port, for encrypted communication. Unused unless enabled in
# encryption_options
ssl_storage_port: 7001
ssl_storage_port: ${cassandra.ssl_storage_port}
# Address to bind to and tell other Cassandra nodes to connect to. You
# _must_ change this if you want multiple nodes to be able to
@@ -334,7 +334,7 @@ listen_address: localhost
# same as the rpc_address. The port however is different and specified below.
start_native_transport: true
# port for the CQL native transport to listen for clients on
native_transport_port: 9042
native_transport_port: ${cassandra.native_transport_port}
# The minimum and maximum threads for handling requests when the native
# transport is used. They are similar to rpc_min_threads and rpc_max_threads,
# though the defaults differ slightly.
@@ -352,7 +352,7 @@ start_rpc: true
# (i.e. it will be based on the configured hostname of the node).
rpc_address: localhost
# port for Thrift to listen for clients on
rpc_port: 9160
rpc_port: ${cassandra.rpc_port}
# enable or disable keepalive on rpc connections
rpc_keepalive: true

View File

@@ -11,7 +11,7 @@
location="classpath:/org/springframework/data/cassandra/test/integration/config/cassandra.properties" />
<cassandra:cluster id="cassandra-cluster"
contactPoints="${cassandra.contactPoints}" port="${cassandra.port}"
contactPoints="${cassandra.contactPoints}" port="${cassandra.native_transport_port}"
compression="SNAPPY">
<cassandra-base:local-pooling-options
min-simultaneous-requests="25" max-simultaneous-requests="100"

View File

@@ -1,7 +1,3 @@
cassandra.contactPoints=localhost
cassandra.port=9042
cassandra.native_transport_port=${cassandra.native_transport_port}
cassandra.keyspace=TestKS123

View File

@@ -13,7 +13,7 @@
location="classpath:/org/springframework/data/cassandra/test/integration/repository/cassandra.properties" />
<cassandra:cluster id="cassandra-cluster"
contactPoints="${cassandra.contactPoints}" port="${cassandra.port}"
contactPoints="${cassandra.contactPoints}" port="${cassandra.native_transport_port}"
compression="SNAPPY">
<cassandra-base:local-pooling-options
min-simultaneous-requests="25" max-simultaneous-requests="100"

View File

@@ -1,7 +1,3 @@
cassandra.contactPoints=localhost
cassandra.port=9042
cassandra.native_transport_port=${cassandra.native_transport_port}
cassandra.keyspace=TestKS123