kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | dab837f5b94586423722e5563f72aba8ad12608098b2cb3d56393ef68723756c |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-12-09 16:02 -08:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-12-09 16:02 -08:00 |
| Parents | f67b9fa82480, eb74149ffde9 |
7 files changed
modified changelog/README.md +6 −0
| @@ -1,5 +1,11 @@ | ||
| 1 | 1 | ## Changelog |
| 2 | 2 | |
| 3 | +### 3.1.3 (in progress) | |
| 4 | + | |
| 5 | +- [bug] JAVA-1330: Add un/register for SchemaChangeListener in DelegatingCluster | |
| 6 | +- [bug] JAVA-1351: Include Custom Payload in Request.copy. | |
| 7 | + | |
| 8 | + | |
| 3 | 9 | ### 3.1.2 |
| 4 | 10 | |
| 5 | 11 | - [bug] JAVA-1321: Wrong OSGi dependency version for Guava. |
modified driver-core/src/main/java/com/datastax/driver/core/DelegatingCluster.java +10 −0
| @@ -121,6 +121,16 @@ | ||
| 121 | 121 | return delegate().unregister(tracker); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | + @Override | |
| 125 | + public Cluster register(SchemaChangeListener listener) { | |
| 126 | + return delegate().register(listener); | |
| 127 | + } | |
| 128 | + | |
| 129 | + @Override | |
| 130 | + public Cluster unregister(SchemaChangeListener listener) { | |
| 131 | + return delegate().unregister(listener); | |
| 132 | + } | |
| 133 | + | |
| 124 | 134 | @Override |
| 125 | 135 | public CloseFuture closeAsync() { |
| 126 | 136 | return delegate().closeAsync(); |
modified driver-core/src/main/java/com/datastax/driver/core/Message.java +13 −1
| @@ -180,9 +180,21 @@ | ||
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - abstract Request copy(); | |
| 183 | + Request copy() { | |
| 184 | + Request request = copyInternal(); | |
| 185 | + request.setCustomPayload(this.getCustomPayload()); | |
| 186 | + return request; | |
| 187 | + } | |
| 188 | + | |
| 189 | + protected abstract Request copyInternal(); | |
| 184 | 190 | |
| 185 | 191 | Request copy(ConsistencyLevel newConsistencyLevel) { |
| 192 | + Request request = copyInternal(newConsistencyLevel); | |
| 193 | + request.setCustomPayload(this.getCustomPayload()); | |
| 194 | + return request; | |
| 195 | + } | |
| 196 | + | |
| 197 | + protected Request copyInternal(ConsistencyLevel newConsistencyLevel) { | |
| 186 | 198 | throw new UnsupportedOperationException(); |
| 187 | 199 | } |
| 188 | 200 | } |
modified driver-core/src/main/java/com/datastax/driver/core/Requests.java +12 −12
| @@ -63,7 +63,7 @@ | ||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | @Override |
| 66 | - Request copy() { | |
| 66 | + protected Request copyInternal() { | |
| 67 | 67 | return new Startup(compression); |
| 68 | 68 | } |
| 69 | 69 | |
| @@ -99,7 +99,7 @@ | ||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | @Override |
| 102 | - Request copy() { | |
| 102 | + protected Request copyInternal() { | |
| 103 | 103 | return new Credentials(credentials); |
| 104 | 104 | } |
| 105 | 105 | } |
| @@ -122,7 +122,7 @@ | ||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | @Override |
| 125 | - Request copy() { | |
| 125 | + protected Request copyInternal() { | |
| 126 | 126 | return new Options(); |
| 127 | 127 | } |
| 128 | 128 | |
| @@ -162,12 +162,12 @@ | ||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | @Override |
| 165 | - Request copy() { | |
| 165 | + protected Request copyInternal() { | |
| 166 | 166 | return new Query(this.query, options, isTracingRequested()); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | @Override |
| 170 | - Request copy(ConsistencyLevel newConsistencyLevel) { | |
| 170 | + protected Request copyInternal(ConsistencyLevel newConsistencyLevel) { | |
| 171 | 171 | return new Query(this.query, options.copy(newConsistencyLevel), isTracingRequested()); |
| 172 | 172 | } |
| 173 | 173 | |
| @@ -203,12 +203,12 @@ | ||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | @Override |
| 206 | - Request copy() { | |
| 206 | + protected Request copyInternal() { | |
| 207 | 207 | return new Execute(statementId, options, isTracingRequested()); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | @Override |
| 211 | - Request copy(ConsistencyLevel newConsistencyLevel) { | |
| 211 | + protected Request copyInternal(ConsistencyLevel newConsistencyLevel) { | |
| 212 | 212 | return new Execute(statementId, options.copy(newConsistencyLevel), isTracingRequested()); |
| 213 | 213 | } |
| 214 | 214 | |
| @@ -460,12 +460,12 @@ | ||
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | @Override |
| 463 | - Request copy() { | |
| 463 | + protected Request copyInternal() { | |
| 464 | 464 | return new Batch(type, queryOrIdList, values, options, isTracingRequested()); |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | @Override |
| 468 | - Request copy(ConsistencyLevel newConsistencyLevel) { | |
| 468 | + protected Request copyInternal(ConsistencyLevel newConsistencyLevel) { | |
| 469 | 469 | return new Batch(type, queryOrIdList, values, options.copy(newConsistencyLevel), isTracingRequested()); |
| 470 | 470 | } |
| 471 | 471 | |
| @@ -571,7 +571,7 @@ | ||
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | @Override |
| 574 | - Request copy() { | |
| 574 | + protected Request copyInternal() { | |
| 575 | 575 | return new Prepare(query); |
| 576 | 576 | } |
| 577 | 577 | |
| @@ -608,7 +608,7 @@ | ||
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | @Override |
| 611 | - Request copy() { | |
| 611 | + protected Request copyInternal() { | |
| 612 | 612 | return new Register(eventTypes); |
| 613 | 613 | } |
| 614 | 614 | |
| @@ -641,7 +641,7 @@ | ||
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | @Override |
| 644 | - Request copy() { | |
| 644 | + protected Request copyInternal() { | |
| 645 | 645 | return new AuthResponse(token); |
| 646 | 646 | } |
| 647 | 647 | } |
deleted driver-core/src/test/java/com/datastax/driver/core/ClusterDelegateTest.java +0 −46
| @@ -1,46 +0,0 @@ | ||
| 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; | |
| 17 | - | |
| 18 | -import org.testng.annotations.Test; | |
| 19 | - | |
| 20 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 21 | - | |
| 22 | -public class ClusterDelegateTest extends CCMTestsSupport { | |
| 23 | - | |
| 24 | - @Test(groups = "short") | |
| 25 | - public void should_allow_subclass_to_delegate_to_other_instance() { | |
| 26 | - SimpleDelegatingCluster delegatingCluster = new SimpleDelegatingCluster(cluster()); | |
| 27 | - | |
| 28 | - ResultSet rs = delegatingCluster.connect().execute("select * from system.local"); | |
| 29 | - | |
| 30 | - assertThat(rs.all()).hasSize(1); | |
| 31 | - } | |
| 32 | - | |
| 33 | - static class SimpleDelegatingCluster extends DelegatingCluster { | |
| 34 | - | |
| 35 | - private final Cluster delegate; | |
| 36 | - | |
| 37 | - public SimpleDelegatingCluster(Cluster delegate) { | |
| 38 | - this.delegate = delegate; | |
| 39 | - } | |
| 40 | - | |
| 41 | - @Override | |
| 42 | - protected Cluster delegate() { | |
| 43 | - return delegate; | |
| 44 | - } | |
| 45 | - } | |
| 46 | -} |
added driver-core/src/test/java/com/datastax/driver/core/DelegatingClusterIntegrationTest.java +46 −0
| @@ -0,0 +1,46 @@ | ||
| 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; | |
| 17 | + | |
| 18 | +import org.testng.annotations.Test; | |
| 19 | + | |
| 20 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 21 | + | |
| 22 | +public class DelegatingClusterIntegrationTest extends CCMTestsSupport { | |
| 23 | + | |
| 24 | + @Test(groups = "short") | |
| 25 | + public void should_allow_subclass_to_delegate_to_other_instance() { | |
| 26 | + SimpleDelegatingCluster delegatingCluster = new SimpleDelegatingCluster(cluster()); | |
| 27 | + | |
| 28 | + ResultSet rs = delegatingCluster.connect().execute("select * from system.local"); | |
| 29 | + | |
| 30 | + assertThat(rs.all()).hasSize(1); | |
| 31 | + } | |
| 32 | + | |
| 33 | + static class SimpleDelegatingCluster extends DelegatingCluster { | |
| 34 | + | |
| 35 | + private final Cluster delegate; | |
| 36 | + | |
| 37 | + public SimpleDelegatingCluster(Cluster delegate) { | |
| 38 | + this.delegate = delegate; | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + protected Cluster delegate() { | |
| 43 | + return delegate; | |
| 44 | + } | |
| 45 | + } | |
| 46 | +} |
added driver-core/src/test/java/com/datastax/driver/core/DelegatingClusterTest.java +84 −0
| @@ -0,0 +1,84 @@ | ||
| 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; | |
| 17 | + | |
| 18 | +import com.datastax.driver.core.DelegatingClusterIntegrationTest.SimpleDelegatingCluster; | |
| 19 | +import com.google.common.collect.ImmutableSet; | |
| 20 | +import org.mockito.Mockito; | |
| 21 | +import org.mockito.exceptions.verification.WantedButNotInvoked; | |
| 22 | +import org.mockito.invocation.Invocation; | |
| 23 | +import org.testng.annotations.Test; | |
| 24 | + | |
| 25 | +import java.lang.reflect.Method; | |
| 26 | +import java.lang.reflect.Modifier; | |
| 27 | +import java.util.Set; | |
| 28 | + | |
| 29 | +import static org.mockito.Mockito.mock; | |
| 30 | +import static org.mockito.Mockito.reset; | |
| 31 | + | |
| 32 | +public class DelegatingClusterTest { | |
| 33 | + private static final Set<String> NON_DELEGATED_METHODS = ImmutableSet.of("getClusterName"); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Checks that all methods of {@link DelegatingCluster} invoke their counterpart in {@link Cluster}. | |
| 37 | + * This protects us from forgetting to add a method to the former when it gets added to the latter. | |
| 38 | + * <p> | |
| 39 | + * Note that a much better, compile-time solution would be to make {@link Cluster} an interface, but that's a | |
| 40 | + * breaking change so it will have to wait until the next major version. | |
| 41 | + */ | |
| 42 | + @Test(groups = "unit") | |
| 43 | + public void should_call_delegate_methods() throws Exception { | |
| 44 | + Cluster delegate = mock(Cluster.class); | |
| 45 | + SimpleDelegatingCluster delegatingCluster = new SimpleDelegatingCluster(delegate); | |
| 46 | + | |
| 47 | + for (Method method : Cluster.class.getMethods()) { | |
| 48 | + if ((method.getModifiers() & Modifier.STATIC) == Modifier.STATIC || | |
| 49 | + NON_DELEGATED_METHODS.contains(method.getName()) || | |
| 50 | + method.getDeclaringClass() == Object.class) { | |
| 51 | + continue; | |
| 52 | + } | |
| 53 | + // we can leave all parameters to null since we're invoking a mock | |
| 54 | + Object[] parameters = new Object[method.getParameterTypes().length]; | |
| 55 | + try { | |
| 56 | + method.invoke(delegatingCluster, parameters); | |
| 57 | + } catch (Exception ignored) { | |
| 58 | + } | |
| 59 | + verify(delegate, method, parameters); | |
| 60 | + reset(delegate); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + private static void verify(Object mock, Method expectedMethod, Object... expectedArguments) { | |
| 65 | + out: | |
| 66 | + for (Invocation invocation : Mockito.mockingDetails(mock).getInvocations()) { | |
| 67 | + if (invocation.getMethod().equals(expectedMethod)) { | |
| 68 | + Object[] actualArguments = invocation.getArguments(); | |
| 69 | + assert actualArguments.length == expectedArguments.length; // because it's the same method | |
| 70 | + for (int i = 0; i < actualArguments.length; i++) { | |
| 71 | + Object actual = actualArguments[i]; | |
| 72 | + Object expected = expectedArguments[i]; | |
| 73 | + boolean equal = (actual == null) ? expected == null : actual.equals(expected); | |
| 74 | + if (!equal) { | |
| 75 | + continue out; | |
| 76 | + } | |
| 77 | + } | |
| 78 | + invocation.markVerified(); | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + } | |
| 82 | + throw new WantedButNotInvoked("Not delegated: " + expectedMethod.toString()); | |
| 83 | + } | |
| 84 | +} | |
| No newline at the end of the file |