DATACASS-73 - merged into master

This commit is contained in:
Matthew Adams
2014-01-22 15:55:39 -06:00
23 changed files with 199 additions and 89 deletions

60
pom.xml
View File

@@ -230,6 +230,40 @@
<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>build.cassandra.native_transport_port</portName>
<portName>build.cassandra.rpc_port</portName>
<portName>build.cassandra.storage_port</portName>
<portName>build.cassandra.ssl_storage_port</portName>
</portNames>
</configuration>
</execution>
<execution>
<id>add-shared-source-dir</id>
<goals>
<goal>add-test-source</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<sources>
<source>../shared/src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
@@ -285,5 +319,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/src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
</build>
</project>

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();
public static final int PORT = PROPS.getCassandraPort();
@Override
protected int getPort() {
return PORT;
}
}

View File

@@ -0,0 +1,64 @@
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) {
loadProperties(resourceName);
}
public void loadProperties(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 getCassandraPort() {
return getInt("build.cassandra.native_transport_port");
}
public int getCassandraRpcPort() {
return getInt("build.cassandra.rpc_port");
}
public int getCassandraStoragePort() {
return getInt("build.cassandra.storage_port");
}
public int getCassandraSslStoragePort() {
return getInt("build.cassandra.ssl_storage_port");
}
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

@@ -0,0 +1,4 @@
build.cassandra.native_transport_port=@build.cassandra.native_transport_port@
build.cassandra.rpc_port=@build.cassandra.rpc_port@
build.cassandra.storage_port=@build.cassandra.storage_port@
build.cassandra.ssl_storage_port=@build.cassandra.ssl_storage_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();
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.getCassandraPort();
/**
* 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

@@ -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="${build.cassandra.native_transport_port}">
<cass:keyspace action="CREATE_DROP" durable-writes="true"
name="full1">
<cass:replication class="SIMPLE_STRATEGY">

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="${build.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="${build.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="${build.cassandra.native_transport_port}">
<cassandra:local-pooling-options
min-simultaneous-requests="25" max-simultaneous-requests="100"
core-connections="2" max-connections="8" />

View File

@@ -1,5 +1,5 @@
cluster.contactPoints=localhost
cluster.port=9042
cluster.port=@build.cassandra.native_transport_port@
cluster.compression=SNAPPY
cluster.deferredInit=true
cluster.metricsEnabled=false

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: ${build.cassandra.storage_port}
# SSL port, for encrypted communication. Unused unless enabled in
# encryption_options
ssl_storage_port: 7001
ssl_storage_port: ${build.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: ${build.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: ${build.cassandra.rpc_port}
# enable or disable keepalive on rpc connections
rpc_keepalive: true

View File

@@ -1,50 +0,0 @@
package org.springframework.data.cassandra.test.integration.config;
import java.io.IOException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
public class DriverTests {
@BeforeClass
public static void startCassandra() throws IOException, TTransportException, ConfigurationException,
InterruptedException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml");
}
@Test
public void test() throws Exception {
Cluster.Builder builder = Cluster.builder().addContactPoint("127.0.0.1");
// builder.withCompression(ProtocolOptions.Compression.SNAPPY);
Cluster cluster = builder.build();
Session session = cluster.connect();
session.shutdown();
cluster.shutdown();
}
@After
public void clearCassandra() {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
@AfterClass
public static void stopCassandra() {
EmbeddedCassandraServerHelper.stopEmbeddedCassandra();
}
}

View File

@@ -1,5 +1,6 @@
package org.springframework.data.cassandra.test.integration.config;
import org.springframework.cassandra.test.integration.support.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.java.AbstractSpringDataCassandraConfiguration;
@@ -18,11 +19,20 @@ import org.springframework.data.cassandra.mapping.CassandraMappingContext;
@Configuration
public class TestConfig extends AbstractSpringDataCassandraConfiguration {
public static final String keyspaceName = "test";
public static final BuildProperties PROPS = new BuildProperties();
public static final int PORT = PROPS.getCassandraPort();
public static final int RPC_PORT = PROPS.getCassandraRpcPort();
public static final String KEYSPACE_NAME = "test";
@Override
protected String getKeyspaceName() {
return keyspaceName;
return KEYSPACE_NAME;
}
@Override
protected int getPort() {
return PORT;
}
@Bean
@@ -32,6 +42,6 @@ public class TestConfig extends AbstractSpringDataCassandraConfiguration {
@Bean
public CassandraDataOperations cassandraDataTemplate() throws Exception {
return new CassandraDataTemplate(session().getObject(), converter(), keyspaceName);
return new CassandraDataTemplate(session().getObject(), converter(), KEYSPACE_NAME);
}
}

View File

@@ -63,7 +63,7 @@ public class CassandraAdminTest {
/*
* Load data file to creat the test keyspace before we init the template
*/
DataLoader dataLoader = new DataLoader("Test Cluster", "localhost:9160");
DataLoader dataLoader = new DataLoader("Test Cluster", "localhost:" + TestConfig.RPC_PORT);
dataLoader.load(new ClassPathYamlDataSet("cassandra-keyspace.yaml"));
}
@@ -74,7 +74,7 @@ public class CassandraAdminTest {
/*
* Load data file to creat the test keyspace before we init the template
*/
DataLoader dataLoader = new DataLoader("Test Cluster", "localhost:9160");
DataLoader dataLoader = new DataLoader("Test Cluster", "localhost:" + TestConfig.RPC_PORT);
dataLoader.load(new ClassPathYamlDataSet("cassandra-keyspace.yaml"));
}

View File

@@ -40,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cassandra.core.ConsistencyLevel;
import org.springframework.cassandra.core.QueryOptions;
import org.springframework.cassandra.core.RetryPolicy;
import org.springframework.cassandra.test.integration.support.BuildProperties;
import org.springframework.data.cassandra.core.CassandraDataOperations;
import org.springframework.data.cassandra.test.integration.config.TestConfig;
import org.springframework.data.cassandra.test.integration.table.Book;
@@ -65,11 +66,12 @@ public class CassandraDataOperationsTest {
private static Logger log = LoggerFactory.getLogger(CassandraDataOperationsTest.class);
private final static BuildProperties PROPS = new BuildProperties();
private final static String CASSANDRA_CONFIG = "cassandra.yaml";
private final static String KEYSPACE_NAME = "test";
private final static String CASSANDRA_HOST = "localhost";
private final static int CASSANDRA_NATIVE_PORT = 9042;
private final static int CASSANDRA_THRIFT_PORT = 9160;
private final static int CASSANDRA_NATIVE_PORT = PROPS.getCassandraPort();
private final static int CASSANDRA_THRIFT_PORT = PROPS.getCassandraRpcPort();
@Rule
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet("cql-dataload.cql",

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: ${build.cassandra.storage_port}
# SSL port, for encrypted communication. Unused unless enabled in
# encryption_options
ssl_storage_port: 7001
ssl_storage_port: ${build.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: ${build.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: ${build.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="${build.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=${build.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="${build.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=${build.cassandra.native_transport_port}
cassandra.keyspace=TestKS123