Elffuss BraidHub

kikocis/java-driver public

Make some internal settings overridable in integration tests.
Changeset5c835f8a2f895d0760e1500ad9ebc7c0b93d916bdfedbdbe36e3fe8400892603
Authorolim7t <omichallat+github@gmail.com> · 2014-07-17 19:12 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-08-28 16:36 +02:00
Parentscd08308b3373

Browse the files at this changeset

3 files changed

modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +11 −7
@@ -63,6 +63,10 @@
6363
6464 private static final Logger logger = LoggerFactory.getLogger(Cluster.class);
6565
66+ private static final int NEW_NODE_DELAY_SECONDS = SystemProperties.getInt("com.datastax.driver.NEW_NODE_DELAY_SECONDS", 1);
67+ private static final int NON_BLOCKING_EXECUTOR_SIZE = SystemProperties.getInt("com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE",
68+ Runtime.getRuntime().availableProcessors());
69+
6670 // Some per-JVM number that allows to generate unique cluster names when
6771 // multiple Cluster instance are created in the same JVM.
6872 private static final AtomicInteger CLUSTER_ID = new AtomicInteger(0);
@@ -1112,7 +1116,7 @@
11121116 this.configuration = configuration;
11131117 this.configuration.register(this);
11141118
1115- this.executor = makeExecutor(Runtime.getRuntime().availableProcessors(), "Cassandra Java Driver worker-%d");
1119+ this.executor = makeExecutor(NON_BLOCKING_EXECUTOR_SIZE, "Cassandra Java Driver worker-%d");
11161120 this.blockingExecutor = makeExecutor(2, "Cassandra Java Driver blocking tasks worker-%d");
11171121
11181122 this.reaper = new ConnectionReaper();
@@ -1792,7 +1796,7 @@
17921796 // Before refreshing the schema, wait for schema agreement so
17931797 // that querying a table just after having created it don't fail.
17941798 if (!ControlConnection.waitForSchemaAgreement(connection, Cluster.Manager.this))
1795- logger.warn("No schema agreement from live replicas after {} ms. The schema may not be up to date on some nodes.", ControlConnection.MAX_SCHEMA_AGREEMENT_WAIT_MS);
1799+ logger.warn("No schema agreement from live replicas after {} s. The schema may not be up to date on some nodes.", ControlConnection.MAX_SCHEMA_AGREEMENT_WAIT_SECONDS);
17961800 ControlConnection.refreshSchema(connection, keyspace, table, Cluster.Manager.this, false);
17971801 } catch (Exception e) {
17981802 logger.error("Error during schema refresh ({}). The schema from Cluster.getMetadata() might appear stale. Asynchronously submitting job to fix.", e.getMessage());
@@ -1828,9 +1832,9 @@
18281832 final Host newHost = metadata.add(tpAddr);
18291833 if (newHost != null) {
18301834 // Cassandra tends to send notifications for new/up nodes a bit early (it is triggered once
1831- // gossip is up, but that is before the client-side server is up), so we add a somewhat random
1832- // 1 second delay (otherwise the connection will likely fail and have to be retry which is
1833- // wasteful). This probably should be fixed C* side, after which we'll be able to remove this.
1835+ // gossip is up, but that is before the client-side server is up), so we add a delay
1836+ // (otherwise the connection will likely fail and have to be retry which is wasteful). This
1837+ // probably should be fixed C* side, after which we'll be able to remove this.
18341838 scheduledTasksExecutor.schedule(new ExceptionCatchingRunnable() {
18351839 @Override
18361840 public void runMayThrow() throws InterruptedException, ExecutionException {
@@ -1842,7 +1846,7 @@
18421846 logger.debug("Not enough info for {}, ignoring host", newHost);
18431847 }
18441848 }
1845- }, 1, TimeUnit.SECONDS);
1849+ }, NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS);
18461850 }
18471851 break;
18481852 case REMOVED_NODE:
@@ -1884,7 +1888,7 @@
18841888 logger.debug("Not enough info for {}, ignoring host", h);
18851889 }
18861890 }
1887- }, 1, TimeUnit.SECONDS);
1891+ }, NEW_NODE_DELAY_SECONDS, TimeUnit.SECONDS);
18881892 } else {
18891893 executor.submit(new ExceptionCatchingRunnable() {
18901894 @Override
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +3 −3
@@ -36,8 +36,8 @@
3636
3737 private static final Logger logger = LoggerFactory.getLogger(ControlConnection.class);
3838
39- // TODO: we might want to make that configurable
40- static final long MAX_SCHEMA_AGREEMENT_WAIT_MS = 10000;
39+ // TODO: we might want to expose that through the API
40+ static final int MAX_SCHEMA_AGREEMENT_WAIT_SECONDS = SystemProperties.getInt("com.datastax.driver.MAX_SCHEMA_AGREEMENT_WAIT_SECONDS", 10);
4141
4242 private static final InetAddress bindAllAddress;
4343 static
@@ -541,7 +541,7 @@
541541
542542 long start = System.nanoTime();
543543 long elapsed = 0;
544- while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_MS) {
544+ while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_SECONDS * 1000) {
545545
546546 DefaultResultSetFuture peersFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_SCHEMA_PEERS));
547547 DefaultResultSetFuture localFuture = new DefaultResultSetFuture(null, new Requests.Query(SELECT_SCHEMA_LOCAL));
added driver-core/src/main/java/com/datastax/driver/core/SystemProperties.java +29 −0
@@ -0,0 +1,29 @@
1+package com.datastax.driver.core;
2+
3+import org.slf4j.Logger;
4+import org.slf4j.LoggerFactory;
5+
6+/**
7+ * Allows overriding internal settings via system properties.
8+ * <p>
9+ * Warning: this is meant for integration tests only, NOT FOR PRODUCTION USE.
10+ */
11+class SystemProperties {
12+ private static final Logger logger = LoggerFactory.getLogger(SystemProperties.class);
13+
14+ static int getInt(String key, int defaultValue) {
15+ String stringValue = System.getProperty(key);
16+ if (stringValue == null) {
17+ logger.debug("{} is undefined, using default value {}", key, defaultValue);
18+ return defaultValue;
19+ }
20+ try {
21+ int value = Integer.parseInt(stringValue);
22+ logger.debug("{} is defined, using value {}", key, value);
23+ return value;
24+ } catch (NumberFormatException e) {
25+ logger.warn("{} is defined but could not parse value {}, using default value {}", key, stringValue, defaultValue);
26+ return defaultValue;
27+ }
28+ }
29+}