DATACASS-238 - Add Cluster configuration options.
We now support configuration of the cluster name, AddressTranslator, MaxSchemaAgreementWaitSeconds, SpeculativeExecutionPolicy and TimestampGenerator in the Cassandra Cluster factory. The cluster name is derived from the bean name, if not configured otherwise. Related tickets: DATACASS-120, DATACASS-316, DATACASS-317, DATACASS-319, DATACASS-320. Original pull request: #79. Related pull request: #80.
This commit is contained in:
@@ -18,35 +18,44 @@ package org.springframework.cassandra.config;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.datastax.driver.core.AuthProvider;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Configuration;
|
||||
import com.datastax.driver.core.JdkSSLOptions;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SSLOptions;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.LoadBalancingPolicy;
|
||||
import com.datastax.driver.core.policies.Policies;
|
||||
import com.datastax.driver.core.policies.ReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.RoundRobinPolicy;
|
||||
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CassandraCqlClusterFactoryBean}.
|
||||
*
|
||||
* @see DATACASS-226
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
*/
|
||||
public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -62,7 +71,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -76,7 +85,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -92,7 +101,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -108,7 +117,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -124,7 +133,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -140,7 +149,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -156,7 +165,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -172,8 +181,8 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see DATACASS-263
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-263">DATACASS-263</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -190,8 +199,8 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see DATACASS-263
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-263">DATACASS-263</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -209,7 +218,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -225,7 +234,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -241,7 +250,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -256,7 +265,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -273,7 +282,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -287,7 +296,7 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226">DATACASS-226</a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -300,6 +309,119 @@ public class CassandraCqlClusterFactoryBeanUnitTests {
|
||||
assertThat(getConfiguration(bean).getMetricsOptions().isJMXReportingEnabled(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-316">DATACASS-316</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetAddressTranslator() throws Exception {
|
||||
|
||||
AddressTranslator mockAddressTranslator = mock(AddressTranslator.class);
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
|
||||
|
||||
bean.setAddressTranslator(mockAddressTranslator);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getPolicies(bean).getAddressTranslator(), is(equalTo(mockAddressTranslator)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-317">DATACASS-317</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetClusterNameWithBeanNameProperty() throws Exception {
|
||||
|
||||
final Cluster.Builder mockClusterBuilder = mock(Cluster.Builder.class);
|
||||
|
||||
when(mockClusterBuilder.addContactPoints(Matchers.<String[]>anyVararg())).thenReturn(mockClusterBuilder);
|
||||
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean() {
|
||||
@Override Cluster.Builder newClusterBuilder() {
|
||||
return mockClusterBuilder;
|
||||
}
|
||||
};
|
||||
|
||||
bean.setBeanName("ABC");
|
||||
bean.setClusterName(" ");
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
verify(mockClusterBuilder, times(1)).withClusterName(eq("ABC"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-317">DATACASS-317</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetClusterNameWithClusterNameProperty() throws Exception {
|
||||
|
||||
final Cluster.Builder mockClusterBuilder = mock(Cluster.Builder.class);
|
||||
|
||||
when(mockClusterBuilder.addContactPoints(Matchers.<String[]>anyVararg())).thenReturn(mockClusterBuilder);
|
||||
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean() {
|
||||
@Override Cluster.Builder newClusterBuilder() {
|
||||
return mockClusterBuilder;
|
||||
}
|
||||
};
|
||||
|
||||
bean.setBeanName("ABC");
|
||||
bean.setClusterName("XYZ");
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
verify(mockClusterBuilder, times(1)).withClusterName(eq("XYZ"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-319">DATACASS-319</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetMaxSchemaAgreementWaitSeconds() throws Exception {
|
||||
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
|
||||
|
||||
bean.setMaxSchemaAgreementWaitSeconds(20);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getProtocolOptions(bean).getMaxSchemaAgreementWaitSeconds(), is(equalTo(20)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-320">DATACASS-320</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetSpeculativeExecutionPolicy() throws Exception {
|
||||
|
||||
SpeculativeExecutionPolicy mockSpeculativeExecutionPolicy = mock(SpeculativeExecutionPolicy.class);
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
|
||||
|
||||
bean.setSpeculativeExecutionPolicy(mockSpeculativeExecutionPolicy);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getPolicies(bean).getSpeculativeExecutionPolicy(), is(equalTo(mockSpeculativeExecutionPolicy)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-238">DATACASS-238</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetTimestampGenerator() throws Exception {
|
||||
|
||||
TimestampGenerator mockTimestampGenerator = mock(TimestampGenerator.class);
|
||||
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
|
||||
|
||||
bean.setTimestampGenerator(mockTimestampGenerator);
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThat(getPolicies(bean).getTimestampGenerator(), is(equalTo(mockTimestampGenerator)));
|
||||
}
|
||||
|
||||
private Policies getPolicies(CassandraCqlClusterFactoryBean bean) throws Exception {
|
||||
return getConfiguration(bean).getPolicies();
|
||||
}
|
||||
|
||||
private ProtocolOptions getProtocolOptions(CassandraCqlClusterFactoryBean bean) throws Exception {
|
||||
return getConfiguration(bean).getProtocolOptions();
|
||||
}
|
||||
|
||||
private Configuration getConfiguration(CassandraCqlClusterFactoryBean bean) throws Exception {
|
||||
return bean.getObject().getConfiguration();
|
||||
}
|
||||
|
||||
@@ -34,14 +34,19 @@ import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Configuration;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.LoadBalancingPolicy;
|
||||
import com.datastax.driver.core.policies.Policies;
|
||||
import com.datastax.driver.core.policies.ReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.RoundRobinPolicy;
|
||||
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractClusterConfiguration}.
|
||||
@@ -53,7 +58,7 @@ import com.datastax.driver.core.policies.RoundRobinPolicy;
|
||||
public class AbstractClusterConfigurationUnitTests {
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -72,7 +77,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -92,7 +97,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -112,7 +117,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -132,7 +137,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -152,7 +157,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -172,7 +177,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -192,7 +197,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -212,7 +217,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -231,7 +236,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -249,7 +254,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -268,7 +273,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -287,7 +292,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -305,7 +310,7 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-226
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-226"></a>
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
@@ -322,12 +327,100 @@ public class AbstractClusterConfigurationUnitTests {
|
||||
assertThat(clusterConfiguration.cluster().getShutdownScripts(), is(equalTo(scripts)));
|
||||
}
|
||||
|
||||
/**
|
||||
* <a href="https://jira.spring.io/browse/DATACASS-316">DATACASS-316</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetAddressTranslator() throws Exception {
|
||||
final AddressTranslator mockAddressTranslator = mock(AddressTranslator.class);
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected AddressTranslator getAddressTranslator() {
|
||||
return mockAddressTranslator;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getAddressTranslator(),
|
||||
is(equalTo(mockAddressTranslator)));
|
||||
}
|
||||
|
||||
/**
|
||||
* <a href="https://jira.spring.io/browse/DATACASS-120">DATACASS-120</a>
|
||||
* <a href="https://jira.spring.io/browse/DATACASS-317">DATACASS-317</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetClusterName() throws Exception {
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected String getClusterName() {
|
||||
return "testCluster";
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getCluster(clusterConfiguration).getClusterName(), is(equalTo("testCluster")));
|
||||
}
|
||||
|
||||
/**
|
||||
* <a href="https://jira.spring.io/browse/DATACASS-319">DATACASS-319</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetMaxSchemaAgreementWaitInSeconds() throws Exception {
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected int getMaxSchemaAgreementWaitSeconds() {
|
||||
return 30;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getProtocolOptions(getCluster(clusterConfiguration)).getMaxSchemaAgreementWaitSeconds(),
|
||||
is(equalTo(30)));
|
||||
}
|
||||
|
||||
/**
|
||||
* <a href="https://jira.spring.io/browse/DATACASS-320">DATACASS-320</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetSpeculativeExecutionPolicy() throws Exception {
|
||||
final SpeculativeExecutionPolicy mockSpeculativeExecutionPolicy = mock(SpeculativeExecutionPolicy.class);
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected SpeculativeExecutionPolicy getSpeculativeExecutionPolicy() {
|
||||
return mockSpeculativeExecutionPolicy;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getSpeculativeExecutionPolicy(),
|
||||
is(equalTo(mockSpeculativeExecutionPolicy)));
|
||||
}
|
||||
|
||||
/**
|
||||
* <a href="https://jira.spring.io/browse/DATACASS-238">DATACASS-238</a>
|
||||
*/
|
||||
@Test
|
||||
public void shouldSetTimestampGenerator() throws Exception {
|
||||
final TimestampGenerator mockTimestampGenerator = mock(TimestampGenerator.class);
|
||||
|
||||
AbstractClusterConfiguration clusterConfiguration = new AbstractClusterConfiguration() {
|
||||
@Override protected TimestampGenerator getTimestampGenerator() {
|
||||
return mockTimestampGenerator;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(getPolicies(getCluster(clusterConfiguration)).getTimestampGenerator(),
|
||||
is(equalTo(mockTimestampGenerator)));
|
||||
}
|
||||
|
||||
private Policies getPolicies(Cluster cluster) throws Exception {
|
||||
return getConfiguration(cluster).getPolicies();
|
||||
}
|
||||
|
||||
private ProtocolOptions getProtocolOptions(Cluster cluster) throws Exception {
|
||||
return getConfiguration(cluster).getProtocolOptions();
|
||||
}
|
||||
|
||||
private Configuration getConfiguration(Cluster cluster) throws Exception {
|
||||
return cluster.getConfiguration();
|
||||
}
|
||||
|
||||
private Cluster getCluster(AbstractClusterConfiguration clusterConfiguration) throws Exception {
|
||||
|
||||
CassandraCqlClusterFactoryBean cluster = clusterConfiguration.cluster();
|
||||
cluster.afterPropertiesSet();
|
||||
return cluster.getObject();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.config.xml;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -85,16 +86,21 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
BeanDefinition mockContainingBeanDefinition = mock(BeanDefinition.class);
|
||||
|
||||
when(mockContainingBeanDefinition.getScope()).thenReturn("Singleton");
|
||||
when(mockElement.getAttribute("address-translator-ref")).thenReturn("testAddressTranslator");
|
||||
when(mockElement.getAttribute("auth-info-provider-ref")).thenReturn("testAuthInfoProvider");
|
||||
when(mockElement.getAttribute("host-state-listener-ref")).thenReturn("testHostStateListener");
|
||||
when(mockElement.getAttribute("latency-tracker-ref")).thenReturn("testLatencyTracker");
|
||||
when(mockElement.getAttribute("load-balancing-policy-ref")).thenReturn("testLoadBalancingPolicy");
|
||||
when(mockElement.getAttribute("reconnection-policy-ref")).thenReturn("testReconnectionPolicy");
|
||||
when(mockElement.getAttribute("retry-policy-ref")).thenReturn("testRetryPolicy");
|
||||
when(mockElement.getAttribute("speculative-execution-policy-ref")).thenReturn("testSpeculativeExecutionPolicy");
|
||||
when(mockElement.getAttribute("ssl-options-ref")).thenReturn("testSslOptions");
|
||||
when(mockElement.getAttribute("timestamp-generator-ref")).thenReturn("testTimestampGenerator");
|
||||
when(mockElement.getAttribute("cluster-name")).thenReturn("testCluster");
|
||||
when(mockElement.getAttribute("contact-points")).thenReturn("skullbox");
|
||||
when(mockElement.getAttribute("compression")).thenReturn("SNAPPY");
|
||||
when(mockElement.getAttribute("jmx-reporting-enabled")).thenReturn("true");
|
||||
when(mockElement.getAttribute("max-schema-agreement-wait-seconds")).thenReturn("30");
|
||||
when(mockElement.getAttribute("metrics-enabled")).thenReturn("true");
|
||||
when(mockElement.getAttribute("password")).thenReturn("p@55w0rd");
|
||||
when(mockElement.getAttribute("port")).thenReturn("12345");
|
||||
@@ -116,16 +122,21 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
assertThat(beanDefinition.getDestroyMethodName(), is(equalTo("destroy")));
|
||||
assertThat((Element) beanDefinition.getSource(), is(equalTo(mockElement)));
|
||||
assertThat(beanDefinition.isLazyInit(), is(false));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "addressTranslator"), is(equalTo("testAddressTranslator")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "authProvider"), is(equalTo("testAuthInfoProvider")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "hostStateListener"), is(equalTo("testHostStateListener")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "latencyTracker"), is(equalTo("testLatencyTracker")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "loadBalancingPolicy"), is(equalTo("testLoadBalancingPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "reconnectionPolicy"), is(equalTo("testReconnectionPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "retryPolicy"), is(equalTo("testRetryPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "speculativeExecutionPolicy"), is(equalTo("testSpeculativeExecutionPolicy")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "sslOptions"), is(equalTo("testSslOptions")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "timestampGenerator"), is(equalTo("testTimestampGenerator")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "clusterName"), is(equalTo("testCluster")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "contactPoints"), is(equalTo("skullbox")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "compressionType"), is(equalTo("SNAPPY")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "jmxReportingEnabled"), is(equalTo("true")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "maxSchemaAgreementWaitSeconds"), is(equalTo("30")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "metricsEnabled"), is(equalTo("true")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "password"), is(equalTo("p@55w0rd")));
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "port"), is(equalTo("12345")));
|
||||
@@ -133,16 +144,21 @@ public class CassandraCqlClusterParserUnitTests {
|
||||
assertThat(getPropertyValueAsString(beanDefinition, "username"), is(equalTo("jonDoe")));
|
||||
|
||||
verify(mockContainingBeanDefinition).getScope();
|
||||
verify(mockElement).getAttribute(eq("address-translator-ref"));
|
||||
verify(mockElement).getAttribute(eq("auth-info-provider-ref"));
|
||||
verify(mockElement).getAttribute(eq("host-state-listener-ref"));
|
||||
verify(mockElement).getAttribute(eq("latency-tracker-ref"));
|
||||
verify(mockElement).getAttribute(eq("load-balancing-policy-ref"));
|
||||
verify(mockElement).getAttribute(eq("reconnection-policy-ref"));
|
||||
verify(mockElement).getAttribute(eq("retry-policy-ref"));
|
||||
verify(mockElement).getAttribute(eq("speculative-execution-policy-ref"));
|
||||
verify(mockElement).getAttribute(eq("timestamp-generator-ref"));
|
||||
verify(mockElement).getAttribute(eq("ssl-options-ref"));
|
||||
verify(mockElement).getAttribute(eq("cluster-name"));
|
||||
verify(mockElement).getAttribute(eq("contact-points"));
|
||||
verify(mockElement).getAttribute(eq("compression"));
|
||||
verify(mockElement).getAttribute(eq("jmx-reporting-enabled"));
|
||||
verify(mockElement).getAttribute(eq("max-schema-agreement-wait-seconds"));
|
||||
verify(mockElement).getAttribute(eq("metrics-enabled"));
|
||||
verify(mockElement).getAttribute(eq("password"));
|
||||
verify(mockElement).getAttribute(eq("port"));
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* {@code BeanDefinitionTestUtils} is a collection of {@link org.springframework.beans.factory.config.BeanDefinition}
|
||||
* -based utility methods for use in unit and integration testing scenarios.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public abstract class BeanDefinitionTestUtils {
|
||||
@@ -35,7 +35,7 @@ public abstract class BeanDefinitionTestUtils {
|
||||
|
||||
/**
|
||||
* Retrieve the {@code propertyValue} from a {@link BeanDefinition} by its {@code propertyName}.
|
||||
*
|
||||
*
|
||||
* @param beanDefinition must not be {@literal null}.
|
||||
* @param propertyName must not be {@literal null} or empty.
|
||||
* @return the property value, may be {@literal null}.
|
||||
@@ -47,12 +47,13 @@ public abstract class BeanDefinitionTestUtils {
|
||||
Assert.notNull(propertyName, "Property name must not be empty");
|
||||
|
||||
PropertyValue propertyValue = beanDefinition.getPropertyValues().getPropertyValue(propertyName);
|
||||
|
||||
return (T) (propertyValue != null ? propertyValue.getValue() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the {@code propertyValue} as {@literal String} from a {@link BeanDefinition} by its {@code propertyName}.
|
||||
*
|
||||
*
|
||||
* @param beanDefinition must not be {@literal null}.
|
||||
* @param propertyName must not be {@literal null} or empty.
|
||||
* @return the property value, may be {@literal null}.
|
||||
@@ -63,8 +64,8 @@ public abstract class BeanDefinitionTestUtils {
|
||||
Assert.notNull(propertyName, "Property name must not be empty");
|
||||
|
||||
Object value = getPropertyValue(beanDefinition, propertyName);
|
||||
return (value instanceof RuntimeBeanReference ? ((RuntimeBeanReference) value).getBeanName()
|
||||
: (value != null ? String.valueOf(value) : null));
|
||||
}
|
||||
|
||||
return (value instanceof RuntimeBeanReference ? ((RuntimeBeanReference) value).getBeanName()
|
||||
: (value != null ? String.valueOf(value) : null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ import com.datastax.driver.core.HostDistance;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
|
||||
|
||||
/**
|
||||
* Test XML namespace configuration using the spring-cql-1.0.xsd.
|
||||
@@ -49,21 +52,29 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
|
||||
|
||||
public static final String KEYSPACE = "xmlconfigtest";
|
||||
|
||||
@Rule public KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE);
|
||||
@Rule
|
||||
public KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE);
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
private AddressTranslator addressTranslator;
|
||||
private Cluster cluster;
|
||||
private Executor executor;
|
||||
private Session session;
|
||||
private SpeculativeExecutionPolicy speculativeExecutionPolicy;
|
||||
private TimestampGenerator timestampGenerator;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.applicationContext = new ClassPathXmlApplicationContext(
|
||||
"XmlConfigIntegrationTests-context.xml", getClass());
|
||||
|
||||
this.addressTranslator = applicationContext.getBean(AddressTranslator.class);
|
||||
this.cluster = applicationContext.getBean(Cluster.class);
|
||||
this.executor = applicationContext.getBean(Executor.class);
|
||||
this.session = applicationContext.getBean(Session.class);
|
||||
this.speculativeExecutionPolicy = applicationContext.getBean(SpeculativeExecutionPolicy.class);
|
||||
this.timestampGenerator = applicationContext.getBean(TimestampGenerator.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -78,6 +89,18 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clusterConfigurationIsCorrect() {
|
||||
assertThat(cluster.getConfiguration().getPolicies().getAddressTranslator(), is(equalTo(addressTranslator)));
|
||||
assertThat(cluster.getClusterName(), is(equalTo("skynet")));
|
||||
assertThat(cluster.getConfiguration().getProtocolOptions().getMaxSchemaAgreementWaitSeconds(), is(equalTo(30)));
|
||||
|
||||
assertThat(cluster.getConfiguration().getPolicies().getSpeculativeExecutionPolicy(),
|
||||
is(equalTo(speculativeExecutionPolicy)));
|
||||
|
||||
assertThat(cluster.getConfiguration().getPolicies().getTimestampGenerator(), is(equalTo(timestampGenerator)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-298">DATACASS-298</a>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user