kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 7ffdb0fa8a5f6dfec035b18d2f1d55be93b89486ff167de64ebe30473f8d2878 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-01-05 18:50 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-01-05 18:52 +01:00 |
| Parents | 59d946262597, 23b289c30570 |
39 files changed
modified changelog/README.md +2 −0
| @@ -256,6 +256,7 @@ | ||
| 256 | 256 | Merged from 2.0 branch: |
| 257 | 257 | |
| 258 | 258 | - [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing. |
| 259 | +- [improvement] JAVA-805: Document that metrics are null until Cluster is initialized. | |
| 259 | 260 | |
| 260 | 261 | |
| 261 | 262 | ### 2.1.9 |
| @@ -580,6 +581,7 @@ | ||
| 580 | 581 | ### 2.0.13 (in progress) |
| 581 | 582 | |
| 582 | 583 | - [bug] JAVA-994: Don't call on(Up|Down|Add|Remove) methods if Cluster is closed/closing. |
| 584 | +- [improvement] JAVA-805: Document that metrics are null until Cluster is initialized. | |
| 583 | 585 | |
| 584 | 586 | ### 2.0.12 |
| 585 | 587 |
modified driver-core/src/main/java/com/datastax/driver/core/AbstractAddressableByIndexData.java +24 −0
| @@ -39,10 +39,12 @@ | ||
| 39 | 39 | return (T) this; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | + @Override | |
| 42 | 43 | protected ByteBuffer getValue(int i) { |
| 43 | 44 | return values[i]; |
| 44 | 45 | } |
| 45 | 46 | |
| 47 | + @Override | |
| 46 | 48 | public T setBool(int i, boolean v) { |
| 47 | 49 | TypeCodec<Boolean> codec = codecFor(i, Boolean.class); |
| 48 | 50 | ByteBuffer bb; |
| @@ -53,6 +55,7 @@ | ||
| 53 | 55 | return setValue(i, bb); |
| 54 | 56 | } |
| 55 | 57 | |
| 58 | + @Override | |
| 56 | 59 | public T setByte(int i, byte v) { |
| 57 | 60 | TypeCodec<Byte> codec = codecFor(i, Byte.class); |
| 58 | 61 | ByteBuffer bb; |
| @@ -63,6 +66,7 @@ | ||
| 63 | 66 | return setValue(i, bb); |
| 64 | 67 | } |
| 65 | 68 | |
| 69 | + @Override | |
| 66 | 70 | public T setShort(int i, short v) { |
| 67 | 71 | TypeCodec<Short> codec = codecFor(i, Short.class); |
| 68 | 72 | ByteBuffer bb; |
| @@ -73,6 +77,7 @@ | ||
| 73 | 77 | return setValue(i, bb); |
| 74 | 78 | } |
| 75 | 79 | |
| 80 | + @Override | |
| 76 | 81 | public T setInt(int i, int v) { |
| 77 | 82 | TypeCodec<Integer> codec = codecFor(i, Integer.class); |
| 78 | 83 | ByteBuffer bb; |
| @@ -83,6 +88,7 @@ | ||
| 83 | 88 | return setValue(i, bb); |
| 84 | 89 | } |
| 85 | 90 | |
| 91 | + @Override | |
| 86 | 92 | public T setLong(int i, long v) { |
| 87 | 93 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 88 | 94 | ByteBuffer bb; |
| @@ -93,14 +99,17 @@ | ||
| 93 | 99 | return setValue(i, bb); |
| 94 | 100 | } |
| 95 | 101 | |
| 102 | + @Override | |
| 96 | 103 | public T setTimestamp(int i, Date v) { |
| 97 | 104 | return setValue(i, codecFor(i, Date.class).serialize(v, protocolVersion)); |
| 98 | 105 | } |
| 99 | 106 | |
| 107 | + @Override | |
| 100 | 108 | public T setDate(int i, LocalDate v) { |
| 101 | 109 | return setValue(i, codecFor(i, LocalDate.class).serialize(v, protocolVersion)); |
| 102 | 110 | } |
| 103 | 111 | |
| 112 | + @Override | |
| 104 | 113 | public T setTime(int i, long v) { |
| 105 | 114 | TypeCodec<Long> codec = codecFor(i, Long.class); |
| 106 | 115 | ByteBuffer bb; |
| @@ -111,6 +120,7 @@ | ||
| 111 | 120 | return setValue(i, bb); |
| 112 | 121 | } |
| 113 | 122 | |
| 123 | + @Override | |
| 114 | 124 | public T setFloat(int i, float v) { |
| 115 | 125 | TypeCodec<Float> codec = codecFor(i, Float.class); |
| 116 | 126 | ByteBuffer bb; |
| @@ -121,6 +131,7 @@ | ||
| 121 | 131 | return setValue(i, bb); |
| 122 | 132 | } |
| 123 | 133 | |
| 134 | + @Override | |
| 124 | 135 | public T setDouble(int i, double v) { |
| 125 | 136 | TypeCodec<Double> codec = codecFor(i, Double.class); |
| 126 | 137 | ByteBuffer bb; |
| @@ -131,34 +142,42 @@ | ||
| 131 | 142 | return setValue(i, bb); |
| 132 | 143 | } |
| 133 | 144 | |
| 145 | + @Override | |
| 134 | 146 | public T setString(int i, String v) { |
| 135 | 147 | return setValue(i, codecFor(i, String.class).serialize(v, protocolVersion)); |
| 136 | 148 | } |
| 137 | 149 | |
| 150 | + @Override | |
| 138 | 151 | public T setBytes(int i, ByteBuffer v) { |
| 139 | 152 | return setValue(i, codecFor(i, ByteBuffer.class).serialize(v, protocolVersion)); |
| 140 | 153 | } |
| 141 | 154 | |
| 155 | + @Override | |
| 142 | 156 | public T setBytesUnsafe(int i, ByteBuffer v) { |
| 143 | 157 | return setValue(i, v == null ? null : v.duplicate()); |
| 144 | 158 | } |
| 145 | 159 | |
| 160 | + @Override | |
| 146 | 161 | public T setVarint(int i, BigInteger v) { |
| 147 | 162 | return setValue(i, codecFor(i, BigInteger.class).serialize(v, protocolVersion)); |
| 148 | 163 | } |
| 149 | 164 | |
| 165 | + @Override | |
| 150 | 166 | public T setDecimal(int i, BigDecimal v) { |
| 151 | 167 | return setValue(i, codecFor(i, BigDecimal.class).serialize(v, protocolVersion)); |
| 152 | 168 | } |
| 153 | 169 | |
| 170 | + @Override | |
| 154 | 171 | public T setUUID(int i, UUID v) { |
| 155 | 172 | return setValue(i, codecFor(i, UUID.class).serialize(v, protocolVersion)); |
| 156 | 173 | } |
| 157 | 174 | |
| 175 | + @Override | |
| 158 | 176 | public T setInet(int i, InetAddress v) { |
| 159 | 177 | return setValue(i, codecFor(i, InetAddress.class).serialize(v, protocolVersion)); |
| 160 | 178 | } |
| 161 | 179 | |
| 180 | + @Override | |
| 162 | 181 | @SuppressWarnings("unchecked") |
| 163 | 182 | public <E> T setList(int i, List<E> v) { |
| 164 | 183 | return setValue(i, codecFor(i).serialize(v, protocolVersion)); |
| @@ -174,6 +193,7 @@ | ||
| 174 | 193 | return setValue(i, codecFor(i, TypeTokens.listOf(elementsType)).serialize(v, protocolVersion)); |
| 175 | 194 | } |
| 176 | 195 | |
| 196 | + @Override | |
| 177 | 197 | @SuppressWarnings("unchecked") |
| 178 | 198 | public <K, V> T setMap(int i, Map<K, V> v) { |
| 179 | 199 | return setValue(i, codecFor(i).serialize(v, protocolVersion)); |
| @@ -189,6 +209,7 @@ | ||
| 189 | 209 | return setValue(i, codecFor(i, TypeTokens.mapOf(keysType, valuesType)).serialize(v, protocolVersion)); |
| 190 | 210 | } |
| 191 | 211 | |
| 212 | + @Override | |
| 192 | 213 | @SuppressWarnings("unchecked") |
| 193 | 214 | public <E> T setSet(int i, Set<E> v) { |
| 194 | 215 | return setValue(i, codecFor(i).serialize(v, protocolVersion)); |
| @@ -204,10 +225,12 @@ | ||
| 204 | 225 | return setValue(i, codecFor(i, TypeTokens.setOf(elementsType)).serialize(v, protocolVersion)); |
| 205 | 226 | } |
| 206 | 227 | |
| 228 | + @Override | |
| 207 | 229 | public T setUDTValue(int i, UDTValue v) { |
| 208 | 230 | return setValue(i, codecFor(i, UDTValue.class).serialize(v, protocolVersion)); |
| 209 | 231 | } |
| 210 | 232 | |
| 233 | + @Override | |
| 211 | 234 | public T setTupleValue(int i, TupleValue v) { |
| 212 | 235 | return setValue(i, codecFor(i, TupleValue.class).serialize(v, protocolVersion)); |
| 213 | 236 | } |
| @@ -228,6 +251,7 @@ | ||
| 228 | 251 | return setValue(i, codec.serialize(v, protocolVersion)); |
| 229 | 252 | } |
| 230 | 253 | |
| 254 | + @Override | |
| 231 | 255 | public T setToNull(int i) { |
| 232 | 256 | return setValue(i, null); |
| 233 | 257 | } |
modified driver-core/src/main/java/com/datastax/driver/core/ArrayBackedResultSet.java +16 −0
| @@ -109,10 +109,12 @@ | ||
| 109 | 109 | return new SinglePage(ColumnDefinitions.EMPTY, null, null, null, EMPTY_QUEUE, info); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | + @Override | |
| 112 | 113 | public ColumnDefinitions getColumnDefinitions() { |
| 113 | 114 | return metadata; |
| 114 | 115 | } |
| 115 | 116 | |
| 117 | + @Override | |
| 116 | 118 | public List<Row> all() { |
| 117 | 119 | if (isExhausted()) |
| 118 | 120 | return Collections.emptyList(); |
| @@ -175,30 +177,37 @@ | ||
| 175 | 177 | this.rows = rows; |
| 176 | 178 | } |
| 177 | 179 | |
| 180 | + @Override | |
| 178 | 181 | public boolean isExhausted() { |
| 179 | 182 | return rows.isEmpty(); |
| 180 | 183 | } |
| 181 | 184 | |
| 185 | + @Override | |
| 182 | 186 | public Row one() { |
| 183 | 187 | return ArrayBackedRow.fromData(metadata, tokenFactory, protocolVersion, rows.poll()); |
| 184 | 188 | } |
| 185 | 189 | |
| 190 | + @Override | |
| 186 | 191 | public int getAvailableWithoutFetching() { |
| 187 | 192 | return rows.size(); |
| 188 | 193 | } |
| 189 | 194 | |
| 195 | + @Override | |
| 190 | 196 | public boolean isFullyFetched() { |
| 191 | 197 | return true; |
| 192 | 198 | } |
| 193 | 199 | |
| 200 | + @Override | |
| 194 | 201 | public ListenableFuture<ResultSet> fetchMoreResults() { |
| 195 | 202 | return Futures.<ResultSet>immediateFuture(this); |
| 196 | 203 | } |
| 197 | 204 | |
| 205 | + @Override | |
| 198 | 206 | public ExecutionInfo getExecutionInfo() { |
| 199 | 207 | return info; |
| 200 | 208 | } |
| 201 | 209 | |
| 210 | + @Override | |
| 202 | 211 | public List<ExecutionInfo> getAllExecutionInfo() { |
| 203 | 212 | return Collections.singletonList(info); |
| 204 | 213 | } |
| @@ -251,16 +260,19 @@ | ||
| 251 | 260 | this.statement = statement; |
| 252 | 261 | } |
| 253 | 262 | |
| 263 | + @Override | |
| 254 | 264 | public boolean isExhausted() { |
| 255 | 265 | prepareNextRow(); |
| 256 | 266 | return currentPage.isEmpty(); |
| 257 | 267 | } |
| 258 | 268 | |
| 269 | + @Override | |
| 259 | 270 | public Row one() { |
| 260 | 271 | prepareNextRow(); |
| 261 | 272 | return ArrayBackedRow.fromData(metadata, tokenFactory, protocolVersion, currentPage.poll()); |
| 262 | 273 | } |
| 263 | 274 | |
| 275 | + @Override | |
| 264 | 276 | public int getAvailableWithoutFetching() { |
| 265 | 277 | int available = currentPage.size(); |
| 266 | 278 | for (Queue<List<ByteBuffer>> page : nextPages) |
| @@ -268,6 +280,7 @@ | ||
| 268 | 280 | return available; |
| 269 | 281 | } |
| 270 | 282 | |
| 283 | + @Override | |
| 271 | 284 | public boolean isFullyFetched() { |
| 272 | 285 | return fetchState == null; |
| 273 | 286 | } |
| @@ -297,6 +310,7 @@ | ||
| 297 | 310 | } |
| 298 | 311 | } |
| 299 | 312 | |
| 313 | + @Override | |
| 300 | 314 | public ListenableFuture<ResultSet> fetchMoreResults() { |
| 301 | 315 | return fetchMoreResults(this.fetchState); |
| 302 | 316 | } |
| @@ -401,10 +415,12 @@ | ||
| 401 | 415 | return future; |
| 402 | 416 | } |
| 403 | 417 | |
| 418 | + @Override | |
| 404 | 419 | public ExecutionInfo getExecutionInfo() { |
| 405 | 420 | return infos.getLast(); |
| 406 | 421 | } |
| 407 | 422 | |
| 423 | + @Override | |
| 408 | 424 | public List<ExecutionInfo> getAllExecutionInfo() { |
| 409 | 425 | return new ArrayList<ExecutionInfo>(infos); |
| 410 | 426 | } |
modified driver-core/src/main/java/com/datastax/driver/core/AuthProvider.java +1 −0
| @@ -34,6 +34,7 @@ | ||
| 34 | 34 | * This is only useful as a placeholder when no authentication is to be used. |
| 35 | 35 | */ |
| 36 | 36 | public static final AuthProvider NONE = new AuthProvider() { |
| 37 | + @Override | |
| 37 | 38 | public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) { |
| 38 | 39 | throw new AuthenticationException(host, |
| 39 | 40 | String.format("Host %s requires authentication, but no authenticator found in Cluster configuration", host)); |
modified driver-core/src/main/java/com/datastax/driver/core/BoundStatement.java +0 −17
| @@ -994,23 +994,6 @@ | ||
| 994 | 994 | /** |
| 995 | 995 | * {@inheritDoc} |
| 996 | 996 | */ |
| 997 | - @Override | |
| 998 | - public long getTime(int i) { | |
| 999 | - return wrapper.getTime(i); | |
| 1000 | - } | |
| 1001 | - | |
| 1002 | - /** | |
| 1003 | - * {@inheritDoc} | |
| 1004 | - */ | |
| 1005 | - @Override | |
| 1006 | - public long getTime(String name) { | |
| 1007 | - return wrapper.getTime(name); | |
| 1008 | - } | |
| 1009 | - | |
| 1010 | - /** | |
| 1011 | - * {@inheritDoc} | |
| 1012 | - */ | |
| 1013 | - @Override | |
| 1014 | 997 | public float getFloat(int i) { |
| 1015 | 998 | return wrapper.getFloat(i); |
| 1016 | 999 | } |
modified driver-core/src/main/java/com/datastax/driver/core/CloseFuture.java +2 −0
| @@ -72,10 +72,12 @@ | ||
| 72 | 72 | this.futures = futures; |
| 73 | 73 | |
| 74 | 74 | Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<Void>>() { |
| 75 | + @Override | |
| 75 | 76 | public void onFailure(Throwable t) { |
| 76 | 77 | Forwarding.this.setException(t); |
| 77 | 78 | } |
| 78 | 79 | |
| 80 | + @Override | |
| 79 | 81 | public void onSuccess(List<Void> v) { |
| 80 | 82 | Forwarding.this.onFuturesDone(); |
| 81 | 83 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +15 −3
| @@ -406,9 +406,8 @@ | ||
| 406 | 406 | /** |
| 407 | 407 | * The cluster metrics. |
| 408 | 408 | * |
| 409 | - * @return the cluster metrics, or {@code null} if metrics collection has | |
| 410 | - * been disabled (that is if {@link Configuration#getMetricsOptions} | |
| 411 | - * returns {@code null}). | |
| 409 | + * @return the cluster metrics, or {@code null} if this cluster has not yet been {@link #init() initialized}, or if | |
| 410 | + * metrics collection has been disabled (that is if {@link Configuration#getMetricsOptions} returns {@code null}). | |
| 412 | 411 | */ |
| 413 | 412 | public Metrics getMetrics() { |
| 414 | 413 | checkNotClosed(manager); |
| @@ -561,6 +560,7 @@ | ||
| 561 | 560 | * <p/> |
| 562 | 561 | * This method is a shortcut for {@code closeAsync().get()}. |
| 563 | 562 | */ |
| 563 | + @Override | |
| 564 | 564 | public void close() { |
| 565 | 565 | try { |
| 566 | 566 | closeAsync().get(); |
| @@ -1797,10 +1797,12 @@ | ||
| 1797 | 1797 | void startPeriodicReconnectionAttempt(final Host host, final boolean isHostAddition) { |
| 1798 | 1798 | new AbstractReconnectionHandler(host.toString(), reconnectionExecutor, reconnectionPolicy().newSchedule(), host.reconnectionAttempt) { |
| 1799 | 1799 | |
| 1800 | + @Override | |
| 1800 | 1801 | protected Connection tryReconnect() throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { |
| 1801 | 1802 | return connectionFactory.open(host); |
| 1802 | 1803 | } |
| 1803 | 1804 | |
| 1805 | + @Override | |
| 1804 | 1806 | protected void onReconnection(Connection connection) { |
| 1805 | 1807 | // Make sure we have up-to-date infos on that host before adding it (so we typically |
| 1806 | 1808 | // catch that an upgraded node uses a new cassandra version). |
| @@ -1822,17 +1824,20 @@ | ||
| 1822 | 1824 | } |
| 1823 | 1825 | } |
| 1824 | 1826 | |
| 1827 | + @Override | |
| 1825 | 1828 | protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { |
| 1826 | 1829 | if (logger.isDebugEnabled()) |
| 1827 | 1830 | logger.debug("Failed reconnection to {} ({}), scheduling retry in {} milliseconds", host, e.getMessage(), nextDelayMs); |
| 1828 | 1831 | return true; |
| 1829 | 1832 | } |
| 1830 | 1833 | |
| 1834 | + @Override | |
| 1831 | 1835 | protected boolean onUnknownException(Exception e, long nextDelayMs) { |
| 1832 | 1836 | logger.error(String.format("Unknown error during reconnection to %s, scheduling retry in %d milliseconds", host, nextDelayMs), e); |
| 1833 | 1837 | return true; |
| 1834 | 1838 | } |
| 1835 | 1839 | |
| 1840 | + @Override | |
| 1836 | 1841 | protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { |
| 1837 | 1842 | logger.error(String.format("Authentication error during reconnection to %s, scheduling retry in %d milliseconds", host, nextDelayMs), e); |
| 1838 | 1843 | return true; |
| @@ -1850,10 +1855,12 @@ | ||
| 1850 | 1855 | // Setting an initial delay of 0 to start immediately, and all the exception handlers return false to prevent further attempts |
| 1851 | 1856 | new AbstractReconnectionHandler(host.toString(), reconnectionExecutor, reconnectionPolicy().newSchedule(), host.reconnectionAttempt, 0) { |
| 1852 | 1857 | |
| 1858 | + @Override | |
| 1853 | 1859 | protected Connection tryReconnect() throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { |
| 1854 | 1860 | return connectionFactory.open(host); |
| 1855 | 1861 | } |
| 1856 | 1862 | |
| 1863 | + @Override | |
| 1857 | 1864 | protected void onReconnection(Connection connection) { |
| 1858 | 1865 | // Make sure we have up-to-date infos on that host before adding it (so we typically |
| 1859 | 1866 | // catch that an upgraded node uses a new cassandra version). |
| @@ -1872,17 +1879,20 @@ | ||
| 1872 | 1879 | } |
| 1873 | 1880 | } |
| 1874 | 1881 | |
| 1882 | + @Override | |
| 1875 | 1883 | protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { |
| 1876 | 1884 | if (logger.isDebugEnabled()) |
| 1877 | 1885 | logger.debug("Failed one-time reconnection to {} ({})", host, e.getMessage()); |
| 1878 | 1886 | return false; |
| 1879 | 1887 | } |
| 1880 | 1888 | |
| 1889 | + @Override | |
| 1881 | 1890 | protected boolean onUnknownException(Exception e, long nextDelayMs) { |
| 1882 | 1891 | logger.error(String.format("Unknown error during one-time reconnection to %s", host), e); |
| 1883 | 1892 | return false; |
| 1884 | 1893 | } |
| 1885 | 1894 | |
| 1895 | + @Override | |
| 1886 | 1896 | protected boolean onAuthenticationException(AuthenticationException e, long nextDelayMs) { |
| 1887 | 1897 | logger.error(String.format("Authentication error during one-time reconnection to %s", host), e); |
| 1888 | 1898 | return false; |
| @@ -2426,6 +2436,7 @@ | ||
| 2426 | 2436 | * a netty worker, which we're going to shutdown. So creates some thread for that. |
| 2427 | 2437 | */ |
| 2428 | 2438 | (new Thread("Shutdown-checker") { |
| 2439 | + @Override | |
| 2429 | 2440 | public void run() { |
| 2430 | 2441 | // Just wait indefinitely on the the completion of the thread pools. Provided the user |
| 2431 | 2442 | // call force(), we'll never really block forever. |
| @@ -2621,6 +2632,7 @@ | ||
| 2621 | 2632 | if (protocolVersion().compareTo(ProtocolVersion.V4) < 0) { |
| 2622 | 2633 | final SettableFuture<?> future = SettableFuture.create(); |
| 2623 | 2634 | scheduledTasksExecutor.schedule(new ExceptionCatchingRunnable() { |
| 2635 | + @Override | |
| 2624 | 2636 | public void runMayThrow() throws Exception { |
| 2625 | 2637 | ListenableFuture<?> f = execute(task); |
| 2626 | 2638 | Futures.addCallback(f, new FutureCallback<Object>() { |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultPreparedStatement.java +18 −0
| @@ -115,42 +115,51 @@ | ||
| 115 | 115 | return true; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | + @Override | |
| 118 | 119 | public ColumnDefinitions getVariables() { |
| 119 | 120 | return preparedId.metadata; |
| 120 | 121 | } |
| 121 | 122 | |
| 123 | + @Override | |
| 122 | 124 | public BoundStatement bind(Object... values) { |
| 123 | 125 | BoundStatement bs = new BoundStatement(this); |
| 124 | 126 | return bs.bind(values); |
| 125 | 127 | } |
| 126 | 128 | |
| 129 | + @Override | |
| 127 | 130 | public BoundStatement bind() { |
| 128 | 131 | return new BoundStatement(this); |
| 129 | 132 | } |
| 130 | 133 | |
| 134 | + @Override | |
| 131 | 135 | public PreparedStatement setRoutingKey(ByteBuffer routingKey) { |
| 132 | 136 | this.routingKey = routingKey; |
| 133 | 137 | return this; |
| 134 | 138 | } |
| 135 | 139 | |
| 140 | + @Override | |
| 136 | 141 | public PreparedStatement setRoutingKey(ByteBuffer... routingKeyComponents) { |
| 137 | 142 | this.routingKey = SimpleStatement.compose(routingKeyComponents); |
| 138 | 143 | return this; |
| 139 | 144 | } |
| 140 | 145 | |
| 146 | + @Override | |
| 141 | 147 | public ByteBuffer getRoutingKey() { |
| 142 | 148 | return routingKey; |
| 143 | 149 | } |
| 144 | 150 | |
| 151 | + @Override | |
| 145 | 152 | public PreparedStatement setConsistencyLevel(ConsistencyLevel consistency) { |
| 146 | 153 | this.consistency = consistency; |
| 147 | 154 | return this; |
| 148 | 155 | } |
| 149 | 156 | |
| 157 | + @Override | |
| 150 | 158 | public ConsistencyLevel getConsistencyLevel() { |
| 151 | 159 | return consistency; |
| 152 | 160 | } |
| 153 | 161 | |
| 162 | + @Override | |
| 154 | 163 | public PreparedStatement setSerialConsistencyLevel(ConsistencyLevel serialConsistency) { |
| 155 | 164 | if (serialConsistency != ConsistencyLevel.SERIAL && serialConsistency != ConsistencyLevel.LOCAL_SERIAL) |
| 156 | 165 | throw new IllegalArgumentException(); |
| @@ -158,41 +167,50 @@ | ||
| 158 | 167 | return this; |
| 159 | 168 | } |
| 160 | 169 | |
| 170 | + @Override | |
| 161 | 171 | public ConsistencyLevel getSerialConsistencyLevel() { |
| 162 | 172 | return serialConsistency; |
| 163 | 173 | } |
| 164 | 174 | |
| 175 | + @Override | |
| 165 | 176 | public String getQueryString() { |
| 166 | 177 | return query; |
| 167 | 178 | } |
| 168 | 179 | |
| 180 | + @Override | |
| 169 | 181 | public String getQueryKeyspace() { |
| 170 | 182 | return queryKeyspace; |
| 171 | 183 | } |
| 172 | 184 | |
| 185 | + @Override | |
| 173 | 186 | public PreparedStatement enableTracing() { |
| 174 | 187 | this.traceQuery = true; |
| 175 | 188 | return this; |
| 176 | 189 | } |
| 177 | 190 | |
| 191 | + @Override | |
| 178 | 192 | public PreparedStatement disableTracing() { |
| 179 | 193 | this.traceQuery = false; |
| 180 | 194 | return this; |
| 181 | 195 | } |
| 182 | 196 | |
| 197 | + @Override | |
| 183 | 198 | public boolean isTracing() { |
| 184 | 199 | return traceQuery; |
| 185 | 200 | } |
| 186 | 201 | |
| 202 | + @Override | |
| 187 | 203 | public PreparedStatement setRetryPolicy(RetryPolicy policy) { |
| 188 | 204 | this.retryPolicy = policy; |
| 189 | 205 | return this; |
| 190 | 206 | } |
| 191 | 207 | |
| 208 | + @Override | |
| 192 | 209 | public RetryPolicy getRetryPolicy() { |
| 193 | 210 | return retryPolicy; |
| 194 | 211 | } |
| 195 | 212 | |
| 213 | + @Override | |
| 196 | 214 | public PreparedId getPreparedId() { |
| 197 | 215 | return preparedId; |
| 198 | 216 | } |
modified driver-core/src/main/java/com/datastax/driver/core/DefaultResultSetFuture.java +2 −0
| @@ -237,6 +237,7 @@ | ||
| 237 | 237 | * @throws QueryValidationException if the query is invalid (syntax error, |
| 238 | 238 | * unauthorized or any other validation problem). |
| 239 | 239 | */ |
| 240 | + @Override | |
| 240 | 241 | public ResultSet getUninterruptibly() { |
| 241 | 242 | try { |
| 242 | 243 | return Uninterruptibles.getUninterruptibly(this); |
| @@ -269,6 +270,7 @@ | ||
| 269 | 270 | * different from a Cassandra timeout, which is a {@code |
| 270 | 271 | * QueryExecutionException}). |
| 271 | 272 | */ |
| 273 | + @Override | |
| 272 | 274 | public ResultSet getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException { |
| 273 | 275 | try { |
| 274 | 276 | return Uninterruptibles.getUninterruptibly(this, timeout, unit); |
modified driver-core/src/main/java/com/datastax/driver/core/FrameCompressor.java +4 −0
| @@ -56,6 +56,7 @@ | ||
| 56 | 56 | Snappy.getNativeLibraryVersion(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | + @Override | |
| 59 | 60 | public Frame compress(Frame frame) throws IOException { |
| 60 | 61 | byte[] input = CBUtil.readRawBytes(frame.body); |
| 61 | 62 | byte[] output = new byte[Snappy.maxCompressedLength(input.length)]; |
| @@ -64,6 +65,7 @@ | ||
| 64 | 65 | return frame.with(Unpooled.wrappedBuffer(output, 0, written)); |
| 65 | 66 | } |
| 66 | 67 | |
| 68 | + @Override | |
| 67 | 69 | public Frame decompress(Frame frame) throws IOException { |
| 68 | 70 | byte[] input = CBUtil.readRawBytes(frame.body); |
| 69 | 71 | |
| @@ -105,6 +107,7 @@ | ||
| 105 | 107 | decompressor = lz4Factory.fastDecompressor(); |
| 106 | 108 | } |
| 107 | 109 | |
| 110 | + @Override | |
| 108 | 111 | public Frame compress(Frame frame) throws IOException { |
| 109 | 112 | byte[] input = CBUtil.readRawBytes(frame.body); |
| 110 | 113 | |
| @@ -124,6 +127,7 @@ | ||
| 124 | 127 | } |
| 125 | 128 | } |
| 126 | 129 | |
| 130 | + @Override | |
| 127 | 131 | public Frame decompress(Frame frame) throws IOException { |
| 128 | 132 | byte[] input = CBUtil.readRawBytes(frame.body); |
| 129 | 133 |
modified driver-core/src/main/java/com/datastax/driver/core/HostConnectionPool.java +1 −0
| @@ -639,6 +639,7 @@ | ||
| 639 | 639 | for (final Connection connection : connections) { |
| 640 | 640 | CloseFuture future = connection.closeAsync(); |
| 641 | 641 | future.addListener(new Runnable() { |
| 642 | + @Override | |
| 642 | 643 | public void run() { |
| 643 | 644 | if (connection.state.compareAndSet(OPEN, GONE)) |
| 644 | 645 | open.decrementAndGet(); |
modified driver-core/src/main/java/com/datastax/driver/core/PlainTextAuthProvider.java +2 −0
| @@ -78,6 +78,7 @@ | ||
| 78 | 78 | * @return an Authenticator instance which can be used to perform |
| 79 | 79 | * authentication negotiations on behalf of the client |
| 80 | 80 | */ |
| 81 | + @Override | |
| 81 | 82 | public Authenticator newAuthenticator(InetSocketAddress host, String authenticator) { |
| 82 | 83 | return new PlainTextAuthenticator(username, password); |
| 83 | 84 | } |
| @@ -117,6 +118,7 @@ | ||
| 117 | 118 | // no-op, the server should send nothing anyway |
| 118 | 119 | } |
| 119 | 120 | |
| 121 | + @Override | |
| 120 | 122 | Map<String, String> getCredentials() { |
| 121 | 123 | return ImmutableMap.of("username", new String(username, Charsets.UTF_8), |
| 122 | 124 | "password", new String(password, Charsets.UTF_8)); |
modified driver-core/src/main/java/com/datastax/driver/core/ReplicationStategy.java +3 −1
| @@ -73,6 +73,7 @@ | ||
| 73 | 73 | this.replicationFactor = replicationFactor; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | + @Override | |
| 76 | 77 | Map<Token, Set<Host>> computeTokenToReplicaMap(String keyspaceName, Map<Token, Host> tokenToPrimary, List<Token> ring) { |
| 77 | 78 | |
| 78 | 79 | int rf = Math.min(replicationFactor, ring.size()); |
| @@ -116,7 +117,8 @@ | ||
| 116 | 117 | this.replicationFactors = replicationFactors; |
| 117 | 118 | } |
| 118 | 119 | |
| 119 | - Map<Token, Set<Host>> computeTokenToReplicaMap(String keyspaceName, Map<Token, Host> tokenToPrimary, List<Token> ring) { | |
| 120 | + @Override | |
| 121 | + Map<Token, Set<Host>> computeTokenToReplicaMap(String keyspaceName, Map<Token, Host> tokenToPrimary, List<Token> ring) { | |
| 120 | 122 | |
| 121 | 123 | // This is essentially a copy of org.apache.cassandra.locator.NetworkTopologyStrategy |
| 122 | 124 | Map<String, Set<String>> racks = getRacksInDcs(tokenToPrimary.values()); |
modified driver-core/src/main/java/com/datastax/driver/core/Requests.java +18 −0
| @@ -36,10 +36,12 @@ | ||
| 36 | 36 | static final String COMPRESSION_OPTION = "COMPRESSION"; |
| 37 | 37 | |
| 38 | 38 | static final Message.Coder<Startup> coder = new Message.Coder<Startup>() { |
| 39 | + @Override | |
| 39 | 40 | public void encode(Startup msg, ByteBuf dest, ProtocolVersion version) { |
| 40 | 41 | CBUtil.writeStringMap(msg.options, dest); |
| 41 | 42 | } |
| 42 | 43 | |
| 44 | + @Override | |
| 43 | 45 | public int encodedSize(Startup msg, ProtocolVersion version) { |
| 44 | 46 | return CBUtil.sizeOfStringMap(msg.options); |
| 45 | 47 | } |
| @@ -68,11 +70,13 @@ | ||
| 68 | 70 | |
| 69 | 71 | static final Message.Coder<Credentials> coder = new Message.Coder<Credentials>() { |
| 70 | 72 | |
| 73 | + @Override | |
| 71 | 74 | public void encode(Credentials msg, ByteBuf dest, ProtocolVersion version) { |
| 72 | 75 | assert version == ProtocolVersion.V1; |
| 73 | 76 | CBUtil.writeStringMap(msg.credentials, dest); |
| 74 | 77 | } |
| 75 | 78 | |
| 79 | + @Override | |
| 76 | 80 | public int encodedSize(Credentials msg, ProtocolVersion version) { |
| 77 | 81 | assert version == ProtocolVersion.V1; |
| 78 | 82 | return CBUtil.sizeOfStringMap(msg.credentials); |
| @@ -90,9 +94,11 @@ | ||
| 90 | 94 | static class Options extends Message.Request { |
| 91 | 95 | |
| 92 | 96 | static final Message.Coder<Options> coder = new Message.Coder<Options>() { |
| 97 | + @Override | |
| 93 | 98 | public void encode(Options msg, ByteBuf dest, ProtocolVersion version) { |
| 94 | 99 | } |
| 95 | 100 | |
| 101 | + @Override | |
| 96 | 102 | public int encodedSize(Options msg, ProtocolVersion version) { |
| 97 | 103 | return 0; |
| 98 | 104 | } |
| @@ -111,11 +117,13 @@ | ||
| 111 | 117 | static class Query extends Message.Request { |
| 112 | 118 | |
| 113 | 119 | static final Message.Coder<Query> coder = new Message.Coder<Query>() { |
| 120 | + @Override | |
| 114 | 121 | public void encode(Query msg, ByteBuf dest, ProtocolVersion version) { |
| 115 | 122 | CBUtil.writeLongString(msg.query, dest); |
| 116 | 123 | msg.options.encode(dest, version); |
| 117 | 124 | } |
| 118 | 125 | |
| 126 | + @Override | |
| 119 | 127 | public int encodedSize(Query msg, ProtocolVersion version) { |
| 120 | 128 | return CBUtil.sizeOfLongString(msg.query) |
| 121 | 129 | + msg.options.encodedSize(version); |
| @@ -154,11 +162,13 @@ | ||
| 154 | 162 | static class Execute extends Message.Request { |
| 155 | 163 | |
| 156 | 164 | static final Message.Coder<Execute> coder = new Message.Coder<Execute>() { |
| 165 | + @Override | |
| 157 | 166 | public void encode(Execute msg, ByteBuf dest, ProtocolVersion version) { |
| 158 | 167 | CBUtil.writeBytes(msg.statementId.bytes, dest); |
| 159 | 168 | msg.options.encode(dest, version); |
| 160 | 169 | } |
| 161 | 170 | |
| 171 | + @Override | |
| 162 | 172 | public int encodedSize(Execute msg, ProtocolVersion version) { |
| 163 | 173 | return CBUtil.sizeOfBytes(msg.statementId.bytes) |
| 164 | 174 | + msg.options.encodedSize(version); |
| @@ -336,6 +346,7 @@ | ||
| 336 | 346 | static class Batch extends Message.Request { |
| 337 | 347 | |
| 338 | 348 | static final Message.Coder<Batch> coder = new Message.Coder<Batch>() { |
| 349 | + @Override | |
| 339 | 350 | public void encode(Batch msg, ByteBuf dest, ProtocolVersion version) { |
| 340 | 351 | int queries = msg.queryOrIdList.size(); |
| 341 | 352 | assert queries <= 0xFFFF; |
| @@ -357,6 +368,7 @@ | ||
| 357 | 368 | msg.options.encode(dest, version); |
| 358 | 369 | } |
| 359 | 370 | |
| 371 | + @Override | |
| 360 | 372 | public int encodedSize(Batch msg, ProtocolVersion version) { |
| 361 | 373 | int size = 3; // type + nb queries |
| 362 | 374 | for (int i = 0; i < msg.queryOrIdList.size(); i++) { |
| @@ -491,10 +503,12 @@ | ||
| 491 | 503 | |
| 492 | 504 | static final Message.Coder<Prepare> coder = new Message.Coder<Prepare>() { |
| 493 | 505 | |
| 506 | + @Override | |
| 494 | 507 | public void encode(Prepare msg, ByteBuf dest, ProtocolVersion version) { |
| 495 | 508 | CBUtil.writeLongString(msg.query, dest); |
| 496 | 509 | } |
| 497 | 510 | |
| 511 | + @Override | |
| 498 | 512 | public int encodedSize(Prepare msg, ProtocolVersion version) { |
| 499 | 513 | return CBUtil.sizeOfLongString(msg.query); |
| 500 | 514 | } |
| @@ -516,12 +530,14 @@ | ||
| 516 | 530 | static class Register extends Message.Request { |
| 517 | 531 | |
| 518 | 532 | static final Message.Coder<Register> coder = new Message.Coder<Register>() { |
| 533 | + @Override | |
| 519 | 534 | public void encode(Register msg, ByteBuf dest, ProtocolVersion version) { |
| 520 | 535 | dest.writeShort(msg.eventTypes.size()); |
| 521 | 536 | for (ProtocolEvent.Type type : msg.eventTypes) |
| 522 | 537 | CBUtil.writeEnumValue(type, dest); |
| 523 | 538 | } |
| 524 | 539 | |
| 540 | + @Override | |
| 525 | 541 | public int encodedSize(Register msg, ProtocolVersion version) { |
| 526 | 542 | int size = 2; |
| 527 | 543 | for (ProtocolEvent.Type type : msg.eventTypes) |
| @@ -547,10 +563,12 @@ | ||
| 547 | 563 | |
| 548 | 564 | static final Message.Coder<AuthResponse> coder = new Message.Coder<AuthResponse>() { |
| 549 | 565 | |
| 566 | + @Override | |
| 550 | 567 | public void encode(AuthResponse response, ByteBuf dest, ProtocolVersion version) { |
| 551 | 568 | CBUtil.writeValue(response.token, dest); |
| 552 | 569 | } |
| 553 | 570 | |
| 571 | + @Override | |
| 554 | 572 | public int encodedSize(AuthResponse response, ProtocolVersion version) { |
| 555 | 573 | return CBUtil.sizeOfValue(response.token); |
| 556 | 574 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Responses.java +12 −0
| @@ -154,6 +154,7 @@ | ||
| 154 | 154 | static class Ready extends Message.Response { |
| 155 | 155 | |
| 156 | 156 | static final Message.Decoder<Ready> decoder = new Message.Decoder<Ready>() { |
| 157 | + @Override | |
| 157 | 158 | public Ready decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 158 | 159 | // TODO: Would it be cool to return a singleton? Check we don't need to |
| 159 | 160 | // set the streamId or something |
| @@ -174,6 +175,7 @@ | ||
| 174 | 175 | static class Authenticate extends Message.Response { |
| 175 | 176 | |
| 176 | 177 | static final Message.Decoder<Authenticate> decoder = new Message.Decoder<Authenticate>() { |
| 178 | + @Override | |
| 177 | 179 | public Authenticate decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 178 | 180 | String authenticator = CBUtil.readString(body); |
| 179 | 181 | return new Authenticate(authenticator); |
| @@ -196,6 +198,7 @@ | ||
| 196 | 198 | static class Supported extends Message.Response { |
| 197 | 199 | |
| 198 | 200 | static final Message.Decoder<Supported> decoder = new Message.Decoder<Supported>() { |
| 201 | + @Override | |
| 199 | 202 | public Supported decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 200 | 203 | return new Supported(CBUtil.readStringToStringListMap(body)); |
| 201 | 204 | } |
| @@ -232,6 +235,7 @@ | ||
| 232 | 235 | static abstract class Result extends Message.Response { |
| 233 | 236 | |
| 234 | 237 | static final Message.Decoder<Result> decoder = new Message.Decoder<Result>() { |
| 238 | + @Override | |
| 235 | 239 | public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 236 | 240 | Kind kind = Kind.fromId(body.readInt()); |
| 237 | 241 | return kind.subDecoder.decode(body, version, codecRegistry); |
| @@ -290,6 +294,7 @@ | ||
| 290 | 294 | } |
| 291 | 295 | |
| 292 | 296 | static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 297 | + @Override | |
| 293 | 298 | public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 294 | 299 | return new Void(); |
| 295 | 300 | } |
| @@ -310,6 +315,7 @@ | ||
| 310 | 315 | } |
| 311 | 316 | |
| 312 | 317 | static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 318 | + @Override | |
| 313 | 319 | public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 314 | 320 | return new SetKeyspace(CBUtil.readString(body)); |
| 315 | 321 | } |
| @@ -429,6 +435,7 @@ | ||
| 429 | 435 | } |
| 430 | 436 | |
| 431 | 437 | static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 438 | + @Override | |
| 432 | 439 | public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 433 | 440 | |
| 434 | 441 | Metadata metadata = Metadata.decode(body, version, codecRegistry); |
| @@ -495,6 +502,7 @@ | ||
| 495 | 502 | static class Prepared extends Result { |
| 496 | 503 | |
| 497 | 504 | static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 505 | + @Override | |
| 498 | 506 | public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 499 | 507 | MD5Digest id = MD5Digest.wrap(CBUtil.readBytes(body)); |
| 500 | 508 | boolean withPkIndices = version.compareTo(V4) >= 0; |
| @@ -545,6 +553,7 @@ | ||
| 545 | 553 | final List<String> targetSignature; |
| 546 | 554 | |
| 547 | 555 | static final Message.Decoder<Result> subcodec = new Message.Decoder<Result>() { |
| 556 | + @Override | |
| 548 | 557 | public Result decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 549 | 558 | // Note: the CREATE KEYSPACE/TABLE/TYPE SCHEMA_CHANGE response is different from the SCHEMA_CHANGE EVENT type |
| 550 | 559 | Change change; |
| @@ -595,6 +604,7 @@ | ||
| 595 | 604 | static class Event extends Message.Response { |
| 596 | 605 | |
| 597 | 606 | static final Message.Decoder<Event> decoder = new Message.Decoder<Event>() { |
| 607 | + @Override | |
| 598 | 608 | public Event decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 599 | 609 | return new Event(ProtocolEvent.deserialize(body, version)); |
| 600 | 610 | } |
| @@ -616,6 +626,7 @@ | ||
| 616 | 626 | static class AuthChallenge extends Message.Response { |
| 617 | 627 | |
| 618 | 628 | static final Message.Decoder<AuthChallenge> decoder = new Message.Decoder<AuthChallenge>() { |
| 629 | + @Override | |
| 619 | 630 | public AuthChallenge decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 620 | 631 | ByteBuffer b = CBUtil.readValue(body); |
| 621 | 632 | if (b == null) |
| @@ -638,6 +649,7 @@ | ||
| 638 | 649 | static class AuthSuccess extends Message.Response { |
| 639 | 650 | |
| 640 | 651 | static final Message.Decoder<AuthSuccess> decoder = new Message.Decoder<AuthSuccess>() { |
| 652 | + @Override | |
| 641 | 653 | public AuthSuccess decode(ByteBuf body, ProtocolVersion version, CodecRegistry codecRegistry) { |
| 642 | 654 | ByteBuffer b = CBUtil.readValue(body); |
| 643 | 655 | if (b == null) |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +13 −0
| @@ -63,6 +63,7 @@ | ||
| 63 | 63 | this.poolsState = new HostConnectionPool.PoolState(); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | + @Override | |
| 66 | 67 | public Session init() { |
| 67 | 68 | try { |
| 68 | 69 | return Uninterruptibles.getUninterruptibly(initAsync()); |
| @@ -71,6 +72,7 @@ | ||
| 71 | 72 | } |
| 72 | 73 | } |
| 73 | 74 | |
| 75 | + @Override | |
| 74 | 76 | public ListenableFuture<Session> initAsync() { |
| 75 | 77 | // If we haven't initialized the cluster, do it now |
| 76 | 78 | cluster.init(); |
| @@ -118,6 +120,7 @@ | ||
| 118 | 120 | return Futures.allAsList(futures); |
| 119 | 121 | } |
| 120 | 122 | |
| 123 | + @Override | |
| 121 | 124 | public String getLoggedKeyspace() { |
| 122 | 125 | return poolsState.keyspace; |
| 123 | 126 | } |
| @@ -154,6 +157,7 @@ | ||
| 154 | 157 | return toPreparedStatement(query, future); |
| 155 | 158 | } |
| 156 | 159 | |
| 160 | + @Override | |
| 157 | 161 | public CloseFuture closeAsync() { |
| 158 | 162 | CloseFuture future = closeFuture.get(); |
| 159 | 163 | if (future != null) |
| @@ -173,20 +177,24 @@ | ||
| 173 | 177 | : closeFuture.get(); // We raced, it's ok, return the future that was actually set |
| 174 | 178 | } |
| 175 | 179 | |
| 180 | + @Override | |
| 176 | 181 | public boolean isClosed() { |
| 177 | 182 | return closeFuture.get() != null; |
| 178 | 183 | } |
| 179 | 184 | |
| 185 | + @Override | |
| 180 | 186 | public Cluster getCluster() { |
| 181 | 187 | return cluster; |
| 182 | 188 | } |
| 183 | 189 | |
| 190 | + @Override | |
| 184 | 191 | public Session.State getState() { |
| 185 | 192 | return new State(this); |
| 186 | 193 | } |
| 187 | 194 | |
| 188 | 195 | private ListenableFuture<PreparedStatement> toPreparedStatement(final String query, final Connection.Future future) { |
| 189 | 196 | return Futures.transform(future, new AsyncFunction<Response, PreparedStatement>() { |
| 197 | + @Override | |
| 190 | 198 | public ListenableFuture<PreparedStatement> apply(Response response) { |
| 191 | 199 | switch (response.type) { |
| 192 | 200 | case RESULT: |
| @@ -694,24 +702,29 @@ | ||
| 694 | 702 | return -1; |
| 695 | 703 | } |
| 696 | 704 | |
| 705 | + @Override | |
| 697 | 706 | public Session getSession() { |
| 698 | 707 | return session; |
| 699 | 708 | } |
| 700 | 709 | |
| 710 | + @Override | |
| 701 | 711 | public Collection<Host> getConnectedHosts() { |
| 702 | 712 | return connectedHosts; |
| 703 | 713 | } |
| 704 | 714 | |
| 715 | + @Override | |
| 705 | 716 | public int getOpenConnections(Host host) { |
| 706 | 717 | int i = getIdx(host); |
| 707 | 718 | return i < 0 ? 0 : openConnections[i]; |
| 708 | 719 | } |
| 709 | 720 | |
| 721 | + @Override | |
| 710 | 722 | public int getTrashedConnections(Host host) { |
| 711 | 723 | int i = getIdx(host); |
| 712 | 724 | return i < 0 ? 0 : trashedConnections[i]; |
| 713 | 725 | } |
| 714 | 726 | |
| 727 | + @Override | |
| 715 | 728 | public int getInFlightQueries(Host host) { |
| 716 | 729 | int i = getIdx(host); |
| 717 | 730 | return i < 0 ? 0 : inFlightQueries[i]; |
modified driver-core/src/main/java/com/datastax/driver/core/TableOrView.java +2 −0
| @@ -27,12 +27,14 @@ | ||
| 27 | 27 | abstract class TableOrView { |
| 28 | 28 | |
| 29 | 29 | static final Comparator<ColumnMetadata> columnMetadataComparator = new Comparator<ColumnMetadata>() { |
| 30 | + @Override | |
| 30 | 31 | public int compare(ColumnMetadata c1, ColumnMetadata c2) { |
| 31 | 32 | return c1.getName().compareTo(c2.getName()); |
| 32 | 33 | } |
| 33 | 34 | }; |
| 34 | 35 | |
| 35 | 36 | static final Predicate<ClusteringOrder> isAscending = new Predicate<ClusteringOrder>() { |
| 37 | + @Override | |
| 36 | 38 | public boolean apply(ClusteringOrder o) { |
| 37 | 39 | return o == ClusteringOrder.ASC; |
| 38 | 40 | } |
modified driver-core/src/main/java/com/datastax/driver/core/UDTValue.java +3 −0
| @@ -27,10 +27,12 @@ | ||
| 27 | 27 | this.definition = definition; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | + @Override | |
| 30 | 31 | protected DataType getType(int i) { |
| 31 | 32 | return definition.byIdx[i].getType(); |
| 32 | 33 | } |
| 33 | 34 | |
| 35 | + @Override | |
| 34 | 36 | protected String getName(int i) { |
| 35 | 37 | return definition.byIdx[i].getName(); |
| 36 | 38 | } |
| @@ -40,6 +42,7 @@ | ||
| 40 | 42 | return definition.getCodecRegistry(); |
| 41 | 43 | } |
| 42 | 44 | |
| 45 | + @Override | |
| 43 | 46 | protected int[] getAllIndexesOf(String name) { |
| 44 | 47 | int[] indexes = definition.byName.get(Metadata.handleId(name)); |
| 45 | 48 | if (indexes == null) |
modified driver-core/src/main/java/com/datastax/driver/core/VersionNumber.java +1 −0
| @@ -171,6 +171,7 @@ | ||
| 171 | 171 | return new VersionNumber(major, minor, patch, dsePatch, null, null); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | + @Override | |
| 174 | 175 | public int compareTo(VersionNumber other) { |
| 175 | 176 | if (major < other.major) |
| 176 | 177 | return -1; |
modified driver-core/src/main/java/com/datastax/driver/core/policies/EC2MultiRegionAddressTranslator.java +1 −0
| @@ -107,6 +107,7 @@ | ||
| 107 | 107 | return null; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | + @Override | |
| 110 | 111 | public void close() { |
| 111 | 112 | try { |
| 112 | 113 | ctx.close(); |
modified driver-core/src/main/java/com/datastax/driver/core/policies/IdentityTranslator.java +1 −0
| @@ -39,6 +39,7 @@ | ||
| 39 | 39 | * @param address the address of a node as returned by Cassandra. |
| 40 | 40 | * @return {@code address} unmodified. |
| 41 | 41 | */ |
| 42 | + @Override | |
| 42 | 43 | public InetSocketAddress translate(InetSocketAddress address) { |
| 43 | 44 | return address; |
| 44 | 45 | } |
modified driver-core/src/main/java/com/datastax/driver/core/policies/LatencyAwarePolicy.java +1 −0
| @@ -387,6 +387,7 @@ | ||
| 387 | 387 | private final ConcurrentMap<Host, HostLatencyTracker> latencies = new ConcurrentHashMap<Host, HostLatencyTracker>(); |
| 388 | 388 | private volatile long cachedMin = -1L; |
| 389 | 389 | |
| 390 | + @Override | |
| 390 | 391 | public void update(Host host, Statement statement, Exception exception, long newLatencyNanos) { |
| 391 | 392 | if (shouldConsiderNewLatency(statement, exception)) { |
| 392 | 393 | HostLatencyTracker hostTracker = latencies.get(host); |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Select.java +7 −0
| @@ -311,6 +311,7 @@ | ||
| 311 | 311 | * |
| 312 | 312 | * @return this in-build SELECT statement. |
| 313 | 313 | */ |
| 314 | + @Override | |
| 314 | 315 | public Selection distinct() { |
| 315 | 316 | this.isDistinct = true; |
| 316 | 317 | return this; |
| @@ -424,6 +425,7 @@ | ||
| 424 | 425 | * @return an in-build SELECT statement. |
| 425 | 426 | * @throws IllegalStateException if some columns had already been selected for this builder. |
| 426 | 427 | */ |
| 428 | + @Override | |
| 427 | 429 | public Builder all() { |
| 428 | 430 | if (columnNames != null) |
| 429 | 431 | throw new IllegalStateException(String.format("Some columns (%s) have already been selected.", columnNames)); |
| @@ -439,6 +441,7 @@ | ||
| 439 | 441 | * @return an in-build SELECT statement. |
| 440 | 442 | * @throws IllegalStateException if some columns had already been selected for this builder. |
| 441 | 443 | */ |
| 444 | + @Override | |
| 442 | 445 | public Builder countAll() { |
| 443 | 446 | if (columnNames != null) |
| 444 | 447 | throw new IllegalStateException(String.format("Some columns (%s) have already been selected.", columnNames)); |
| @@ -455,6 +458,7 @@ | ||
| 455 | 458 | * @param name the new column name to add. |
| 456 | 459 | * @return this in-build SELECT statement |
| 457 | 460 | */ |
| 461 | + @Override | |
| 458 | 462 | public SelectionOrAlias column(String name) { |
| 459 | 463 | return queueName(name); |
| 460 | 464 | } |
| @@ -482,6 +486,7 @@ | ||
| 482 | 486 | * @param name the name of the column to select the write time of. |
| 483 | 487 | * @return this in-build SELECT statement |
| 484 | 488 | */ |
| 489 | + @Override | |
| 485 | 490 | public SelectionOrAlias writeTime(String name) { |
| 486 | 491 | return queueName(new Utils.FCall("writetime", new Utils.CName(name))); |
| 487 | 492 | } |
| @@ -494,6 +499,7 @@ | ||
| 494 | 499 | * @param name the name of the column to select the ttl of. |
| 495 | 500 | * @return this in-build SELECT statement |
| 496 | 501 | */ |
| 502 | + @Override | |
| 497 | 503 | public SelectionOrAlias ttl(String name) { |
| 498 | 504 | return queueName(new Utils.FCall("ttl", new Utils.CName(name))); |
| 499 | 505 | } |
| @@ -509,6 +515,7 @@ | ||
| 509 | 515 | * {@link QueryBuilder#column} method, and so |
| 510 | 516 | * {@code fcall("textToBlob", QueryBuilder.column(foo)}. |
| 511 | 517 | */ |
| 518 | + @Override | |
| 512 | 519 | public SelectionOrAlias fcall(String name, Object... parameters) { |
| 513 | 520 | return queueName(new Utils.FCall(name, parameters)); |
| 514 | 521 | } |
modified driver-core/src/main/java/com/datastax/driver/core/schemabuilder/TableOptions.java +2 −0
| @@ -1038,10 +1038,12 @@ | ||
| 1038 | 1038 | super(Algorithm.NONE); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | + @Override | |
| 1041 | 1042 | public CompressionOptions withChunkLengthInKb(Integer chunkLengthInKb) { |
| 1042 | 1043 | return this; |
| 1043 | 1044 | } |
| 1044 | 1045 | |
| 1046 | + @Override | |
| 1045 | 1047 | public CompressionOptions withCRCCheckChance(Double crcCheckChance) { |
| 1046 | 1048 | return this; |
| 1047 | 1049 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +180 −14
| @@ -51,9 +51,11 @@ | ||
| 51 | 51 | |
| 52 | 52 | public static final String IP_PREFIX; |
| 53 | 53 | |
| 54 | - static final String CASSANDRA_VERSION; | |
| 54 | + private static final String CASSANDRA_VERSION; | |
| 55 | 55 | |
| 56 | - static final String CASSANDRA_INSTALL_ARGS; | |
| 56 | + private static final String CASSANDRA_INSTALL_ARGS; | |
| 57 | + | |
| 58 | + private static final boolean IS_DSE; | |
| 57 | 59 | |
| 58 | 60 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PASSWORD = "cassandra1sfun"; |
| 59 | 61 | public static final String DEFAULT_CLIENT_TRUSTSTORE_PATH = "/client.truststore"; |
| @@ -89,6 +91,49 @@ | ||
| 89 | 91 | */ |
| 90 | 92 | private static final Map<String, String> ENVIRONMENT_MAP; |
| 91 | 93 | |
| 94 | + /** | |
| 95 | + * A mapping of full DSE versions to their C* counterpart. This is not meant to be comprehensive. Used by | |
| 96 | + * {@link #getCassandraVersion()}. If C* version cannot be derived, the method makes a 'best guess'. | |
| 97 | + */ | |
| 98 | + private static final Map<String, String> dseToCassandraVersions = ImmutableMap.<String, String>builder() | |
| 99 | + .put("5.0", "3.0") | |
| 100 | + .put("4.8.3", "2.1.11") | |
| 101 | + .put("4.8.2", "2.1.11") | |
| 102 | + .put("4.8.1", "2.1.11") | |
| 103 | + .put("4.8", "2.1.9") | |
| 104 | + .put("4.7.6", "2.1.11") | |
| 105 | + .put("4.7.5", "2.1.11") | |
| 106 | + .put("4.7.4", "2.1.11") | |
| 107 | + .put("4.7.3", "2.1.8") | |
| 108 | + .put("4.7.2", "2.1.8") | |
| 109 | + .put("4.7.1", "2.1.5") | |
| 110 | + .put("4.6.11", "2.0.16") | |
| 111 | + .put("4.6.10", "2.0.16") | |
| 112 | + .put("4.6.9", "2.0.16") | |
| 113 | + .put("4.6.8", "2.0.16") | |
| 114 | + .put("4.6.7", "2.0.14") | |
| 115 | + .put("4.6.6", "2.0.14") | |
| 116 | + .put("4.6.5", "2.0.14") | |
| 117 | + .put("4.6.4", "2.0.14") | |
| 118 | + .put("4.6.3", "2.0.12") | |
| 119 | + .put("4.6.2", "2.0.12") | |
| 120 | + .put("4.6.1", "2.0.12") | |
| 121 | + .put("4.6", "2.0.11") | |
| 122 | + .put("4.5.9", "2.0.16") | |
| 123 | + .put("4.5.8", "2.0.14") | |
| 124 | + .put("4.5.7", "2.0.12") | |
| 125 | + .put("4.5.6", "2.0.12") | |
| 126 | + .put("4.5.5", "2.0.12") | |
| 127 | + .put("4.5.4", "2.0.11") | |
| 128 | + .put("4.5.3", "2.0.11") | |
| 129 | + .put("4.5.2", "2.0.10") | |
| 130 | + .put("4.5.1", "2.0.8") | |
| 131 | + .put("4.5", "2.0.8") | |
| 132 | + .put("4.0", "2.0") | |
| 133 | + .put("3.2", "1.2") | |
| 134 | + .put("3.1", "1.2") | |
| 135 | + .build(); | |
| 136 | + | |
| 92 | 137 | /** |
| 93 | 138 | * The command to use to launch CCM |
| 94 | 139 | */ |
| @@ -98,14 +143,30 @@ | ||
| 98 | 143 | CASSANDRA_VERSION = System.getProperty("cassandra.version"); |
| 99 | 144 | String installDirectory = System.getProperty("cassandra.directory"); |
| 100 | 145 | String branch = System.getProperty("cassandra.branch"); |
| 146 | + | |
| 147 | + String dseProperty = System.getProperty("dse"); | |
| 148 | + // If -Ddse, if the value is empty interpret it as enabled, | |
| 149 | + // otherwise if there is a value, parse as boolean. | |
| 150 | + IS_DSE = dseProperty != null && (dseProperty.isEmpty() || Boolean.parseBoolean(dseProperty)); | |
| 151 | + | |
| 152 | + StringBuilder installArgs = new StringBuilder(); | |
| 101 | 153 | if (installDirectory != null && !installDirectory.trim().isEmpty()) { |
| 102 | - CASSANDRA_INSTALL_ARGS = "--install-dir=" + new File(installDirectory).getAbsolutePath(); | |
| 154 | + installArgs.append("--install-dir="); | |
| 155 | + installArgs.append(new File(installDirectory).getAbsolutePath()); | |
| 103 | 156 | } else if (branch != null && !branch.trim().isEmpty()) { |
| 104 | - CASSANDRA_INSTALL_ARGS = "-v " + branch.replaceAll("\"", ""); | |
| 157 | + installArgs.append("-v git:"); | |
| 158 | + installArgs.append(branch.trim().replaceAll("\"", "")); | |
| 105 | 159 | } else { |
| 106 | - CASSANDRA_INSTALL_ARGS = "-v " + CASSANDRA_VERSION; | |
| 160 | + installArgs.append("-v"); | |
| 161 | + installArgs.append(CASSANDRA_VERSION); | |
| 107 | 162 | } |
| 108 | 163 | |
| 164 | + if (IS_DSE) { | |
| 165 | + installArgs.append(" --dse"); | |
| 166 | + } | |
| 167 | + | |
| 168 | + CASSANDRA_INSTALL_ARGS = installArgs.toString(); | |
| 169 | + | |
| 109 | 170 | String ip_prefix = System.getProperty("ipprefix"); |
| 110 | 171 | if (ip_prefix == null || ip_prefix.isEmpty()) { |
| 111 | 172 | ip_prefix = "127.0.1."; |
| @@ -136,6 +197,14 @@ | ||
| 136 | 197 | envMap.put("JAVA_HOME", ccmJavaHome); |
| 137 | 198 | } |
| 138 | 199 | ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); |
| 200 | + | |
| 201 | + if (CCMBridge.isDSE()) { | |
| 202 | + logger.info("Tests requiring CCM will use DSE version {} (C* {}, install arguments: {})", | |
| 203 | + CCMBridge.getDSEVersion(), CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); | |
| 204 | + } else { | |
| 205 | + logger.info("Tests requiring CCM will use Cassandra version {} (install arguments: {})", | |
| 206 | + CCMBridge.getCassandraVersion(), CCMBridge.getInstallArguments()); | |
| 207 | + } | |
| 139 | 208 | } |
| 140 | 209 | |
| 141 | 210 | /** |
| @@ -151,8 +220,68 @@ | ||
| 151 | 220 | |
| 152 | 221 | private final File ccmDir; |
| 153 | 222 | |
| 154 | - private CCMBridge() { | |
| 223 | + private final boolean isDSE; | |
| 224 | + | |
| 225 | + private CCMBridge(boolean isDSE) { | |
| 155 | 226 | this.ccmDir = Files.createTempDir(); |
| 227 | + this.isDSE = isDSE; | |
| 228 | + } | |
| 229 | + | |
| 230 | + /** | |
| 231 | + * @return The configured cassandra version. If -Ddse=true was used, this value is derived from the | |
| 232 | + * DSE version provided. If the DSE version can't be derived the following logic is used: | |
| 233 | + * <ol> | |
| 234 | + * <li>If <= 3.X, use C* 1.2</li> | |
| 235 | + * <li>If 4.X, use 2.1 for >= 4.7, 2.0 otherwise.</li> | |
| 236 | + * <li>Otherwise 3.0</li> | |
| 237 | + * </ol> | |
| 238 | + */ | |
| 239 | + public static String getCassandraVersion() { | |
| 240 | + if (isDSE()) { | |
| 241 | + String cassandraVersion = dseToCassandraVersions.get(CASSANDRA_VERSION); | |
| 242 | + if (cassandraVersion != null) { | |
| 243 | + return cassandraVersion; | |
| 244 | + } else if (CASSANDRA_VERSION.startsWith("3.") || CASSANDRA_VERSION.compareTo("3") <= 0) { | |
| 245 | + return "1.2"; | |
| 246 | + } else if (CASSANDRA_VERSION.startsWith("4.")) { | |
| 247 | + if (CASSANDRA_VERSION.compareTo("4.7") >= 0) { | |
| 248 | + return "2.1"; | |
| 249 | + } else { | |
| 250 | + return "2.0"; | |
| 251 | + } | |
| 252 | + } else { | |
| 253 | + // Fallback on 3.0 by default. | |
| 254 | + return "3.0"; | |
| 255 | + } | |
| 256 | + | |
| 257 | + } else { | |
| 258 | + return CASSANDRA_VERSION; | |
| 259 | + } | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** | |
| 263 | + * @return The configured DSE version if '-Ddse=true' specified, otherwise null. | |
| 264 | + */ | |
| 265 | + public static String getDSEVersion() { | |
| 266 | + if (isDSE()) { | |
| 267 | + return CASSANDRA_VERSION; | |
| 268 | + } else { | |
| 269 | + return null; | |
| 270 | + } | |
| 271 | + } | |
| 272 | + | |
| 273 | + /** | |
| 274 | + * @return Whether or not DSE was configured via '-Ddse=true'. | |
| 275 | + */ | |
| 276 | + public static boolean isDSE() { | |
| 277 | + return IS_DSE; | |
| 278 | + } | |
| 279 | + | |
| 280 | + /** | |
| 281 | + * @return The install arguments to pass to CCM when creating the cluster. | |
| 282 | + */ | |
| 283 | + public static String getInstallArguments() { | |
| 284 | + return CASSANDRA_INSTALL_ARGS; | |
| 156 | 285 | } |
| 157 | 286 | |
| 158 | 287 | /** |
| @@ -220,9 +349,14 @@ | ||
| 220 | 349 | execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n); |
| 221 | 350 | } |
| 222 | 351 | |
| 223 | - public void start(int n, String jvmArg) { | |
| 224 | - logger.info("Starting: " + IP_PREFIX + n + " with " + jvmArg); | |
| 225 | - execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto --jvm_arg=%s", n, jvmArg); | |
| 352 | + public void start(int n, String... jvmArg) { | |
| 353 | + StringBuilder jvmArgs = new StringBuilder(""); | |
| 354 | + for (int i = 0; i < jvmArg.length; i++) { | |
| 355 | + jvmArgs.append(" --jvm_arg="); | |
| 356 | + jvmArgs.append(jvmArg[i]); | |
| 357 | + } | |
| 358 | + logger.info("Starting: " + IP_PREFIX + n + " with " + jvmArgs); | |
| 359 | + execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto %s", n, jvmArgs.toString()); | |
| 226 | 360 | } |
| 227 | 361 | |
| 228 | 362 | public void stop(int n) { |
| @@ -261,9 +395,9 @@ | ||
| 261 | 395 | |
| 262 | 396 | public void bootstrapNode(int n, String dc) { |
| 263 | 397 | if (dc == null) |
| 264 | - execute(CCM_COMMAND + " add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100 * n, 8000 + 100 * n); | |
| 398 | + execute(CCM_COMMAND + " add node%d -i %s%d -j %d -r %d -b -s" + (isDSE ? " --dse" : ""), n, IP_PREFIX, n, 7000 + 100 * n, 8000 + 100 * n); | |
| 265 | 399 | else |
| 266 | - execute(CCM_COMMAND + " add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100 * n, dc); | |
| 400 | + execute(CCM_COMMAND + " add node%d -i %s%d -j %d -b -d %s -s" + (isDSE ? " --dse" : ""), n, IP_PREFIX, n, 7000 + 100 * n, dc); | |
| 267 | 401 | execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n); |
| 268 | 402 | } |
| 269 | 403 | |
| @@ -272,7 +406,7 @@ | ||
| 272 | 406 | String storageItf = IP_PREFIX + n + ":" + storagePort; |
| 273 | 407 | String binaryItf = IP_PREFIX + n + ":" + binaryPort; |
| 274 | 408 | String remoteLogItf = IP_PREFIX + n + ":" + remoteDebugPort; |
| 275 | - execute(CCM_COMMAND + " add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s", | |
| 409 | + execute(CCM_COMMAND + " add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s" + (isDSE ? " --dse" : ""), | |
| 276 | 410 | n, IP_PREFIX, n, thriftItf, storageItf, binaryItf, jmxPort, remoteLogItf); |
| 277 | 411 | if (option == null) start(n); |
| 278 | 412 | else start(n, option); |
| @@ -290,6 +424,18 @@ | ||
| 290 | 424 | execute(CCM_COMMAND + " updateconf " + confStr); |
| 291 | 425 | } |
| 292 | 426 | |
| 427 | + public void updateDSEConfig(Map<String, String> configs) { | |
| 428 | + StringBuilder confStr = new StringBuilder(); | |
| 429 | + for (Map.Entry<String, String> entry : configs.entrySet()) { | |
| 430 | + confStr.append(entry.getKey() + ":" + entry.getValue() + " "); | |
| 431 | + } | |
| 432 | + execute(CCM_COMMAND + " updatedseconf " + confStr); | |
| 433 | + } | |
| 434 | + | |
| 435 | + public void setWorkload(int node, String workload) { | |
| 436 | + execute(CCM_COMMAND + " node%d setworkload %s", node, workload); | |
| 437 | + } | |
| 438 | + | |
| 293 | 439 | private void execute(String command, Object... args) { |
| 294 | 440 | |
| 295 | 441 | String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; |
| @@ -391,6 +537,7 @@ | ||
| 391 | 537 | } |
| 392 | 538 | |
| 393 | 539 | public static class TerminationHook extends Thread { |
| 540 | + @Override | |
| 394 | 541 | public void run() { |
| 395 | 542 | logger.debug("shut down hook task.."); |
| 396 | 543 | |
| @@ -627,10 +774,14 @@ | ||
| 627 | 774 | private final String clusterName; |
| 628 | 775 | private Integer[] nodes = {1}; |
| 629 | 776 | private boolean start = true; |
| 777 | + private boolean isDSE = IS_DSE; | |
| 630 | 778 | private String cassandraInstallArgs = CASSANDRA_INSTALL_ARGS; |
| 631 | 779 | private String[] startOptions = new String[0]; |
| 780 | + | |
| 632 | 781 | private Map<String, String> cassandraConfiguration = Maps.newHashMap(); |
| 633 | 782 | |
| 783 | + private Map<String, String> dseConfiguration = Maps.newHashMap(); | |
| 784 | + | |
| 634 | 785 | |
| 635 | 786 | Builder(String clusterName) { |
| 636 | 787 | this.clusterName = clusterName; |
| @@ -674,6 +825,13 @@ | ||
| 674 | 825 | */ |
| 675 | 826 | public Builder withCassandraVersion(String cassandraVersion) { |
| 676 | 827 | this.cassandraInstallArgs = "-v " + cassandraVersion; |
| 828 | + this.isDSE = false; | |
| 829 | + return this; | |
| 830 | + } | |
| 831 | + | |
| 832 | + public Builder withDSEVersion(String dseVersion) { | |
| 833 | + this.cassandraInstallArgs = "-v " + dseVersion + " --dse"; | |
| 834 | + this.isDSE = true; | |
| 677 | 835 | return this; |
| 678 | 836 | } |
| 679 | 837 | |
| @@ -693,10 +851,18 @@ | ||
| 693 | 851 | return this; |
| 694 | 852 | } |
| 695 | 853 | |
| 854 | + public Builder withDSEConfiguration(String key, String value) { | |
| 855 | + this.dseConfiguration.put(key, value); | |
| 856 | + return this; | |
| 857 | + } | |
| 858 | + | |
| 696 | 859 | public CCMBridge build() { |
| 697 | - CCMBridge ccm = new CCMBridge(); | |
| 860 | + CCMBridge ccm = new CCMBridge(isDSE); | |
| 698 | 861 | ccm.execute(buildCreateCommand()); |
| 699 | - ccm.updateConfig(cassandraConfiguration); | |
| 862 | + if (!cassandraConfiguration.isEmpty()) | |
| 863 | + ccm.updateConfig(cassandraConfiguration); | |
| 864 | + if (!dseConfiguration.isEmpty()) | |
| 865 | + ccm.updateDSEConfig(dseConfiguration); | |
| 700 | 866 | if (start) |
| 701 | 867 | ccm.start(); |
| 702 | 868 | return ccm; |
modified driver-core/src/test/java/com/datastax/driver/core/TestListener.java +47 −10
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | 18 | import com.datastax.driver.core.utils.CassandraVersion; |
| 19 | +import com.datastax.driver.core.utils.DseVersion; | |
| 19 | 20 | import org.testng.*; |
| 20 | 21 | import org.testng.internal.ConstructorOrMethod; |
| 21 | 22 | |
| @@ -27,10 +28,6 @@ | ||
| 27 | 28 | private long start_time = System.nanoTime(); |
| 28 | 29 | private int test_index = 0; |
| 29 | 30 | |
| 30 | - static { | |
| 31 | - System.out.println("[CCMBridge] Using Cassandra version: " + CCMBridge.CASSANDRA_VERSION + " (install arguments: " + CCMBridge.CASSANDRA_INSTALL_ARGS + ")"); | |
| 32 | - } | |
| 33 | - | |
| 34 | 31 | @Override |
| 35 | 32 | public void onTestFailure(ITestResult tr) { |
| 36 | 33 | long elapsedTime = TimeUnit.NANOSECONDS.toSeconds((System.nanoTime() - start_time)); |
| @@ -90,15 +87,27 @@ | ||
| 90 | 87 | ConstructorOrMethod constructorOrMethod = testNgMethod.getConstructorOrMethod(); |
| 91 | 88 | |
| 92 | 89 | Class<?> clazz = testNgMethod.getInstance().getClass(); |
| 93 | - if (clazz != null && clazz.isAnnotationPresent(CassandraVersion.class)) { | |
| 94 | - CassandraVersion cassandraVersion = clazz.getAnnotation(CassandraVersion.class); | |
| 95 | - TestUtils.versionCheck(cassandraVersion.major(), cassandraVersion.minor(), cassandraVersion.description()); | |
| 90 | + if (clazz != null) { | |
| 91 | + if (clazz.isAnnotationPresent(CassandraVersion.class)) { | |
| 92 | + CassandraVersion cassandraVersion = clazz.getAnnotation(CassandraVersion.class); | |
| 93 | + cassandraVersionCheck(cassandraVersion); | |
| 94 | + } | |
| 95 | + if (clazz.isAnnotationPresent(DseVersion.class)) { | |
| 96 | + DseVersion dseVersion = clazz.getAnnotation(DseVersion.class); | |
| 97 | + dseVersionCheck(dseVersion); | |
| 98 | + } | |
| 96 | 99 | } |
| 97 | 100 | |
| 98 | 101 | Method method = constructorOrMethod.getMethod(); |
| 99 | - if (method != null && method.isAnnotationPresent(CassandraVersion.class)) { | |
| 100 | - CassandraVersion cassandraVersion = method.getAnnotation(CassandraVersion.class); | |
| 101 | - TestUtils.versionCheck(cassandraVersion.major(), cassandraVersion.minor(), cassandraVersion.description()); | |
| 102 | + if (method != null) { | |
| 103 | + if (method.isAnnotationPresent(CassandraVersion.class)) { | |
| 104 | + CassandraVersion cassandraVersion = method.getAnnotation(CassandraVersion.class); | |
| 105 | + cassandraVersionCheck(cassandraVersion); | |
| 106 | + } | |
| 107 | + if (method.isAnnotationPresent(DseVersion.class)) { | |
| 108 | + DseVersion dseVersion = method.getAnnotation(DseVersion.class); | |
| 109 | + dseVersionCheck(dseVersion); | |
| 110 | + } | |
| 102 | 111 | } |
| 103 | 112 | } |
| 104 | 113 | |
| @@ -106,4 +115,32 @@ | ||
| 106 | 115 | public void afterInvocation(IInvokedMethod testMethod, ITestResult testResult) { |
| 107 | 116 | // Do nothing |
| 108 | 117 | } |
| 118 | + | |
| 119 | + private static void cassandraVersionCheck(CassandraVersion version) { | |
| 120 | + versionCheck(CCMBridge.getCassandraVersion(), version.major(), version.minor(), version.description()); | |
| 121 | + } | |
| 122 | + | |
| 123 | + private static void dseVersionCheck(DseVersion version) { | |
| 124 | + if (CCMBridge.isDSE()) { | |
| 125 | + versionCheck(CCMBridge.getDSEVersion(), version.major(), version.minor(), version.description()); | |
| 126 | + } else { | |
| 127 | + throw new SkipException("Skipping test because not configured for DataStax Enterprise cluster."); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + | |
| 131 | + private static void versionCheck(String version, double majorCheck, int minorCheck, String skipString) { | |
| 132 | + if (version == null) { | |
| 133 | + throw new SkipException("Skipping test because provided version is null"); | |
| 134 | + } else { | |
| 135 | + String[] versionArray = version.split("\\.|-"); | |
| 136 | + double major = Double.parseDouble(versionArray[0] + "." + versionArray[1]); | |
| 137 | + // If there is no minor version, assume latest version of whatever was provided. | |
| 138 | + int minor = versionArray.length >= 3 ? Integer.parseInt(versionArray[2]) : Integer.MAX_VALUE; | |
| 139 | + | |
| 140 | + if (major < majorCheck || (major == majorCheck && minor < minorCheck)) { | |
| 141 | + throw new SkipException("Version >= " + majorCheck + "." + minorCheck + " required. " + | |
| 142 | + "Description: " + skipString); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + } | |
| 109 | 146 | } |
modified driver-core/src/test/java/com/datastax/driver/core/TestUtils.java +0 −11
| @@ -24,7 +24,6 @@ | ||
| 24 | 24 | import org.scassandra.ScassandraFactory; |
| 25 | 25 | import org.slf4j.Logger; |
| 26 | 26 | import org.slf4j.LoggerFactory; |
| 27 | -import org.testng.SkipException; | |
| 28 | 27 | |
| 29 | 28 | import java.io.IOException; |
| 30 | 29 | import java.math.BigDecimal; |
| @@ -560,16 +559,6 @@ | ||
| 560 | 559 | return testForDown ? !host.isUp() : host.isUp(); |
| 561 | 560 | } |
| 562 | 561 | |
| 563 | - public static void versionCheck(double majorCheck, int minorCheck, String skipString) { | |
| 564 | - String version = System.getProperty("cassandra.version"); | |
| 565 | - String[] versionArray = version.split("\\.|-"); | |
| 566 | - double major = Double.parseDouble(versionArray[0] + "." + versionArray[1]); | |
| 567 | - int minor = Integer.parseInt(versionArray[2]); | |
| 568 | - | |
| 569 | - if (major < majorCheck || (major == majorCheck && minor < minorCheck)) { | |
| 570 | - throw new SkipException("Version >= " + majorCheck + "." + minorCheck + " required. Description: " + skipString); | |
| 571 | - } | |
| 572 | - } | |
| 573 | 562 | |
| 574 | 563 | public static Host findOrWaitForHost(Cluster cluster, int node, long duration, TimeUnit unit) { |
| 575 | 564 | return findOrWaitForHost(cluster, CCMBridge.ipOfNode(node), duration, unit); |
modified driver-core/src/test/java/com/datastax/driver/core/utils/CassandraVersion.java +4 −4
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | import java.lang.annotation.RetentionPolicy; |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * <p>Annotation for a Class or Method that defines a Cassandra Version requirement. If the cassandra verison in used | |
| 22 | + * <p>Annotation for a Class or Method that defines a Cassandra Version requirement. If the cassandra version in use | |
| 23 | 23 | * does not meet the version requirement, the test is skipped.</p> |
| 24 | 24 | * |
| 25 | 25 | * @see {@link com.datastax.driver.core.TestListener#beforeInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)} for usage. |
| @@ -29,15 +29,15 @@ | ||
| 29 | 29 | /** |
| 30 | 30 | * @return The major version required to execute this test, i.e. "2.0" |
| 31 | 31 | */ |
| 32 | - public double major(); | |
| 32 | + double major(); | |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @return The minor version required to execute this test, i.e. "0" |
| 36 | 36 | */ |
| 37 | - public int minor() default 0; | |
| 37 | + int minor() default 0; | |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * @return The description returned if this version requirement is not met. |
| 41 | 41 | */ |
| 42 | - public String description() default "Does not meet minimum version requirement."; | |
| 42 | + String description() default "Does not meet minimum version requirement."; | |
| 43 | 43 | } |
added driver-core/src/test/java/com/datastax/driver/core/utils/DseVersion.java +43 −0
| @@ -0,0 +1,43 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 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.utils; | |
| 17 | + | |
| 18 | +import java.lang.annotation.Retention; | |
| 19 | +import java.lang.annotation.RetentionPolicy; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * <p>Annotation for a Class or Method that defines a DataStax Enterprise Version requirement. | |
| 23 | + * If the version in use does not meet the version requirement or DSE is not used, the test is skipped.</p> | |
| 24 | + * | |
| 25 | + * @see {@link com.datastax.driver.core.TestListener#beforeInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)} for usage. | |
| 26 | + */ | |
| 27 | +@Retention(RetentionPolicy.RUNTIME) | |
| 28 | +public @interface DseVersion { | |
| 29 | + /** | |
| 30 | + * @return The major version required to execute this test, i.e. "4.8" | |
| 31 | + */ | |
| 32 | + double major() default 0.0; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @return The minor version required to execute this test, i.e. "3" | |
| 36 | + */ | |
| 37 | + int minor() default 0; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @return The description returned if this version requirement is not met. | |
| 41 | + */ | |
| 42 | + String description() default "Does not meet minimum version requirement."; | |
| 43 | +} |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/BlockingConsumer.java +1 −0
| @@ -52,6 +52,7 @@ | ||
| 52 | 52 | super("Consumer Threads"); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | + @Override | |
| 55 | 56 | public void run() { |
| 56 | 57 | try { |
| 57 | 58 | while (requests.hasNext()) |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/Generators.java +9 −0
| @@ -26,6 +26,7 @@ | ||
| 26 | 26 | |
| 27 | 27 | public class Generators { |
| 28 | 28 | private static ThreadLocal<Random> random = new ThreadLocal<Random>() { |
| 29 | + @Override | |
| 29 | 30 | protected Random initialValue() { |
| 30 | 31 | return new Random(); |
| 31 | 32 | } |
| @@ -62,10 +63,12 @@ | ||
| 62 | 63 | |
| 63 | 64 | public static final QueryGenerator.Builder INSERTER = new QueryGenerator.Builder() { |
| 64 | 65 | |
| 66 | + @Override | |
| 65 | 67 | public String name() { |
| 66 | 68 | return "insert"; |
| 67 | 69 | } |
| 68 | 70 | |
| 71 | + @Override | |
| 69 | 72 | public OptionParser addOptions(OptionParser parser) { |
| 70 | 73 | String msg = "Simple insertion of CQL3 rows (using prepared statements unless the --no-prepare option is used). " |
| 71 | 74 | + "The inserted rows have a fixed set of columns but no clustering columns."; |
| @@ -78,6 +81,7 @@ | ||
| 78 | 81 | return parser; |
| 79 | 82 | } |
| 80 | 83 | |
| 84 | + @Override | |
| 81 | 85 | public void prepare(OptionSet options, Session session) { |
| 82 | 86 | |
| 83 | 87 | try { |
| @@ -100,6 +104,7 @@ | ||
| 100 | 104 | session.execute(sb.toString()); |
| 101 | 105 | } |
| 102 | 106 | |
| 107 | + @Override | |
| 103 | 108 | public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { |
| 104 | 109 | |
| 105 | 110 | return options.has("no-prepare") |
| @@ -159,10 +164,12 @@ | ||
| 159 | 164 | |
| 160 | 165 | public static final QueryGenerator.Builder READER = new QueryGenerator.Builder() { |
| 161 | 166 | |
| 167 | + @Override | |
| 162 | 168 | public String name() { |
| 163 | 169 | return "read"; |
| 164 | 170 | } |
| 165 | 171 | |
| 172 | + @Override | |
| 166 | 173 | public OptionParser addOptions(OptionParser parser) { |
| 167 | 174 | String msg = "Read the rows inserted with the insert generator. Use prepared statements unless the --no-prepare option is used."; |
| 168 | 175 | parser.formatHelpWith(Stress.Help.formatFor(name(), msg)); |
| @@ -171,6 +178,7 @@ | ||
| 171 | 178 | return parser; |
| 172 | 179 | } |
| 173 | 180 | |
| 181 | + @Override | |
| 174 | 182 | public void prepare(OptionSet options, Session session) { |
| 175 | 183 | KeyspaceMetadata ks = session.getCluster().getMetadata().getKeyspace("stress"); |
| 176 | 184 | if (ks == null || ks.getTable("standard1") == null) { |
| @@ -181,6 +189,7 @@ | ||
| 181 | 189 | session.execute("USE stress"); |
| 182 | 190 | } |
| 183 | 191 | |
| 192 | + @Override | |
| 184 | 193 | public QueryGenerator create(int id, int iterations, OptionSet options, Session session) { |
| 185 | 194 | return options.has("no-prepare") |
| 186 | 195 | ? createRegular(id, iterations, session) |
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/QueryGenerator.java +4 −0
| @@ -59,10 +59,12 @@ | ||
| 59 | 59 | this.statement = statement; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | + @Override | |
| 62 | 63 | public ResultSet execute(Session session) { |
| 63 | 64 | return session.execute(statement); |
| 64 | 65 | } |
| 65 | 66 | |
| 67 | + @Override | |
| 66 | 68 | public ResultSetFuture executeAsync(Session session) { |
| 67 | 69 | return session.executeAsync(statement); |
| 68 | 70 | } |
| @@ -76,10 +78,12 @@ | ||
| 76 | 78 | this.query = query; |
| 77 | 79 | } |
| 78 | 80 | |
| 81 | + @Override | |
| 79 | 82 | public ResultSet execute(Session session) { |
| 80 | 83 | return session.execute(query); |
| 81 | 84 | } |
| 82 | 85 | |
| 86 | + @Override | |
| 83 | 87 | public ResultSetFuture executeAsync(Session session) { |
| 84 | 88 | return session.executeAsync(query); |
| 85 | 89 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AccessorInvocationHandler.java +1 −0
| @@ -49,6 +49,7 @@ | ||
| 49 | 49 | methodMap.put(method.method, method); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + @Override | |
| 52 | 53 | public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { |
| 53 | 54 | if (m.equals(TO_STRING)) |
| 54 | 55 | return mapper.daoClass.getSimpleName() + " implementation generated by the Cassandra driver mapper"; |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AccessorReflectionMapper.java +1 −0
| @@ -47,6 +47,7 @@ | ||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | private static class AccessorReflectionFactory implements Factory { |
| 50 | + @Override | |
| 50 | 51 | public <T> AccessorMapper<T> create(Class<T> daoClass, List<MethodMapper> methods) { |
| 51 | 52 | return new AccessorReflectionMapper<T>(daoClass, methods); |
| 52 | 53 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/AnnotationParser.java +1 −0
| @@ -37,6 +37,7 @@ | ||
| 37 | 37 | class AnnotationParser { |
| 38 | 38 | |
| 39 | 39 | private static final Comparator<Field> fieldComparator = new Comparator<Field>() { |
| 40 | + @Override | |
| 40 | 41 | public int compare(Field f1, Field f2) { |
| 41 | 42 | return position(f1) - position(f2); |
| 42 | 43 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/Mapper.java +5 −0
| @@ -77,16 +77,19 @@ | ||
| 77 | 77 | |
| 78 | 78 | this.protocolVersion = manager.getSession().getCluster().getConfiguration().getProtocolOptions().getProtocolVersion(); |
| 79 | 79 | this.mapOneFunction = new Function<ResultSet, T>() { |
| 80 | + @Override | |
| 80 | 81 | public T apply(ResultSet rs) { |
| 81 | 82 | return Mapper.this.mapAliased(rs).one(); |
| 82 | 83 | } |
| 83 | 84 | }; |
| 84 | 85 | this.mapOneFunctionWithoutAliases = new Function<ResultSet, T>() { |
| 86 | + @Override | |
| 85 | 87 | public T apply(ResultSet rs) { |
| 86 | 88 | return Mapper.this.map(rs).one(); |
| 87 | 89 | } |
| 88 | 90 | }; |
| 89 | 91 | this.mapAllFunctionWithoutAliases = new Function<ResultSet, Result<T>>() { |
| 92 | + @Override | |
| 90 | 93 | public Result<T> apply(ResultSet rs) { |
| 91 | 94 | return Mapper.this.map(rs); |
| 92 | 95 | } |
| @@ -830,6 +833,7 @@ | ||
| 830 | 833 | this.ttlValue = value; |
| 831 | 834 | } |
| 832 | 835 | |
| 836 | + @Override | |
| 833 | 837 | void appendTo(Insert.Options usings) { |
| 834 | 838 | usings.and(QueryBuilder.ttl(QueryBuilder.bindMarker())); |
| 835 | 839 | } |
| @@ -1033,6 +1037,7 @@ | ||
| 1033 | 1037 | return false; |
| 1034 | 1038 | } |
| 1035 | 1039 | |
| 1040 | + @Override | |
| 1036 | 1041 | public int hashCode() { |
| 1037 | 1042 | return Objects.hashCode(queryType, optionTypes, columns); |
| 1038 | 1043 | } |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/ReflectionMapper.java +2 −0
| @@ -84,11 +84,13 @@ | ||
| 84 | 84 | |
| 85 | 85 | private static class ReflectionFactory implements Factory { |
| 86 | 86 | |
| 87 | + @Override | |
| 87 | 88 | public <T> EntityMapper<T> create(Class<T> entityClass, String keyspace, String table, ConsistencyLevel writeConsistency, ConsistencyLevel readConsistency) { |
| 88 | 89 | return new ReflectionMapper<T>(entityClass, keyspace, table, writeConsistency, readConsistency); |
| 89 | 90 | } |
| 90 | 91 | |
| 91 | 92 | @SuppressWarnings({"unchecked", "rawtypes"}) |
| 93 | + @Override | |
| 92 | 94 | public <T> ColumnMapper<T> createColumnMapper(Class<T> entityClass, Field field, int position, MappingManager mappingManager, AtomicInteger columnCounter) { |
| 93 | 95 | String fieldName = field.getName(); |
| 94 | 96 | try { |
modified driver-mapping/src/main/java/com/datastax/driver/mapping/Result.java +5 −1
| @@ -119,18 +119,22 @@ | ||
| 119 | 119 | * @return an iterator that will consume and return the remaining rows of |
| 120 | 120 | * this mapped result set. |
| 121 | 121 | */ |
| 122 | - public Iterator<T> iterator() { | |
| 122 | + @Override | |
| 123 | + public Iterator<T> iterator() { | |
| 123 | 124 | return new Iterator<T>() { |
| 124 | 125 | private final Iterator<Row> rowIterator = rs.iterator(); |
| 125 | 126 | |
| 127 | + @Override | |
| 126 | 128 | public boolean hasNext() { |
| 127 | 129 | return rowIterator.hasNext(); |
| 128 | 130 | } |
| 129 | 131 | |
| 132 | + @Override | |
| 130 | 133 | public T next() { |
| 131 | 134 | return map(rowIterator.next()); |
| 132 | 135 | } |
| 133 | 136 | |
| 137 | + @Override | |
| 134 | 138 | public void remove() { |
| 135 | 139 | throw new UnsupportedOperationException(); |
| 136 | 140 | } |
modified upgrade_guide/README.md +2 −1
| @@ -449,7 +449,8 @@ | ||
| 449 | 449 | |
| 450 | 450 | 4. The internal initialization sequence of the Cluster object has been slightly changed: |
| 451 | 451 | some fields that were previously initialized in the constructor are now set when |
| 452 | - the `init()` method is called. This is unlikely to affect regular driver users. | |
| 452 | + the `init()` method is called. In particular, `Cluster#getMetrics()` will return | |
| 453 | + `null` until the cluster is initialized. | |
| 453 | 454 | |
| 454 | 455 | ### 1.0 to 2.0 |
| 455 | 456 |