DATACASS-381 - Improve integration test stability.

Reuse Thread pools during integration test runs to not recreate and dispose Threads multiple times. Increase build and Cassandra memory. Use an external Cassandra instance for TravisCI build jobs.
This commit is contained in:
Mark Paluch
2017-01-19 16:44:40 +01:00
parent 49436f867f
commit efba60b72f
16 changed files with 112 additions and 63 deletions

View File

@@ -4,6 +4,8 @@ jdk:
- oraclejdk8
env:
global:
- CASSANDRA_VERSION=3.9
matrix:
- PROFILE=ci
- PROFILE=ci CASSANDRA_DRIVER_VERSION=3.0.3
@@ -11,10 +13,10 @@ env:
- PROFILE=spring43
- PROFILE=spring43-next
- PROFILE=spring5-next
- PROFILE=external-cassandra CASSANDRA_VERSION=2.2.8
- PROFILE=external-cassandra CASSANDRA_VERSION=3.0.10
- PROFILE=external-cassandra CASSANDRA_VERSION=3.2.1
- PROFILE=external-cassandra CASSANDRA_VERSION=3.9
- CASSANDRA_VERSION=2.2.8
- CASSANDRA_VERSION=3.0.10
- CASSANDRA_VERSION=3.2.1
- CASSANDRA_VERSION=3.9
addons:
apt:
@@ -36,7 +38,7 @@ install: if [ ! -z ${CASSANDRA_VERSION+x} ]; then ./setup-cassandra.sh; fi;
script:
- |
if [ ! -z ${CASSANDRA_DRIVER_VERSION+x} ]; then
mvn clean install -P${PROFILE} -Dcassandra-driver.version=${CASSANDRA_DRIVER_VERSION} -Dmaven.javadoc.skip=true
mvn clean install -P${PROFILE},external-cassandra -Dcassandra-driver.version=${CASSANDRA_DRIVER_VERSION} -Dmaven.javadoc.skip=true
else
mvn clean install -P${PROFILE} -Dmaven.javadoc.skip=true
mvn clean install -P${PROFILE},external-cassandra -Dmaven.javadoc.skip=true
fi

View File

@@ -294,7 +294,7 @@
<version>${failsafe.version}</version>
<configuration>
<forkCount>1</forkCount>
<argLine>-Xms1g -Xmx1g -Xss256k</argLine>
<argLine>-Xms1g -Xmx1500m -Xss256k</argLine>
<reuseForks>true</reuseForks>
<useFile>false</useFile>
<includes>

View File

@@ -47,8 +47,8 @@ rm -Rf data
mkdir -p data
echo "[INFO] Starting Apache Cassandra ${CASSANDRA_VERSION}"
export MAX_HEAP_SIZE=1G
export HEAP_NEWSIZE=100M
export MAX_HEAP_SIZE=1500M
export HEAP_NEWSIZE=300M
bin/cassandra
for start in {1..20}

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.config;
import static org.assertj.core.api.Assertions.*;

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cassandra.test.integration;
import static org.springframework.cassandra.test.integration.CassandraRule.InvocationMode.*;
@@ -28,7 +27,7 @@ import org.junit.rules.ExternalResource;
import org.springframework.cassandra.core.SessionCallback;
import org.springframework.cassandra.test.integration.support.CassandraConnectionProperties;
import org.springframework.cassandra.test.integration.support.CqlDataSet;
import org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions;
import org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.dao.DataAccessException;
import org.springframework.util.Assert;
import org.springframework.util.SocketUtils;
@@ -332,7 +331,7 @@ public class CassandraRule extends ExternalResource {
.withQueryOptions(queryOptions) //
.withMaxSchemaAgreementWaitSeconds(3) //
.withSocketOptions(socketOptions) //
.withNettyOptions(FastShutdownNettyOptions.INSTANCE) //
.withNettyOptions(IntegrationTestNettyOptions.INSTANCE) //
.build();
if (properties.getBoolean("build.cassandra.reuse-cluster")) {

View File

@@ -21,7 +21,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cassandra.config.CassandraCqlClusterFactoryBean;
import org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions;
import org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.test.util.ReflectionTestUtils;
import com.datastax.driver.core.ProtocolVersion;
@@ -49,7 +49,7 @@ public class CassandraCqlClusterFactoryBeanIntegrationTests {
@Test
public void configuredProtocolVersionShouldBeSet() throws Exception {
cassandraCqlClusterFactoryBean.setNettyOptions(FastShutdownNettyOptions.INSTANCE);
cassandraCqlClusterFactoryBean.setNettyOptions(IntegrationTestNettyOptions.INSTANCE);
cassandraCqlClusterFactoryBean.setProtocolVersion(ProtocolVersion.V2);
cassandraCqlClusterFactoryBean.afterPropertiesSet();

View File

@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.cassandra.config.java.AbstractCqlTemplateConfiguration;
import org.springframework.cassandra.core.CqlTemplate;
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
import org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions;
import org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -55,7 +55,7 @@ public class CqlTemplateConfigIntegrationTests extends AbstractEmbeddedCassandra
@Override
protected NettyOptions getNettyOptions() {
return FastShutdownNettyOptions.INSTANCE;
return IntegrationTestNettyOptions.INSTANCE;
}
}

View File

@@ -39,7 +39,7 @@ public abstract class AbstractTestJavaConfig extends AbstractSessionConfiguratio
@Override
protected NettyOptions getNettyOptions() {
return FastShutdownNettyOptions.INSTANCE;
return IntegrationTestNettyOptions.INSTANCE;
}
@Override

View File

@@ -1,38 +0,0 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed 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.springframework.cassandra.test.integration.support;
import io.netty.channel.EventLoopGroup;
import java.util.concurrent.TimeUnit;
import com.datastax.driver.core.NettyOptions;
/**
* {@link NettyOptions} to shutdown a {@link com.datastax.driver.core.Cluster} instance without wait time.
*
* @author Mark Paluch
* @since 1.5
*/
public class FastShutdownNettyOptions extends NettyOptions {
public final static FastShutdownNettyOptions INSTANCE = new FastShutdownNettyOptions();
@Override
public void onClusterClose(EventLoopGroup eventLoopGroup) {
eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS);
}
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed 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.springframework.cassandra.test.integration.support;
import io.netty.channel.EventLoopGroup;
import io.netty.util.Timer;
import java.util.concurrent.ThreadFactory;
import com.datastax.driver.core.NettyOptions;
/**
* {@link NettyOptions} to for Integration tests a {@link com.datastax.driver.core.Cluster}. This class caches and
* reuses (on a best-effort basis) {@link EventLoopGroup} and {@link Timer} instances during the tests. Caching reduces
* thread disposal that leads to a overall improved resource reusage during tests.
*
* @author Mark Paluch
* @since 1.5
*/
public class IntegrationTestNettyOptions extends NettyOptions {
public final static IntegrationTestNettyOptions INSTANCE = new IntegrationTestNettyOptions();
private volatile static EventLoopGroup eventLoopGroup;
private volatile static Timer timer;
@Override
public EventLoopGroup eventLoopGroup(final ThreadFactory threadFactory) {
if (eventLoopGroup != null) {
return eventLoopGroup;
}
EventLoopGroup eventLoopGroup = super.eventLoopGroup(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = threadFactory.newThread(r);
thread.setDaemon(true);
return thread;
}
});
IntegrationTestNettyOptions.eventLoopGroup = eventLoopGroup;
return eventLoopGroup;
}
@Override
public Timer timer(ThreadFactory threadFactory) {
if (timer != null) {
return timer;
}
final Timer timer = super.timer(threadFactory);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
timer.stop();
}
}));
IntegrationTestNettyOptions.timer = timer;
return timer;
}
@Override
public void onClusterClose(EventLoopGroup eventLoopGroup) {}
@Override
public void onClusterClose(Timer timer) {}
}

