kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 2faf4660456e135a2656596b38848ecfc722d74cdc0bb324a9c8adf342677b31 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-20 10:05 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-20 10:43 +02:00 |
| Parents | 60bd2ef68991, ac8f154e6fc9 |
43 files changed
modified .gitignore +3 −0
| @@ -7,3 +7,6 @@ | ||
| 7 | 7 | doc |
| 8 | 8 | notes |
| 9 | 9 | .DS_Store |
| 10 | + | |
| 11 | +/.idea | |
| 12 | +*.iml |
added CONTRIBUTING.rst +72 −0
| @@ -0,0 +1,72 @@ | ||
| 1 | +Contributing guidelines | |
| 2 | +======================= | |
| 3 | + | |
| 4 | +Working on an issue | |
| 5 | +------------------- | |
| 6 | + | |
| 7 | +Before starting to work on something, please comment in JIRA or ask on the mailing list | |
| 8 | +to make sure nobody else is working on it. | |
| 9 | + | |
| 10 | +If a fix applies both to 2.0 and 2.1, work on the 2.0 branch, your commit will eventually | |
| 11 | +get merged in 2.1. | |
| 12 | + | |
| 13 | +Before you send your pull request, make sure that: | |
| 14 | + | |
| 15 | +- you have a unit test that failed before the fix and succeeds after. | |
| 16 | +- the fix is mentioned in ``driver-core/CHANGELOG.rst``. | |
| 17 | +- the commit message include the reference of the JIRA ticket for automatic linking | |
| 18 | + (example: ``Fix NPE when a connection fails during pool construction (JAVA-503).``). | |
| 19 | + | |
| 20 | +As long as your pull request is not merged, it's OK to rebase your branch and push with | |
| 21 | +``--force``. | |
| 22 | + | |
| 23 | +If you want to contribute but don't have a specific issue in mind, the `lhf <https://datastax-oss.atlassian.net/secure/IssueNavigator.jspa?reset=true&mode=hide&jqlQuery=project%20%3D%20JAVA%20AND%20status%20in%20(Open%2C%20Reopened)%20AND%20labels%20%3D%20lhf>`_ | |
| 24 | +label in JIRA is a good place to start: it marks "low hanging fruits" that don't require | |
| 25 | +in-depth knowledge of the codebase. | |
| 26 | + | |
| 27 | +Editor configuration | |
| 28 | +-------------------- | |
| 29 | + | |
| 30 | +General | |
| 31 | +~~~~~~~ | |
| 32 | + | |
| 33 | +We consider automatic formatting as a help, not a crutch. Sometimes it makes sense to | |
| 34 | +break the rules to make the code more readable, for instance aligning columns (see the | |
| 35 | +constant declarations in ``DataType.Name`` for an example of this). | |
| 36 | + | |
| 37 | +**Please do not reformat whole files, only the lines that you have added or modified**. | |
| 38 | + | |
| 39 | + | |
| 40 | +Eclipse | |
| 41 | +~~~~~~~ | |
| 42 | + | |
| 43 | +Formatter: | |
| 44 | + | |
| 45 | +- Preferences > Java > Code Style > Formatter. | |
| 46 | +- Click "Import". | |
| 47 | +- Select ``src/main/config/ide/eclipse-formatter.xml``. | |
| 48 | + | |
| 49 | +Import order: | |
| 50 | + | |
| 51 | +- Preferences > Java > Code Style > Organize imports. | |
| 52 | +- Click "Import". | |
| 53 | +- Select ``src/main/config/ide/eclipse.importorder``. | |
| 54 | + | |
| 55 | +Prevent trailing whitespaces: | |
| 56 | + | |
| 57 | +- Preferences > Java > Editor > Save Actions. | |
| 58 | +- Check "Perform the selected actions on save". | |
| 59 | +- Ensure "Format source code" and "Organize imports" are unchecked. | |
| 60 | +- Check "Additional actions". | |
| 61 | +- Click "Configure". | |
| 62 | +- In the "Code Organizing" tab, check "Remove trailing whitespace" and "All lines". | |
| 63 | +- Click "OK" (the text area should only have one action "Remove trailing white spaces"). | |
| 64 | + | |
| 65 | + | |
| 66 | +IntelliJ IDEA | |
| 67 | +~~~~~~~~~~~~~ | |
| 68 | + | |
| 69 | +- File > Import Settings... | |
| 70 | +- Select ``src/main/config/ide/intellij-code-style.jar``. | |
| 71 | + | |
| 72 | +This should add a new Code Style scheme called "java-driver". |
modified driver-core/CHANGELOG.rst +34 −0
| @@ -1,6 +1,29 @@ | ||
| 1 | 1 | CHANGELOG |
| 2 | 2 | ========= |
| 3 | 3 | |
| 4 | +2.1.3: | |
| 5 | +------ | |
| 6 | + | |
| 7 | +Merged from 2.0 branch: | |
| 8 | + | |
| 9 | +- [bug] Handle null pool in PooledConnection.release (JAVA-449) | |
| 10 | +- [improvement] Defunct connection on request timeout (JAVA-425) | |
| 11 | +- [improvement] Try next host when we get a SERVER_ERROR (JAVA-426) | |
| 12 | +- [bug] Handle race between query timeout and completion (JAVA-449, JAVA-460, JAVA-471) | |
| 13 | +- [bug] Fix DCAwareRoundRobinPolicy datacenter auto-discovery (JAVA-496) | |
| 14 | +- [bug] Ensure control connection does not trigger concurrent reconnects (JAVA-497) | |
| 15 | +- [improvement] Keep trying to reconnect on authentication errors (JAVA-472) | |
| 16 | +- [improvement] Expose close method on load balancing policy (JAVA-463) | |
| 17 | +- [improvement] Allow load balancing policy to trigger refresh for a single host (JAVA-459) | |
| 18 | +- [bug] Expose an API to cancel reconnection attempts (JAVA-493) | |
| 19 | +- [bug] Fix NPE when a connection fails during pool construction (JAVA-503) | |
| 20 | +- [improvement] Log datacenter name in DCAware policy's init when it is explicitly provided | |
| 21 | + (JAVA-423) | |
| 22 | +- [improvement] Shuffle the replicas in TokenAwarePolicy.newQueryPlan (JAVA-504) | |
| 23 | +- [improvement] Make schema agreement wait tuneable (JAVA-507) | |
| 24 | +- [improvement] Document how to inject the driver metrics into another registry (JAVA-494) | |
| 25 | + | |
| 26 | + | |
| 4 | 27 | 2.1.2: |
| 5 | 28 | ------ |
| 6 | 29 | |
| @@ -96,6 +119,17 @@ | ||
| 96 | 119 | - [improvement] Try next host when we get a SERVER_ERROR (JAVA-426) |
| 97 | 120 | - [bug] Handle race between query timeout and completion (JAVA-449, JAVA-460, JAVA-471) |
| 98 | 121 | - [bug] Fix DCAwareRoundRobinPolicy datacenter auto-discovery (JAVA-496) |
| 122 | +- [bug] Ensure control connection does not trigger concurrent reconnects (JAVA-497) | |
| 123 | +- [improvement] Keep trying to reconnect on authentication errors (JAVA-472) | |
| 124 | +- [improvement] Expose close method on load balancing policy (JAVA-463) | |
| 125 | +- [improvement] Allow load balancing policy to trigger refresh for a single host (JAVA-459) | |
| 126 | +- [bug] Expose an API to cancel reconnection attempts (JAVA-493) | |
| 127 | +- [bug] Fix NPE when a connection fails during pool construction (JAVA-503) | |
| 128 | +- [improvement] Log datacenter name in DCAware policy's init when it is explicitly provided | |
| 129 | + (JAVA-423) | |
| 130 | +- [improvement] Shuffle the replicas in TokenAwarePolicy.newQueryPlan (JAVA-504) | |
| 131 | +- [improvement] Make schema agreement wait tuneable (JAVA-507) | |
| 132 | +- [improvement] Document how to inject the driver metrics into another registry (JAVA-494) | |
| 99 | 133 | |
| 100 | 134 | |
| 101 | 135 | 2.0.6: |
modified driver-core/pom.xml +14 −0
| @@ -71,6 +71,20 @@ | ||
| 71 | 71 | <scope>test</scope> |
| 72 | 72 | </dependency> |
| 73 | 73 | |
| 74 | + <dependency> | |
| 75 | + <groupId>org.assertj</groupId> | |
| 76 | + <artifactId>assertj-core</artifactId> | |
| 77 | + <version>1.7.0</version> | |
| 78 | + <scope>test</scope> | |
| 79 | + </dependency> | |
| 80 | + | |
| 81 | + <dependency> | |
| 82 | + <groupId>org.mockito</groupId> | |
| 83 | + <artifactId>mockito-all</artifactId> | |
| 84 | + <version>1.10.8</version> | |
| 85 | + <scope>test</scope> | |
| 86 | + </dependency> | |
| 87 | + | |
| 74 | 88 | </dependencies> |
| 75 | 89 | |
| 76 | 90 | <build> |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractReconnectionHandler.java +83 −38
| @@ -15,13 +15,11 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.concurrent.RejectedExecutionException; | |
| 19 | -import java.util.concurrent.ScheduledExecutorService; | |
| 20 | -import java.util.concurrent.ScheduledFuture; | |
| 21 | -import java.util.concurrent.TimeUnit; | |
| 18 | +import java.util.concurrent.*; | |
| 22 | 19 | import java.util.concurrent.atomic.AtomicReference; |
| 23 | 20 | |
| 24 | -import com.google.common.util.concurrent.Uninterruptibles; | |
| 21 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 22 | +import com.google.common.util.concurrent.AbstractFuture; | |
| 25 | 23 | import org.slf4j.Logger; |
| 26 | 24 | import org.slf4j.LoggerFactory; |
| 27 | 25 | |
| @@ -34,15 +32,26 @@ | ||
| 34 | 32 | |
| 35 | 33 | private final ScheduledExecutorService executor; |
| 36 | 34 | private final ReconnectionPolicy.ReconnectionSchedule schedule; |
| 37 | - private final AtomicReference<ScheduledFuture<?>> currentAttempt; | |
| 35 | + /** | |
| 36 | + * The future that is exposed to clients, representing completion of the current active handler | |
| 37 | + */ | |
| 38 | + private final AtomicReference<ListenableFuture<?>> currentAttempt; | |
| 38 | 39 | |
| 39 | - private volatile boolean readyForNext; | |
| 40 | - private volatile ScheduledFuture<?> localFuture; | |
| 40 | + private final HandlerFuture handlerFuture = new HandlerFuture(); | |
| 41 | 41 | |
| 42 | - public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<ScheduledFuture<?>> currentAttempt) { | |
| 42 | + private final long initialDelayMs; | |
| 43 | + | |
| 44 | + private volatile boolean isActive; | |
| 45 | + | |
| 46 | + public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<ListenableFuture<?>> currentAttempt) { | |
| 47 | + this(executor, schedule, currentAttempt, -1); | |
| 48 | + } | |
| 49 | + | |
| 50 | + public AbstractReconnectionHandler(ScheduledExecutorService executor, ReconnectionPolicy.ReconnectionSchedule schedule, AtomicReference<ListenableFuture<?>> currentAttempt, long initialDelayMs) { | |
| 43 | 51 | this.executor = executor; |
| 44 | 52 | this.schedule = schedule; |
| 45 | 53 | this.currentAttempt = currentAttempt; |
| 54 | + this.initialDelayMs = initialDelayMs; | |
| 46 | 55 | } |
| 47 | 56 | |
| 48 | 57 | protected abstract Connection tryReconnect() throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException; |
| @@ -51,27 +60,33 @@ | ||
| 51 | 60 | protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { return true; } |
| 52 | 61 | protected boolean onUnknownException(Exception e, long nextDelayMs) { return true; } |
| 53 | 62 | |
| 54 | - // Retrying on authentication or unsupported protocol version error is unlikely to work | |
| 55 | - protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { return false; } | |
| 63 | + // Retrying on authentication errors makes sense for applications that can update the credentials at runtime, we don't want to force them | |
| 64 | + // to restart. | |
| 65 | + protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { return true; } | |
| 66 | + | |
| 67 | + // Retrying on these errors is unlikely to work | |
| 56 | 68 | protected boolean onUnsupportedProtocolVersionException(UnsupportedProtocolVersionException e, long nextDelayMs) { return false; } |
| 57 | 69 | protected boolean onClusterNameMismatchException(ClusterNameMismatchException e, long nextDelayMs) { return false; } |
| 58 | 70 | |
| 59 | 71 | public void start() { |
| 60 | - long firstDelay = schedule.nextDelayMs(); | |
| 72 | + long firstDelay = (initialDelayMs >= 0) ? initialDelayMs : schedule.nextDelayMs(); | |
| 61 | 73 | logger.debug("First reconnection scheduled in {}ms", firstDelay); |
| 62 | 74 | try { |
| 63 | - localFuture = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); | |
| 75 | + handlerFuture.nextTry = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); | |
| 64 | 76 | |
| 65 | - // If there a previous task, cancel it, so only one reconnection handler runs. | |
| 66 | 77 | while (true) { |
| 67 | - ScheduledFuture<?> previous = currentAttempt.get(); | |
| 68 | - if (currentAttempt.compareAndSet(previous, localFuture)) { | |
| 69 | - if (previous != null) | |
| 70 | - previous.cancel(false); | |
| 78 | + ListenableFuture<?> previous = currentAttempt.get(); | |
| 79 | + if (previous != null && !previous.isCancelled()) { | |
| 80 | + logger.debug("Found another already active handler, cancelling"); | |
| 81 | + handlerFuture.cancel(false); | |
| 82 | + return; | |
| 83 | + } | |
| 84 | + if (currentAttempt.compareAndSet(previous, handlerFuture)) { | |
| 85 | + logger.debug("Becoming the active handler"); | |
| 71 | 86 | break; |
| 72 | 87 | } |
| 73 | 88 | } |
| 74 | - readyForNext = true; | |
| 89 | + isActive = true; | |
| 75 | 90 | } catch (RejectedExecutionException e) { |
| 76 | 91 | // The executor has been shutdown, fair enough, just ignore |
| 77 | 92 | logger.debug("Aborting reconnection handling since the cluster is shutting down"); |
| @@ -80,23 +95,34 @@ | ||
| 80 | 95 | |
| 81 | 96 | @Override |
| 82 | 97 | public void run() { |
| 83 | - // We shouldn't arrive here if the future is cancelled but better safe than sorry | |
| 84 | - if (localFuture.isCancelled()) | |
| 98 | + if (handlerFuture.isCancelled()) { | |
| 99 | + logger.debug("Got cancelled, stopping"); | |
| 100 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 85 | 101 | return; |
| 102 | + } | |
| 86 | 103 | |
| 87 | - // Don't run before ready, otherwise our cancel business might end up removing all connection attempts. | |
| 88 | - while (!readyForNext) | |
| 89 | - Uninterruptibles.sleepUninterruptibly(5, TimeUnit.MILLISECONDS); | |
| 104 | + // Just make sure we don't start the first try too fast, in case we find out in start() that we need to cancel ourselves | |
| 105 | + while (!isActive && !Thread.currentThread().isInterrupted()) { | |
| 106 | + try { | |
| 107 | + TimeUnit.MILLISECONDS.sleep(5); | |
| 108 | + } catch (InterruptedException e) { | |
| 109 | + // This can happen at shutdown | |
| 110 | + Thread.currentThread().interrupt(); | |
| 111 | + return; | |
| 112 | + } | |
| 113 | + } | |
| 90 | 114 | |
| 91 | 115 | try { |
| 92 | 116 | onReconnection(tryReconnect()); |
| 93 | - currentAttempt.compareAndSet(localFuture, null); | |
| 117 | + handlerFuture.markAsDone(); | |
| 118 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 119 | + logger.debug("Reconnection successful, cleared the future"); | |
| 94 | 120 | } catch (ConnectionException e) { |
| 95 | 121 | long nextDelay = schedule.nextDelayMs(); |
| 96 | 122 | if (onConnectionException(e, nextDelay)) |
| 97 | 123 | reschedule(nextDelay); |
| 98 | 124 | else |
| 99 | - currentAttempt.compareAndSet(localFuture, null); | |
| 125 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 100 | 126 | } catch (AuthenticationException e) { |
| 101 | 127 | logger.error(e.getMessage()); |
| 102 | 128 | long nextDelay = schedule.nextDelayMs(); |
| @@ -104,7 +130,7 @@ | ||
| 104 | 130 | reschedule(nextDelay); |
| 105 | 131 | } else { |
| 106 | 132 | logger.error("Retry against {} have been suspended. It won't be retried unless the node is restarted.", e.getHost()); |
| 107 | - currentAttempt.compareAndSet(localFuture, null); | |
| 133 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 108 | 134 | } |
| 109 | 135 | } catch (InterruptedException e) { |
| 110 | 136 | // If interrupted, skip this attempt but still skip scheduling reconnections |
| @@ -117,7 +143,7 @@ | ||
| 117 | 143 | reschedule(nextDelay); |
| 118 | 144 | } else { |
| 119 | 145 | logger.error("Retry against {} have been suspended. It won't be retried unless the node is restarted.", e.address); |
| 120 | - currentAttempt.compareAndSet(localFuture, null); | |
| 146 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 121 | 147 | } |
| 122 | 148 | } catch (ClusterNameMismatchException e) { |
| 123 | 149 | logger.error(e.getMessage()); |
| @@ -126,26 +152,45 @@ | ||
| 126 | 152 | reschedule(nextDelay); |
| 127 | 153 | } else { |
| 128 | 154 | logger.error("Retry against {} have been suspended. It won't be retried unless the node is restarted.", e.address); |
| 129 | - currentAttempt.compareAndSet(localFuture, null); | |
| 155 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 130 | 156 | } |
| 131 | 157 | } catch (Exception e) { |
| 132 | 158 | long nextDelay = schedule.nextDelayMs(); |
| 133 | 159 | if (onUnknownException(e, nextDelay)) |
| 134 | 160 | reschedule(nextDelay); |
| 135 | 161 | else |
| 136 | - currentAttempt.compareAndSet(localFuture, null); | |
| 162 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 137 | 163 | } |
| 138 | 164 | } |
| 139 | 165 | |
| 140 | 166 | private void reschedule(long nextDelay) { |
| 141 | - readyForNext = false; | |
| 142 | - ScheduledFuture<?> newFuture = executor.schedule(this, nextDelay, TimeUnit.MILLISECONDS); | |
| 143 | - assert localFuture != null; | |
| 144 | - // If it's not our future the current one, then we've been canceled | |
| 145 | - if (!currentAttempt.compareAndSet(localFuture, newFuture)) { | |
| 146 | - newFuture.cancel(false); | |
| 167 | + // If we got cancelled during the failed reconnection attempt that lead here, don't reschedule | |
| 168 | + if (handlerFuture.isCancelled()) { | |
| 169 | + currentAttempt.compareAndSet(handlerFuture, null); | |
| 170 | + return; | |
| 171 | + } | |
| 172 | + | |
| 173 | + handlerFuture.nextTry = executor.schedule(this, nextDelay, TimeUnit.MILLISECONDS); | |
| 174 | + } | |
| 175 | + | |
| 176 | + // The future that the handler exposes to its clients via currentAttempt | |
| 177 | + private static class HandlerFuture extends AbstractFuture<Void> { | |
| 178 | + // A future representing completion of the next task submitted to the executor | |
| 179 | + volatile ScheduledFuture<?> nextTry; | |
| 180 | + | |
| 181 | + @Override | |
| 182 | + public boolean cancel(boolean mayInterruptIfRunning) { | |
| 183 | + // This is a check-then-act, so we may race with the scheduling of the first try, but in that case | |
| 184 | + // we'll re-check for cancellation when this first try starts running | |
| 185 | + if (nextTry != null) { | |
| 186 | + nextTry.cancel(mayInterruptIfRunning); | |
| 187 | + } | |
| 188 | + | |
| 189 | + return super.cancel(mayInterruptIfRunning); | |
| 190 | + } | |
| 191 | + | |
| 192 | + void markAsDone() { | |
| 193 | + super.set(null); | |
| 147 | 194 | } |
| 148 | - localFuture = newFuture; | |
| 149 | - readyForNext = true; | |
| 150 | 195 | } |
| 151 | 196 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +97 −4
| @@ -24,6 +24,7 @@ | ||
| 24 | 24 | import java.util.concurrent.atomic.AtomicInteger; |
| 25 | 25 | import java.util.concurrent.atomic.AtomicReference; |
| 26 | 26 | |
| 27 | +import com.google.common.annotations.VisibleForTesting; | |
| 27 | 28 | import com.google.common.base.Predicates; |
| 28 | 29 | import com.google.common.collect.HashMultimap; |
| 29 | 30 | import com.google.common.collect.Iterables; |
| @@ -63,7 +64,8 @@ | ||
| 63 | 64 | |
| 64 | 65 | private static final Logger logger = LoggerFactory.getLogger(Cluster.class); |
| 65 | 66 | |
| 66 | - private static final int NEW_NODE_DELAY_SECONDS = SystemProperties.getInt("com.datastax.driver.NEW_NODE_DELAY_SECONDS", 1); | |
| 67 | + @VisibleForTesting | |
| 68 | + static final int NEW_NODE_DELAY_SECONDS = SystemProperties.getInt("com.datastax.driver.NEW_NODE_DELAY_SECONDS", 1); | |
| 67 | 69 | private static final int NON_BLOCKING_EXECUTOR_SIZE = SystemProperties.getInt("com.datastax.driver.NON_BLOCKING_EXECUTOR_SIZE", |
| 68 | 70 | Runtime.getRuntime().availableProcessors()); |
| 69 | 71 | |
| @@ -536,6 +538,7 @@ | ||
| 536 | 538 | private final List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>(); |
| 537 | 539 | private final List<InetAddress> rawAddresses = new ArrayList<InetAddress>(); |
| 538 | 540 | private int port = ProtocolOptions.DEFAULT_PORT; |
| 541 | + private int maxSchemaAgreementWaitSeconds = ProtocolOptions.DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS; | |
| 539 | 542 | private ProtocolVersion protocolVersion; |
| 540 | 543 | private AuthProvider authProvider = AuthProvider.NONE; |
| 541 | 544 | |
| @@ -607,6 +610,24 @@ | ||
| 607 | 610 | return this; |
| 608 | 611 | } |
| 609 | 612 | |
| 613 | + /** | |
| 614 | + * Sets the maximum time to wait for schema agreement before returning from a DDL query. | |
| 615 | + * <p> | |
| 616 | + * If not set through this method, the default value (10 seconds) will be used. | |
| 617 | + * | |
| 618 | + * @param maxSchemaAgreementWaitSeconds the new value to set. | |
| 619 | + * @return this Builder. | |
| 620 | + * | |
| 621 | + * @throws IllegalStateException if the provided value is zero or less. | |
| 622 | + */ | |
| 623 | + public Builder withMaxSchemaAgreementWaitSeconds(int maxSchemaAgreementWaitSeconds) { | |
| 624 | + if (maxSchemaAgreementWaitSeconds <= 0) | |
| 625 | + throw new IllegalArgumentException("Max schema agreement wait must be greater than zero"); | |
| 626 | + | |
| 627 | + this.maxSchemaAgreementWaitSeconds = maxSchemaAgreementWaitSeconds; | |
| 628 | + return this; | |
| 629 | + } | |
| 630 | + | |
| 610 | 631 | /** |
| 611 | 632 | * The native protocol version to use. |
| 612 | 633 | * <p> |
| @@ -1051,7 +1072,7 @@ | ||
| 1051 | 1072 | timestampGenerator == null ? Policies.defaultTimestampGenerator() : timestampGenerator |
| 1052 | 1073 | ); |
| 1053 | 1074 | return new Configuration(policies, |
| 1054 | - new ProtocolOptions(port, protocolVersion, sslOptions, authProvider).setCompression(compression), | |
| 1075 | + new ProtocolOptions(port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider).setCompression(compression), | |
| 1055 | 1076 | poolingOptions == null ? new PoolingOptions() : poolingOptions, |
| 1056 | 1077 | socketOptions == null ? new SocketOptions() : socketOptions, |
| 1057 | 1078 | metricsEnabled ? new MetricsOptions(jmxEnabled) : null, |
| @@ -1290,6 +1311,11 @@ | ||
| 1290 | 1311 | if (metrics != null) |
| 1291 | 1312 | metrics.shutdown(); |
| 1292 | 1313 | |
| 1314 | + // And the load balancing policy | |
| 1315 | + LoadBalancingPolicy loadBalancingPolicy = loadBalancingPolicy(); | |
| 1316 | + if (loadBalancingPolicy instanceof CloseableLoadBalancingPolicy) | |
| 1317 | + ((CloseableLoadBalancingPolicy)loadBalancingPolicy).close(); | |
| 1318 | + | |
| 1293 | 1319 | // Then we shutdown all connections |
| 1294 | 1320 | List<CloseFuture> futures = new ArrayList<CloseFuture>(sessions.size() + 1); |
| 1295 | 1321 | futures.add(controlConnection.closeAsync()); |
| @@ -1350,7 +1376,7 @@ | ||
| 1350 | 1376 | } |
| 1351 | 1377 | |
| 1352 | 1378 | // If there is a reconnection attempt scheduled for that node, cancel it |
| 1353 | - ScheduledFuture<?> scheduledAttempt = host.reconnectionAttempt.getAndSet(null); | |
| 1379 | + Future<?> scheduledAttempt = host.reconnectionAttempt.getAndSet(null); | |
| 1354 | 1380 | if (scheduledAttempt != null) { |
| 1355 | 1381 | logger.debug("Cancelling reconnection attempt since node is UP"); |
| 1356 | 1382 | scheduledAttempt.cancel(false); |
| @@ -1578,6 +1604,63 @@ | ||
| 1578 | 1604 | return true; |
| 1579 | 1605 | } |
| 1580 | 1606 | |
| 1607 | + protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { | |
| 1608 | + logger.error(String.format("Authentication error during reconnection to %s, scheduling retry in %d milliseconds", host, nextDelayMs), e); | |
| 1609 | + return true; | |
| 1610 | + } | |
| 1611 | + | |
| 1612 | + }.start(); | |
| 1613 | + } | |
| 1614 | + | |
| 1615 | + public void tryReconnectOnce(final Host host) { | |
| 1616 | + if (isClosed() || host.isUp()) | |
| 1617 | + return; | |
| 1618 | + | |
| 1619 | + logger.debug("Scheduling one-time reconnection to {}", host); | |
| 1620 | + | |
| 1621 | + // Setting an initial delay of 0 to start immediately, and all the exception handlers return false to prevent further attempts | |
| 1622 | + new AbstractReconnectionHandler(reconnectionExecutor, reconnectionPolicy().newSchedule(), host.reconnectionAttempt, 0) { | |
| 1623 | + | |
| 1624 | + protected Connection tryReconnect() throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { | |
| 1625 | + return connectionFactory.open(host); | |
| 1626 | + } | |
| 1627 | + | |
| 1628 | + protected void onReconnection(Connection connection) { | |
| 1629 | + // We don't use that first connection so close it. | |
| 1630 | + // TODO: this is a bit wasteful, we should consider passing it to onAdd/onUp so | |
| 1631 | + // we use it for the first HostConnectionPool created | |
| 1632 | + connection.closeAsync(); | |
| 1633 | + // Make sure we have up-to-date infos on that host before adding it (so we typically | |
| 1634 | + // catch that an upgraded node uses a new cassandra version). | |
| 1635 | + if (controlConnection.refreshNodeInfo(host)) { | |
| 1636 | + logger.debug("Successful reconnection to {}, setting host UP", host); | |
| 1637 | + try { | |
| 1638 | + onUp(host); | |
| 1639 | + } catch (InterruptedException e) { | |
| 1640 | + Thread.currentThread().interrupt(); | |
| 1641 | + } catch (Exception e) { | |
| 1642 | + logger.error("Unexpected error while setting node up", e); | |
| 1643 | + } | |
| 1644 | + } else { | |
| 1645 | + logger.debug("Not enough info for {}, ignoring host", host); | |
| 1646 | + } | |
| 1647 | + } | |
| 1648 | + | |
| 1649 | + protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { | |
| 1650 | + if (logger.isDebugEnabled()) | |
| 1651 | + logger.debug("Failed one-time reconnection to {} ({})", host, e.getMessage()); | |
| 1652 | + return false; | |
| 1653 | + } | |
| 1654 | + | |
| 1655 | + protected boolean onUnknownException(Exception e, long nextDelayMs) { | |
| 1656 | + logger.error(String.format("Unknown error during one-time reconnection to %s", host), e); | |
| 1657 | + return false; | |
| 1658 | + } | |
| 1659 | + | |
| 1660 | + protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { | |
| 1661 | + logger.error(String.format("Authentication error during one-time reconnection to %s", host), e); | |
| 1662 | + return false; | |
| 1663 | + } | |
| 1581 | 1664 | }.start(); |
| 1582 | 1665 | } |
| 1583 | 1666 | |
| @@ -1844,7 +1927,7 @@ | ||
| 1844 | 1927 | // Before refreshing the schema, wait for schema agreement so |
| 1845 | 1928 | // that querying a table just after having created it don't fail. |
| 1846 | 1929 | if (!ControlConnection.waitForSchemaAgreement(connection, Cluster.Manager.this)) |
| 1847 | - 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); | |
| 1930 | + logger.warn("No schema agreement from live replicas after {} s. The schema may not be up to date on some nodes.", configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds()); | |
| 1848 | 1931 | ControlConnection.refreshSchema(connection, keyspace, table, Cluster.Manager.this, false); |
| 1849 | 1932 | } catch (Exception e) { |
| 1850 | 1933 | logger.error("Error during schema refresh ({}). The schema from Cluster.getMetadata() might appear stale. Asynchronously submitting job to fix.", e.getMessage()); |
| @@ -2000,6 +2083,16 @@ | ||
| 2000 | 2083 | s.updateCreatedPools(executor); |
| 2001 | 2084 | } |
| 2002 | 2085 | |
| 2086 | + void refreshConnectedHost(Host host) { | |
| 2087 | + // Deal with the control connection if it was using this host | |
| 2088 | + Host ccHost = controlConnection.connectedHost(); | |
| 2089 | + if (ccHost == null || ccHost.equals(host) && loadBalancingPolicy().distance(ccHost) != HostDistance.LOCAL) | |
| 2090 | + controlConnection.reconnect(); | |
| 2091 | + | |
| 2092 | + for (SessionManager s : sessions) | |
| 2093 | + s.updateCreatedPools(host, executor); | |
| 2094 | + } | |
| 2095 | + | |
| 2003 | 2096 | private class ClusterCloseFuture extends CloseFuture.Forwarding { |
| 2004 | 2097 | |
| 2005 | 2098 | ClusterCloseFuture(List<CloseFuture> futures) { |
modified driver-core/src/main/java/com/datastax/driver/core/Connection.java +9 −2
| @@ -267,8 +267,15 @@ | ||
| 267 | 267 | // sure the "suspected" mechanism work as expected |
| 268 | 268 | Host host = factory.manager.metadata.getHost(address); |
| 269 | 269 | if (host != null) { |
| 270 | - boolean isDown = factory.manager.signalConnectionFailure(host, ce, host.wasJustAdded(), isInitialized); | |
| 271 | - notifyOwnerWhenDefunct(isDown); | |
| 270 | + // If we get an error on a host that was already DOWN or SUSPECTED, this is a reconnection attempt. | |
| 271 | + // We don't want to signal, because that would invoke triggerOnDown unnecessarily (the host's bad | |
| 272 | + // condition is already taken care of by the reattempt in progress) | |
| 273 | + boolean isReconnectionAttempt = (host.state == Host.State.DOWN || host.state == Host.State.SUSPECT) | |
| 274 | + && !(this instanceof PooledConnection); | |
| 275 | + if (!isReconnectionAttempt) { | |
| 276 | + boolean isDown = factory.manager.signalConnectionFailure(host, ce, host.wasJustAdded(), isInitialized); | |
| 277 | + notifyOwnerWhenDefunct(isDown); | |
| 278 | + } | |
| 272 | 279 | } |
| 273 | 280 | |
| 274 | 281 | // Force the connection to close to make sure the future completes. Otherwise force() might never get called and |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +63 −51
| @@ -20,11 +20,11 @@ | ||
| 20 | 20 | import java.net.UnknownHostException; |
| 21 | 21 | import java.util.*; |
| 22 | 22 | import java.util.concurrent.ExecutionException; |
| 23 | -import java.util.concurrent.ScheduledFuture; | |
| 24 | 23 | import java.util.concurrent.TimeUnit; |
| 25 | 24 | import java.util.concurrent.atomic.AtomicReference; |
| 26 | 25 | |
| 27 | 26 | import com.google.common.base.Objects; |
| 27 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 28 | 28 | import org.slf4j.Logger; |
| 29 | 29 | import org.slf4j.LoggerFactory; |
| 30 | 30 | |
| @@ -36,9 +36,6 @@ | ||
| 36 | 36 | |
| 37 | 37 | private static final Logger logger = LoggerFactory.getLogger(ControlConnection.class); |
| 38 | 38 | |
| 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); | |
| 41 | - | |
| 42 | 39 | private static final InetAddress bindAllAddress; |
| 43 | 40 | static |
| 44 | 41 | { |
| @@ -64,7 +61,7 @@ | ||
| 64 | 61 | |
| 65 | 62 | private final Cluster.Manager cluster; |
| 66 | 63 | |
| 67 | - private final AtomicReference<ScheduledFuture<?>> reconnectionAttempt = new AtomicReference<ScheduledFuture<?>>(); | |
| 64 | + private final AtomicReference<ListenableFuture<?>> reconnectionAttempt = new AtomicReference<ListenableFuture<?>>(); | |
| 68 | 65 | |
| 69 | 66 | private volatile boolean isShutdown; |
| 70 | 67 | |
| @@ -84,6 +81,12 @@ | ||
| 84 | 81 | // We don't have to be fancy here. We just set a flag so that we stop trying to reconnect (and thus change the |
| 85 | 82 | // connection used) and shutdown the current one. |
| 86 | 83 | isShutdown = true; |
| 84 | + | |
| 85 | + // Cancel any reconnection attempt in progress | |
| 86 | + ListenableFuture<?> r = reconnectionAttempt.get(); | |
| 87 | + if (r != null) | |
| 88 | + r.cancel(false); | |
| 89 | + | |
| 87 | 90 | Connection connection = connectionRef.get(); |
| 88 | 91 | return connection == null ? CloseFuture.immediateFuture() : connection.closeAsync(); |
| 89 | 92 | } |
| @@ -101,37 +104,7 @@ | ||
| 101 | 104 | setNewConnection(reconnectInternal(queryPlan(), false)); |
| 102 | 105 | } catch (NoHostAvailableException e) { |
| 103 | 106 | logger.error("[Control connection] Cannot connect to any host, scheduling retry"); |
| 104 | - new AbstractReconnectionHandler(cluster.reconnectionExecutor, cluster.reconnectionPolicy().newSchedule(), reconnectionAttempt) { | |
| 105 | - @Override | |
| 106 | - protected Connection tryReconnect() throws ConnectionException { | |
| 107 | - try { | |
| 108 | - return reconnectInternal(queryPlan(), false); | |
| 109 | - } catch (NoHostAvailableException e) { | |
| 110 | - throw new ConnectionException(null, e.getMessage()); | |
| 111 | - } catch (UnsupportedProtocolVersionException e) { | |
| 112 | - // reconnectInternal only propagate those if we've not decided on the protocol version yet, | |
| 113 | - // which should only happen on the initial connection and thus in connect() but never here. | |
| 114 | - throw new AssertionError(); | |
| 115 | - } | |
| 116 | - } | |
| 117 | - | |
| 118 | - @Override | |
| 119 | - protected void onReconnection(Connection connection) { | |
| 120 | - setNewConnection(connection); | |
| 121 | - } | |
| 122 | - | |
| 123 | - @Override | |
| 124 | - protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { | |
| 125 | - logger.error("[Control connection] Cannot connect to any host, scheduling retry in {} milliseconds", nextDelayMs); | |
| 126 | - return true; | |
| 127 | - } | |
| 128 | - | |
| 129 | - @Override | |
| 130 | - protected boolean onUnknownException(Exception e, long nextDelayMs) { | |
| 131 | - logger.error(String.format("[Control connection] Unknown error during reconnection, scheduling retry in %d milliseconds", nextDelayMs), e); | |
| 132 | - return true; | |
| 133 | - } | |
| 134 | - }.start(); | |
| 107 | + backgroundReconnect(-1); | |
| 135 | 108 | } catch (UnsupportedProtocolVersionException e) { |
| 136 | 109 | // reconnectInternal only propagate those if we've not decided on the protocol version yet, |
| 137 | 110 | // which should only happen on the initial connection and thus in connect() but never here. |
| @@ -139,18 +112,60 @@ | ||
| 139 | 112 | } |
| 140 | 113 | } |
| 141 | 114 | |
| 115 | + /** | |
| 116 | + * @param initialDelayMs if >=0, bypass the schedule and use this for the first call | |
| 117 | + */ | |
| 118 | + private void backgroundReconnect(long initialDelayMs) { | |
| 119 | + if (isShutdown) | |
| 120 | + return; | |
| 121 | + | |
| 122 | + new AbstractReconnectionHandler(cluster.reconnectionExecutor, cluster.reconnectionPolicy().newSchedule(), reconnectionAttempt, initialDelayMs) { | |
| 123 | + @Override | |
| 124 | + protected Connection tryReconnect() throws ConnectionException { | |
| 125 | + try { | |
| 126 | + return reconnectInternal(queryPlan(), false); | |
| 127 | + } catch (NoHostAvailableException e) { | |
| 128 | + throw new ConnectionException(null, e.getMessage()); | |
| 129 | + } catch (UnsupportedProtocolVersionException e) { | |
| 130 | + // reconnectInternal only propagate those if we've not decided on the protocol version yet, | |
| 131 | + // which should only happen on the initial connection and thus in connect() but never here. | |
| 132 | + throw new AssertionError(); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + @Override | |
| 137 | + protected void onReconnection(Connection connection) { | |
| 138 | + setNewConnection(connection); | |
| 139 | + } | |
| 140 | + | |
| 141 | + @Override | |
| 142 | + protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { | |
| 143 | + logger.error("[Control connection] Cannot connect to any host, scheduling retry in {} milliseconds", nextDelayMs); | |
| 144 | + return true; | |
| 145 | + } | |
| 146 | + | |
| 147 | + @Override | |
| 148 | + protected boolean onUnknownException(Exception e, long nextDelayMs) { | |
| 149 | + logger.error(String.format("[Control connection] Unknown error during reconnection, scheduling retry in %d milliseconds", nextDelayMs), e); | |
| 150 | + return true; | |
| 151 | + } | |
| 152 | + }.start(); | |
| 153 | + } | |
| 154 | + | |
| 142 | 155 | private Iterator<Host> queryPlan() { |
| 143 | 156 | return cluster.loadBalancingPolicy().newQueryPlan(null, Statement.DEFAULT); |
| 144 | 157 | } |
| 145 | 158 | |
| 146 | 159 | private void signalError() { |
| 147 | - // If the connection was marked as defunct, this already reported the | |
| 148 | - // node down, which will trigger a reconnect. Otherwise, just reconnect | |
| 149 | - // manually | |
| 150 | 160 | Connection connection = connectionRef.get(); |
| 151 | - if (connection == null || !connection.isDefunct()) { | |
| 152 | - reconnect(); | |
| 161 | + if (connection != null && connection.isDefunct()) { | |
| 162 | + // If the connection was marked as defunct, this already reported the | |
| 163 | + // node down, which will trigger a reconnect. Otherwise, just reconnect | |
| 164 | + // manually | |
| 165 | + return; | |
| 153 | 166 | } |
| 167 | + // If the connection is not defunct, or the host has left, just reconnect manually | |
| 168 | + backgroundReconnect(0); | |
| 154 | 169 | } |
| 155 | 170 | |
| 156 | 171 | private void setNewConnection(Connection newConnection) { |
| @@ -554,7 +569,8 @@ | ||
| 554 | 569 | |
| 555 | 570 | long start = System.nanoTime(); |
| 556 | 571 | long elapsed = 0; |
| 557 | - while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_SECONDS * 1000) { | |
| 572 | + int maxSchemaAgreementWaitSeconds = cluster.configuration.getProtocolOptions().getMaxSchemaAgreementWaitSeconds(); | |
| 573 | + while (elapsed < maxSchemaAgreementWaitSeconds * 1000) { | |
| 558 | 574 | |
| 559 | 575 | DefaultResultSetFuture peersFuture = new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_PEERS)); |
| 560 | 576 | DefaultResultSetFuture localFuture = new DefaultResultSetFuture(null, cluster.protocolVersion(), new Requests.Query(SELECT_SCHEMA_LOCAL)); |
| @@ -607,15 +623,11 @@ | ||
| 607 | 623 | Connection current = connectionRef.get(); |
| 608 | 624 | if (logger.isDebugEnabled()) |
| 609 | 625 | logger.debug("[Control connection] {} is down, currently connected to {}", host, current == null ? "nobody" : current.address); |
| 610 | - if (current != null && current.address.equals(host.getSocketAddress()) && reconnectionAttempt.get() == null) { | |
| 611 | - // We might very be on an I/O thread when we reach this so we should not do that on this thread. | |
| 612 | - // Besides, there is no reason to block the onDown method while we try to reconnect. | |
| 613 | - cluster.blockingExecutor.submit(new Runnable() { | |
| 614 | - @Override | |
| 615 | - public void run() { | |
| 616 | - reconnect(); | |
| 617 | - } | |
| 618 | - }); | |
| 626 | + | |
| 627 | + if (current != null && current.address.equals(host.getSocketAddress())) { | |
| 628 | + // This starts an AbstractReconnectionHandler, which will take care of checking if another reconnection is | |
| 629 | + // already in progress | |
| 630 | + backgroundReconnect(0); | |
| 619 | 631 | } |
| 620 | 632 | } |
| 621 | 633 |
modified driver-core/src/main/java/com/datastax/driver/core/DynamicConnectionPool.java +10 −0
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import java.util.concurrent.atomic.AtomicInteger; |
| 22 | 22 | import java.util.concurrent.locks.*; |
| 23 | 23 | |
| 24 | +import com.google.common.collect.Lists; | |
| 24 | 25 | import com.google.common.util.concurrent.MoreExecutors; |
| 25 | 26 | import org.slf4j.Logger; |
| 26 | 27 | import org.slf4j.LoggerFactory; |
| @@ -75,6 +76,12 @@ | ||
| 75 | 76 | Thread.currentThread().interrupt(); |
| 76 | 77 | // If asked to interrupt, we can skip opening core connections, the pool will still work. |
| 77 | 78 | // But we ignore otherwise cause I'm not sure we can do much better currently. |
| 79 | + } catch (RuntimeException e) { | |
| 80 | + // Rethrow but make sure to properly close the connections in our temporary list. | |
| 81 | + for (PooledConnection connection : l) { | |
| 82 | + connection.closeAsync().force(); | |
| 83 | + } | |
| 84 | + throw e; | |
| 78 | 85 | } |
| 79 | 86 | this.connections = new CopyOnWriteArrayList<PooledConnection>(l); |
| 80 | 87 | this.open = new AtomicInteger(connections.size()); |
| @@ -385,6 +392,9 @@ | ||
| 385 | 392 | } |
| 386 | 393 | |
| 387 | 394 | private List<CloseFuture> discardAvailableConnections() { |
| 395 | + // This can happen if creating the connections in the constructor fails | |
| 396 | + if (connections == null) | |
| 397 | + return Lists.newArrayList(CloseFuture.immediateFuture()); | |
| 388 | 398 | |
| 389 | 399 | List<CloseFuture> futures = new ArrayList<CloseFuture>(connections.size()); |
| 390 | 400 | for (final PooledConnection connection : connections) { |
modified driver-core/src/main/java/com/datastax/driver/core/Host.java +52 −3
| @@ -17,7 +17,6 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.net.InetAddress; |
| 19 | 19 | import java.net.InetSocketAddress; |
| 20 | -import java.util.concurrent.ScheduledFuture; | |
| 21 | 20 | import java.util.concurrent.atomic.AtomicReference; |
| 22 | 21 | |
| 23 | 22 | import com.google.common.collect.ImmutableList; |
| @@ -44,12 +43,13 @@ | ||
| 44 | 43 | volatile State state; |
| 45 | 44 | |
| 46 | 45 | private final ConvictionPolicy policy; |
| 46 | + private final Cluster.Manager manager; | |
| 47 | 47 | |
| 48 | 48 | // Tracks the first "immediate" reconnection attempt when a node get suspected. |
| 49 | 49 | final AtomicReference<ListenableFuture<?>> initialReconnectionAttempt = new AtomicReference<ListenableFuture<?>>(Futures.immediateFuture(null)); |
| 50 | 50 | |
| 51 | 51 | // Tracks later reconnection attempts to that host so we avoid adding multiple tasks. |
| 52 | - final AtomicReference<ScheduledFuture<?>> reconnectionAttempt = new AtomicReference<ScheduledFuture<?>>(); | |
| 52 | + final AtomicReference<ListenableFuture<?>> reconnectionAttempt = new AtomicReference<ListenableFuture<?>>(); | |
| 53 | 53 | |
| 54 | 54 | final ExecutionInfo defaultExecutionInfo; |
| 55 | 55 | |
| @@ -66,12 +66,13 @@ | ||
| 66 | 66 | // ClusterMetadata keeps one Host object per inet address and we rely on this (more precisely, |
| 67 | 67 | // we rely on the fact that we can use Object equality as a valid equality), so don't use |
| 68 | 68 | // that constructor but ClusterMetadata.getHost instead. |
| 69 | - Host(InetSocketAddress address, ConvictionPolicy.Factory policy) { | |
| 69 | + Host(InetSocketAddress address, ConvictionPolicy.Factory policy, Cluster.Manager manager) { | |
| 70 | 70 | if (address == null || policy == null) |
| 71 | 71 | throw new NullPointerException(); |
| 72 | 72 | |
| 73 | 73 | this.address = address; |
| 74 | 74 | this.policy = policy.create(this); |
| 75 | + this.manager = manager; | |
| 75 | 76 | this.defaultExecutionInfo = new ExecutionInfo(ImmutableList.of(this)); |
| 76 | 77 | this.state = State.ADDED; |
| 77 | 78 | } |
| @@ -173,10 +174,58 @@ | ||
| 173 | 174 | return state == State.UP || state == State.SUSPECT; |
| 174 | 175 | } |
| 175 | 176 | |
| 177 | + /** | |
| 178 | + * Returns a {@code ListenableFuture} representing the completion of the first | |
| 179 | + * reconnection attempt after a node has been suspected. | |
| 180 | + * <p> | |
| 181 | + * This is useful in load balancing policies when there are no more live nodes and | |
| 182 | + * we are trying suspected nodes. | |
| 183 | + * | |
| 184 | + * @return the future. | |
| 185 | + */ | |
| 176 | 186 | public ListenableFuture<?> getInitialReconnectionAttemptFuture() { |
| 177 | 187 | return initialReconnectionAttempt.get(); |
| 178 | 188 | } |
| 179 | 189 | |
| 190 | + /** | |
| 191 | + * Returns a {@code ListenableFuture} representing the completion of the reconnection | |
| 192 | + * attempts scheduled after a host is marked {@code DOWN}. | |
| 193 | + * <p> | |
| 194 | + * <b>If the caller cancels this future,</b> the driver will not try to reconnect to | |
| 195 | + * this host until it receives an UP event for it. Note that this could mean never, if | |
| 196 | + * the node was marked down because of a driver-side error (e.g. read timeout) but no | |
| 197 | + * failure was detected by Cassandra. The caller might decide to trigger an explicit | |
| 198 | + * reconnection attempt at a later point with {@link #tryReconnectOnce()}. | |
| 199 | + * | |
| 200 | + * @return the future, or {@code null} if no reconnection attempt was in progress. | |
| 201 | + */ | |
| 202 | + public ListenableFuture<?> getReconnectionAttemptFuture() { | |
| 203 | + return reconnectionAttempt.get(); | |
| 204 | + } | |
| 205 | + | |
| 206 | + /** | |
| 207 | + * Triggers an asynchronous one-time reconnection attempt to this host. | |
| 208 | + * <p> | |
| 209 | + * If reconnection succeeds, the host will be marked {@code UP} and its connection pool(s) | |
| 210 | + * will be initialized (unless the load balancing policy returns {@link HostDistance#IGNORED} | |
| 211 | + * for it). If reconnection fails, no further attempts will be scheduled. | |
| 212 | + * <p> | |
| 213 | + * This method has no effect if the node is already {@code UP}, or if a reconnection attempt | |
| 214 | + * is already in progress. | |
| 215 | + */ | |
| 216 | + public void tryReconnectOnce() { | |
| 217 | + this.manager.tryReconnectOnce(this); | |
| 218 | + } | |
| 219 | + | |
| 220 | + @Override | |
| 221 | + public boolean equals(Object other) { | |
| 222 | + if (other instanceof Host) { | |
| 223 | + Host that = (Host)other; | |
| 224 | + return this.address.equals(that.address); | |
| 225 | + } | |
| 226 | + return false; | |
| 227 | + } | |
| 228 | + | |
| 180 | 229 | @Override |
| 181 | 230 | public int hashCode() { |
| 182 | 231 | return address.hashCode(); |
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +1 −1
| @@ -185,7 +185,7 @@ | ||
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | Host add(InetSocketAddress address) { |
| 188 | - Host newHost = new Host(address, cluster.convictionPolicyFactory); | |
| 188 | + Host newHost = new Host(address, cluster.convictionPolicyFactory, cluster); | |
| 189 | 189 | Host previous = hosts.putIfAbsent(address, newHost); |
| 190 | 190 | return previous == null ? newHost : null; |
| 191 | 191 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Metrics.java +26 −2
| @@ -18,7 +18,8 @@ | ||
| 18 | 18 | import java.util.HashSet; |
| 19 | 19 | import java.util.Set; |
| 20 | 20 | |
| 21 | -import com.codahale.metrics.Counter; | |
| 21 | +import com.codahale.metrics.Gauge; | |
| 22 | +import com.codahale.metrics.MetricRegistryListener; | |
| 22 | 23 | |
| 23 | 24 | import com.codahale.metrics.*; |
| 24 | 25 | |
| @@ -82,7 +83,7 @@ | ||
| 82 | 83 | /** |
| 83 | 84 | * Returns the registry containing all metrics. |
| 84 | 85 | * <p> |
| 85 | - * The metrics registry allows you to easily use the reporters that ships | |
| 86 | + * The metrics registry allows you to easily use the reporters that ship | |
| 86 | 87 | * with <a href="http://metrics.codahale.com/manual/core/#reporters">Metrics</a> |
| 87 | 88 | * or a custom written one. |
| 88 | 89 | * <p> |
| @@ -91,6 +92,29 @@ | ||
| 91 | 92 | * <pre> |
| 92 | 93 | * com.codahale.metrics.CsvReporter.forRegistry(metrics.getRegistry()).build(new File("measurements/")).start(1, TimeUnit.SECONDS); |
| 93 | 94 | * </pre> |
| 95 | + * <p> | |
| 96 | + * If you already have a {@code MetricRegistry} in your application and which to | |
| 97 | + * add the driver's metrics to it, the recommended approach is to use a listener: | |
| 98 | + * <pre> | |
| 99 | + * // Your existing registry: | |
| 100 | + * final com.codahale.metrics.MetricRegistry myRegistry = ... | |
| 101 | + * | |
| 102 | + * cluster.getMetrics().getRegistry().addListener(new com.codahale.metrics.MetricRegistryListener() { | |
| 103 | + * @Override | |
| 104 | + * public void onGaugeAdded(String name, Gauge<?> gauge) { | |
| 105 | + * if (myRegistry.getNames().contains(name)) { | |
| 106 | + * // name is already taken, maybe prefix with a namespace | |
| 107 | + * ... | |
| 108 | + * } else { | |
| 109 | + * myRegistry.register(name, gauge); | |
| 110 | + * } | |
| 111 | + * } | |
| 112 | + * | |
| 113 | + * ... // Implement other methods in a similar fashion | |
| 114 | + * }); | |
| 115 | + * </pre> | |
| 116 | + * Since reporting is handled by your registry, you'll probably also want to disable | |
| 117 | + * JMX reporting with {@link Cluster.Builder#withoutJMXReporting()}. | |
| 94 | 118 | * |
| 95 | 119 | * @return the registry containing all metrics. |
| 96 | 120 | */ |
modified driver-core/src/main/java/com/datastax/driver/core/PoolingOptions.java +11 −0
| @@ -305,6 +305,17 @@ | ||
| 305 | 305 | manager.refreshConnectedHosts(); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | + /** | |
| 309 | + * Requests the driver to re-evaluate the {@link HostDistance} for a given node. | |
| 310 | + * | |
| 311 | + * @param host the host to refresh. | |
| 312 | + * | |
| 313 | + * @see #refreshConnectedHosts() | |
| 314 | + */ | |
| 315 | + public void refreshConnectedHost(Host host) { | |
| 316 | + manager.refreshConnectedHost(host); | |
| 317 | + } | |
| 318 | + | |
| 308 | 319 | private static void checkRequestsPerConnectionRange(int value, String description, HostDistance distance) { |
| 309 | 320 | if (value < 0 || value > StreamIdGenerator.MAX_STREAM_PER_CONNECTION_V2) |
| 310 | 321 | throw new IllegalArgumentException(String.format("%s for %s hosts must be in the range (0, %d)", |
modified driver-core/src/main/java/com/datastax/driver/core/ProtocolOptions.java +21 −7
| @@ -62,6 +62,11 @@ | ||
| 62 | 62 | */ |
| 63 | 63 | public static final int DEFAULT_PORT = 9042; |
| 64 | 64 | |
| 65 | + /** | |
| 66 | + * The default value for {@link #getMaxSchemaAgreementWaitSeconds()}: 10. | |
| 67 | + */ | |
| 68 | + public static final int DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS = 10; | |
| 69 | + | |
| 65 | 70 | /** |
| 66 | 71 | * The newest version of the protocol that this version of the driver support. |
| 67 | 72 | * |
| @@ -75,6 +80,8 @@ | ||
| 75 | 80 | private final int port; |
| 76 | 81 | final ProtocolVersion initialProtocolVersion; // What the user asked us. Will be null by default. |
| 77 | 82 | |
| 83 | + private final int maxSchemaAgreementWaitSeconds; | |
| 84 | + | |
| 78 | 85 | private final SSLOptions sslOptions; // null if no SSL |
| 79 | 86 | private final AuthProvider authProvider; |
| 80 | 87 | |
| @@ -97,7 +104,7 @@ | ||
| 97 | 104 | * @param port the port to use for the binary protocol. |
| 98 | 105 | */ |
| 99 | 106 | public ProtocolOptions(int port) { |
| 100 | - this(port, null, null, AuthProvider.NONE); | |
| 107 | + this(port, null, DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS, null, AuthProvider.NONE); | |
| 101 | 108 | } |
| 102 | 109 | |
| 103 | 110 | /** |
| @@ -113,9 +120,10 @@ | ||
| 113 | 120 | * @param authProvider the {@code AuthProvider} to use for authentication against |
| 114 | 121 | * the Cassandra nodes. |
| 115 | 122 | */ |
| 116 | - public ProtocolOptions(int port, ProtocolVersion protocolVersion, SSLOptions sslOptions, AuthProvider authProvider) { | |
| 123 | + public ProtocolOptions(int port, ProtocolVersion protocolVersion, int maxSchemaAgreementWaitSeconds, SSLOptions sslOptions, AuthProvider authProvider) { | |
| 117 | 124 | this.port = port; |
| 118 | 125 | this.initialProtocolVersion = protocolVersion; |
| 126 | + this.maxSchemaAgreementWaitSeconds = maxSchemaAgreementWaitSeconds; | |
| 119 | 127 | this.sslOptions = sslOptions; |
| 120 | 128 | this.authProvider = authProvider; |
| 121 | 129 | } |
| @@ -123,14 +131,11 @@ | ||
| 123 | 131 | /** |
| 124 | 132 | * @throws IllegalArgumentException if {@code protocolVersion} does not correspond to any known version. |
| 125 | 133 | * |
| 126 | - * @deprecated This is provided for backward compatibility; use {@link #ProtocolOptions(int, ProtocolVersion, SSLOptions, AuthProvider))} instead. | |
| 134 | + * @deprecated This is provided for backward compatibility; use {@link #ProtocolOptions(int, ProtocolVersion, int, SSLOptions, AuthProvider))} instead. | |
| 127 | 135 | */ |
| 128 | 136 | @Deprecated |
| 129 | 137 | public ProtocolOptions(int port, int protocolVersion, SSLOptions sslOptions, AuthProvider authProvider) { |
| 130 | - this.port = port; | |
| 131 | - this.initialProtocolVersion = ProtocolVersion.fromInt(protocolVersion); | |
| 132 | - this.sslOptions = sslOptions; | |
| 133 | - this.authProvider = authProvider; | |
| 138 | + this(port, ProtocolVersion.fromInt(protocolVersion), DEFAULT_MAX_SCHEMA_AGREEMENT_WAIT_SECONDS, sslOptions, authProvider); | |
| 134 | 139 | } |
| 135 | 140 | |
| 136 | 141 | void register(Cluster.Manager manager) { |
| @@ -203,6 +208,15 @@ | ||
| 203 | 208 | return this; |
| 204 | 209 | } |
| 205 | 210 | |
| 211 | + /** | |
| 212 | + * Returns the maximum time to wait for schema agreement before returning from a DDL query. | |
| 213 | + * | |
| 214 | + * @return the time. | |
| 215 | + */ | |
| 216 | + public int getMaxSchemaAgreementWaitSeconds() { | |
| 217 | + return maxSchemaAgreementWaitSeconds; | |
| 218 | + } | |
| 219 | + | |
| 206 | 220 | /** |
| 207 | 221 | * The {@code SSLOptions} used by this cluster. |
| 208 | 222 | * |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +23 −0
| @@ -337,6 +337,29 @@ | ||
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | + void updateCreatedPools(Host h, ListeningExecutorService executor) { | |
| 341 | + HostDistance dist = loadBalancingPolicy().distance(h); | |
| 342 | + HostConnectionPool pool = pools.get(h); | |
| 343 | + | |
| 344 | + try { | |
| 345 | + if (pool == null) { | |
| 346 | + if (dist != HostDistance.IGNORED && h.isUp()) | |
| 347 | + maybeAddPool(h, executor).get(); | |
| 348 | + } else if (dist != pool.hostDistance) { | |
| 349 | + if (dist == HostDistance.IGNORED) { | |
| 350 | + removePool(h).get(); | |
| 351 | + } else { | |
| 352 | + pool.hostDistance = dist; | |
| 353 | + pool.ensureCoreConnections(); | |
| 354 | + } | |
| 355 | + } | |
| 356 | + } catch (InterruptedException e) { | |
| 357 | + Thread.currentThread().interrupt(); | |
| 358 | + } catch (ExecutionException e) { | |
| 359 | + logger.error("Unexpected error while refreshing connection pools", e.getCause()); | |
| 360 | + } | |
| 361 | + } | |
| 362 | + | |
| 340 | 363 | void onDown(Host host) throws InterruptedException, ExecutionException { |
| 341 | 364 | // Note that with well behaved balancing policy (that ignore dead nodes), the removePool call is not necessary |
| 342 | 365 | // since updateCreatedPools should take care of it. But better protect against non well behaving policies. |
added driver-core/src/main/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicy.java +31 −0
| @@ -0,0 +1,31 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2014 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core.policies; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * A load balancing policy that wants to be notified at cluster shutdown. | |
| 20 | + * | |
| 21 | + * The only reason that this is separate from {@link LoadBalancingPolicy} is to avoid breaking binary compatibility at the | |
| 22 | + * time this was introduced (2.0.7 / 2.1.3). It might be merged with the parent interface in a future major version. | |
| 23 | + */ | |
| 24 | +public interface CloseableLoadBalancingPolicy extends LoadBalancingPolicy { | |
| 25 | + /** | |
| 26 | + * Gets invoked at cluster shutdown. | |
| 27 | + * | |
| 28 | + * This gives the policy the opportunity to perform some cleanup, for instance stop threads that it might have started. | |
| 29 | + */ | |
| 30 | + void close(); | |
| 31 | +} |
modified driver-core/src/main/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicy.java +9 −1
| @@ -53,7 +53,7 @@ | ||
| 53 | 53 | * incurs a slight overhead so the {@code LoadBalancingPolicy.RoundRobin} |
| 54 | 54 | * policy could be preferred to this policy in that case. |
| 55 | 55 | */ |
| 56 | -public class DCAwareRoundRobinPolicy implements LoadBalancingPolicy { | |
| 56 | +public class DCAwareRoundRobinPolicy implements LoadBalancingPolicy, CloseableLoadBalancingPolicy { | |
| 57 | 57 | |
| 58 | 58 | private static final Logger logger = LoggerFactory.getLogger(DCAwareRoundRobinPolicy.class); |
| 59 | 59 | |
| @@ -183,6 +183,9 @@ | ||
| 183 | 183 | |
| 184 | 184 | @Override |
| 185 | 185 | public void init(Cluster cluster, Collection<Host> hosts) { |
| 186 | + if (localDc != UNSET) | |
| 187 | + logger.info("Using provided data-center name '{}' for DCAwareRoundRobinPolicy", localDc); | |
| 188 | + | |
| 186 | 189 | this.configuration = cluster.getConfiguration(); |
| 187 | 190 | |
| 188 | 191 | ArrayList<String> notInLocalDC = new ArrayList<String>(); |
| @@ -431,4 +434,9 @@ | ||
| 431 | 434 | public void onRemove(Host host) { |
| 432 | 435 | onDown(host); |
| 433 | 436 | } |
| 437 | + | |
| 438 | + @Override | |
| 439 | + public void close() { | |
| 440 | + // nothing to do | |
| 441 | + } | |
| 434 | 442 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/LatencyAwarePolicy.java +7 −1
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 | * |
| 58 | 58 | * @since 1.0.4 |
| 59 | 59 | */ |
| 60 | -public class LatencyAwarePolicy implements ChainableLoadBalancingPolicy { | |
| 60 | +public class LatencyAwarePolicy implements ChainableLoadBalancingPolicy, CloseableLoadBalancingPolicy { | |
| 61 | 61 | |
| 62 | 62 | private static final Logger logger = LoggerFactory.getLogger(LatencyAwarePolicy.class); |
| 63 | 63 | |
| @@ -688,4 +688,10 @@ | ||
| 688 | 688 | return new LatencyAwarePolicy(childPolicy, exclusionThreshold, scale, retryPeriod, updateRate, minMeasure); |
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | + | |
| 692 | + @Override | |
| 693 | + public void close() { | |
| 694 | + if (childPolicy instanceof CloseableLoadBalancingPolicy) | |
| 695 | + ((CloseableLoadBalancingPolicy)childPolicy).close(); | |
| 696 | + } | |
| 691 | 697 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/RoundRobinPolicy.java +6 −1
| @@ -48,7 +48,7 @@ | ||
| 48 | 48 | * datacenter this will be inefficient and you will want to use the |
| 49 | 49 | * {@link DCAwareRoundRobinPolicy} load balancing policy instead. |
| 50 | 50 | */ |
| 51 | -public class RoundRobinPolicy implements LoadBalancingPolicy { | |
| 51 | +public class RoundRobinPolicy implements LoadBalancingPolicy, CloseableLoadBalancingPolicy { | |
| 52 | 52 | |
| 53 | 53 | private static final Logger logger = LoggerFactory.getLogger(RoundRobinPolicy.class); |
| 54 | 54 | |
| @@ -198,4 +198,9 @@ | ||
| 198 | 198 | public void onRemove(Host host) { |
| 199 | 199 | onDown(host); |
| 200 | 200 | } |
| 201 | + | |
| 202 | + @Override | |
| 203 | + public void close() { | |
| 204 | + // nothing to do | |
| 205 | + } | |
| 201 | 206 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/TokenAwarePolicy.java +37 −8
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | package com.datastax.driver.core.policies; |
| 17 | 17 | |
| 18 | 18 | import java.nio.ByteBuffer; |
| 19 | -import java.util.Collection; | |
| 20 | -import java.util.Iterator; | |
| 21 | -import java.util.Set; | |
| 19 | +import java.util.*; | |
| 20 | + | |
| 21 | +import com.google.common.collect.Lists; | |
| 22 | 22 | |
| 23 | 23 | import com.google.common.collect.AbstractIterator; |
| 24 | 24 | |
| @@ -46,20 +46,35 @@ | ||
| 46 | 46 | * token aware policy, replicas from remote data centers may only be |
| 47 | 47 | * returned after all the host of the local data center. |
| 48 | 48 | */ |
| 49 | -public class TokenAwarePolicy implements ChainableLoadBalancingPolicy { | |
| 49 | +public class TokenAwarePolicy implements ChainableLoadBalancingPolicy, CloseableLoadBalancingPolicy { | |
| 50 | 50 | |
| 51 | 51 | private final LoadBalancingPolicy childPolicy; |
| 52 | + private final boolean shuffleReplicas; | |
| 52 | 53 | private Metadata clusterMetadata; |
| 53 | 54 | |
| 54 | 55 | /** |
| 55 | - * Creates a new {@code TokenAware} policy that wraps the provided child | |
| 56 | - * load balancing policy. | |
| 56 | + * Creates a new {@code TokenAware} policy. | |
| 57 | 57 | * |
| 58 | 58 | * @param childPolicy the load balancing policy to wrap with token |
| 59 | 59 | * awareness. |
| 60 | + * @param shuffleReplicas whether to shuffle the replicas returned | |
| 61 | + * by {@code getRoutingKey}. | |
| 60 | 62 | */ |
| 61 | - public TokenAwarePolicy(LoadBalancingPolicy childPolicy) { | |
| 63 | + public TokenAwarePolicy(LoadBalancingPolicy childPolicy, boolean shuffleReplicas) { | |
| 62 | 64 | this.childPolicy = childPolicy; |
| 65 | + this.shuffleReplicas = shuffleReplicas; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Creates a new {@code TokenAware} policy with no shuffling of replicas. | |
| 70 | + * | |
| 71 | + * @param childPolicy the load balancing policy to wrap with token | |
| 72 | + * awareness. | |
| 73 | + * | |
| 74 | + * @see #TokenAwarePolicy(LoadBalancingPolicy, boolean) | |
| 75 | + */ | |
| 76 | + public TokenAwarePolicy(LoadBalancingPolicy childPolicy) { | |
| 77 | + this(childPolicy, false); | |
| 63 | 78 | } |
| 64 | 79 | |
| 65 | 80 | @Override |
| @@ -110,9 +125,17 @@ | ||
| 110 | 125 | if (replicas.isEmpty()) |
| 111 | 126 | return childPolicy.newQueryPlan(loggedKeyspace, statement); |
| 112 | 127 | |
| 128 | + final Iterator<Host> iter; | |
| 129 | + if (shuffleReplicas) { | |
| 130 | + List<Host> l = Lists.newArrayList(replicas); | |
| 131 | + Collections.shuffle(l); | |
| 132 | + iter = l.iterator(); | |
| 133 | + } else { | |
| 134 | + iter = replicas.iterator(); | |
| 135 | + } | |
| 136 | + | |
| 113 | 137 | return new AbstractIterator<Host>() { |
| 114 | 138 | |
| 115 | - private final Iterator<Host> iter = replicas.iterator(); | |
| 116 | 139 | private Iterator<Host> childIterator; |
| 117 | 140 | |
| 118 | 141 | @Override |
| @@ -161,4 +184,10 @@ | ||
| 161 | 184 | public void onRemove(Host host) { |
| 162 | 185 | childPolicy.onRemove(host); |
| 163 | 186 | } |
| 187 | + | |
| 188 | + @Override | |
| 189 | + public void close() { | |
| 190 | + if (childPolicy instanceof CloseableLoadBalancingPolicy) | |
| 191 | + ((CloseableLoadBalancingPolicy)childPolicy).close(); | |
| 192 | + } | |
| 164 | 193 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/WhiteListPolicy.java +7 −1
| @@ -47,7 +47,7 @@ | ||
| 47 | 47 | * data-center then you should use DCAwareRoundRobinPolicy and *not* this policy |
| 48 | 48 | * in particular. |
| 49 | 49 | */ |
| 50 | -public class WhiteListPolicy implements ChainableLoadBalancingPolicy { | |
| 50 | +public class WhiteListPolicy implements ChainableLoadBalancingPolicy, CloseableLoadBalancingPolicy { | |
| 51 | 51 | private final LoadBalancingPolicy childPolicy; |
| 52 | 52 | private final Set<InetSocketAddress> whiteList; |
| 53 | 53 | |
| @@ -153,4 +153,10 @@ | ||
| 153 | 153 | if (whiteList.contains(host.getSocketAddress())) |
| 154 | 154 | childPolicy.onRemove(host); |
| 155 | 155 | } |
| 156 | + | |
| 157 | + @Override | |
| 158 | + public void close() { | |
| 159 | + if (childPolicy instanceof CloseableLoadBalancingPolicy) | |
| 160 | + ((CloseableLoadBalancingPolicy)childPolicy).close(); | |
| 161 | + } | |
| 156 | 162 | } |
added driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +325 −0
| @@ -0,0 +1,325 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import java.net.InetSocketAddress; | |
| 4 | +import java.util.concurrent.CyclicBarrier; | |
| 5 | +import java.util.concurrent.Executors; | |
| 6 | +import java.util.concurrent.ScheduledExecutorService; | |
| 7 | +import java.util.concurrent.TimeUnit; | |
| 8 | +import java.util.concurrent.atomic.AtomicReference; | |
| 9 | + | |
| 10 | +import com.google.common.util.concurrent.Futures; | |
| 11 | +import com.google.common.util.concurrent.ListenableFuture; | |
| 12 | +import com.google.common.util.concurrent.SettableFuture; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.testng.annotations.AfterMethod; | |
| 16 | +import org.testng.annotations.BeforeMethod; | |
| 17 | +import org.testng.annotations.Test; | |
| 18 | + | |
| 19 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 20 | +import static org.testng.Assert.fail; | |
| 21 | + | |
| 22 | +import com.datastax.driver.core.AbstractReconnectionHandlerTest.MockReconnectionWork.ReconnectBehavior; | |
| 23 | +import com.datastax.driver.core.policies.ReconnectionPolicy.ReconnectionSchedule; | |
| 24 | + | |
| 25 | +public class AbstractReconnectionHandlerTest { | |
| 26 | + private static final Logger logger = LoggerFactory.getLogger(AbstractReconnectionHandlerTest.class); | |
| 27 | + | |
| 28 | + ScheduledExecutorService executor; | |
| 29 | + MockReconnectionSchedule schedule; | |
| 30 | + MockReconnectionWork work; | |
| 31 | + final AtomicReference<ListenableFuture<?>> future = new AtomicReference<ListenableFuture<?>>(); | |
| 32 | + AbstractReconnectionHandler handler; | |
| 33 | + | |
| 34 | + @BeforeMethod(groups = "unit") | |
| 35 | + public void setup() { | |
| 36 | + executor = Executors.newScheduledThreadPool(2); | |
| 37 | + schedule = new MockReconnectionSchedule(); | |
| 38 | + work = new MockReconnectionWork(); | |
| 39 | + future.set(null); | |
| 40 | + handler = new AbstractReconnectionHandler(executor, schedule, future) { | |
| 41 | + @Override | |
| 42 | + protected Connection tryReconnect() throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { | |
| 43 | + return work.tryReconnect(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + protected void onReconnection(Connection connection) { | |
| 48 | + work.onReconnection(connection); | |
| 49 | + } | |
| 50 | + }; | |
| 51 | + } | |
| 52 | + | |
| 53 | + @AfterMethod(groups = "unit") | |
| 54 | + public void tearDown() { | |
| 55 | + if (future.get() != null) | |
| 56 | + future.get().cancel(false); | |
| 57 | + executor.shutdownNow(); | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Test(groups = "unit") | |
| 61 | + public void should_complete_if_first_reconnection_succeeds() { | |
| 62 | + handler.start(); | |
| 63 | + | |
| 64 | + assertThat(future.get()).isNotNull(); | |
| 65 | + assertThat(future.get().isDone()).isFalse(); | |
| 66 | + | |
| 67 | + schedule.tick(); | |
| 68 | + work.nextReconnect = ReconnectBehavior.SUCCEED; | |
| 69 | + work.tick(); | |
| 70 | + | |
| 71 | + waitForCompletion(); | |
| 72 | + | |
| 73 | + assertThat(work.success).isTrue(); | |
| 74 | + assertThat(work.tries).isEqualTo(1); | |
| 75 | + assertThat(future.get()).isNull(); | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Test(groups = "unit") | |
| 79 | + public void should_retry_until_success() { | |
| 80 | + handler.start(); | |
| 81 | + | |
| 82 | + int simulatedErrors = 10; | |
| 83 | + for (int i = 0; i < simulatedErrors; i++) { | |
| 84 | + schedule.tick(); | |
| 85 | + work.nextReconnect = ReconnectBehavior.THROW_EXCEPTION; | |
| 86 | + work.tick(); | |
| 87 | + assertThat(work.success).isFalse(); | |
| 88 | + assertThat(future.get().isDone()).isFalse(); | |
| 89 | + } | |
| 90 | + | |
| 91 | + schedule.tick(); | |
| 92 | + work.nextReconnect = ReconnectBehavior.SUCCEED; | |
| 93 | + work.tick(); | |
| 94 | + | |
| 95 | + waitForCompletion(); | |
| 96 | + | |
| 97 | + assertThat(work.success).isTrue(); | |
| 98 | + assertThat(work.tries).isEqualTo(simulatedErrors + 1); | |
| 99 | + assertThat(future.get()).isNull(); | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Test(groups = "unit") | |
| 103 | + public void should_stop_if_cancelled_between_attempts() { | |
| 104 | + handler.start(); | |
| 105 | + | |
| 106 | + schedule.delay = 10 * 1000; // give ourselves time to cancel | |
| 107 | + schedule.tick(); | |
| 108 | + | |
| 109 | + future.get().cancel(false); | |
| 110 | + | |
| 111 | + waitForCompletion(); | |
| 112 | + | |
| 113 | + assertThat(work.success).isFalse(); | |
| 114 | + assertThat(work.tries).isEqualTo(0); | |
| 115 | + assertThat(future.get().isCancelled()).isTrue(); | |
| 116 | + } | |
| 117 | + | |
| 118 | + @Test(groups = "unit") | |
| 119 | + public void should_complete_if_cancelled_during_successful_reconnect() throws InterruptedException { | |
| 120 | + handler.start(); | |
| 121 | + | |
| 122 | + schedule.tick(); | |
| 123 | + work.nextReconnect = ReconnectBehavior.SUCCEED; | |
| 124 | + | |
| 125 | + // short pause to make sure we are in the middle of the handler's run method (it checks | |
| 126 | + // if the future is cancelled at the beginning) | |
| 127 | + TimeUnit.MILLISECONDS.sleep(100); | |
| 128 | + // don't force interruption because that's what the production code does | |
| 129 | + future.get().cancel(false); | |
| 130 | + | |
| 131 | + work.tick(); | |
| 132 | + | |
| 133 | + waitForCompletion(); | |
| 134 | + | |
| 135 | + assertThat(work.success).isTrue(); | |
| 136 | + assertThat(work.tries).isEqualTo(1); | |
| 137 | + } | |
| 138 | + | |
| 139 | + @Test(groups = "unit") | |
| 140 | + public void should_stop_if_cancelled_during_failed_reconnect() throws InterruptedException { | |
| 141 | + handler.start(); | |
| 142 | + | |
| 143 | + schedule.tick(); | |
| 144 | + work.nextReconnect = ReconnectBehavior.THROW_EXCEPTION; | |
| 145 | + | |
| 146 | + // short pause to make sure we are in the middle of the handler's run method (it checks | |
| 147 | + // if the future is cancelled at the beginning) | |
| 148 | + TimeUnit.MILLISECONDS.sleep(100); | |
| 149 | + // don't force interruption because that's what the production code does | |
| 150 | + future.get().cancel(false); | |
| 151 | + | |
| 152 | + work.tick(); | |
| 153 | + | |
| 154 | + // Need to | |
| 155 | + schedule.tick(); | |
| 156 | + | |
| 157 | + waitForCompletion(); | |
| 158 | + | |
| 159 | + assertThat(work.success).isFalse(); | |
| 160 | + assertThat(work.tries).isEqualTo(1); | |
| 161 | + } | |
| 162 | + | |
| 163 | + @Test(groups = "unit") | |
| 164 | + public void should_yield_to_another_running_handler() { | |
| 165 | + // Set an uncompleted future, representing a running handler | |
| 166 | + future.set(SettableFuture.create()); | |
| 167 | + | |
| 168 | + handler.start(); | |
| 169 | + | |
| 170 | + // Increase the delay to make sure that the first attempt does not start before the check | |
| 171 | + // for cancellation (which would require calling work.tick()) | |
| 172 | + schedule.delay = 5000; | |
| 173 | + schedule.tick(); | |
| 174 | + | |
| 175 | + waitForCompletion(); | |
| 176 | + | |
| 177 | + assertThat(work.success).isFalse(); | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Note: a handler that succeeds immediately resets the future to null, so there is a very small window of opportunity | |
| 182 | + * for this scenario. Therefore we consider that if we find a completed future, the connection was successfully | |
| 183 | + * re-established a few milliseconds ago, so we don't start another attempt. | |
| 184 | + */ | |
| 185 | + @Test(groups = "unit") | |
| 186 | + public void should_yield_to_another_handler_that_just_succeeded() { | |
| 187 | + future.set(Futures.immediateCheckedFuture(null)); | |
| 188 | + | |
| 189 | + handler.start(); | |
| 190 | + | |
| 191 | + schedule.tick(); | |
| 192 | + | |
| 193 | + waitForCompletion(); | |
| 194 | + | |
| 195 | + assertThat(work.success).isFalse(); | |
| 196 | + } | |
| 197 | + | |
| 198 | + @Test(groups = "unit") | |
| 199 | + public void should_run_if_another_handler_was_cancelled() { | |
| 200 | + future.set(Futures.immediateCancelledFuture()); | |
| 201 | + | |
| 202 | + handler.start(); | |
| 203 | + | |
| 204 | + schedule.tick(); | |
| 205 | + work.nextReconnect = ReconnectBehavior.SUCCEED; | |
| 206 | + work.tick(); | |
| 207 | + | |
| 208 | + waitForCompletion(); | |
| 209 | + | |
| 210 | + assertThat(work.success).isTrue(); | |
| 211 | + assertThat(work.tries).isEqualTo(1); | |
| 212 | + assertThat(future.get()).isNull(); | |
| 213 | + } | |
| 214 | + | |
| 215 | + /** | |
| 216 | + * A reconnection schedule that allows manually setting the delay. | |
| 217 | + * | |
| 218 | + * To make testing easier, nextDelay blocks until tick() is called from the main thread. | |
| 219 | + */ | |
| 220 | + static class MockReconnectionSchedule implements ReconnectionSchedule { | |
| 221 | + volatile long delay; | |
| 222 | + private final CyclicBarrier barrier = new CyclicBarrier(2); | |
| 223 | + | |
| 224 | + // Hack to work around the fact that the first call to nextDelayMs is synchronous | |
| 225 | + private volatile boolean firstDelay = true; | |
| 226 | + private volatile boolean firstTick = true; | |
| 227 | + | |
| 228 | + @Override | |
| 229 | + public long nextDelayMs() { | |
| 230 | + if (firstDelay) | |
| 231 | + firstDelay = false; | |
| 232 | + else { | |
| 233 | + logger.debug("in schedule, waiting for tick from main thread"); | |
| 234 | + try { | |
| 235 | + barrier.await(10, TimeUnit.SECONDS); | |
| 236 | + logger.debug("in schedule, got tick from main thread, proceeding"); | |
| 237 | + } catch (Exception e) { | |
| 238 | + fail("Error while waiting for tick", e); | |
| 239 | + } | |
| 240 | + } | |
| 241 | + logger.debug("in schedule, returning {}", delay); | |
| 242 | + return delay; | |
| 243 | + } | |
| 244 | + | |
| 245 | + public void tick() { | |
| 246 | + if (firstTick) | |
| 247 | + firstTick = false; | |
| 248 | + else { | |
| 249 | + logger.debug("send tick to schedule"); | |
| 250 | + try { | |
| 251 | + barrier.await(10, TimeUnit.SECONDS); | |
| 252 | + } catch (Exception e) { | |
| 253 | + fail("Error while sending tick, no thread was waiting", e); | |
| 254 | + } | |
| 255 | + barrier.reset(); | |
| 256 | + } | |
| 257 | + } | |
| 258 | + } | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * Simulates the work done by the overridable methods of the handler. | |
| 262 | + * | |
| 263 | + * Allows choosing whether the next reconnect will succeed or throw an exception. | |
| 264 | + * To make testing easier, tryReconnect blocks until tick() is called from the main thread. | |
| 265 | + */ | |
| 266 | + static class MockReconnectionWork { | |
| 267 | + enum ReconnectBehavior { | |
| 268 | + SUCCEED, THROW_EXCEPTION | |
| 269 | + }; | |
| 270 | + | |
| 271 | + private final CyclicBarrier barrier = new CyclicBarrier(2); | |
| 272 | + | |
| 273 | + volatile ReconnectBehavior nextReconnect; | |
| 274 | + | |
| 275 | + volatile int tries = 0; | |
| 276 | + volatile boolean success = false; | |
| 277 | + | |
| 278 | + protected Connection tryReconnect() throws ConnectionException { | |
| 279 | + tries += 1; | |
| 280 | + logger.debug("in reconnection work, wait for tick from main thread"); | |
| 281 | + try { | |
| 282 | + barrier.await(10, TimeUnit.SECONDS); | |
| 283 | + logger.debug("in reconnection work, got tick from main thread, proceeding"); | |
| 284 | + } catch (Exception e) { | |
| 285 | + fail("Error while waiting for tick", e); | |
| 286 | + } | |
| 287 | + switch (nextReconnect) { | |
| 288 | + case SUCCEED: | |
| 289 | + logger.debug("simulate reconnection success"); | |
| 290 | + return null; | |
| 291 | + case THROW_EXCEPTION: | |
| 292 | + logger.debug("simulate reconnection error"); | |
| 293 | + throw new ConnectionException(new InetSocketAddress(8888), | |
| 294 | + "Simulated exception from mock reconnection"); | |
| 295 | + default: | |
| 296 | + throw new AssertionError(); | |
| 297 | + } | |
| 298 | + } | |
| 299 | + | |
| 300 | + public void tick() { | |
| 301 | + logger.debug("send tick to reconnection work"); | |
| 302 | + try { | |
| 303 | + barrier.await(10, TimeUnit.SECONDS); | |
| 304 | + } catch (Exception e) { | |
| 305 | + fail("Error while sending tick, no thread was waiting", e); | |
| 306 | + } | |
| 307 | + barrier.reset(); | |
| 308 | + } | |
| 309 | + | |
| 310 | + protected void onReconnection(Connection connection) { | |
| 311 | + success = true; | |
| 312 | + } | |
| 313 | + } | |
| 314 | + | |
| 315 | + private void waitForCompletion() { | |
| 316 | + executor.shutdown(); | |
| 317 | + try { | |
| 318 | + boolean shutdown = executor.awaitTermination(10, TimeUnit.SECONDS); | |
| 319 | + if (!shutdown) | |
| 320 | + fail("executor ran for longer than expected"); | |
| 321 | + } catch (InterruptedException e) { | |
| 322 | + fail("Interrupted while waiting for executor to shutdown"); | |
| 323 | + } | |
| 324 | + } | |
| 325 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReplicationStrategyTest.java +1 −1
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | private final String address; |
| 40 | 40 | |
| 41 | 41 | private HostMock(String address) throws UnknownHostException { |
| 42 | - super(new InetSocketAddress(InetAddress.getByName(address), 9042), new ConvictionPolicy.Simple.Factory()); | |
| 42 | + super(new InetSocketAddress(InetAddress.getByName(address), 9042), new ConvictionPolicy.Simple.Factory(), null); | |
| 43 | 43 | this.address = address; |
| 44 | 44 | } |
| 45 | 45 |
added driver-core/src/test/java/com/datastax/driver/core/Assertions.java +14 −0
| @@ -0,0 +1,14 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Augment AssertJ with custom assertions for the Java driver. | |
| 5 | + */ | |
| 6 | +public class Assertions extends org.assertj.core.api.Assertions{ | |
| 7 | + public static ClusterAssert assertThat(Cluster cluster) { | |
| 8 | + return new ClusterAssert(cluster); | |
| 9 | + } | |
| 10 | + | |
| 11 | + public static SessionAssert assertThat(Session session) { | |
| 12 | + return new SessionAssert(session); | |
| 13 | + } | |
| 14 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +68 −0
| @@ -30,9 +30,15 @@ | ||
| 30 | 30 | import java.io.File; |
| 31 | 31 | import java.io.IOException; |
| 32 | 32 | import java.io.InputStreamReader; |
| 33 | +import java.net.InetAddress; | |
| 33 | 34 | import java.net.InetSocketAddress; |
| 35 | +import java.net.Socket; | |
| 36 | +import java.net.UnknownHostException; | |
| 34 | 37 | import java.util.Collection; |
| 35 | 38 | import java.util.Map; |
| 39 | +import java.util.concurrent.TimeUnit; | |
| 40 | + | |
| 41 | +import static org.testng.Assert.fail; | |
| 36 | 42 | |
| 37 | 43 | import static com.google.common.base.Preconditions.checkArgument; |
| 38 | 44 | |
| @@ -225,6 +231,68 @@ | ||
| 225 | 231 | } |
| 226 | 232 | } |
| 227 | 233 | |
| 234 | + /** | |
| 235 | + * Waits for a host to be up by pinging the TCP socket directly, without using the Java driver's API. | |
| 236 | + */ | |
| 237 | + public void waitForUp(int node) { | |
| 238 | + try { | |
| 239 | + InetAddress address = InetAddress.getByName(ipOfNode(node)); | |
| 240 | + CCMBridge.busyWaitForPort(address, 9042, true); | |
| 241 | + } catch (UnknownHostException e) { | |
| 242 | + fail("Unknown host " + ipOfNode(node) + "( node " + node + " of CCMBridge)"); | |
| 243 | + } | |
| 244 | + } | |
| 245 | + | |
| 246 | + /** | |
| 247 | + * Waits for a host to be down by pinging the TCP socket directly, without using the Java driver's API. | |
| 248 | + */ | |
| 249 | + public void waitForDown(int node) { | |
| 250 | + try { | |
| 251 | + InetAddress address = InetAddress.getByName(ipOfNode(node)); | |
| 252 | + CCMBridge.busyWaitForPort(address, 9042, false); | |
| 253 | + } catch (UnknownHostException e) { | |
| 254 | + fail("Unknown host " + ipOfNode(node) + "( node " + node + " of CCMBridge)"); | |
| 255 | + } | |
| 256 | + } | |
| 257 | + | |
| 258 | + private static void busyWaitForPort(InetAddress address, int port, boolean expectedConnectionState) { | |
| 259 | + long maxAcceptableWaitTime = TimeUnit.SECONDS.toMillis(10); | |
| 260 | + long waitQuantum = TimeUnit.MILLISECONDS.toMillis(500); | |
| 261 | + long waitTimeSoFar = 0; | |
| 262 | + boolean connectionState = !expectedConnectionState; | |
| 263 | + | |
| 264 | + while (connectionState != expectedConnectionState && waitTimeSoFar < maxAcceptableWaitTime) { | |
| 265 | + connectionState = CCMBridge.pingPort(address, port); | |
| 266 | + try { | |
| 267 | + Thread.sleep(waitQuantum); | |
| 268 | + waitTimeSoFar += waitQuantum; | |
| 269 | + } catch (InterruptedException e) { | |
| 270 | + throw new RuntimeException("Interrupted while pinging " + address + ":" + port, e); | |
| 271 | + } | |
| 272 | + } | |
| 273 | + } | |
| 274 | + | |
| 275 | + private static boolean pingPort(InetAddress address, int port) { | |
| 276 | + logger.debug("Trying {}:{}...", address, port); | |
| 277 | + boolean connectionSuccessful = false; | |
| 278 | + Socket socket = null; | |
| 279 | + try { | |
| 280 | + socket = new Socket(address, port); | |
| 281 | + connectionSuccessful = true; | |
| 282 | + logger.debug("Successfully connected"); | |
| 283 | + } catch (IOException e) { | |
| 284 | + logger.debug("Connection failed"); | |
| 285 | + } finally { | |
| 286 | + if (socket != null) | |
| 287 | + try { | |
| 288 | + socket.close(); | |
| 289 | + } catch (IOException e) { | |
| 290 | + logger.warn("Error closing socket to " + address); | |
| 291 | + } | |
| 292 | + } | |
| 293 | + return connectionSuccessful; | |
| 294 | + } | |
| 295 | + | |
| 228 | 296 | public static String ipOfNode(int nodeNumber) { |
| 229 | 297 | return IP_PREFIX + Integer.toString(nodeNumber); |
| 230 | 298 | } |
added driver-core/src/test/java/com/datastax/driver/core/ClusterAssert.java +25 −0
| @@ -0,0 +1,25 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 4 | +import org.assertj.core.api.AbstractAssert; | |
| 5 | + | |
| 6 | +public class ClusterAssert extends AbstractAssert<ClusterAssert, Cluster> { | |
| 7 | + protected ClusterAssert(Cluster actual) { | |
| 8 | + super(actual, ClusterAssert.class); | |
| 9 | + } | |
| 10 | + | |
| 11 | + public ClusterAssert usesControlHost(int node) { | |
| 12 | + String expectedAddress = CCMBridge.ipOfNode(node); | |
| 13 | + Host controlHost = actual.manager.controlConnection.connectedHost(); | |
| 14 | + assertThat(controlHost.getAddress().getHostAddress()).isEqualTo(expectedAddress); | |
| 15 | + return this; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public HostAssert host(int hostNumber) { | |
| 19 | + // TODO at some point this won't work anymore if we have assertions that wait for a node to | |
| 20 | + // join the cluster, e.g. assertThat(cluster).node(3).comesUp(). | |
| 21 | + Host host = TestUtils.findHost(actual, hostNumber); | |
| 22 | + | |
| 23 | + return new HostAssert(host, actual); | |
| 24 | + } | |
| 25 | +} |
added driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +77 −0
| @@ -0,0 +1,77 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import java.util.Iterator; | |
| 4 | +import java.util.concurrent.TimeUnit; | |
| 5 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 6 | + | |
| 7 | +import org.testng.annotations.Test; | |
| 8 | + | |
| 9 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 10 | + | |
| 11 | +import com.datastax.driver.core.policies.DelegatingLoadBalancingPolicy; | |
| 12 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 13 | +import com.datastax.driver.core.policies.Policies; | |
| 14 | +import com.datastax.driver.core.policies.ReconnectionPolicy; | |
| 15 | + | |
| 16 | +public class ControlConnectionTest { | |
| 17 | + @Test(groups = "short") | |
| 18 | + public void should_prevent_simultaneous_reconnection_attempts() throws InterruptedException { | |
| 19 | + CCMBridge ccm = null; | |
| 20 | + Cluster cluster = null; | |
| 21 | + | |
| 22 | + // Custom load balancing policy that counts the number of calls to newQueryPlan(). | |
| 23 | + // Since we don't open any session from our Cluster, only the control connection reattempts are calling this | |
| 24 | + // method, therefore the invocation count is equal to the number of attempts. | |
| 25 | + QueryPlanCountingPolicy loadBalancingPolicy = new QueryPlanCountingPolicy(Policies.defaultLoadBalancingPolicy()); | |
| 26 | + | |
| 27 | + // Custom reconnection policy with a very large delay (longer than the test duration), to make sure we count | |
| 28 | + // only the first reconnection attempt of each reconnection handler. | |
| 29 | + ReconnectionPolicy reconnectionPolicy = new ReconnectionPolicy() { | |
| 30 | + @Override | |
| 31 | + public ReconnectionSchedule newSchedule() { | |
| 32 | + return new ReconnectionSchedule() { | |
| 33 | + @Override | |
| 34 | + public long nextDelayMs() { | |
| 35 | + return 60 * 1000; | |
| 36 | + } | |
| 37 | + }; | |
| 38 | + } | |
| 39 | + }; | |
| 40 | + | |
| 41 | + try { | |
| 42 | + ccm = CCMBridge.create("test", 1); | |
| 43 | + cluster = Cluster.builder() | |
| 44 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 45 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 46 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 47 | + .build(); | |
| 48 | + cluster.init(); | |
| 49 | + | |
| 50 | + ccm.stop(1); | |
| 51 | + | |
| 52 | + // Sleep for a while to make sure our final count is not the result of lucky timing | |
| 53 | + TimeUnit.SECONDS.sleep(1); | |
| 54 | + | |
| 55 | + } finally { | |
| 56 | + if (cluster != null) | |
| 57 | + cluster.close(); | |
| 58 | + if (ccm != null) | |
| 59 | + ccm.remove(); | |
| 60 | + } | |
| 61 | + assertThat(loadBalancingPolicy.counter.get()).isEqualTo(1); | |
| 62 | + } | |
| 63 | + | |
| 64 | + static class QueryPlanCountingPolicy extends DelegatingLoadBalancingPolicy { | |
| 65 | + | |
| 66 | + final AtomicInteger counter = new AtomicInteger(); | |
| 67 | + | |
| 68 | + public QueryPlanCountingPolicy(LoadBalancingPolicy delegate) { | |
| 69 | + super(delegate); | |
| 70 | + } | |
| 71 | + | |
| 72 | + public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) { | |
| 73 | + counter.incrementAndGet(); | |
| 74 | + return super.newQueryPlan(loggedKeyspace, statement); | |
| 75 | + } | |
| 76 | + } | |
| 77 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/DynamicConnectionPoolTest.java +1 −1
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | * |
| 37 | 37 | * @throws InterruptedException |
| 38 | 38 | */ |
| 39 | - @Test(groups = "long") | |
| 39 | + @Test(groups = "long", enabled = false /* this test causes timeouts on Jenkins */) | |
| 40 | 40 | public void open_connections_metric_should_always_be_positive() throws InterruptedException { |
| 41 | 41 | // Track progress in a dedicated thread |
| 42 | 42 | int numberOfInserts = 100 * 1000; |
added driver-core/src/test/java/com/datastax/driver/core/HostAssert.java +111 −0
| @@ -0,0 +1,111 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import java.util.concurrent.TimeUnit; | |
| 4 | +import java.util.concurrent.atomic.AtomicBoolean; | |
| 5 | + | |
| 6 | +import static org.assertj.core.api.Assertions.fail; | |
| 7 | +import org.assertj.core.api.AbstractAssert; | |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 9 | + | |
| 10 | +import com.datastax.driver.core.Host.State; | |
| 11 | +import com.datastax.driver.core.Host.StateListener; | |
| 12 | +import com.datastax.driver.core.policies.LoadBalancingPolicy; | |
| 13 | + | |
| 14 | +public class HostAssert extends AbstractAssert<HostAssert, Host> { | |
| 15 | + | |
| 16 | + private final Cluster cluster; | |
| 17 | + | |
| 18 | + protected HostAssert(Host host, Cluster cluster) { | |
| 19 | + super(host, HostAssert.class); | |
| 20 | + this.cluster = cluster; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public HostAssert hasState(Host.State expected) { | |
| 24 | + assertThat(actual.state).isEqualTo(expected); | |
| 25 | + return this; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public HostAssert isAtDistance(HostDistance expected) { | |
| 29 | + LoadBalancingPolicy loadBalancingPolicy = cluster.manager.loadBalancingPolicy(); | |
| 30 | + assertThat(loadBalancingPolicy.distance(actual)).isEqualTo(expected); | |
| 31 | + return this; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public HostAssert comesUpWithin(long duration, TimeUnit unit) { | |
| 35 | + final AtomicBoolean notification = new AtomicBoolean(); | |
| 36 | + StateListener upListener = new StateListenerBase() { | |
| 37 | + public void onUp(Host host) { | |
| 38 | + notification.set(true); | |
| 39 | + }; | |
| 40 | + }; | |
| 41 | + cluster.register(upListener); | |
| 42 | + try { | |
| 43 | + // Make sure the host did not come up while we were installing the listener | |
| 44 | + if (actual.isUp()) | |
| 45 | + return this; | |
| 46 | + | |
| 47 | + long maxTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(duration, unit); | |
| 48 | + do { | |
| 49 | + TimeUnit.SECONDS.sleep(10); | |
| 50 | + if (notification.get()) | |
| 51 | + return this; | |
| 52 | + } while (System.nanoTime() < maxTime); | |
| 53 | + } catch (InterruptedException e) { | |
| 54 | + fail("Got interrupted while waiting for host to come up"); | |
| 55 | + } finally { | |
| 56 | + cluster.unregister(upListener); | |
| 57 | + } | |
| 58 | + fail(actual + " did not come up within " + duration + " " + unit); | |
| 59 | + return this; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public HostAssert goesDownWithin(long duration, TimeUnit unit) { | |
| 63 | + final AtomicBoolean notification = new AtomicBoolean(); | |
| 64 | + StateListener upListener = new StateListenerBase() { | |
| 65 | + public void onDown(Host host) { | |
| 66 | + notification.set(true); | |
| 67 | + }; | |
| 68 | + }; | |
| 69 | + cluster.register(upListener); | |
| 70 | + try { | |
| 71 | + // Make sure the host did not go down while we were installing the listener | |
| 72 | + if (actual.state == State.DOWN) | |
| 73 | + return this; | |
| 74 | + | |
| 75 | + long maxTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(duration, unit); | |
| 76 | + do { | |
| 77 | + TimeUnit.SECONDS.sleep(10); | |
| 78 | + if (notification.get()) | |
| 79 | + return this; | |
| 80 | + } while (System.nanoTime() < maxTime); | |
| 81 | + } catch (InterruptedException e) { | |
| 82 | + fail("Got interrupted while waiting for host to go down"); | |
| 83 | + } finally { | |
| 84 | + cluster.unregister(upListener); | |
| 85 | + } | |
| 86 | + fail(actual + " did not go down within " + duration + " " + unit); | |
| 87 | + return this; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public static class StateListenerBase implements StateListener { | |
| 91 | + @Override | |
| 92 | + public void onAdd(Host host) { | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Override | |
| 96 | + public void onUp(Host host) { | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public void onSuspected(Host host) { | |
| 101 | + } | |
| 102 | + | |
| 103 | + @Override | |
| 104 | + public void onDown(Host host) { | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public void onRemove(Host host) { | |
| 109 | + } | |
| 110 | + } | |
| 111 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/LoadBalancingPolicyBootstrapTest.java +12 −25
| @@ -17,13 +17,14 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.io.PrintWriter; |
| 19 | 19 | import java.io.StringWriter; |
| 20 | -import java.util.Collection; | |
| 21 | -import java.util.Iterator; | |
| 22 | 20 | |
| 23 | -import org.testng.annotations.*; | |
| 21 | +import org.testng.annotations.AfterClass; | |
| 22 | +import org.testng.annotations.BeforeClass; | |
| 23 | +import org.testng.annotations.Test; | |
| 24 | 24 | |
| 25 | 25 | import static org.testng.Assert.assertEquals; |
| 26 | 26 | |
| 27 | +import com.datastax.driver.core.policies.DelegatingLoadBalancingPolicy; | |
| 27 | 28 | import com.datastax.driver.core.policies.LoadBalancingPolicy; |
| 28 | 29 | import com.datastax.driver.core.policies.RoundRobinPolicy; |
| 29 | 30 | |
| @@ -52,9 +53,8 @@ | ||
| 52 | 53 | c.discard(); |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | - static class CountingPolicy implements LoadBalancingPolicy { | |
| 56 | + static class CountingPolicy extends DelegatingLoadBalancingPolicy { | |
| 56 | 57 | |
| 57 | - private final LoadBalancingPolicy delegate; | |
| 58 | 58 | int adds; |
| 59 | 59 | int suspecteds; |
| 60 | 60 | int removes; |
| @@ -64,51 +64,38 @@ | ||
| 64 | 64 | final StringWriter history = new StringWriter(); |
| 65 | 65 | private final PrintWriter out = new PrintWriter(history); |
| 66 | 66 | |
| 67 | - CountingPolicy(LoadBalancingPolicy delegate) { | |
| 68 | - this.delegate = delegate; | |
| 67 | + public CountingPolicy(LoadBalancingPolicy delegate) { | |
| 68 | + super(delegate); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public void onAdd(Host host) { |
| 72 | 72 | out.printf("add %s%n", host); |
| 73 | 73 | adds++; |
| 74 | - delegate.onAdd(host); | |
| 74 | + super.onAdd(host); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public void onSuspected(Host host) { |
| 78 | 78 | out.printf("suspect %s%n", host); |
| 79 | 79 | suspecteds++; |
| 80 | - delegate.onSuspected(host); | |
| 80 | + super.onSuspected(host); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | public void onUp(Host host) { |
| 84 | 84 | out.printf("up %s%n", host); |
| 85 | 85 | ups++; |
| 86 | - delegate.onUp(host); | |
| 86 | + super.onUp(host); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | public void onDown(Host host) { |
| 90 | 90 | out.printf("down %s%n", host); |
| 91 | 91 | downs++; |
| 92 | - delegate.onDown(host); | |
| 92 | + super.onDown(host); | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | public void onRemove(Host host) { |
| 96 | 96 | out.printf("remove %s%n", host); |
| 97 | 97 | removes++; |
| 98 | - delegate.onRemove(host); | |
| 99 | - } | |
| 100 | - | |
| 101 | - public void init(Cluster cluster, Collection<Host> hosts) { | |
| 102 | - delegate.init(cluster, hosts); | |
| 103 | - } | |
| 104 | - | |
| 105 | - public HostDistance distance(Host host) { | |
| 106 | - return delegate.distance(host); | |
| 107 | - } | |
| 108 | - | |
| 109 | - @Override | |
| 110 | - public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) { | |
| 111 | - return delegate.newQueryPlan(loggedKeyspace, statement); | |
| 98 | + super.onRemove(host); | |
| 112 | 99 | } |
| 113 | 100 | } |
| 114 | 101 | } |
added driver-core/src/test/java/com/datastax/driver/core/PoolingOptionsTest.java +96 −0
| @@ -0,0 +1,96 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import static java.util.concurrent.TimeUnit.SECONDS; | |
| 4 | + | |
| 5 | +import org.mockito.Mockito; | |
| 6 | +import org.testng.annotations.Test; | |
| 7 | + | |
| 8 | +import com.datastax.driver.core.Host.State; | |
| 9 | +import com.datastax.driver.core.policies.ConstantReconnectionPolicy; | |
| 10 | +import com.datastax.driver.core.policies.LimitingLoadBalancingPolicy; | |
| 11 | +import com.datastax.driver.core.policies.RoundRobinPolicy; | |
| 12 | + | |
| 13 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 14 | + | |
| 15 | +public class PoolingOptionsTest { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Tests {@link PoolingOptions#refreshConnectedHost(Host)} through a custom load balancing policy. | |
| 19 | + */ | |
| 20 | + @Test(groups = "long") | |
| 21 | + public void should_refresh_single_connected_host() { | |
| 22 | + CCMBridge ccm = null; | |
| 23 | + Cluster cluster = null; | |
| 24 | + try { | |
| 25 | + // This will make the driver use at most 2 hosts, the others will be ignored | |
| 26 | + LimitingLoadBalancingPolicy loadBalancingPolicy = new LimitingLoadBalancingPolicy(new RoundRobinPolicy(), 2, 1); | |
| 27 | + | |
| 28 | + // Setup a 3-host cluster, start only two hosts so that we know in advance which ones the policy will use | |
| 29 | + ccm = CCMBridge.create("test"); | |
| 30 | + ccm.populate(3); | |
| 31 | + ccm.start(1); | |
| 32 | + ccm.start(2); | |
| 33 | + ccm.waitForUp(1); | |
| 34 | + ccm.waitForUp(2); | |
| 35 | + | |
| 36 | + PoolingOptions poolingOptions = Mockito.spy(new PoolingOptions()); | |
| 37 | + cluster = Cluster.builder() | |
| 38 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 39 | + .withPoolingOptions(poolingOptions) | |
| 40 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 41 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) | |
| 42 | + .build(); | |
| 43 | + | |
| 44 | + Session session = cluster.connect(); | |
| 45 | + | |
| 46 | + assertThat(cluster).usesControlHost(1); | |
| 47 | + assertThat(cluster).host(1) | |
| 48 | + .hasState(State.UP) | |
| 49 | + .isAtDistance(HostDistance.LOCAL); | |
| 50 | + // Wait for the node to be up, because apparently on Jenkins it's still only ADDED when we reach this line | |
| 51 | + assertThat(cluster).host(2) | |
| 52 | + .comesUpWithin(120, SECONDS) | |
| 53 | + .isAtDistance(HostDistance.LOCAL); | |
| 54 | + | |
| 55 | + // Bring host 3 up, its presence should be acknowledged but it should be ignored | |
| 56 | + ccm.start(3); | |
| 57 | + ccm.waitForUp(3); | |
| 58 | + | |
| 59 | + assertThat(cluster).host(1) | |
| 60 | + .hasState(State.UP) | |
| 61 | + .isAtDistance(HostDistance.LOCAL); | |
| 62 | + assertThat(cluster).host(2) | |
| 63 | + .hasState(State.UP) | |
| 64 | + .isAtDistance(HostDistance.LOCAL); | |
| 65 | + assertThat(cluster).host(3) | |
| 66 | + .hasState(State.ADDED) | |
| 67 | + .isAtDistance(HostDistance.IGNORED); | |
| 68 | + assertThat(session).hasNoPoolFor(3); | |
| 69 | + | |
| 70 | + // Kill host 2, host 3 should take its place | |
| 71 | + ccm.stop(2); | |
| 72 | + TestUtils.waitFor(CCMBridge.ipOfNode(3), cluster); | |
| 73 | + | |
| 74 | + assertThat(cluster).host(1) | |
| 75 | + .hasState(State.UP) | |
| 76 | + .isAtDistance(HostDistance.LOCAL); | |
| 77 | + assertThat(cluster).host(2) | |
| 78 | + .hasState(State.DOWN); | |
| 79 | + assertThat(cluster).host(3) | |
| 80 | + .hasState(State.UP) | |
| 81 | + .isAtDistance(HostDistance.LOCAL); | |
| 82 | + assertThat(session).hasPoolFor(3); | |
| 83 | + | |
| 84 | + // This is when refreshConnectedHost should have been invoked, it triggers pool creation when | |
| 85 | + // we switch the node from IGNORED to UP: | |
| 86 | + Mockito.verify(poolingOptions) | |
| 87 | + .refreshConnectedHost(TestUtils.findHost(cluster, 3)); | |
| 88 | + | |
| 89 | + } finally { | |
| 90 | + if (cluster != null) | |
| 91 | + cluster.close(); | |
| 92 | + if (ccm != null) | |
| 93 | + ccm.remove(); | |
| 94 | + } | |
| 95 | + } | |
| 96 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/RecommissionnedNodeTest.java +4 −56
| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | package com.datastax.driver.core; |
| 2 | 2 | |
| 3 | -import java.io.IOException; | |
| 4 | -import java.net.InetAddress; | |
| 5 | -import java.net.Socket; | |
| 6 | 3 | import java.util.concurrent.TimeUnit; |
| 7 | 4 | |
| 8 | 5 | import org.slf4j.Logger; |
| @@ -31,7 +28,7 @@ | ||
| 31 | 28 | mainCcm = CCMBridge.create("main", 3); |
| 32 | 29 | // node1 will be our "recommissionned" node, for now we just stop it so that it stays in the peers table. |
| 33 | 30 | mainCcm.stop(1); |
| 34 | - waitForDown(1); | |
| 31 | + mainCcm.waitForDown(1); | |
| 35 | 32 | |
| 36 | 33 | // Now start the driver that will connect to node2 and node3, and consider node1 down |
| 37 | 34 | Cluster mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); |
| @@ -41,7 +38,7 @@ | ||
| 41 | 38 | |
| 42 | 39 | // Start another ccm that will reuse node1's address |
| 43 | 40 | otherCcm = CCMBridge.create("other", 1); |
| 44 | - waitForUp(1); | |
| 41 | + otherCcm.waitForUp(1); | |
| 45 | 42 | |
| 46 | 43 | // Give the driver the time to notice the node is back up and try to connect to it. |
| 47 | 44 | TimeUnit.SECONDS.sleep(32); |
| @@ -56,7 +53,7 @@ | ||
| 56 | 53 | public void testControlConnection() throws Exception { |
| 57 | 54 | mainCcm = CCMBridge.create("main", 2); |
| 58 | 55 | mainCcm.stop(1); |
| 59 | - waitForDown(1); | |
| 56 | + mainCcm.waitForDown(1); | |
| 60 | 57 | |
| 61 | 58 | // Start the driver, the control connection will be on node2 |
| 62 | 59 | Cluster mainCluster = Cluster.builder().addContactPoint(CCMBridge.IP_PREFIX + "2").build(); |
| @@ -65,7 +62,7 @@ | ||
| 65 | 62 | |
| 66 | 63 | // Start another ccm that will reuse node1's address |
| 67 | 64 | otherCcm = CCMBridge.create("other", 1); |
| 68 | - waitForUp(1); | |
| 65 | + otherCcm.waitForUp(1); | |
| 69 | 66 | |
| 70 | 67 | // Stop node2, the control connection gets defunct |
| 71 | 68 | mainCcm.stop(2); |
| @@ -113,53 +110,4 @@ | ||
| 113 | 110 | TimeUnit.SECONDS.sleep(interval); |
| 114 | 111 | } |
| 115 | 112 | } |
| 116 | - | |
| 117 | - // Methods to wait for a node's state by pinging the TCP socket directly, instead of using a Cluster instance. | |
| 118 | - // This decouples these checks from the system under test, and avoids CASSANDRA-7510. | |
| 119 | - // Contributed by Pierre Laporte. | |
| 120 | - // TODO: move to a utility class, generalize their use to other tests. | |
| 121 | - | |
| 122 | - private static void waitForUp(int node) throws Exception { | |
| 123 | - InetAddress address = InetAddress.getByName(CCMBridge.IP_PREFIX + Integer.toString(node)); | |
| 124 | - busyWaitForPort(address, 9042, true); | |
| 125 | - } | |
| 126 | - | |
| 127 | - private static void waitForDown(int node) throws Exception { | |
| 128 | - InetAddress address = InetAddress.getByName(CCMBridge.IP_PREFIX + Integer.toString(node)); | |
| 129 | - busyWaitForPort(address, 9042, false); | |
| 130 | - } | |
| 131 | - | |
| 132 | - private static void busyWaitForPort(InetAddress address, int port, boolean expectedConnectionState) throws Exception { | |
| 133 | - long maxAcceptableWaitTime = TimeUnit.SECONDS.toMillis(10); | |
| 134 | - long waitQuantum = TimeUnit.MILLISECONDS.toMillis(500); | |
| 135 | - long waitTimeSoFar = 0; | |
| 136 | - boolean connectionState = !expectedConnectionState; | |
| 137 | - | |
| 138 | - while (connectionState != expectedConnectionState && waitTimeSoFar < maxAcceptableWaitTime) { | |
| 139 | - connectionState = pingPort(address, port); | |
| 140 | - try { | |
| 141 | - Thread.sleep(waitQuantum); | |
| 142 | - waitTimeSoFar += waitQuantum; | |
| 143 | - } catch (InterruptedException e) { | |
| 144 | - throw new RuntimeException("Interrupted while pinging " + address + ":" + port, e); | |
| 145 | - } | |
| 146 | - } | |
| 147 | - } | |
| 148 | - | |
| 149 | - private static boolean pingPort(InetAddress address, int port) throws Exception { | |
| 150 | - logger.debug("Trying {}:{}...", address, port); | |
| 151 | - boolean connectionSuccessful = false; | |
| 152 | - Socket socket = null; | |
| 153 | - try { | |
| 154 | - socket = new Socket(address, port); | |
| 155 | - connectionSuccessful = true; | |
| 156 | - logger.debug("Successfully connected"); | |
| 157 | - } catch (IOException e) { | |
| 158 | - logger.debug("Connection failed"); | |
| 159 | - } finally { | |
| 160 | - if (socket != null) | |
| 161 | - socket.close(); | |
| 162 | - } | |
| 163 | - return connectionSuccessful; | |
| 164 | - } | |
| 165 | 113 | } |
| No newline at the end of the file |
added driver-core/src/test/java/com/datastax/driver/core/ReconnectionTest.java +319 −0
| @@ -0,0 +1,319 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import java.io.IOException; | |
| 4 | +import java.net.InetSocketAddress; | |
| 5 | +import java.util.Collections; | |
| 6 | +import java.util.Iterator; | |
| 7 | +import java.util.Map; | |
| 8 | +import java.util.concurrent.TimeUnit; | |
| 9 | +import java.util.concurrent.atomic.AtomicInteger; | |
| 10 | + | |
| 11 | +import static java.util.concurrent.TimeUnit.SECONDS; | |
| 12 | + | |
| 13 | +import com.google.common.base.Charsets; | |
| 14 | +import com.google.common.collect.ImmutableMap; | |
| 15 | +import org.testng.annotations.Test; | |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.Host.State; | |
| 19 | +import com.datastax.driver.core.policies.*; | |
| 20 | + | |
| 21 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * Scenarios where a Cluster loses connection to a host and reconnects. | |
| 25 | + */ | |
| 26 | +public class ReconnectionTest { | |
| 27 | + | |
| 28 | + @Test(groups = "long") | |
| 29 | + public void should_reconnect_after_full_connectivity_loss() throws InterruptedException { | |
| 30 | + CCMBridge ccm = null; | |
| 31 | + Cluster cluster = null; | |
| 32 | + try { | |
| 33 | + ccm = CCMBridge.create("test", 2); | |
| 34 | + int reconnectionDelay = 1000; | |
| 35 | + cluster = Cluster.builder() | |
| 36 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 37 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelay)) | |
| 38 | + .build(); | |
| 39 | + cluster.connect(); | |
| 40 | + | |
| 41 | + assertThat(cluster).usesControlHost(1); | |
| 42 | + | |
| 43 | + // Stop all nodes. We won't get notifications anymore, so the only mechanism to | |
| 44 | + // reconnect is the background reconnection attempts. | |
| 45 | + ccm.stop(2); | |
| 46 | + ccm.stop(1); | |
| 47 | + | |
| 48 | + ccm.waitForDown(2); | |
| 49 | + ccm.start(2); | |
| 50 | + ccm.waitForUp(2); | |
| 51 | + | |
| 52 | + assertThat(cluster).host(2).comesUpWithin(120, SECONDS); | |
| 53 | + | |
| 54 | + // Give the control connection a few moments to reconnect | |
| 55 | + TimeUnit.MILLISECONDS.sleep(reconnectionDelay * 2); | |
| 56 | + assertThat(cluster).usesControlHost(2); | |
| 57 | + } finally { | |
| 58 | + if (cluster != null) | |
| 59 | + cluster.close(); | |
| 60 | + if (ccm != null) | |
| 61 | + ccm.remove(); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Test(groups = "long") | |
| 66 | + public void should_keep_reconnecting_on_authentication_error() throws InterruptedException { | |
| 67 | + CCMBridge ccm = null; | |
| 68 | + Cluster cluster = null; | |
| 69 | + try { | |
| 70 | + ccm = CCMBridge.create("test"); | |
| 71 | + ccm.populate(1); | |
| 72 | + // Configure password authentication on the server (default: cassandra / cassandra) | |
| 73 | + ccm.updateConfig("authenticator", "PasswordAuthenticator"); | |
| 74 | + ccm.start(1, "-Dcassandra.superuser_setup_delay_ms=0"); | |
| 75 | + | |
| 76 | + DynamicPlainTextAuthProvider authProvider = new DynamicPlainTextAuthProvider("cassandra", "cassandra"); | |
| 77 | + int reconnectionDelayMs = 1000; | |
| 78 | + CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMs)); | |
| 79 | + | |
| 80 | + cluster = Cluster.builder() | |
| 81 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 82 | + // Start with the correct auth so that we can initialize the server | |
| 83 | + .withAuthProvider(authProvider) | |
| 84 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 85 | + .build(); | |
| 86 | + | |
| 87 | + cluster.init(); | |
| 88 | + assertThat(cluster).usesControlHost(1); | |
| 89 | + | |
| 90 | + // Stop the server, set wrong credentials and restart | |
| 91 | + ccm.stop(1); | |
| 92 | + ccm.waitForDown(1); | |
| 93 | + authProvider.password = "wrongPassword"; | |
| 94 | + ccm.start(1); | |
| 95 | + ccm.waitForUp(1); | |
| 96 | + | |
| 97 | + // Wait a few iterations to ensure that our authProvider has returned the wrong credentials at least once | |
| 98 | + // NB: authentication errors show up in the logs | |
| 99 | + int initialCount = authProvider.count.get(); | |
| 100 | + int iterations = 0, maxIterations = 12; // make sure we don't wait indefinitely | |
| 101 | + do { | |
| 102 | + iterations += 1; | |
| 103 | + TimeUnit.SECONDS.sleep(5); | |
| 104 | + } while (iterations < maxIterations && authProvider.count.get() <= initialCount); | |
| 105 | + assertThat(iterations).isLessThan(maxIterations); | |
| 106 | + | |
| 107 | + // Fix the credentials | |
| 108 | + authProvider.password = "cassandra"; | |
| 109 | + | |
| 110 | + // The driver should eventually reconnect to the node | |
| 111 | + assertThat(cluster).host(1).comesUpWithin(120, SECONDS); | |
| 112 | + } finally { | |
| 113 | + if (cluster != null) | |
| 114 | + cluster.close(); | |
| 115 | + if (ccm != null) | |
| 116 | + ccm.remove(); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + @Test(groups = "long") | |
| 121 | + public void should_cancel_reconnection_attempts() throws InterruptedException { | |
| 122 | + CCMBridge ccm = null; | |
| 123 | + Cluster cluster = null; | |
| 124 | + | |
| 125 | + long reconnectionDelayMillis = 1 * 1000; | |
| 126 | + CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)); | |
| 127 | + | |
| 128 | + try { | |
| 129 | + ccm = CCMBridge.create("test", 2); | |
| 130 | + cluster = Cluster.builder() | |
| 131 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 132 | + .withReconnectionPolicy(reconnectionPolicy) | |
| 133 | + .build(); | |
| 134 | + cluster.connect(); | |
| 135 | + | |
| 136 | + // Stop a node and cancel the reconnection attempts to it | |
| 137 | + ccm.stop(2); | |
| 138 | + Host host2 = TestUtils.findHost(cluster, 2); | |
| 139 | + host2.getReconnectionAttemptFuture().cancel(false); | |
| 140 | + | |
| 141 | + // The reconnection count should not vary over time anymore | |
| 142 | + int initialCount = reconnectionPolicy.count.get(); | |
| 143 | + TimeUnit.MILLISECONDS.sleep(reconnectionDelayMillis * 2); | |
| 144 | + assertThat(reconnectionPolicy.count.get()).isEqualTo(initialCount); | |
| 145 | + | |
| 146 | + // Restart the node, which will trigger an UP notification | |
| 147 | + ccm.start(2); | |
| 148 | + ccm.waitForUp(2); | |
| 149 | + | |
| 150 | + // The driver should now see the node as UP again | |
| 151 | + assertThat(cluster).host(2).comesUpWithin(120, SECONDS); | |
| 152 | + | |
| 153 | + } finally { | |
| 154 | + if (cluster != null) | |
| 155 | + cluster.close(); | |
| 156 | + if (ccm != null) | |
| 157 | + ccm.remove(); | |
| 158 | + } | |
| 159 | + } | |
| 160 | + | |
| 161 | + @Test(groups = "long") | |
| 162 | + public void should_trigger_one_time_reconnect() throws InterruptedException, IOException { | |
| 163 | + CCMBridge ccm = null; | |
| 164 | + Cluster cluster = null; | |
| 165 | + | |
| 166 | + long reconnectionDelayMillis = 1 * 1000; | |
| 167 | + TogglabePolicy loadBalancingPolicy = new TogglabePolicy(new RoundRobinPolicy()); | |
| 168 | + | |
| 169 | + try { | |
| 170 | + ccm = CCMBridge.create("test", 1); | |
| 171 | + cluster = Cluster.builder() | |
| 172 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 173 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 174 | + .withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis)) | |
| 175 | + .build(); | |
| 176 | + cluster.connect(); | |
| 177 | + | |
| 178 | + // Tweak the LBP so that the control connection never reconnects, otherwise | |
| 179 | + // it would interfere with the rest of the test (this is a bit of a hack) | |
| 180 | + loadBalancingPolicy.returnEmptyQueryPlan = true; | |
| 181 | + | |
| 182 | + // Stop the node and cancel the reconnection attempts to it | |
| 183 | + ccm.stop(1); | |
| 184 | + ccm.waitForDown(1); | |
| 185 | + assertThat(cluster).host(1).goesDownWithin(20, SECONDS); | |
| 186 | + Host host1 = TestUtils.findHost(cluster, 1); | |
| 187 | + host1.getReconnectionAttemptFuture().cancel(false); | |
| 188 | + | |
| 189 | + // Trigger a one-time reconnection attempt (this will fail) | |
| 190 | + host1.tryReconnectOnce(); | |
| 191 | + | |
| 192 | + // Wait for a few reconnection cycles before checking | |
| 193 | + TimeUnit.MILLISECONDS.sleep(reconnectionDelayMillis * 2); | |
| 194 | + assertThat(cluster).host(1).hasState(State.DOWN); | |
| 195 | + | |
| 196 | + // Restart the node (this will not trigger an UP notification thanks to our | |
| 197 | + // hack to disable the control connection reconnects). The host should stay | |
| 198 | + // down for the driver. | |
| 199 | + ccm.start(1); | |
| 200 | + ccm.waitForUp(1); | |
| 201 | + | |
| 202 | + TimeUnit.SECONDS.sleep(Cluster.NEW_NODE_DELAY_SECONDS); | |
| 203 | + assertThat(cluster).host(1).hasState(State.DOWN); | |
| 204 | + | |
| 205 | + // Trigger another one-time reconnection attempt (this will succeed). The | |
| 206 | + // host should be back up. | |
| 207 | + host1.tryReconnectOnce(); | |
| 208 | + assertThat(cluster).host(1).comesUpWithin(120, SECONDS); | |
| 209 | + } finally { | |
| 210 | + if (cluster != null) | |
| 211 | + cluster.close(); | |
| 212 | + if (ccm != null) | |
| 213 | + ccm.remove(); | |
| 214 | + } | |
| 215 | + } | |
| 216 | + | |
| 217 | + /** | |
| 218 | + * An authentication provider that allows changing the credentials at runtime, and tracks how many times they have been requested. | |
| 219 | + */ | |
| 220 | + static class DynamicPlainTextAuthProvider implements AuthProvider { | |
| 221 | + volatile String username; | |
| 222 | + volatile String password; | |
| 223 | + | |
| 224 | + final AtomicInteger count = new AtomicInteger(); | |
| 225 | + | |
| 226 | + public DynamicPlainTextAuthProvider(String username, String password) { | |
| 227 | + this.username = username; | |
| 228 | + this.password = password; | |
| 229 | + } | |
| 230 | + | |
| 231 | + public Authenticator newAuthenticator(InetSocketAddress host) { | |
| 232 | + return new PlainTextAuthenticator(); | |
| 233 | + } | |
| 234 | + | |
| 235 | + private class PlainTextAuthenticator extends ProtocolV1Authenticator implements Authenticator { | |
| 236 | + | |
| 237 | + @Override | |
| 238 | + public byte[] initialResponse() { | |
| 239 | + count.incrementAndGet(); | |
| 240 | + | |
| 241 | + byte[] usernameBytes = username.getBytes(Charsets.UTF_8); | |
| 242 | + byte[] passwordBytes = password.getBytes(Charsets.UTF_8); | |
| 243 | + byte[] initialToken = new byte[usernameBytes.length + passwordBytes.length + 2]; | |
| 244 | + initialToken[0] = 0; | |
| 245 | + System.arraycopy(usernameBytes, 0, initialToken, 1, usernameBytes.length); | |
| 246 | + initialToken[usernameBytes.length + 1] = 0; | |
| 247 | + System.arraycopy(passwordBytes, 0, initialToken, usernameBytes.length + 2, passwordBytes.length); | |
| 248 | + return initialToken; | |
| 249 | + } | |
| 250 | + | |
| 251 | + @Override | |
| 252 | + public byte[] evaluateChallenge(byte[] challenge) { | |
| 253 | + return null; | |
| 254 | + } | |
| 255 | + | |
| 256 | + @Override | |
| 257 | + public void onAuthenticationSuccess(byte[] token) { | |
| 258 | + // no-op, the server should send nothing anyway | |
| 259 | + } | |
| 260 | + | |
| 261 | + @Override | |
| 262 | + Map<String, String> getCredentials() { | |
| 263 | + return ImmutableMap.of("username", username, | |
| 264 | + "password", password); | |
| 265 | + } | |
| 266 | + } | |
| 267 | + } | |
| 268 | + | |
| 269 | + /** | |
| 270 | + * A reconnection policy that tracks how many times its schedule has been invoked. | |
| 271 | + */ | |
| 272 | + public static class CountingReconnectionPolicy implements ReconnectionPolicy { | |
| 273 | + public final AtomicInteger count = new AtomicInteger(); | |
| 274 | + private final ReconnectionPolicy childPolicy; | |
| 275 | + | |
| 276 | + public CountingReconnectionPolicy(ReconnectionPolicy childPolicy) { | |
| 277 | + this.childPolicy = childPolicy; | |
| 278 | + } | |
| 279 | + | |
| 280 | + @Override | |
| 281 | + public ReconnectionSchedule newSchedule() { | |
| 282 | + return new CountingSchedule(childPolicy.newSchedule()); | |
| 283 | + } | |
| 284 | + | |
| 285 | + class CountingSchedule implements ReconnectionSchedule { | |
| 286 | + private final ReconnectionSchedule childSchedule; | |
| 287 | + | |
| 288 | + public CountingSchedule(ReconnectionSchedule childSchedule) { | |
| 289 | + this.childSchedule = childSchedule; | |
| 290 | + } | |
| 291 | + | |
| 292 | + @Override | |
| 293 | + public long nextDelayMs() { | |
| 294 | + count.incrementAndGet(); | |
| 295 | + return childSchedule.nextDelayMs(); | |
| 296 | + } | |
| 297 | + } | |
| 298 | + } | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * A load balancing policy that can be "disabled" by having its query plan return no hosts. | |
| 302 | + */ | |
| 303 | + public static class TogglabePolicy extends DelegatingLoadBalancingPolicy { | |
| 304 | + | |
| 305 | + volatile boolean returnEmptyQueryPlan; | |
| 306 | + | |
| 307 | + public TogglabePolicy(LoadBalancingPolicy delegate) { | |
| 308 | + super(delegate); | |
| 309 | + } | |
| 310 | + | |
| 311 | + @Override | |
| 312 | + public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) { | |
| 313 | + if (returnEmptyQueryPlan) | |
| 314 | + return Collections.<Host>emptyList().iterator(); | |
| 315 | + else | |
| 316 | + return super.newQueryPlan(loggedKeyspace, statement); | |
| 317 | + } | |
| 318 | + } | |
| 319 | +} |
added driver-core/src/test/java/com/datastax/driver/core/SessionAssert.java +25 −0
| @@ -0,0 +1,25 @@ | ||
| 1 | +package com.datastax.driver.core; | |
| 2 | + | |
| 3 | +import org.assertj.core.api.AbstractAssert; | |
| 4 | + | |
| 5 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 6 | + | |
| 7 | +public class SessionAssert extends AbstractAssert<SessionAssert, SessionManager> { | |
| 8 | + | |
| 9 | + protected SessionAssert(Session actual) { | |
| 10 | + // We are cheating a bit by casting, but this is the only implementation anyway | |
| 11 | + super((SessionManager)actual, SessionAssert.class); | |
| 12 | + } | |
| 13 | + | |
| 14 | + public SessionAssert hasPoolFor(int hostNumber) { | |
| 15 | + Host host = TestUtils.findHost(actual.cluster, hostNumber); | |
| 16 | + assertThat(actual.pools.containsKey(host)).isTrue(); | |
| 17 | + return this; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public SessionAssert hasNoPoolFor(int hostNumber) { | |
| 21 | + Host host = TestUtils.findHost(actual.cluster, hostNumber); | |
| 22 | + assertThat(actual.pools.containsKey(host)).isFalse(); | |
| 23 | + return this; | |
| 24 | + } | |
| 25 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +13 −0
| @@ -21,6 +21,8 @@ | ||
| 21 | 21 | import java.nio.ByteBuffer; |
| 22 | 22 | import java.util.*; |
| 23 | 23 | |
| 24 | +import static org.testng.Assert.fail; | |
| 25 | + | |
| 24 | 26 | import org.slf4j.Logger; |
| 25 | 27 | import org.slf4j.LoggerFactory; |
| 26 | 28 | import org.testng.SkipException; |
| @@ -370,6 +372,17 @@ | ||
| 370 | 372 | } |
| 371 | 373 | } |
| 372 | 374 | |
| 375 | + /** Utility method to find the {@code Host} object corresponding to a node in a cluster. */ | |
| 376 | + public static Host findHost(Cluster cluster, int hostNumber) { | |
| 377 | + String address = CCMBridge.ipOfNode(hostNumber); | |
| 378 | + for (Host host : cluster.getMetadata().getAllHosts()) { | |
| 379 | + if (host.getAddress().getHostAddress().equals(address)) | |
| 380 | + return host; | |
| 381 | + } | |
| 382 | + fail(address + " not found in cluster metadata"); | |
| 383 | + return null; // never reached | |
| 384 | + } | |
| 385 | + | |
| 373 | 386 | public static int numberOfLocalCoreConnections(Cluster cluster) { |
| 374 | 387 | Configuration configuration = cluster.getConfiguration(); |
| 375 | 388 | ProtocolVersion protocolVersion = configuration.getProtocolOptions().getProtocolVersionEnum(); |
added driver-core/src/test/java/com/datastax/driver/core/policies/CloseableLoadBalancingPolicyTest.java +45 −0
| @@ -0,0 +1,45 @@ | ||
| 1 | +package com.datastax.driver.core.policies; | |
| 2 | + | |
| 3 | +import org.testng.annotations.Test; | |
| 4 | + | |
| 5 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 6 | + | |
| 7 | +import com.datastax.driver.core.CCMBridge; | |
| 8 | +import com.datastax.driver.core.Cluster; | |
| 9 | + | |
| 10 | +public class CloseableLoadBalancingPolicyTest { | |
| 11 | + @Test(groups = "short") | |
| 12 | + public void should_be_invoked_at_shutdown() { | |
| 13 | + CloseMonitoringPolicy policy = new CloseMonitoringPolicy(Policies.defaultLoadBalancingPolicy()); | |
| 14 | + CCMBridge ccm = null; | |
| 15 | + Cluster cluster = null; | |
| 16 | + try { | |
| 17 | + ccm = CCMBridge.create("test", 1); | |
| 18 | + cluster = Cluster.builder() | |
| 19 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 20 | + .withLoadBalancingPolicy(policy) | |
| 21 | + .build(); | |
| 22 | + cluster.connect(); | |
| 23 | + } finally { | |
| 24 | + if (cluster != null) | |
| 25 | + cluster.close(); | |
| 26 | + if (ccm != null) | |
| 27 | + ccm.remove(); | |
| 28 | + } | |
| 29 | + assertThat(policy.wasClosed).isTrue(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + static class CloseMonitoringPolicy extends DelegatingLoadBalancingPolicy { | |
| 33 | + | |
| 34 | + volatile boolean wasClosed = false; | |
| 35 | + | |
| 36 | + public CloseMonitoringPolicy(LoadBalancingPolicy delegate) { | |
| 37 | + super(delegate); | |
| 38 | + } | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public void close() { | |
| 42 | + wasClosed = true; | |
| 43 | + } | |
| 44 | + } | |
| 45 | +} |
modified driver-core/src/test/java/com/datastax/driver/core/policies/DCAwareRoundRobinPolicyTest.java +2 −12
| @@ -1,13 +1,12 @@ | ||
| 1 | 1 | package com.datastax.driver.core.policies; |
| 2 | 2 | |
| 3 | 3 | import org.testng.annotations.Test; |
| 4 | - | |
| 5 | 4 | import static org.testng.Assert.assertEquals; |
| 6 | -import static org.testng.Assert.fail; | |
| 7 | 5 | |
| 8 | 6 | import com.datastax.driver.core.CCMBridge; |
| 9 | 7 | import com.datastax.driver.core.Cluster; |
| 10 | 8 | import com.datastax.driver.core.Host; |
| 9 | +import com.datastax.driver.core.TestUtils; | |
| 11 | 10 | |
| 12 | 11 | public class DCAwareRoundRobinPolicyTest { |
| 13 | 12 | |
| @@ -30,7 +29,7 @@ | ||
| 30 | 29 | cluster.init(); |
| 31 | 30 | |
| 32 | 31 | // Policy's localDC should be the one from the contact point |
| 33 | - Host host1 = findHost(cluster, CCMBridge.ipOfNode(1)); | |
| 32 | + Host host1 = TestUtils.findHost(cluster, 1); | |
| 34 | 33 | assertEquals(policy.localDc, host1.getDatacenter()); |
| 35 | 34 | |
| 36 | 35 | } finally { |
| @@ -40,13 +39,4 @@ | ||
| 40 | 39 | ccm.remove(); |
| 41 | 40 | } |
| 42 | 41 | } |
| 43 | - | |
| 44 | - private static Host findHost(Cluster cluster, String ip) { | |
| 45 | - for (Host host : cluster.getMetadata().getAllHosts()) { | |
| 46 | - if (host.getAddress().getHostAddress().equals(ip)) | |
| 47 | - return host; | |
| 48 | - } | |
| 49 | - fail(ip + " not found in cluster metadata"); | |
| 50 | - return null; | |
| 51 | - } | |
| 52 | 42 | } |
added driver-core/src/test/java/com/datastax/driver/core/policies/DelegatingLoadBalancingPolicy.java +65 −0
| @@ -0,0 +1,65 @@ | ||
| 1 | +package com.datastax.driver.core.policies; | |
| 2 | + | |
| 3 | +import java.util.Collection; | |
| 4 | +import java.util.Iterator; | |
| 5 | + | |
| 6 | +import com.datastax.driver.core.Cluster; | |
| 7 | +import com.datastax.driver.core.Host; | |
| 8 | +import com.datastax.driver.core.HostDistance; | |
| 9 | +import com.datastax.driver.core.Statement; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Base class for tests that want to wrap a policy to add some instrumentation. | |
| 13 | + * | |
| 14 | + * NB: this is currently only used in tests, but could be provided as a convenience in the production code. | |
| 15 | + */ | |
| 16 | +public abstract class DelegatingLoadBalancingPolicy implements ChainableLoadBalancingPolicy, CloseableLoadBalancingPolicy { | |
| 17 | + protected final LoadBalancingPolicy delegate; | |
| 18 | + | |
| 19 | + public DelegatingLoadBalancingPolicy(LoadBalancingPolicy delegate) { | |
| 20 | + this.delegate = delegate; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void init(Cluster cluster, Collection<Host> hosts) { | |
| 24 | + delegate.init(cluster, hosts); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public HostDistance distance(Host host) { | |
| 28 | + return delegate.distance(host); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) { | |
| 32 | + return delegate.newQueryPlan(loggedKeyspace, statement); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public void onAdd(Host host) { | |
| 36 | + delegate.onAdd(host); | |
| 37 | + } | |
| 38 | + | |
| 39 | + public void onUp(Host host) { | |
| 40 | + delegate.onUp(host); | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void onSuspected(Host host) { | |
| 44 | + delegate.onSuspected(host); | |
| 45 | + } | |
| 46 | + | |
| 47 | + public void onDown(Host host) { | |
| 48 | + delegate.onDown(host); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void onRemove(Host host) { | |
| 52 | + delegate.onRemove(host); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public LoadBalancingPolicy getChildPolicy() { | |
| 57 | + return delegate; | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Override | |
| 61 | + public void close() { | |
| 62 | + if (delegate instanceof CloseableLoadBalancingPolicy) | |
| 63 | + ((CloseableLoadBalancingPolicy)delegate).close(); | |
| 64 | + } | |
| 65 | +} | |
| No newline at the end of the file |
added driver-core/src/test/java/com/datastax/driver/core/policies/LimitingLoadBalancingPolicy.java +142 −0
| @@ -0,0 +1,142 @@ | ||
| 1 | +package com.datastax.driver.core.policies; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import java.util.concurrent.locks.Lock; | |
| 5 | +import java.util.concurrent.locks.ReentrantLock; | |
| 6 | + | |
| 7 | +import com.google.common.collect.Sets; | |
| 8 | + | |
| 9 | +import com.datastax.driver.core.Cluster; | |
| 10 | +import com.datastax.driver.core.Host; | |
| 11 | +import com.datastax.driver.core.HostDistance; | |
| 12 | +import com.datastax.driver.core.Statement; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Sample load balancing policy that limits the number of nodes the driver connects to. | |
| 16 | + * | |
| 17 | + * If more nodes are available, they are marked as IGNORED. When one of the "chosen" nodes | |
| 18 | + * goes down, the policy picks one of the ignored nodes to replace it. | |
| 19 | + * <p> | |
| 20 | + * This kind of policy can be used to alleviate the load on a cluster that has a lot of | |
| 21 | + * clients. | |
| 22 | + * <p> | |
| 23 | + * For simplicity, this policy does not distinguish LOCAL and REMOTE nodes. | |
| 24 | + */ | |
| 25 | +public class LimitingLoadBalancingPolicy extends DelegatingLoadBalancingPolicy { | |
| 26 | + private final int maxHosts; | |
| 27 | + private final int threshold; | |
| 28 | + private final Set<Host> liveHosts = Sets.newConcurrentHashSet(); | |
| 29 | + private final Set<Host> chosenHosts = Sets.newConcurrentHashSet(); | |
| 30 | + private final Lock updateLock = new ReentrantLock(); | |
| 31 | + | |
| 32 | + private volatile Cluster cluster; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @param delegate the underlying policy that will be fed with the chosen nodes | |
| 36 | + * @param maxHosts the maximum number of chosen nodes | |
| 37 | + * @param threshold how many chosen nodes we accept to lose before we start picking new ones | |
| 38 | + */ | |
| 39 | + public LimitingLoadBalancingPolicy(LoadBalancingPolicy delegate, int maxHosts, int threshold) { | |
| 40 | + super(delegate); | |
| 41 | + this.maxHosts = maxHosts; | |
| 42 | + this.threshold = threshold; | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public void init(Cluster cluster, Collection<Host> hosts) { | |
| 47 | + this.cluster = cluster; | |
| 48 | + for (Host host : hosts) | |
| 49 | + if (host.isUp()) | |
| 50 | + this.liveHosts.add(host); | |
| 51 | + this.delegate.init(cluster, Collections.<Host>emptyList()); | |
| 52 | + updateChosenHosts(); | |
| 53 | + } | |
| 54 | + | |
| 55 | + private void updateChosenHosts() { | |
| 56 | + if (chosenHosts.size() > maxHosts - threshold || liveHosts.size() == 0) | |
| 57 | + return; | |
| 58 | + | |
| 59 | + // We lock to prevent two events from triggering this simultaneously. | |
| 60 | + updateLock.lock(); | |
| 61 | + try { | |
| 62 | + int missing = maxHosts - chosenHosts.size(); | |
| 63 | + if (missing < threshold || liveHosts.size() == 0) | |
| 64 | + return; | |
| 65 | + Set<Host> newlyChosen = new HashSet<Host>(); | |
| 66 | + | |
| 67 | + for (Host host : liveHosts) { | |
| 68 | + // Note that this picks hosts whatever their distance is. | |
| 69 | + // We can't reliably call childPolicy.distance() here, because the childPolicy | |
| 70 | + // might require hosts to be already added to compute their distance properly | |
| 71 | + // (this is the case for DCAware policy). | |
| 72 | + newlyChosen.add(host); | |
| 73 | + missing -= 1; | |
| 74 | + if (missing == 0) | |
| 75 | + break; | |
| 76 | + } | |
| 77 | + | |
| 78 | + chosenHosts.addAll(newlyChosen); | |
| 79 | + liveHosts.removeAll(newlyChosen); | |
| 80 | + for (Host host : newlyChosen) { | |
| 81 | + delegate.onAdd(host); | |
| 82 | + | |
| 83 | + // delegate should have updated the distance, inform the driver so that it can | |
| 84 | + // recreate the pool. | |
| 85 | + cluster.getConfiguration().getPoolingOptions().refreshConnectedHost(host); | |
| 86 | + } | |
| 87 | + } finally { | |
| 88 | + updateLock.unlock(); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public HostDistance distance(Host host) { | |
| 94 | + if (chosenHosts.contains(host)) | |
| 95 | + return delegate.distance(host); | |
| 96 | + else | |
| 97 | + return HostDistance.IGNORED; | |
| 98 | + } | |
| 99 | + | |
| 100 | + @Override | |
| 101 | + public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) { | |
| 102 | + // Since we only add chosen nodes to the child policy, its query plan will only contain chosen nodes | |
| 103 | + return delegate.newQueryPlan(loggedKeyspace, statement); | |
| 104 | + } | |
| 105 | + | |
| 106 | + @Override | |
| 107 | + public void onAdd(Host host) { | |
| 108 | + liveHosts.add(host); | |
| 109 | + // update in case we didn't have enough chosen hosts before the addition | |
| 110 | + updateChosenHosts(); | |
| 111 | + } | |
| 112 | + | |
| 113 | + @Override | |
| 114 | + public void onUp(Host host) { | |
| 115 | + onAdd(host); | |
| 116 | + } | |
| 117 | + | |
| 118 | + @Override | |
| 119 | + public void onSuspected(Host host) { | |
| 120 | + // If a node gets suspected, it means the driver was connected to it, so it was a chosen node. | |
| 121 | + // Keep it as chosen for now, but notify the child policy which might reorder the query plan accordingly. | |
| 122 | + delegate.onSuspected(host); | |
| 123 | + } | |
| 124 | + | |
| 125 | + @Override | |
| 126 | + public void onDown(Host host) { | |
| 127 | + delegate.onDown(host); | |
| 128 | + | |
| 129 | + liveHosts.remove(host); | |
| 130 | + chosenHosts.remove(host); | |
| 131 | + updateChosenHosts(); | |
| 132 | + } | |
| 133 | + | |
| 134 | + @Override | |
| 135 | + public void onRemove(Host host) { | |
| 136 | + delegate.onRemove(host); | |
| 137 | + | |
| 138 | + liveHosts.remove(host); | |
| 139 | + chosenHosts.remove(host); | |
| 140 | + updateChosenHosts(); | |
| 141 | + } | |
| 142 | +} |
added driver-core/src/test/java/com/datastax/driver/core/policies/TokenAwarePolicyTest.java +78 −0
| @@ -0,0 +1,78 @@ | ||
| 1 | +package com.datastax.driver.core.policies; | |
| 2 | + | |
| 3 | +import java.nio.ByteBuffer; | |
| 4 | +import java.util.ArrayList; | |
| 5 | +import java.util.List; | |
| 6 | +import java.util.Set; | |
| 7 | + | |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 9 | +import com.google.common.collect.Lists; | |
| 10 | +import org.testng.annotations.Test; | |
| 11 | + | |
| 12 | +import com.datastax.driver.core.*; | |
| 13 | +import com.datastax.driver.core.utils.Bytes; | |
| 14 | + | |
| 15 | +public class TokenAwarePolicyTest { | |
| 16 | + @Test(groups = "long") | |
| 17 | + public void should_shuffle_replicas_when_requested() { | |
| 18 | + testShuffleReplicas(new TokenAwarePolicy(new RoundRobinPolicy(), true), | |
| 19 | + true); | |
| 20 | + } | |
| 21 | + | |
| 22 | + @Test(groups = "long") | |
| 23 | + public void should_not_shuffle_replicas_when_not_requested() { | |
| 24 | + testShuffleReplicas(new TokenAwarePolicy(new RoundRobinPolicy(), false), | |
| 25 | + false); | |
| 26 | + } | |
| 27 | + | |
| 28 | + private void testShuffleReplicas(TokenAwarePolicy loadBalancingPolicy, boolean expectShuffled) { | |
| 29 | + CCMBridge ccm = null; | |
| 30 | + Cluster cluster = null; | |
| 31 | + try { | |
| 32 | + ccm = CCMBridge.create("test", 3); | |
| 33 | + cluster = Cluster.builder() | |
| 34 | + .addContactPoint(CCMBridge.ipOfNode(1)) | |
| 35 | + .withLoadBalancingPolicy(loadBalancingPolicy) | |
| 36 | + .build(); | |
| 37 | + | |
| 38 | + String keyspace = "ks"; | |
| 39 | + ByteBuffer routingKey = Bytes.fromHexString("0xCAFEBABE"); | |
| 40 | + | |
| 41 | + Session session = cluster.connect(); | |
| 42 | + // Use a replication factor of 2, each routing key on this keyspace will corresponding to 2 hosts out of 3 | |
| 43 | + session.execute(String.format("CREATE KEYSPACE %s " | |
| 44 | + + "WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}", | |
| 45 | + keyspace)); | |
| 46 | + | |
| 47 | + // Actual query does not matter, only the keyspace and routing key will be used | |
| 48 | + SimpleStatement statement = new SimpleStatement("foo"); | |
| 49 | + statement.setKeyspace(keyspace); | |
| 50 | + statement.setRoutingKey(routingKey); | |
| 51 | + | |
| 52 | + // Identify the two replicas for our routing key | |
| 53 | + List<Host> replicas = Lists.newArrayList(cluster.getMetadata().getReplicas(keyspace, routingKey)); | |
| 54 | + assertThat(replicas).hasSize(2); | |
| 55 | + | |
| 56 | + // Run a few query plans, make sure that these two replicas come first, shuffled or not depending on | |
| 57 | + // what we expect | |
| 58 | + boolean shuffledAtLeastOnce = false; | |
| 59 | + for (int i = 0; i < 10; i++) { | |
| 60 | + List<Host> queryPlan = Lists.newArrayList(loadBalancingPolicy.newQueryPlan(null, statement)); | |
| 61 | + assertThat(queryPlan).hasSize(3); | |
| 62 | + | |
| 63 | + List<Host> firstTwo = queryPlan.subList(0, 2); | |
| 64 | + assertThat(firstTwo).containsAll(replicas); // order does not matter | |
| 65 | + | |
| 66 | + if (!firstTwo.equals(replicas)) | |
| 67 | + shuffledAtLeastOnce = true; | |
| 68 | + } | |
| 69 | + assertThat(shuffledAtLeastOnce).isEqualTo(expectShuffled); | |
| 70 | + | |
| 71 | + } finally { | |
| 72 | + if (cluster != null) | |
| 73 | + cluster.close(); | |
| 74 | + if (ccm != null) | |
| 75 | + ccm.remove(); | |
| 76 | + } | |
| 77 | + } | |
| 78 | +} |
added src/main/config/ide/eclipse-formatter.xml +295 −0
| @@ -0,0 +1,295 @@ | ||
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 2 | +<profiles version="12"> | |
| 3 | +<profile kind="CodeFormatterProfile" name="java-driver" version="12"> | |
| 4 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/> | |
| 5 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/> | |
| 6 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/> | |
| 7 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/> | |
| 8 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/> | |
| 9 | +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/> | |
| 10 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/> | |
| 11 | +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/> | |
| 12 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/> | |
| 13 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/> | |
| 14 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/> | |
| 15 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/> | |
| 16 | +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/> | |
| 17 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/> | |
| 18 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/> | |
| 19 | +<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="false"/> | |
| 20 | +<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/> | |
| 21 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> | |
| 22 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/> | |
| 23 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/> | |
| 24 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/> | |
| 25 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/> | |
| 26 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/> | |
| 27 | +<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/> | |
| 28 | +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="4"/> | |
| 29 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="2"/> | |
| 30 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/> | |
| 31 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/> | |
| 32 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/> | |
| 33 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/> | |
| 34 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="18"/> | |
| 35 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> | |
| 36 | +<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="false"/> | |
| 37 | +<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/> | |
| 38 | +<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/> | |
| 39 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/> | |
| 40 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/> | |
| 41 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="18"/> | |
| 42 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/> | |
| 43 | +<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/> | |
| 44 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/> | |
| 45 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/> | |
| 46 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/> | |
| 47 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/> | |
| 48 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/> | |
| 49 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/> | |
| 50 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/> | |
| 51 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/> | |
| 52 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/> | |
| 53 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/> | |
| 54 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/> | |
| 55 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/> | |
| 56 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/> | |
| 57 | +<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/> | |
| 58 | +<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/> | |
| 59 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/> | |
| 60 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/> | |
| 61 | +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/> | |
| 62 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/> | |
| 63 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/> | |
| 64 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/> | |
| 65 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/> | |
| 66 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/> | |
| 67 | +<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="140"/> | |
| 68 | +<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/> | |
| 69 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/> | |
| 70 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/> | |
| 71 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/> | |
| 72 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/> | |
| 73 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/> | |
| 74 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/> | |
| 75 | +<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/> | |
| 76 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/> | |
| 77 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/> | |
| 78 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/> | |
| 79 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="20"/> | |
| 80 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/> | |
| 81 | +<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/> | |
| 82 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/> | |
| 83 | +<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/> | |
| 84 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="20"/> | |
| 85 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/> | |
| 86 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/> | |
| 87 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/> | |
| 88 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/> | |
| 89 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="20"/> | |
| 90 | +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/> | |
| 91 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/> | |
| 92 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/> | |
| 93 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/> | |
| 94 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/> | |
| 95 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/> | |
| 96 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/> | |
| 97 | +<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/> | |
| 98 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/> | |
| 99 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/> | |
| 100 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/> | |
| 101 | +<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/> | |
| 102 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="18"/> | |
| 103 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/> | |
| 104 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="20"/> | |
| 105 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="18"/> | |
| 106 | +<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/> | |
| 107 | +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/> | |
| 108 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/> | |
| 109 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/> | |
| 110 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/> | |
| 111 | +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/> | |
| 112 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/> | |
| 113 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/> | |
| 114 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/> | |
| 115 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="20"/> | |
| 116 | +<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/> | |
| 117 | +<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/> | |
| 118 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/> | |
| 119 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/> | |
| 120 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/> | |
| 121 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/> | |
| 122 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/> | |
| 123 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/> | |
| 124 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/> | |
| 125 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/> | |
| 126 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/> | |
| 127 | +<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/> | |
| 128 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/> | |
| 129 | +<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/> | |
| 130 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="4"/> | |
| 131 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/> | |
| 132 | +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/> | |
| 133 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/> | |
| 134 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/> | |
| 135 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/> | |
| 136 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/> | |
| 137 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="52"/> | |
| 138 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/> | |
| 139 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/> | |
| 140 | +<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/> | |
| 141 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/> | |
| 142 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/> | |
| 143 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/> | |
| 144 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/> | |
| 145 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/> | |
| 146 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/> | |
| 147 | +<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/> | |
| 148 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="20"/> | |
| 149 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/> | |
| 150 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/> | |
| 151 | +<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/> | |
| 152 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/> | |
| 153 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="2"/> | |
| 154 | +<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/> | |
| 155 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/> | |
| 156 | +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/> | |
| 157 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/> | |
| 158 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/> | |
| 159 | +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/> | |
| 160 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> | |
| 161 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/> | |
| 162 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="84"/> | |
| 163 | +<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/> | |
| 164 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="20"/> | |
| 165 | +<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/> | |
| 166 | +<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/> | |
| 167 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/> | |
| 168 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/> | |
| 169 | +<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/> | |
| 170 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/> | |
| 171 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/> | |
| 172 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/> | |
| 173 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/> | |
| 174 | +<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/> | |
| 175 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="do not insert"/> | |
| 176 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/> | |
| 177 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/> | |
| 178 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/> | |
| 179 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/> | |
| 180 | +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="4"/> | |
| 181 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/> | |
| 182 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> | |
| 183 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/> | |
| 184 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="18"/> | |
| 185 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/> | |
| 186 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/> | |
| 187 | +<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/> | |
| 188 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/> | |
| 189 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/> | |
| 190 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/> | |
| 191 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/> | |
| 192 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/> | |
| 193 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/> | |
| 194 | +<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="false"/> | |
| 195 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/> | |
| 196 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/> | |
| 197 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="20"/> | |
| 198 | +<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/> | |
| 199 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/> | |
| 200 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/> | |
| 201 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/> | |
| 202 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="2"/> | |
| 203 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/> | |
| 204 | +<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/> | |
| 205 | +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/> | |
| 206 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/> | |
| 207 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/> | |
| 208 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/> | |
| 209 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/> | |
| 210 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/> | |
| 211 | +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/> | |
| 212 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/> | |
| 213 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/> | |
| 214 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/> | |
| 215 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> | |
| 216 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/> | |
| 217 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/> | |
| 218 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/> | |
| 219 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/> | |
| 220 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/> | |
| 221 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/> | |
| 222 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/> | |
| 223 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/> | |
| 224 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="20"/> | |
| 225 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/> | |
| 226 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/> | |
| 227 | +<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/> | |
| 228 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/> | |
| 229 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/> | |
| 230 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/> | |
| 231 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/> | |
| 232 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/> | |
| 233 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/> | |
| 234 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/> | |
| 235 | +<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/> | |
| 236 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/> | |
| 237 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/> | |
| 238 | +<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/> | |
| 239 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/> | |
| 240 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="18"/> | |
| 241 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/> | |
| 242 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/> | |
| 243 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/> | |
| 244 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/> | |
| 245 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/> | |
| 246 | +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/> | |
| 247 | +<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/> | |
| 248 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/> | |
| 249 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/> | |
| 250 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/> | |
| 251 | +<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/> | |
| 252 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/> | |
| 253 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/> | |
| 254 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/> | |
| 255 | +<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/> | |
| 256 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/> | |
| 257 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/> | |
| 258 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/> | |
| 259 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/> | |
| 260 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/> | |
| 261 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/> | |
| 262 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/> | |
| 263 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/> | |
| 264 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/> | |
| 265 | +<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/> | |
| 266 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="do not insert"/> | |
| 267 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/> | |
| 268 | +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/> | |
| 269 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/> | |
| 270 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/> | |
| 271 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/> | |
| 272 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/> | |
| 273 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/> | |
| 274 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/> | |
| 275 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/> | |
| 276 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/> | |
| 277 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/> | |
| 278 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/> | |
| 279 | +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/> | |
| 280 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/> | |
| 281 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/> | |
| 282 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/> | |
| 283 | +<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/> | |
| 284 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/> | |
| 285 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/> | |
| 286 | +<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/> | |
| 287 | +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/> | |
| 288 | +<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/> | |
| 289 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/> | |
| 290 | +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/> | |
| 291 | +<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="300"/> | |
| 292 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/> | |
| 293 | +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/> | |
| 294 | +</profile> | |
| 295 | +</profiles> |
added src/main/config/ide/eclipse.importorder +8 −0
| @@ -0,0 +1,8 @@ | ||
| 1 | +#Organize Import Order | |
| 2 | +#Sun Oct 19 21:16:33 CEST 2014 | |
| 3 | +5=\#com.datastax.driver.core | |
| 4 | +4=com.datastax.driver.core | |
| 5 | +3=\# | |
| 6 | +2= | |
| 7 | +1=\#java | |
| 8 | +0=java |
added src/main/config/ide/intellij-code-style.jar +0 −0
Binary content is not shown. View the file.