Elffuss BraidHub

kikocis/java-driver public

Merge pull request #585 from datastax/ccm-minor-enhancements

More enhancements to CCM tests.
Changesetdb0a78f782ac6945a8879a98fd06e87fd853459cd8683f88413bd3cc6190fd10
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-03-15 10:56 -05:00
CommitterAndrew Tolbert <andrew.tolbert@datastax.com> · 2016-03-15 10:56 -05:00
Parentsc3395b80b593, 605634f891ea

Browse the files at this changeset

14 files changed

modified driver-core/pom.xml +0 −141
@@ -304,66 +304,6 @@
304304 </build>
305305
306306 <profiles>
307- <profile>
308- <id>default</id>
309- <properties>
310- <env>default</env>
311- </properties>
312- <activation>
313- <activeByDefault>true</activeByDefault>
314- </activation>
315- <build>
316- <plugins>
317- <plugin>
318- <groupId>org.apache.maven.plugins</groupId>
319- <artifactId>maven-surefire-plugin</artifactId>
320- <version>2.16</version>
321- <configuration>
322- <groups>unit</groups>
323- <useFile>false</useFile>
324- <systemPropertyVariables>
325- <cassandra.version>${cassandra.version}</cassandra.version>
326- <ipprefix>${ipprefix}</ipprefix>
327- <com.datastax.driver.NEW_NODE_DELAY_SECONDS>60</com.datastax.driver.NEW_NODE_DELAY_SECONDS>
328- </systemPropertyVariables>
329- <classpathDependencyExcludes>
330- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
331- </classpathDependencyExcludes>
332- <!--May be needed for debugging-->
333- <!--<forkMode>never</forkMode>-->
334- </configuration>
335- </plugin>
336- </plugins>
337- </build>
338- </profile>
339-
340- <profile>
341- <id>short</id>
342- <properties>
343- <env>default</env>
344- </properties>
345- <build>
346- <plugins>
347- <plugin>
348- <groupId>org.apache.maven.plugins</groupId>
349- <artifactId>maven-surefire-plugin</artifactId>
350- <version>2.16</version>
351- <configuration>
352- <groups>unit,short</groups>
353- <useFile>false</useFile>
354- <systemPropertyVariables>
355- <cassandra.version>${cassandra.version}</cassandra.version>
356- <ipprefix>${ipprefix}</ipprefix>
357- </systemPropertyVariables>
358- <classpathDependencyExcludes>
359- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
360- </classpathDependencyExcludes>
361- </configuration>
362- </plugin>
363- </plugins>
364- </build>
365- </profile>
366-
367307 <profile>
368308 <id>isolated</id>
369309 <properties>
@@ -388,87 +328,6 @@
388328 </plugins>
389329 </build>
390330 </profile>
391-
392- <profile>
393- <id>long</id>
394- <properties>
395- <env>default</env>
396- </properties>
397- <build>
398- <plugins>
399- <plugin>
400- <groupId>org.apache.maven.plugins</groupId>
401- <artifactId>maven-surefire-plugin</artifactId>
402- <version>2.16</version>
403- <configuration>
404- <groups>unit,short,long</groups>
405- <useFile>false</useFile>
406- <systemPropertyVariables>
407- <cassandra.version>${cassandra.version}</cassandra.version>
408- <ipprefix>${ipprefix}</ipprefix>
409- </systemPropertyVariables>
410- <classpathDependencyExcludes>
411- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
412- </classpathDependencyExcludes>
413- </configuration>
414- </plugin>
415- </plugins>
416- </build>
417- </profile>
418-
419- <profile>
420- <id>duration</id>
421- <properties>
422- <env>default</env>
423- </properties>
424- <build>
425- <plugins>
426- <plugin>
427- <groupId>org.apache.maven.plugins</groupId>
428- <artifactId>maven-surefire-plugin</artifactId>
429- <version>2.16</version>
430- <configuration>
431- <groups>unit,short,long,duration</groups>
432- <useFile>false</useFile>
433- <systemPropertyVariables>
434- <cassandra.version>${cassandra.version}</cassandra.version>
435- <ipprefix>${ipprefix}</ipprefix>
436- </systemPropertyVariables>
437- <classpathDependencyExcludes>
438- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
439- </classpathDependencyExcludes>
440- </configuration>
441- </plugin>
442- </plugins>
443- </build>
444- </profile>
445-
446- <profile>
447- <id>doc</id>
448- <properties>
449- <env>default</env>
450- </properties>
451- <build>
452- <plugins>
453- <plugin>
454- <groupId>org.apache.maven.plugins</groupId>
455- <artifactId>maven-surefire-plugin</artifactId>
456- <version>2.16</version>
457- <configuration>
458- <groups>unit,doc</groups>
459- <useFile>false</useFile>
460- <systemPropertyVariables>
461- <cassandra.version>${cassandra.version}</cassandra.version>
462- <ipprefix>${ipprefix}</ipprefix>
463- </systemPropertyVariables>
464- <classpathDependencyExcludes>
465- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
466- </classpathDependencyExcludes>
467- </configuration>
468- </plugin>
469- </plugins>
470- </build>
471- </profile>
472331 </profiles>
473332
474333 <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;
@@ -659,22 +661,25 @@
659661 * use {@link #builder()} to get an instance
660662 */
661663 public static class Builder {
662- private final String clusterName = TestUtils.generateIdentifier("cluster_");
664+
665+ public static final String RANDOM_PORT = "__RANDOM_PORT__";
666+ private static final Pattern RANDOM_PORT_PATTERN = Pattern.compile(RANDOM_PORT);
667+
663668 int[] nodes = {1};
664669 private boolean start = true;
665670 private boolean isDSE = isDSE();
666671 private String version = getCassandraVersion();
667- private Set<String> createOptions = new HashSet<String>(getInstallArguments());
672+ private Set<String> createOptions = new LinkedHashSet<String>(getInstallArguments());
668673 private Set<String> jvmArgs = new LinkedHashSet<String>();
669- private final Map<String, Object> cassandraConfiguration = Maps.newHashMap();
670- private final Map<String, Object> dseConfiguration = Maps.newHashMap();
671- // -1 means random
672- private int thriftPort = -1;
673- private int binaryPort = -1;
674- private int storagePort = -1;
674+ private final Map<String, Object> cassandraConfiguration = Maps.newLinkedHashMap();
675+ private final Map<String, Object> dseConfiguration = Maps.newLinkedHashMap();
675676 private Map<Integer, Workload> workloads = new HashMap<Integer, Workload>();
676677
677678 private Builder() {
679+ cassandraConfiguration.put("start_rpc", false);
680+ cassandraConfiguration.put("storage_port", RANDOM_PORT);
681+ cassandraConfiguration.put("rpc_port", RANDOM_PORT);
682+ cassandraConfiguration.put("native_transport_port", RANDOM_PORT);
678683 }
679684
680685 /**
@@ -781,17 +786,17 @@
781786 }
782787
783788 public Builder withStoragePort(int port) {
784- storagePort = port;
789+ cassandraConfiguration.put("storage_port", port);
785790 return this;
786791 }
787792
788793 public Builder withThriftPort(int port) {
789- thriftPort = port;
794+ cassandraConfiguration.put("rpc_port", port);
790795 return this;
791796 }
792797
793798 public Builder withBinaryPort(int port) {
794- binaryPort = port;
799+ cassandraConfiguration.put("native_transport_port", port);
795800 return this;
796801 }
797802
@@ -809,10 +814,13 @@
809814
810815 public CCMBridge build() {
811816 // be careful NOT to alter internal state (hashCode/equals) during build!
812- int storagePort = this.storagePort == -1 ? findAvailablePort() : this.storagePort;
813- int thriftPort = this.thriftPort == -1 ? findAvailablePort() : this.thriftPort;
814- int binaryPort = this.binaryPort == -1 ? findAvailablePort() : this.binaryPort;
817+ String clusterName = TestUtils.generateIdentifier("ccm_");
818+ Map<String, Object> cassandraConfiguration = randomizePorts(this.cassandraConfiguration);
819+ Map<String, Object> dseConfiguration = randomizePorts(this.dseConfiguration);
815820 VersionNumber version = VersionNumber.parse(this.version);
821+ int storagePort = Integer.parseInt(cassandraConfiguration.get("storage_port").toString());
822+ int thriftPort = Integer.parseInt(cassandraConfiguration.get("rpc_port").toString());
823+ int binaryPort = Integer.parseInt(cassandraConfiguration.get("native_transport_port").toString());
816824 final CCMBridge ccm = new CCMBridge(clusterName, isDSE, version, storagePort, thriftPort, binaryPort, joinJvmArgs());
817825 Runtime.getRuntime().addShutdownHook(new Thread() {
818826 @Override
@@ -820,14 +828,9 @@
820828 ccm.close();
821829 }
822830 });
823- ccm.execute(buildCreateCommand());
831+ ccm.execute(buildCreateCommand(clusterName));
824832 updateNodeConf(ccm);
825- HashMap<String, Object> config = new HashMap<String, Object>(cassandraConfiguration);
826- config.put("start_rpc", false);
827- config.put("storage_port", storagePort);
828- config.put("rpc_port", thriftPort);
829- config.put("native_transport_port", binaryPort);
830- ccm.updateConfig(config);
833+ ccm.updateConfig(cassandraConfiguration);
831834 if (!dseConfiguration.isEmpty())
832835 ccm.updateDSEConfig(dseConfiguration);
833836 for (Map.Entry<Integer, Workload> entry : workloads.entrySet()) {
@@ -851,12 +854,12 @@
851854 StringBuilder allJvmArgs = new StringBuilder("");
852855 for (String jvmArg : jvmArgs) {
853856 allJvmArgs.append(" --jvm_arg=");
854- allJvmArgs.append(jvmArg);
857+ allJvmArgs.append(randomizePorts(jvmArg));
855858 }
856859 return allJvmArgs.toString();
857860 }
858861
859- private String buildCreateCommand() {
862+ private String buildCreateCommand(String clusterName) {
860863 StringBuilder result = new StringBuilder(CCM_COMMAND + " create");
861864 result.append(" ").append(clusterName);
862865 result.append(" -i ").append(TestUtils.IP_PREFIX);
@@ -870,7 +873,7 @@
870873 result.append(node);
871874 }
872875 }
873- result.append(" ").append(Joiner.on(" ").join(createOptions));
876+ result.append(" ").append(Joiner.on(" ").join(randomizePorts(createOptions)));
874877 return result.toString();
875878 }
876879
@@ -888,7 +891,7 @@
888891 for (int i = 0; i < nodesInDc; i++) {
889892 int jmxPort = findAvailablePort();
890893 int debugPort = findAvailablePort();
891- logger.trace("Node {} in cluster {} using JMX port {} and debug port {}", n, clusterName, jmxPort, debugPort);
894+ logger.trace("Node {} in cluster {} using JMX port {} and debug port {}", n, ccm.getClusterName(), jmxPort, debugPort);
892895 File nodeConf = new File(ccm.getNodeDir(n), "node.conf");
893896 File nodeConf2 = new File(ccm.getNodeDir(n), "node.conf.tmp");
894897 BufferedReader br = closer.register(new BufferedReader(new FileReader(nodeConf)));
@@ -923,6 +926,36 @@
923926 }
924927 }
925928
929+ private Set<String> randomizePorts(Set<String> set) {
930+ Set<String> randomized = new LinkedHashSet<String>();
931+ for (String value : set) {
932+ randomized.add(randomizePorts(value));
933+ }
934+ return randomized;
935+ }
936+
937+ private Map<String, Object> randomizePorts(Map<String, Object> map) {
938+ Map<String, Object> randomized = new HashMap<String, Object>();
939+ for (Map.Entry<String, Object> entry : map.entrySet()) {
940+ Object value = entry.getValue();
941+ if (value instanceof CharSequence) {
942+ value = randomizePorts((CharSequence) value);
943+ }
944+ randomized.put(entry.getKey(), value);
945+ }
946+ return randomized;
947+ }
948+
949+ private String randomizePorts(CharSequence str) {
950+ Matcher matcher = RANDOM_PORT_PATTERN.matcher(str);
951+ StringBuffer sb = new StringBuffer();
952+ while (matcher.find()) {
953+ matcher.appendReplacement(sb, Integer.toString(TestUtils.findAvailablePort()));
954+ }
955+ matcher.appendTail(sb);
956+ return sb.toString();
957+ }
958+
926959 @Override
927960 @SuppressWarnings("SimplifiableIfStatement")
928961 public boolean equals(Object o) {
@@ -932,9 +965,6 @@
932965 if (o == null || getClass() != o.getClass()) return false;
933966 Builder builder = (Builder) o;
934967 if (isDSE != builder.isDSE) return false;
935- if (thriftPort != builder.thriftPort) return false;
936- if (binaryPort != builder.binaryPort) return false;
937- if (storagePort != builder.storagePort) return false;
938968 if (!Arrays.equals(nodes, builder.nodes)) return false;
939969 if (!createOptions.equals(builder.createOptions)) return false;
940970 if (!jvmArgs.equals(builder.jvmArgs)) return false;
@@ -955,17 +985,10 @@
955985 result = 31 * result + cassandraConfiguration.hashCode();
956986 result = 31 * result + dseConfiguration.hashCode();
957987 result = 31 * result + workloads.hashCode();
958- result = 31 * result + thriftPort;
959- result = 31 * result + binaryPort;
960- result = 31 * result + storagePort;
961988 result = 31 * result + version.hashCode();
962989 return result;
963990 }
964991
965- @Override
966- public String toString() {
967- return String.format("%s (%s nodes)", clusterName, weight());
968- }
969992 }
970993
971994 }
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;
@@ -64,9 +63,10 @@
6463 .build());
6564 Session session = cluster.connect();
6665 String deleteStmt = String.format("DELETE rpc_address FROM system.peers WHERE peer = '%s'",
67- InetAddress.getByName(TestUtils.IP_PREFIX + "2").getHostName());
66+ ccm().addressOfNode(2).getHostName());
6867 session.execute(deleteStmt);
6968 session.close();
69+ cluster.close();
7070 }
7171
7272 }
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +17 −35
@@ -18,6 +18,7 @@
1818 import com.datastax.driver.core.policies.RoundRobinPolicy;
1919 import com.datastax.driver.core.policies.WhiteListPolicy;
2020 import com.google.common.base.Predicate;
21+import com.google.common.base.Throwables;
2122 import com.google.common.util.concurrent.Futures;
2223 import com.google.common.util.concurrent.Uninterruptibles;
2324 import com.sun.management.OperatingSystemMXBean;
@@ -39,7 +40,6 @@
3940 import java.util.*;
4041 import java.util.concurrent.*;
4142 import java.util.concurrent.atomic.AtomicInteger;
42-import java.util.concurrent.locks.ReentrantLock;
4343
4444 import static com.datastax.driver.core.ConditionChecker.check;
4545 import static java.util.concurrent.TimeUnit.MINUTES;
@@ -489,47 +489,29 @@
489489 return prefix + seq.incrementAndGet();
490490 }
491491
492- // use ports in the ephemeral range
493- private static int nextPort = 50000;
494-
495- private static final ReentrantLock PORT_LOCK = new ReentrantLock();
496-
497492 /**
498- * Find an available port in the ephemeral range.
493+ * Finds an available port in the ephemeral range.
494+ * This is loosely inspired by Apache MINA's AvailablePortFinder.
499495 *
500496 * @return A local port that is currently unused.
501497 */
502- public static int findAvailablePort() {
503- PORT_LOCK.lock();
498+ public synchronized static int findAvailablePort() throws RuntimeException {
499+ ServerSocket ss = null;
504500 try {
505- for (int i = 0; i < 3; i++) {
506- int port = nextPort;
507- ServerSocket s = null;
508- for (int j = 0; j < 100; j++) {
509- try {
510- s = new ServerSocket(port);
511- s.close();
512- nextPort = port + 1;
513- return port;
514- } catch (IOException e) {
515- // ok
516- } finally {
517- port++;
518- if (s != null) {
519- try {
520- s.close();
521- } catch (IOException e) {
522- // ok
523- }
524- }
525- }
501+ // let the system pick an ephemeral port
502+ ss = new ServerSocket(0);
503+ ss.setReuseAddress(true);
504+ return ss.getLocalPort();
505+ } catch (IOException e) {
506+ throw Throwables.propagate(e);
507+ } finally {
508+ if (ss != null) {
509+ try {
510+ ss.close();
511+ } catch (IOException e) {
512+ Throwables.propagate(e);
526513 }
527- logger.warn("Could not acquire an available port after 100 attempts, sleeping for 1 minute");
528- Uninterruptibles.sleepUninterruptibly(1, TimeUnit.MINUTES);
529514 }
530- throw new RuntimeException(String.format("Could not acquire an available port within range: %s-%s", nextPort, nextPort + 100));
531- } finally {
532- PORT_LOCK.unlock();
533515 }
534516 }
535517
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +27 −9
@@ -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
@@ -37,15 +40,29 @@
3740 public class UserTypesTest extends CCMTestsSupport {
3841
3942 private final static List<DataType> DATA_TYPE_PRIMITIVES = new ArrayList<DataType>(DataType.allPrimitiveTypes());
43+
44+ static {
45+ DATA_TYPE_PRIMITIVES.remove(DataType.counter());
46+ }
47+
4048 private final static List<DataType.Name> DATA_TYPE_NON_PRIMITIVE_NAMES =
4149 new ArrayList<DataType.Name>(EnumSet.of(DataType.Name.LIST, DataType.Name.SET, DataType.Name.MAP, DataType.Name.TUPLE));
4250
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+
4358 @Override
4459 public void onTestContextInitialized() {
4560 String type1 = "CREATE TYPE phone (alias text, number text)";
46- String type2 = "CREATE TYPE address (street text, \"ZIP\" int, phones set<frozen<phone>>)";
47- String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<address>)";
61+ String type2 = "CREATE TYPE \"\"\"User Address\"\"\" (street text, \"ZIP\"\"\" int, phones set<frozen<phone>>)";
62+ String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<\"\"\"User Address\"\"\">)";
4863 execute(type1, type2, table);
64+ // Ci tests fail with "unconfigured columnfamily user"
65+ check().that(userTableExists).before(5, MINUTES).becomesTrue();
4966 }
5067
5168 /**
@@ -59,13 +76,13 @@
5976 PreparedStatement ins = session().prepare("INSERT INTO user(id, addr) VALUES (?, ?)");
6077 PreparedStatement sel = session().prepare("SELECT * FROM user WHERE id=?");
6178
62- UserType addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("address");
79+ UserType addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
6380 UserType phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone");
6481
6582 UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
6683 UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
6784
68- UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP"), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
85+ UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP\""), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
6986
7087 session().execute(ins.bind(userId, addr));
7188
@@ -83,13 +100,14 @@
83100 @Test(groups = "short")
84101 public void simpleUnpreparedWriteReadTest() throws Exception {
85102 int userId = 1;
86- UserType addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("address");
103+ session().execute("USE " + keyspace);
104+ UserType addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
87105 UserType phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone");
88106
89107 UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
90108 UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
91109
92- UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP"), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
110+ UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP\""), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
93111
94112 session().execute("INSERT INTO user(id, addr) VALUES (?, ?)", userId, addr);
95113
@@ -111,7 +129,7 @@
111129 assertEquals(addrDef, null);
112130 assertEquals(phoneDef, null);
113131
114- addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("address");
132+ addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
115133 phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone");
116134 assertNotEquals(addrDef, null);
117135 assertNotEquals(phoneDef, null);
@@ -122,14 +140,14 @@
122140 "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
123141 session().execute("USE " + nonExistingKeyspace);
124142
125- addrDef = cluster().getMetadata().getKeyspace(nonExistingKeyspace).getUserType("address");
143+ addrDef = cluster().getMetadata().getKeyspace(nonExistingKeyspace).getUserType(quote("\"User Address\""));
126144 phoneDef = cluster().getMetadata().getKeyspace(nonExistingKeyspace).getUserType("phone");
127145 assertEquals(addrDef, null);
128146 assertEquals(phoneDef, null);
129147
130148 session().execute("USE " + keyspace);
131149
132- addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("address");
150+ addrDef = cluster().getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
133151 phoneDef = cluster().getMetadata().getKeyspace(keyspace).getUserType("phone");
134152 assertNotEquals(addrDef, null);
135153 assertNotEquals(phoneDef, null);
modified driver-examples/osgi/pom.xml +4 −77
@@ -138,7 +138,7 @@
138138 <plugin>
139139 <groupId>org.apache.maven.plugins</groupId>
140140 <artifactId>maven-failsafe-plugin</artifactId>
141- <version>2.18.1</version>
141+ <version>2.16</version>
142142 <executions>
143143 <execution>
144144 <goals>
@@ -196,14 +196,15 @@
196196 <plugin>
197197 <groupId>org.apache.maven.plugins</groupId>
198198 <artifactId>maven-surefire-plugin</artifactId>
199- <version>2.14</version>
199+ <version>2.16</version>
200200 <configuration>
201+ <skip>true</skip>
201202 </configuration>
202203 </plugin>
203204 <plugin>
204205 <groupId>org.apache.maven.plugins</groupId>
205206 <artifactId>maven-failsafe-plugin</artifactId>
206- <version>2.18.1</version>
207+ <version>2.16</version>
207208 <configuration>
208209 <skip>true</skip>
209210 </configuration>
@@ -219,80 +220,6 @@
219220 </plugins>
220221 </build>
221222 </profile>
222-
223- <profile>
224- <id>short</id>
225- <properties>
226- <env>default</env>
227- </properties>
228- <build>
229- <plugins>
230- <plugin>
231- <groupId>org.apache.maven.plugins</groupId>
232- <artifactId>maven-surefire-plugin</artifactId>
233- <version>2.14</version>
234- <configuration>
235- <groups>unit,short</groups>
236- <useFile>false</useFile>
237- <systemPropertyVariables>
238- <cassandra.version>${cassandra.version}</cassandra.version>
239- <ipprefix>${ipprefix}</ipprefix>
240- </systemPropertyVariables>
241- </configuration>
242- </plugin>
243- <plugin>
244- <groupId>org.apache.maven.plugins</groupId>
245- <artifactId>maven-failsafe-plugin</artifactId>
246- <version>2.18.1</version>
247- <configuration>
248- <groups>unit,short</groups>
249- <useFile>false</useFile>
250- <systemPropertyVariables>
251- <cassandra.version>${cassandra.version}</cassandra.version>
252- <ipprefix>${ipprefix}</ipprefix>
253- </systemPropertyVariables>
254- </configuration>
255- </plugin>
256- </plugins>
257- </build>
258- </profile>
259-
260- <profile>
261- <id>long</id>
262- <properties>
263- <env>default</env>
264- </properties>
265- <build>
266- <plugins>
267- <plugin>
268- <groupId>org.apache.maven.plugins</groupId>
269- <artifactId>maven-surefire-plugin</artifactId>
270- <version>2.16</version>
271- <configuration>
272- <groups>unit,short,long</groups>
273- <useFile>false</useFile>
274- <systemPropertyVariables>
275- <cassandra.version>${cassandra.version}</cassandra.version>
276- <ipprefix>${ipprefix}</ipprefix>
277- </systemPropertyVariables>
278- </configuration>
279- </plugin>
280- <plugin>
281- <groupId>org.apache.maven.plugins</groupId>
282- <artifactId>maven-failsafe-plugin</artifactId>
283- <version>2.18.1</version>
284- <configuration>
285- <groups>unit,short,long</groups>
286- <useFile>false</useFile>
287- <systemPropertyVariables>
288- <cassandra.version>${cassandra.version}</cassandra.version>
289- <ipprefix>${ipprefix}</ipprefix>
290- </systemPropertyVariables>
291- </configuration>
292- </plugin>
293- </plugins>
294- </build>
295- </profile>
296223 </profiles>
297224
298225 <licenses>
modified driver-mapping/pom.xml +0 −87
@@ -126,93 +126,6 @@
126126 </plugin>
127127 </plugins>
128128 </build>
129-
130- <profiles>
131- <profile>
132- <id>default</id>
133- <properties>
134- <env>default</env>
135- </properties>
136- <activation>
137- <activeByDefault>true</activeByDefault>
138- </activation>
139- <build>
140- <plugins>
141- <plugin>
142- <groupId>org.apache.maven.plugins</groupId>
143- <artifactId>maven-surefire-plugin</artifactId>
144- <version>2.14</version>
145- <configuration>
146- <groups>unit</groups>
147- <useFile>false</useFile>
148- <systemPropertyVariables>
149- <cassandra.version>${cassandra.version}</cassandra.version>
150- <ipprefix>${ipprefix}</ipprefix>
151- </systemPropertyVariables>
152- </configuration>
153- </plugin>
154- <plugin>
155- <artifactId>maven-compiler-plugin</artifactId>
156- <configuration>
157- <compilerArgument>-Xlint:all</compilerArgument>
158- <showWarnings>true</showWarnings>
159- <showDeprecation>true</showDeprecation>
160- </configuration>
161- </plugin>
162- </plugins>
163- </build>
164- </profile>
165-
166- <profile>
167- <id>short</id>
168- <properties>
169- <env>default</env>
170- </properties>
171- <build>
172- <plugins>
173- <plugin>
174- <groupId>org.apache.maven.plugins</groupId>
175- <artifactId>maven-surefire-plugin</artifactId>
176- <version>2.14</version>
177- <configuration>
178- <groups>unit,short</groups>
179- <useFile>false</useFile>
180- <systemPropertyVariables>
181- <cassandra.version>${cassandra.version}</cassandra.version>
182- <ipprefix>${ipprefix}</ipprefix>
183- </systemPropertyVariables>
184- </configuration>
185- </plugin>
186- </plugins>
187- </build>
188- </profile>
189-
190- <profile>
191- <id>long</id>
192- <properties>
193- <env>default</env>
194- </properties>
195- <build>
196- <plugins>
197- <plugin>
198- <groupId>org.apache.maven.plugins</groupId>
199- <artifactId>maven-surefire-plugin</artifactId>
200- <version>2.14</version>
201- <configuration>
202- <groups>unit,short,long</groups>
203- <useFile>false</useFile>
204- <systemPropertyVariables>
205- <cassandra.version>${cassandra.version}</cassandra.version>
206- <ipprefix>${ipprefix}</ipprefix>
207- </systemPropertyVariables>
208- </configuration>
209- </plugin>
210- </plugins>
211- </build>
212- </profile>
213-
214- </profiles>
215-
216129 <licenses>
217130 <license>
218131 <name>Apache 2</name>
modified driver-mapping/src/test/java/com/datastax/driver/mapping/MapperTest.java +4 −0
@@ -468,6 +468,7 @@
468468 * @test_category object_mapper
469469 */
470470 @Test(groups = "short")
471+ @CassandraVersion(major = 2.0)
471472 public void should_flag_statement_as_idempotent() {
472473 MappingManager manager = new MappingManager(session());
473474 PostAccessor post = manager.createAccessor(PostAccessor.class);
@@ -484,6 +485,7 @@
484485 * @test_category object_mapper
485486 */
486487 @Test(groups = "short")
488+ @CassandraVersion(major = 2.0)
487489 public void should_flag_statement_as_non_idempotent() {
488490 MappingManager manager = new MappingManager(session());
489491 PostAccessor post = manager.createAccessor(PostAccessor.class);
@@ -500,6 +502,7 @@
500502 * @test_category object_mapper
501503 */
502504 @Test(groups = "short")
505+ @CassandraVersion(major = 2.0)
503506 public void should_flag_statement_with_null_idempotence() {
504507 MappingManager manager = new MappingManager(session());
505508 PostAccessor post = manager.createAccessor(PostAccessor.class);
@@ -515,6 +518,7 @@
515518 * @test_category object_mapper
516519 */
517520 @Test(groups = "short")
521+ @CassandraVersion(major = 2.0)
518522 public void should_flag_all_mapper_generated_statements_as_idempotent() {
519523 MappingManager manager = new MappingManager(session());
520524 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.CCMTestsSupport;
1919 import com.datastax.driver.core.ResultSet;
20+import com.datastax.driver.core.utils.CassandraVersion;
2021 import com.datastax.driver.mapping.annotations.*;
2122 import com.google.common.base.Objects;
2223 import com.google.common.collect.Maps;
@@ -29,6 +30,7 @@
2930 import static org.testng.Assert.*;
3031
3132 @SuppressWarnings("unused")
33+@CassandraVersion(major = 2.1)
3234 public class MapperUDTTest extends CCMTestsSupport {
3335
3436 @Override
modified pom.xml +91 −10
@@ -64,6 +64,8 @@
6464 <mockito.version>1.10.8</mockito.version>
6565 <scassandra.version>0.11.0</scassandra.version>
6666 <main.basedir>${project.basedir}</main.basedir>
67+ <ipprefix>127.0.1.</ipprefix>
68+ <test.groups>unit</test.groups>
6769 </properties>
6870
6971 <dependencies>
@@ -83,6 +85,16 @@
8385 </dependencies>
8486
8587 <profiles>
88+ <profile>
89+ <id>default</id>
90+ <properties>
91+ <env>default</env>
92+ <test.groups>unit</test.groups>
93+ </properties>
94+ <activation>
95+ <activeByDefault>true</activeByDefault>
96+ </activation>
97+ </profile>
8698 <profile>
8799 <id>doclint-java8-disable</id>
88100 <activation>
@@ -93,10 +105,39 @@
93105 </properties>
94106 </profile>
95107 <profile>
96- <!-- default profile settings for 'isolated' test group, will skip tests unless overriden in child module. -->
108+ <id>short</id>
109+ <properties>
110+ <env>default</env>
111+ <test.groups>unit,short</test.groups>
112+ </properties>
113+ </profile>
114+ <profile>
115+ <id>long</id>
116+ <properties>
117+ <env>default</env>
118+ <test.groups>unit,short,long</test.groups>
119+ </properties>
120+ </profile>
121+ <profile>
122+ <id>duration</id>
123+ <properties>
124+ <env>default</env>
125+ <test.groups>unit,short,long,duration</test.groups>
126+ </properties>
127+ </profile>
128+ <profile>
129+ <id>doc</id>
130+ <properties>
131+ <env>default</env>
132+ <test.groups>unit,doc</test.groups>
133+ </properties>
134+ </profile>
135+ <profile>
136+ <!-- default profile settings for 'isolated' test group, will skip tests unless overridden in child module. -->
97137 <id>isolated</id>
98138 <properties>
99139 <env>default</env>
140+ <test.groups>isolated</test.groups>
100141 </properties>
101142 <build>
102143 <plugins>
@@ -108,16 +149,7 @@
108149 <skip>true</skip>
109150 <forkCount>1</forkCount>
110151 <reuseForks>false</reuseForks>
111- <groups>isolated</groups>
112152 <reportNameSuffix>isolated</reportNameSuffix>
113- <useFile>false</useFile>
114- <systemPropertyVariables>
115- <cassandra.version>${cassandra.version}</cassandra.version>
116- <ipprefix>${ipprefix}</ipprefix>
117- </systemPropertyVariables>
118- <classpathDependencyExcludes>
119- <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
120- </classpathDependencyExcludes>
121153 <!-- This requires includes to be explicitly specified by implementing classes.
122154 This is needed to prevent creating a JVM fork for each test, even those that don't
123155 have the isolated group. -->
@@ -242,7 +274,56 @@
242274 </execution>
243275 </executions>
244276 </plugin>
277+ <plugin>
278+ <groupId>org.apache.maven.plugins</groupId>
279+ <artifactId>maven-surefire-plugin</artifactId>
280+ <version>2.16</version>
281+ <configuration>
282+ <groups>${test.groups}</groups>
283+ <useFile>false</useFile>
284+ <systemPropertyVariables>
285+ <cassandra.version>${cassandra.version}</cassandra.version>
286+ <ipprefix>${ipprefix}</ipprefix>
287+ <com.datastax.driver.NEW_NODE_DELAY_SECONDS>60</com.datastax.driver.NEW_NODE_DELAY_SECONDS>
288+ </systemPropertyVariables>
289+ <classpathDependencyExcludes>
290+ <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
291+ </classpathDependencyExcludes>
292+ <properties>
293+ <property>
294+ <!-- Don't skip tests after a @Before method throws a SkipException -->
295+ <name>configfailurepolicy</name>
296+ <value>continue</value>
297+ </property>
298+ </properties>
299+ </configuration>
300+ </plugin>
301+ <plugin>
302+ <groupId>org.apache.maven.plugins</groupId>
303+ <artifactId>maven-failsafe-plugin</artifactId>
304+ <version>2.16</version>
305+ <configuration>
306+ <groups>${test.groups}</groups>
307+ <useFile>false</useFile>
308+ <systemPropertyVariables>
309+ <cassandra.version>${cassandra.version}</cassandra.version>
310+ <ipprefix>${ipprefix}</ipprefix>
311+ <com.datastax.driver.NEW_NODE_DELAY_SECONDS>60</com.datastax.driver.NEW_NODE_DELAY_SECONDS>
312+ </systemPropertyVariables>
313+ <classpathDependencyExcludes>
314+ <classpathDependencyExcludes>io.netty:netty-transport-native-epoll</classpathDependencyExcludes>
315+ </classpathDependencyExcludes>
316+ <properties>
317+ <property>
318+ <!-- Don't skip tests after a @Before method throws a SkipException -->
319+ <name>configfailurepolicy</name>
320+ <value>continue</value>
321+ </property>
322+ </properties>
323+ </configuration>
324+ </plugin>
245325 </plugins>
326+
246327 </build>
247328
248329 <licenses>