View File

@@ -10,7 +10,7 @@
<context:property-placeholder
location="classpath:/config/cassandra-connection.properties,classpath:/org/springframework/cassandra/test/integration/config/xml/FullySpecifiedKeyspaceCreatingXmlConfigIntegrationTests.properties" />
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions" />
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions"/>
<cass:cluster port="${build.cassandra.native_transport_port}" compression="LZ4" netty-options-ref="nettyOptions">
<cass:keyspace action="CREATE_DROP" durable-writes="true"

View File

@@ -12,6 +12,8 @@
<context:property-placeholder
location="classpath:/org/springframework/cassandra/test/integration/config/xml/ppncxct.properties"/>
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions"/>
<bean id="authProvider" class="com.datastax.driver.core.PlainTextAuthProvider">
<constructor-arg index="0" value="foo" />
<constructor-arg index="1" value="bar" />
@@ -44,7 +46,7 @@
pool-timeout-milliseconds="${cluster.poolingoptions.pooltimeoutmilliseconds}"
reconnection-policy-ref="reconnectionPolicy"
retry-policy-ref="retryPolicy"
username="${auth.username}" password="${auth.password}">
username="${auth.username}" password="${auth.password}" netty-options-ref="nettyOptions">
<cassandra:local-pooling-options
core-connections="${local.core.connections}"
max-connections="${local.max.connections}"

View File

@@ -23,7 +23,7 @@
<bean name="testTimestampGenerator" class="com.datastax.driver.core.AtomicMonotonicTimestampGenerator"/>
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions" />
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions"/>
<cassandra:cluster
cluster-name="skynet" contact-points="localhost" port="${build.cassandra.native_transport_port}"

View File

@@ -24,7 +24,7 @@ import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
import org.springframework.cassandra.support.RandomKeySpaceName;
import org.springframework.cassandra.test.integration.support.CassandraConnectionProperties;
import org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions;
import org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
@@ -64,7 +64,7 @@ public class IntegrationTestConfig extends AbstractCassandraConfiguration {
@Override
protected NettyOptions getNettyOptions() {
return FastShutdownNettyOptions.INSTANCE;
return IntegrationTestNettyOptions.INSTANCE;
}
@Override

View File

@@ -13,7 +13,7 @@
<constructor-arg value="#{T(org.springframework.cassandra.support.RandomKeySpaceName).create()}"/>
</bean>
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions" />
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions"/>
<context:property-placeholder location="classpath:/config/cassandra-connection.properties"/>

View File

@@ -7,7 +7,7 @@
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">
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.FastShutdownNettyOptions" />
<bean id="nettyOptions" class="org.springframework.cassandra.test.integration.support.IntegrationTestNettyOptions"/>
<context:property-placeholder
location="classpath:/config/cassandra-connection.properties,classpath:/org/springframework/data/cassandra/config/xml/cassandra.properties" />