Elffuss BraidHub

kikocis/java-driver public

More enhancements to CCM tests.

(cherry picked from 2.1)
Changeset1316e514ed9195d8ae5c6fe461bb09c6ebf1269954918634de39e3523528b939
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-03-15 10:56 -05:00
Committerolim7t <omichallat+github@gmail.com> · 2016-04-01 17:57 +02:00
Parentsd2bae80385ee

Browse the files at this changeset

14 files changed

modified driver-core/pom.xml +0 −150
@@ -295,72 +295,6 @@
295295 </build>
296296
297297 <profiles>
298- <profile>
299- <id>unit</id>
300- <properties>
301- <env>default</env>
302- </properties>
303- <!-- do not use activeByDefault as other profiles might be active -->
304- <activation>
305- <property>
306- <name>!activateUnitTests</name>
307- </property>
308- </activation>
309- <build>
310- <plugins>
311- <plugin>
312- <groupId>org.apache.maven.plugins</groupId>
313- <artifactId>maven-surefire-plugin</artifactId>
314- <version>2.16</version>
315- <configuration>
316- <groups>unit</groups>
317- <useFile>false</useFile>
318- <systemPropertyVariables>
319- <cassandra.version>${cassandra.version}</cassandra.version>
320- <ipprefix>${ipprefix}</ipprefix>
321- <com.datastax.driver.NEW_NODE_DELAY_SECONDS>60
322- </com.datastax.driver.NEW_NODE_DELAY_SECONDS>
323- </systemPropertyVariables>
324- <classpathDependencyExcludes>
325- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll
326- </classpathDependencyExcludes>
327- </classpathDependencyExcludes>
328- <!--May be needed for debugging-->
329- <!--<forkMode>never</forkMode>-->
330- </configuration>
331- </plugin>
332- </plugins>
333- </build>
334- </profile>
335-
336- <profile>
337- <id>short</id>
338- <properties>
339- <env>default</env>
340- </properties>
341- <build>
342- <plugins>
343- <plugin>
344- <groupId>org.apache.maven.plugins</groupId>
345- <artifactId>maven-surefire-plugin</artifactId>
346- <version>2.16</version>
347- <configuration>
348- <groups>unit,short</groups>
349- <useFile>false</useFile>
350- <systemPropertyVariables>
351- <cassandra.version>${cassandra.version}</cassandra.version>
352- <ipprefix>${ipprefix}</ipprefix>
353- </systemPropertyVariables>
354- <classpathDependencyExcludes>
355- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll
356- </classpathDependencyExcludes>
357- </classpathDependencyExcludes>
358- </configuration>
359- </plugin>
360- </plugins>
361- </build>
362- </profile>
363-
364298 <profile>
365299 <id>isolated</id>
366300 <properties>
@@ -384,90 +318,6 @@
384318 </plugins>
385319 </build>
386320 </profile>
387-
388- <profile>
389- <id>long</id>
390- <properties>
391- <env>default</env>
392- </properties>
393- <build>
394- <plugins>
395- <plugin>
396- <groupId>org.apache.maven.plugins</groupId>
397- <artifactId>maven-surefire-plugin</artifactId>
398- <version>2.16</version>
399- <configuration>
400- <groups>unit,short,long</groups>
401- <useFile>false</useFile>
402- <systemPropertyVariables>
403- <cassandra.version>${cassandra.version}</cassandra.version>
404- <ipprefix>${ipprefix}</ipprefix>
405- </systemPropertyVariables>
406- <classpathDependencyExcludes>
407- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll
408- </classpathDependencyExcludes>
409- </classpathDependencyExcludes>
410- </configuration>
411- </plugin>
412- </plugins>
413- </build>
414- </profile>
415-
416- <profile>
417- <id>duration</id>
418- <properties>
419- <env>default</env>
420- </properties>
421- <build>
422- <plugins>
423- <plugin>
424- <groupId>org.apache.maven.plugins</groupId>
425- <artifactId>maven-surefire-plugin</artifactId>
426- <version>2.16</version>
427- <configuration>
428- <groups>unit,short,long,duration</groups>
429- <useFile>false</useFile>
430- <systemPropertyVariables>
431- <cassandra.version>${cassandra.version}</cassandra.version>
432- <ipprefix>${ipprefix}</ipprefix>
433- </systemPropertyVariables>
434- <classpathDependencyExcludes>
435- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll
436- </classpathDependencyExcludes>
437- </classpathDependencyExcludes>
438- </configuration>
439- </plugin>
440- </plugins>
441- </build>
442- </profile>
443-
444- <profile>
445- <id>doc</id>
446- <properties>
447- <env>default</env>
448- </properties>
449- <build>
450- <plugins>
451- <plugin>
452- <groupId>org.apache.maven.plugins</groupId>
453- <artifactId>maven-surefire-plugin</artifactId>
454- <version>2.16</version>
455- <configuration>
456- <groups>unit,doc</groups>
457- <useFile>false</useFile>
458- <systemPropertyVariables>
459- <cassandra.version>${cassandra.version}</cassandra.version>
460- <ipprefix>${ipprefix}</ipprefix>
461- </systemPropertyVariables>
462- <classpathDependencyExcludes>
463- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll
464- </classpathDependencyExcludes>
465- </classpathDependencyExcludes>
466- </configuration>
467- </plugin>
468- </plugins>
469- </build>
470- </profile>
471321 </profiles>
472322
473323 <licenses>
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +58 −35
@@ -31,6 +31,8 @@
3131 import java.net.InetSocketAddress;
3232 import java.util.*;
3333 import java.util.concurrent.TimeUnit;
34+import java.util.regex.Matcher;
35+import java.util.regex.Pattern;
3436
3537 import static com.datastax.driver.core.TestUtils.executeNoFail;
3638 import static com.datastax.driver.core.TestUtils.findAvailablePort;
@@ -663,22 +665,25 @@
663665 * use {@link #builder()} to get an instance
664666 */
665667 public static class Builder {
666- private final String clusterName = TestUtils.generateIdentifier("cluster_");
668+
669+ public static final String RANDOM_PORT = "__RANDOM_PORT__";
670+ private static final Pattern RANDOM_PORT_PATTERN = Pattern.compile(RANDOM_PORT);
671+
667672 int[] nodes = {1};
668673 private boolean start = true;
669674 private boolean isDSE = isDSE();
670675 private String version = getCassandraVersion();
671- private Set<String> createOptions = new HashSet<String>(getInstallArguments());
676+ private Set<String> createOptions = new LinkedHashSet<String>(getInstallArguments());
672677 private Set<String> jvmArgs = new LinkedHashSet<String>();
673- private final Map<String, Object> cassandraConfiguration = Maps.newHashMap();
674- private final Map<String, Object> dseConfiguration = Maps.newHashMap();
675- // -1 means random
676- private int thriftPort = -1;
677- private int binaryPort = -1;
678- private int storagePort = -1;
678+ private final Map<String, Object> cassandraConfiguration = Maps.newLinkedHashMap();
679+ private final Map<String, Object> dseConfiguration = Maps.newLinkedHashMap();
679680 private Map<Integer, Workload> workloads = new HashMap<Integer, Workload>();
680681
681682 private Builder() {
683+ cassandraConfiguration.put("start_rpc", false);
684+ cassandraConfiguration.put("storage_port", RANDOM_PORT);
685+ cassandraConfiguration.put("rpc_port", RANDOM_PORT);
686+ cassandraConfiguration.put("native_transport_port", RANDOM_PORT);
682687 }
683688
684689 /**
@@ -785,17 +790,17 @@
785790 }
786791
787792 public Builder withStoragePort(int port) {
788- storagePort = port;
793+ cassandraConfiguration.put("storage_port", port);
789794 return this;
790795 }
791796
792797 public Builder withThriftPort(int port) {
793- thriftPort = port;
798+ cassandraConfiguration.put("rpc_port", port);
794799 return this;
795800 }
796801
797802 public Builder withBinaryPort(int port) {
798- binaryPort = port;
803+ cassandraConfiguration.put("native_transport_port", port);
799804 return this;
800805 }
801806
@@ -813,10 +818,13 @@
813818
814819 public CCMBridge build() {
815820 // be careful NOT to alter internal state (hashCode/equals) during build!
816- int storagePort = this.storagePort == -1 ? findAvailablePort() : this.storagePort;
817- int thriftPort = this.thriftPort == -1 ? findAvailablePort() : this.thriftPort;
818- int binaryPort = this.binaryPort == -1 ? findAvailablePort() : this.binaryPort;
821+ String clusterName = TestUtils.generateIdentifier("ccm_");
822+ Map<String, Object> cassandraConfiguration = randomizePorts(this.cassandraConfiguration);
823+ Map<String, Object> dseConfiguration = randomizePorts(this.dseConfiguration);
819824 VersionNumber version = VersionNumber.parse(this.version);
825+ int storagePort = Integer.parseInt(cassandraConfiguration.get("storage_port").toString());
826+ int thriftPort = Integer.parseInt(cassandraConfiguration.get("rpc_port").toString());
827+ int binaryPort = Integer.parseInt(cassandraConfiguration.get("native_transport_port").toString());
820828 final CCMBridge ccm = new CCMBridge(clusterName, isDSE, version, storagePort, thriftPort, binaryPort, joinJvmArgs());
821829 Runtime.getRuntime().addShutdownHook(new Thread() {
822830 @Override
@@ -824,14 +832,9 @@
824832 ccm.close();
825833 }
826834 });
827- ccm.execute(buildCreateCommand());
835+ ccm.execute(buildCreateCommand(clusterName));
828836 updateNodeConf(ccm);
829- HashMap<String, Object> config = new HashMap<String, Object>(cassandraConfiguration);
830- config.put("start_rpc", false);
831- config.put("storage_port", storagePort);
832- config.put("rpc_port", thriftPort);
833- config.put("native_transport_port", binaryPort);
834- ccm.updateConfig(config);
837+ ccm.updateConfig(cassandraConfiguration);
835838 if (!dseConfiguration.isEmpty())
836839 ccm.updateDSEConfig(dseConfiguration);
837840 for (Map.Entry<Integer, Workload> entry : workloads.entrySet()) {
@@ -855,12 +858,12 @@
855858 StringBuilder allJvmArgs = new StringBuilder("");
856859 for (String jvmArg : jvmArgs) {
857860 allJvmArgs.append(" --jvm_arg=");
858- allJvmArgs.append(jvmArg);
861+ allJvmArgs.append(randomizePorts(jvmArg));
859862 }
860863 return allJvmArgs.toString();
861864 }
862865
863- private String buildCreateCommand() {
866+ private String buildCreateCommand(String clusterName) {
864867 StringBuilder result = new StringBuilder(CCM_COMMAND + " create");
865868 result.append(" ").append(clusterName);
866869 result.append(" -i ").append(TestUtils.IP_PREFIX);
@@ -874,7 +877,7 @@
874877 result.append(node);
875878 }
876879 }
877- result.append(" ").append(Joiner.on(" ").join(createOptions));
880+ result.append(" ").append(Joiner.on(" ").join(randomizePorts(createOptions)));
878881 return result.toString();
879882 }
880883
@@ -892,7 +895,7 @@
892895 for (int i = 0; i < nodesInDc; i++) {
893896 int jmxPort = findAvailablePort();
894897 int debugPort = findAvailablePort();
895- logger.trace("Node {} in cluster {} using JMX port {} and debug port {}", n, clusterName, jmxPort, debugPort);
898+ logger.trace("Node {} in cluster {} using JMX port {} and debug port {}", n, ccm.getClusterName(), jmxPort, debugPort);
896899 File nodeConf = new File(ccm.getNodeDir(n), "node.conf");
897900 File nodeConf2 = new File(ccm.getNodeDir(n), "node.conf.tmp");
898901 BufferedReader br = closer.register(new BufferedReader(new FileReader(nodeConf)));
@@ -927,6 +930,36 @@
927930 }
928931 }
929932
933+ private Set<String> randomizePorts(Set<String> set) {
934+ Set<String> randomized = new LinkedHashSet<String>();
935+ for (String value : set) {
936+ randomized.add(randomizePorts(value));
937+ }
938+ return randomized;
939+ }
940+
941+ private Map<String, Object> randomizePorts(Map<String, Object> map) {
942+ Map<String, Object> randomized = new HashMap<String, Object>();
943+ for (Map.Entry<String, Object> entry : map.entrySet()) {
944+ Object value = entry.getValue();
945+ if (value instanceof CharSequence) {
946+ value = randomizePorts((CharSequence) value);
947+ }
948+ randomized.put(entry.getKey(), value);
949+ }
950+ return randomized;
951+ }
952+
953+ private String randomizePorts(CharSequence str) {
954+ Matcher matcher = RANDOM_PORT_PATTERN.matcher(str);
955+ StringBuffer sb = new StringBuffer();
956+ while (matcher.find()) {
957+ matcher.appendReplacement(sb, Integer.toString(TestUtils.findAvailablePort()));
958+ }
959+ matcher.appendTail(sb);
960+ return sb.toString();
961+ }
962+
930963 @Override
931964 @SuppressWarnings("SimplifiableIfStatement")
932965 public boolean equals(Object o) {
@@ -936,9 +969,6 @@
936969 if (o == null || getClass() != o.getClass()) return false;
937970 Builder builder = (Builder) o;
938971 if (isDSE != builder.isDSE) return false;
939- if (thriftPort != builder.thriftPort) return false;
940- if (binaryPort != builder.binaryPort) return false;
941- if (storagePort != builder.storagePort) return false;
942972 if (!Arrays.equals(nodes, builder.nodes)) return false;
943973 if (!createOptions.equals(builder.createOptions)) return false;
944974 if (!jvmArgs.equals(builder.jvmArgs)) return false;
@@ -959,17 +989,10 @@
959989 result = 31 * result + cassandraConfiguration.hashCode();
960990 result = 31 * result + dseConfiguration.hashCode();
961991 result = 31 * result + workloads.hashCode();
962- result = 31 * result + thriftPort;
963- result = 31 * result + binaryPort;
964- result = 31 * result + storagePort;
965992 result = 31 * result + version.hashCode();
966993 return result;
967994 }
968995
969- @Override
970- public String toString() {
971- return String.format("%s (%s nodes)", clusterName, weight());
972- }
973996 }
974997
975998 }
modified driver-core/src/test/java/com/datastax/driver/core/CCMCache.java +24 −5
@@ -22,6 +22,7 @@
2222
2323 import java.io.File;
2424 import java.net.InetSocketAddress;
25+import java.util.Iterator;
2526 import java.util.Map;
2627 import java.util.concurrent.ExecutionException;
2728 import java.util.concurrent.atomic.AtomicInteger;
@@ -247,20 +248,23 @@
247248 */
248249 private static final LoadingCache<CCMBridge.Builder, CachedCCMAccess> CACHE;
249250
251+ // The amount of memory one CCM node takes in MB.
252+ private static final int ONE_CCM_NODE_MB = 800;
253+
250254 static {
251255 long maximumWeight;
252256 String numberOfNodes = System.getProperty("ccm.maxNumberOfNodes");
253257 if (numberOfNodes == null) {
254258 long freeMemoryMB = TestUtils.getFreeMemoryMB();
255- if (freeMemoryMB < 1000)
256- LOGGER.warn("Available memory below 1GB: {}MB, CCM clusters might fail to start", freeMemoryMB);
259+ if (freeMemoryMB < ONE_CCM_NODE_MB)
260+ LOGGER.warn("Not enough available memory: {} MB, CCM clusters might fail to start", freeMemoryMB);
257261 // CCM nodes are started with -Xms500M -Xmx500M
258262 // and allocate up to 100MB non-heap memory in the general case,
259263 // to be conservative we treat 1 "slot" as 800Mb.
260264 // We leave 2 slots out to avoid starving system memory,
261265 // and we pick a value with a minimum of 1 slot and a maximum of 8 slots.
262266 // For example, an 8GB VM with ~6.5GB currently available heap will yield 6 slots ((6500/800) - 2 = 6).
263- long slotsAvailable = (freeMemoryMB / 800) - 2;
267+ long slotsAvailable = (freeMemoryMB / ONE_CCM_NODE_MB) - 2;
264268 maximumWeight = Math.min(8, Math.max(1, slotsAvailable));
265269 } else {
266270 maximumWeight = Integer.parseInt(numberOfNodes);
@@ -272,6 +276,7 @@
272276 .maximumWeight(maximumWeight)
273277 .weigher(new CCMAccessWeigher())
274278 .removalListener(new CCMAccessRemovalListener())
279+ .recordStats()
275280 .build(new CCMAccessLoader());
276281 }
277282
@@ -304,8 +309,22 @@
304309 }
305310
306311 private static void logCache() {
307- if (LOGGER.isDebugEnabled())
308- LOGGER.debug("Free memory: {}, Cache {}", TestUtils.getFreeMemoryMB(), CACHE.asMap().keySet());
312+ if (LOGGER.isDebugEnabled()) {
313+ LOGGER.debug("Free memory: {} MB", TestUtils.getFreeMemoryMB());
314+ StringBuilder sb = new StringBuilder();
315+ Iterator<Map.Entry<CCMBridge.Builder, CachedCCMAccess>> iterator = CACHE.asMap().entrySet().iterator();
316+ while (iterator.hasNext()) {
317+ Map.Entry<CCMBridge.Builder, CachedCCMAccess> entry = iterator.next();
318+ sb.append(entry.getValue().getClusterName())
319+ .append(" (")
320+ .append(entry.getKey().weight())
321+ .append(")");
322+ if (iterator.hasNext())
323+ sb.append(", ");
324+ }
325+ LOGGER.debug("Cache contents: {{}}", sb.toString());
326+ LOGGER.debug("Cache stats: {}", CACHE.stats());
327+ }
309328 }
310329
311330 }
modified driver-core/src/test/java/com/datastax/driver/core/CCMTestsSupport.java +26 −26
@@ -417,32 +417,32 @@
417417 ccmBuilder = ccmProvider(testInstance);
418418 if (ccmBuilder == null) {
419419 ccmBuilder = CCMBridge.builder().withNodes(numberOfNodes()).notStarted();
420- if (version() != null)
421- ccmBuilder.withVersion(version());
422- if (dse())
423- ccmBuilder.withDSE();
424- if (ssl())
425- ccmBuilder.withSSL();
426- if (auth())
427- ccmBuilder.withAuth();
428- for (Map.Entry<String, Object> entry : config().entrySet()) {
429- ccmBuilder.withCassandraConfiguration(entry.getKey(), entry.getValue());
430- }
431- for (Map.Entry<String, Object> entry : dseConfig().entrySet()) {
432- ccmBuilder.withDSEConfiguration(entry.getKey(), entry.getValue());
433- }
434- for (String option : startOptions()) {
435- ccmBuilder.withCreateOptions(option);
436- }
437- for (String arg : jvmArgs()) {
438- ccmBuilder.withJvmArgs(arg);
439- }
440- List<Workload> workloads = workloads();
441- for (int i = 0; i < workloads.size(); i++) {
442- Workload workload = workloads.get(i);
443- if (workload != null)
444- ccmBuilder.withWorkload(i + 1, workload);
445- }
420+ }
421+ if (version() != null)
422+ ccmBuilder.withVersion(version());
423+ if (dse())
424+ ccmBuilder.withDSE();
425+ if (ssl())
426+ ccmBuilder.withSSL();
427+ if (auth())
428+ ccmBuilder.withAuth();
429+ for (Map.Entry<String, Object> entry : config().entrySet()) {
430+ ccmBuilder.withCassandraConfiguration(entry.getKey(), entry.getValue());
431+ }
432+ for (Map.Entry<String, Object> entry : dseConfig().entrySet()) {
433+ ccmBuilder.withDSEConfiguration(entry.getKey(), entry.getValue());
434+ }
435+ for (String option : startOptions()) {
436+ ccmBuilder.withCreateOptions(option);
437+ }
438+ for (String arg : jvmArgs()) {
439+ ccmBuilder.withJvmArgs(arg);
440+ }
441+ List<Workload> workloads = workloads();
442+ for (int i = 0; i < workloads.size(); i++) {
443+ Workload workload = workloads.get(i);
444+ if (workload != null)
445+ ccmBuilder.withWorkload(i + 1, workload);
446446 }
447447 }
448448 return ccmBuilder;
modified driver-core/src/test/java/com/datastax/driver/core/ConsistencyTest.java +8 −9
@@ -49,10 +49,9 @@
4949 createKeyspace = false,
5050 config = {
5151 // tests fail often with write or read timeouts
52- "hinted_handoff_enabled:true",
5352 "phi_convict_threshold:5",
54- "read_request_timeout_in_ms:100000",
55- "write_request_timeout_in_ms:100000"
53+ "read_request_timeout_in_ms:200000",
54+ "write_request_timeout_in_ms:200000"
5655 }
5756 )
5857 public class ConsistencyTest extends AbstractPoliciesTest {
@@ -61,40 +60,40 @@
6160
6261 private Cluster.Builder tokenAwareRoundRobin() {
6362 return Cluster.builder()
64- .withSocketOptions(new SocketOptions().setReadTimeoutMillis(120000))
63+ .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000))
6564 .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
6665 }
6766
6867 private Cluster.Builder tokenAwareRoundRobinNoShuffle() {
6968 return Cluster.builder()
70- .withSocketOptions(new SocketOptions().setReadTimeoutMillis(120000))
69+ .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000))
7170 .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false));
7271 }
7372
7473 private Cluster.Builder tokenAwareRoundRobinDowngrading() {
7574 return Cluster.builder()
76- .withSocketOptions(new SocketOptions().setReadTimeoutMillis(120000))
75+ .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000))
7776 .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()))
7877 .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
7978 }
8079
8180 private Cluster.Builder tokenAwareRoundRobinNoShuffleDowngrading() {
8281 return Cluster.builder()
83- .withSocketOptions(new SocketOptions().setReadTimeoutMillis(120000))
82+ .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000))
8483 .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy(), false))
8584 .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
8685 }
8786
8887 private Cluster.Builder roundRobinDowngrading() {
8988 return Cluster.builder()
90- .withSocketOptions(new SocketOptions().setReadTimeoutMillis(120000))
89+ .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000))
9190 .withLoadBalancingPolicy(new RoundRobinPolicy())
9291 .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
9392 }
9493
9594 private Cluster.Builder tokenAwareDCAwareRoundRobinNoShuffleDowngrading() {
9695 return Cluster.builder()
97- .withSocketOptions(new SocketOptions().setReadTimeoutMillis(120000))
96+ .withSocketOptions(new SocketOptions().setReadTimeoutMillis(300000))
9897 .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc("dc2").build(), false))
9998 .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
10099 }
modified driver-core/src/test/java/com/datastax/driver/core/MissingRpcAddressTest.java +2 −2
@@ -20,7 +20,6 @@
2020 import com.google.common.collect.Lists;
2121 import org.testng.annotations.Test;
2222
23-import java.net.InetAddress;
2423 import java.net.InetSocketAddress;
2524
2625 import static com.datastax.driver.core.CreateCCM.TestMode.PER_METHOD;
@@ -63,9 +62,10 @@
6362 .build());
6463 Session session = cluster.connect();
6564 String deleteStmt = String.format("DELETE rpc_address FROM system.peers WHERE peer = '%s'",
66- InetAddress.getByName(TestUtils.IP_PREFIX + "2").getHostName());
65+ ccm().addressOfNode(2).getHostName());
6766 session.execute(deleteStmt);
6867 session.close();
68+ cluster.close();
6969 }
7070
7171 }
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +16 −35
@@ -37,7 +37,6 @@
3737 import java.util.*;
3838 import java.util.concurrent.*;
3939 import java.util.concurrent.atomic.AtomicInteger;
40-import java.util.concurrent.locks.ReentrantLock;
4140
4241 import static com.datastax.driver.core.ConditionChecker.check;
4342 import static java.util.concurrent.TimeUnit.MINUTES;
@@ -672,47 +671,29 @@
672671 return prefix + seq.incrementAndGet();
673672 }
674673
675- // use ports in the ephemeral range
676- private static int nextPort = 50000;
677-
678- private static final ReentrantLock PORT_LOCK = new ReentrantLock();
679-
680674 /**
681- * Find an available port in the ephemeral range.
675+ * Finds an available port in the ephemeral range.
676+ * This is loosely inspired by Apache MINA's AvailablePortFinder.
682677 *
683678 * @return A local port that is currently unused.
684679 */
685- public static int findAvailablePort() {
686- PORT_LOCK.lock();
680+ public synchronized static int findAvailablePort() throws RuntimeException {
681+ ServerSocket ss = null;
687682 try {
688- for (int i = 0; i < 3; i++) {
689- int port = nextPort;
690- ServerSocket s = null;
691- for (int j = 0; j < 100; j++) {
692- try {
693- s = new ServerSocket(port);
694- s.close();
695- nextPort = port + 1;
696- return port;
697- } catch (IOException e) {
698- // ok
699- } finally {
700- port++;
701- if (s != null) {
702- try {
703- s.close();
704- } catch (IOException e) {
705- // ok
706- }
707- }
708- }
683+ // let the system pick an ephemeral port
684+ ss = new ServerSocket(0);
685+ ss.setReuseAddress(true);
686+ return ss.getLocalPort();
687+ } catch (IOException e) {
688+ throw Throwables.propagate(e);
689+ } finally {
690+ if (ss != null) {
691+ try {
692+ ss.close();
693+ } catch (IOException e) {
694+ Throwables.propagate(e);
709695 }
710- logger.warn("Could not acquire an available port after 100 attempts, sleeping for 1 minute");
711- Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MINUTES);
712696 }
713- throw new RuntimeException(String.format("Could not acquire an available port within range: %s-%s", nextPort, nextPort + 100));
714- } finally {
715- PORT_LOCK.unlock();
716697 }
717698 }
718699
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +12 −0
@@ -28,8 +28,11 @@
2828 import java.net.InetAddress;
2929 import java.nio.ByteBuffer;
3030 import java.util.*;
31+import java.util.concurrent.Callable;
3132
33+import static com.datastax.driver.core.ConditionChecker.check;
3234 import static com.datastax.driver.core.Metadata.quote;
35+import static java.util.concurrent.TimeUnit.MINUTES;
3336 import static org.testng.Assert.assertEquals;
3437 import static org.testng.Assert.assertNotEquals;
3538
@@ -45,12 +48,21 @@
4548 private final static List<DataType.Name> DATA_TYPE_NON_PRIMITIVE_NAMES =
4649 new ArrayList<DataType.Name>(EnumSet.of(DataType.Name.LIST, DataType.Name.SET, DataType.Name.MAP, DataType.Name.TUPLE));
4750
51+ private final Callable<Boolean> userTableExists = new Callable<Boolean>() {
52+ @Override
53+ public Boolean call() throws Exception {
54+ return cluster().getMetadata().getKeyspace(keyspace).getTable("user") != null;
55+ }
56+ };
57+
4858 @Override
4959 public void onTestContextInitialized() {
5060 String type1 = "CREATE TYPE phone (alias text, number text)";
5161 String type2 = "CREATE TYPE \"\"\"User Address\"\"\" (street text, \"ZIP\"\"\" int, phones set<frozen<phone>>)";
5262 String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<\"\"\"User Address\"\"\">)";
5363 execute(type1, type2, table);
64+ // Ci tests fail with "unconfigured columnfamily user"
65+ check().that(userTableExists).before(5, MINUTES).becomesTrue();
5466 }
5567
5668 /**
modified driver-examples/osgi/pom.xml +5 −77
@@ -15,7 +15,8 @@
1515 limitations under the License.
1616
1717 -->
18-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
18+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1920 <modelVersion>4.0.0</modelVersion>
2021 <parent>
2122 <groupId>com.datastax.cassandra</groupId>
@@ -137,7 +138,7 @@
137138 <plugin>
138139 <groupId>org.apache.maven.plugins</groupId>
139140 <artifactId>maven-failsafe-plugin</artifactId>
140- <version>2.18.1</version>
141+ <version>2.16</version>
141142 <executions>
142143 <execution>
143144 <goals>
@@ -195,90 +196,17 @@
195196 <plugin>
196197 <groupId>org.apache.maven.plugins</groupId>
197198 <artifactId>maven-surefire-plugin</artifactId>
198- <version>2.14</version>
199- <configuration>
200- </configuration>
201- </plugin>
202- <plugin>
203- <groupId>org.apache.maven.plugins</groupId>
204- <artifactId>maven-failsafe-plugin</artifactId>
205- <version>2.18.1</version>
199+ <version>2.16</version>
206200 <configuration>
207201 <skip>true</skip>
208202 </configuration>
209203 </plugin>
210- </plugins>
211- </build>
212- </profile>
213-
214- <profile>
215- <id>short</id>
216- <properties>
217- <env>default</env>
218- </properties>
219- <build>
220- <plugins>
221- <plugin>
222- <groupId>org.apache.maven.plugins</groupId>
223- <artifactId>maven-surefire-plugin</artifactId>
224- <version>2.14</version>
225- <configuration>
226- <groups>unit,short</groups>
227- <useFile>false</useFile>
228- <systemPropertyVariables>
229- <cassandra.version>${cassandra.version}</cassandra.version>
230- <ipprefix>${ipprefix}</ipprefix>
231- </systemPropertyVariables>
232- </configuration>
233- </plugin>
234204 <plugin>
235205 <groupId>org.apache.maven.plugins</groupId>
236206 <artifactId>maven-failsafe-plugin</artifactId>
237- <version>2.18.1</version>
238- <configuration>
239- <groups>unit,short</groups>
240- <useFile>false</useFile>
241- <systemPropertyVariables>
242- <cassandra.version>${cassandra.version}</cassandra.version>
243- <ipprefix>${ipprefix}</ipprefix>
244- </systemPropertyVariables>
245- </configuration>
246- </plugin>
247- </plugins>
248- </build>
249- </profile>
250-
251- <profile>
252- <id>long</id>
253- <properties>
254- <env>default</env>
255- </properties>
256- <build>
257- <plugins>
258- <plugin>
259- <groupId>org.apache.maven.plugins</groupId>
260- <artifactId>maven-surefire-plugin</artifactId>
261207 <version>2.16</version>
262208 <configuration>
263- <groups>unit,short,long</groups>
264- <useFile>false</useFile>
265- <systemPropertyVariables>
266- <cassandra.version>${cassandra.version}</cassandra.version>
267- <ipprefix>${ipprefix}</ipprefix>
268- </systemPropertyVariables>
269- </configuration>
270- </plugin>
271- <plugin>
272- <groupId>org.apache.maven.plugins</groupId>
273- <artifactId>maven-failsafe-plugin</artifactId>
274- <version>2.18.1</version>
275- <configuration>
276- <groups>unit,short,long</groups>
277- <useFile>false</useFile>
278- <systemPropertyVariables>
279- <cassandra.version>${cassandra.version}</cassandra.version>
280- <ipprefix>${ipprefix}</ipprefix>
281- </systemPropertyVariables>
209+ <skip>true</skip>
282210 </configuration>
283211 </plugin>
284212 </plugins>
modified driver-mapping/pom.xml +2 −82
@@ -15,7 +15,8 @@
1515 limitations under the License.
1616
1717 -->
18-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
18+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1920 <modelVersion>4.0.0</modelVersion>
2021 <parent>
2122 <groupId>com.datastax.cassandra</groupId>
@@ -127,87 +128,6 @@
127128 </plugins>
128129 </build>
129130
130- <profiles>
131- <profile>
132- <id>unit</id>
133- <properties>
134- <env>default</env>
135- </properties>
136- <!-- do not use activeByDefault as other profiles might be active -->
137- <activation>
138- <property>
139- <name>!activateUnitTests</name>
140- </property>
141- </activation>
142- <build>
143- <plugins>
144- <plugin>
145- <groupId>org.apache.maven.plugins</groupId>
146- <artifactId>maven-surefire-plugin</artifactId>
147- <version>2.14</version>
148- <configuration>
149- <groups>unit</groups>
150- <useFile>false</useFile>
151- <systemPropertyVariables>
152- <cassandra.version>${cassandra.version}</cassandra.version>
153- <ipprefix>${ipprefix}</ipprefix>
154- </systemPropertyVariables>
155- </configuration>
156- </plugin>
157- </plugins>
158- </build>
159- </profile>
160-
161- <profile>
162- <id>short</id>
163- <properties>
164- <env>default</env>
165- </properties>
166- <build>
167- <plugins>
168- <plugin>
169- <groupId>org.apache.maven.plugins</groupId>
170- <artifactId>maven-surefire-plugin</artifactId>
171- <version>2.14</version>
172- <configuration>
173- <groups>unit,short</groups>
174- <useFile>false</useFile>
175- <systemPropertyVariables>
176- <cassandra.version>${cassandra.version}</cassandra.version>
177- <ipprefix>${ipprefix}</ipprefix>
178- </systemPropertyVariables>
179- </configuration>
180- </plugin>
181- </plugins>
182- </build>
183- </profile>
184-
185- <profile>
186- <id>long</id>
187- <properties>
188- <env>default</env>
189- </properties>
190- <build>
191- <plugins>
192- <plugin>
193- <groupId>org.apache.maven.plugins</groupId>
194- <artifactId>maven-surefire-plugin</artifactId>
195- <version>2.14</version>
196- <configuration>
197- <groups>unit,short,long</groups>
198- <useFile>false</useFile>
199- <systemPropertyVariables>
200- <cassandra.version>${cassandra.version}</cassandra.version>
201- <ipprefix>${ipprefix}</ipprefix>
202- </systemPropertyVariables>
203- </configuration>
204- </plugin>
205- </plugins>
206- </build>
207- </profile>
208-
209- </profiles>
210-
211131 <licenses>
212132 <license>
213133 <name>Apache 2</name>
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperTest.java +4 −0
@@ -440,6 +440,7 @@
440440 * @test_category object_mapper
441441 */
442442 @Test(groups = "short")
443+ @CassandraVersion(major = 2.0)
443444 public void should_flag_statement_as_idempotent() {
444445 MappingManager manager = new MappingManager(session());
445446 PostAccessor post = manager.createAccessor(PostAccessor.class);
@@ -456,6 +457,7 @@
456457 * @test_category object_mapper
457458 */
458459 @Test(groups = "short")
460+ @CassandraVersion(major = 2.0)
459461 public void should_flag_statement_as_non_idempotent() {
460462 MappingManager manager = new MappingManager(session());
461463 PostAccessor post = manager.createAccessor(PostAccessor.class);
@@ -472,6 +474,7 @@
472474 * @test_category object_mapper
473475 */
474476 @Test(groups = "short")
477+ @CassandraVersion(major = 2.0)
475478 public void should_flag_statement_with_null_idempotence() {
476479 MappingManager manager = new MappingManager(session());
477480 PostAccessor post = manager.createAccessor(PostAccessor.class);
@@ -487,6 +490,7 @@
487490 * @test_category object_mapper
488491 */
489492 @Test(groups = "short")
493+ @CassandraVersion(major = 2.0)
490494 public void should_flag_all_mapper_generated_statements_as_idempotent() {
491495 MappingManager manager = new MappingManager(session());
492496 Mapper<User> mapper = manager.mapper(User.class);
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTCollectionsTest.java +2 −0
@@ -16,6 +16,7 @@
1616 package com.datastax.driver.mapping;
1717
1818 import com.datastax.driver.core.CCMTestsSupport;
19+import com.datastax.driver.core.utils.CassandraVersion;
1920 import com.datastax.driver.mapping.annotations.*;
2021 import com.google.common.base.Objects;
2122 import com.google.common.collect.ImmutableMap;
@@ -33,6 +34,7 @@
3334 * Tests mapping of collections of UDTs.
3435 */
3536 @SuppressWarnings("unused")
37+@CassandraVersion(major = 2.1)
3638 public class MapperUDTCollectionsTest extends CCMTestsSupport {
3739
3840 @Override
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperUDTTest.java +2 −0
@@ -17,6 +17,7 @@
1717
1818 import com.datastax.driver.core.*;
1919 import com.datastax.driver.core.exceptions.CodecNotFoundException;
20+import com.datastax.driver.core.utils.CassandraVersion;
2021 import com.datastax.driver.core.utils.UUIDs;
2122 import com.datastax.driver.mapping.annotations.*;
2223 import com.google.common.base.Objects;
@@ -32,6 +33,7 @@
3233 import static org.testng.Assert.*;
3334
3435 @SuppressWarnings("unused")
36+@CassandraVersion(major = 2.1)
3537 public class MapperUDTTest extends CCMTestsSupport {
3638
3739 @Override
modified pom.xml +93 −13
@@ -15,13 +15,14 @@
1515 limitations under the License.
1616
1717 -->
18-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
18+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1920 <modelVersion>4.0.0</modelVersion>
2021 <parent>
2122 <groupId>org.sonatype.oss</groupId>
2223 <artifactId>oss-parent</artifactId>
2324 <version>7</version>
24- <relativePath />
25+ <relativePath/>
2526 </parent>
2627
2728 <groupId>com.datastax.cassandra</groupId>
@@ -68,8 +69,9 @@
6869 <scassandra.version>0.11.0</scassandra.version>
6970 <main.basedir>${project.basedir}</main.basedir>
7071 <ipprefix>127.0.1.</ipprefix>
72+ <test.groups>unit</test.groups>
7173 <!-- Set default javadoc.opts, overriden by profiles -->
72- <javadoc.opts />
74+ <javadoc.opts/>
7375 </properties>
7476
7577 <dependencies>
@@ -89,6 +91,16 @@
8991 </dependencies>
9092
9193 <profiles>
94+ <profile>
95+ <id>default</id>
96+ <properties>
97+ <env>default</env>
98+ <test.groups>unit</test.groups>
99+ </properties>
100+ <activation>
101+ <activeByDefault>true</activeByDefault>
102+ </activation>
103+ </profile>
92104
93105 <profile>
94106 <id>doclint-java8-disable</id>
@@ -101,10 +113,39 @@
101113 </profile>
102114
103115 <profile>
104- <!-- default profile settings for 'isolated' test group, will skip tests unless overriden in child module. -->
116+ <id>short</id>
117+ <properties>
118+ <env>default</env>
119+ <test.groups>unit,short</test.groups>
120+ </properties>
121+ </profile>
122+ <profile>
123+ <id>long</id>
124+ <properties>
125+ <env>default</env>
126+ <test.groups>unit,short,long</test.groups>
127+ </properties>
128+ </profile>
129+ <profile>
130+ <id>duration</id>
131+ <properties>
132+ <env>default</env>
133+ <test.groups>unit,short,long,duration</test.groups>
134+ </properties>
135+ </profile>
136+ <profile>
137+ <id>doc</id>
138+ <properties>
139+ <env>default</env>
140+ <test.groups>unit,doc</test.groups>
141+ </properties>
142+ </profile>
143+ <profile>
144+ <!-- default profile settings for 'isolated' test group, will skip tests unless overridden in child module. -->
105145 <id>isolated</id>
106146 <properties>
107147 <env>default</env>
148+ <test.groups>isolated</test.groups>
108149 </properties>
109150 <build>
110151 <plugins>
@@ -116,16 +157,7 @@
116157 <skip>true</skip>
117158 <forkCount>1</forkCount>
118159 <reuseForks>false</reuseForks>
119- <groups>isolated</groups>
120160 <reportNameSuffix>isolated</reportNameSuffix>
121- <useFile>false</useFile>
122- <systemPropertyVariables>
123- <cassandra.version>${cassandra.version}</cassandra.version>
124- <ipprefix>${ipprefix}</ipprefix>
125- </systemPropertyVariables>
126- <classpathDependencyExcludes>
127- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
128- </classpathDependencyExcludes>
129161 <!-- This requires includes to be explicitly specified by implementing classes.
130162 This is needed to prevent creating a JVM fork for each test, even those that don't
131163 have the isolated group. -->
@@ -343,6 +375,54 @@
343375 </execution>
344376 </executions>
345377 </plugin>
378+ <plugin>
379+ <groupId>org.apache.maven.plugins</groupId>
380+ <artifactId>maven-surefire-plugin</artifactId>
381+ <version>2.16</version>
382+ <configuration>
383+ <groups>${test.groups}</groups>
384+ <useFile>false</useFile>
385+ <systemPropertyVariables>
386+ <cassandra.version>${cassandra.version}</cassandra.version>
387+ <ipprefix>${ipprefix}</ipprefix>
388+ <com.datastax.driver.NEW_NODE_DELAY_SECONDS>60</com.datastax.driver.NEW_NODE_DELAY_SECONDS>
389+ </systemPropertyVariables>
390+ <classpathDependencyExcludes>
391+ <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
392+ </classpathDependencyExcludes>
393+ <properties>
394+ <property>
395+ <!-- Don't skip tests after a @Before method throws a SkipException -->
396+ <name>configfailurepolicy</name>
397+ <value>continue</value>
398+ </property>
399+ </properties>
400+ </configuration>
401+ </plugin>
402+ <plugin>
403+ <groupId>org.apache.maven.plugins</groupId>
404+ <artifactId>maven-failsafe-plugin</artifactId>
405+ <version>2.16</version>
406+ <configuration>
407+ <groups>${test.groups}</groups>
408+ <useFile>false</useFile>
409+ <systemPropertyVariables>
410+ <cassandra.version>${cassandra.version}</cassandra.version>
411+ <ipprefix>${ipprefix}</ipprefix>
412+ <com.datastax.driver.NEW_NODE_DELAY_SECONDS>60</com.datastax.driver.NEW_NODE_DELAY_SECONDS>
413+ </systemPropertyVariables>
414+ <classpathDependencyExcludes>
415+ <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
416+ </classpathDependencyExcludes>
417+ <properties>
418+ <property>
419+ <!-- Don't skip tests after a @Before method throws a SkipException -->
420+ <name>configfailurepolicy</name>
421+ <value>continue</value>
422+ </property>
423+ </properties>
424+ </configuration>
425+ </plugin>
346426 </plugins>
347427 </build>
348428