Elffuss BraidHub

kikocis/java-driver public

Merge branch '3.0.x' into 3.1.x
Changesetdab837f5b94586423722e5563f72aba8ad12608098b2cb3d56393ef68723756c
Authorolim7t <omichallat+github@gmail.com> · 2016-12-09 16:02 -08:00
Committerolim7t <omichallat+github@gmail.com> · 2016-12-09 16:02 -08:00
Parentsf67b9fa82480, eb74149ffde9

Browse the files at this changeset

7 files changed

modified changelog/README.md +6 −0
@@ -1,5 +1,11 @@
11 ## Changelog
22
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+
39 ### 3.1.2
410
511 - [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 @@
121121 return delegate().unregister(tracker);
122122 }
123123
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+
124134 @Override
125135 public CloseFuture closeAsync() {
126136 return delegate().closeAsync();
modified driver-core/src/main/java/com/datastax/driver/core/Message.java +13 −1
@@ -180,9 +180,21 @@
180180 }
181181 }
182182
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();
184190
185191 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) {
186198 throw new UnsupportedOperationException();
187199 }
188200 }
modified driver-core/src/main/java/com/datastax/driver/core/Requests.java +12 −12
@@ -63,7 +63,7 @@
6363 }
6464
6565 @Override
66- Request copy() {
66+ protected Request copyInternal() {
6767 return new Startup(compression);
6868 }
6969
@@ -99,7 +99,7 @@
9999 }
100100
101101 @Override
102- Request copy() {
102+ protected Request copyInternal() {
103103 return new Credentials(credentials);
104104 }
105105 }
@@ -122,7 +122,7 @@
122122 }
123123
124124 @Override
125- Request copy() {
125+ protected Request copyInternal() {
126126 return new Options();
127127 }
128128
@@ -162,12 +162,12 @@
162162 }
163163
164164 @Override
165- Request copy() {
165+ protected Request copyInternal() {
166166 return new Query(this.query, options, isTracingRequested());
167167 }
168168
169169 @Override
170- Request copy(ConsistencyLevel newConsistencyLevel) {
170+ protected Request copyInternal(ConsistencyLevel newConsistencyLevel) {
171171 return new Query(this.query, options.copy(newConsistencyLevel), isTracingRequested());
172172 }
173173
@@ -203,12 +203,12 @@
203203 }
204204
205205 @Override
206- Request copy() {
206+ protected Request copyInternal() {
207207 return new Execute(statementId, options, isTracingRequested());
208208 }
209209
210210 @Override
211- Request copy(ConsistencyLevel newConsistencyLevel) {
211+ protected Request copyInternal(ConsistencyLevel newConsistencyLevel) {
212212 return new Execute(statementId, options.copy(newConsistencyLevel), isTracingRequested());
213213 }
214214
@@ -460,12 +460,12 @@
460460 }
461461
462462 @Override
463- Request copy() {
463+ protected Request copyInternal() {
464464 return new Batch(type, queryOrIdList, values, options, isTracingRequested());
465465 }
466466
467467 @Override
468- Request copy(ConsistencyLevel newConsistencyLevel) {
468+ protected Request copyInternal(ConsistencyLevel newConsistencyLevel) {
469469 return new Batch(type, queryOrIdList, values, options.copy(newConsistencyLevel), isTracingRequested());
470470 }
471471
@@ -571,7 +571,7 @@
571571 }
572572
573573 @Override
574- Request copy() {
574+ protected Request copyInternal() {
575575 return new Prepare(query);
576576 }
577577
@@ -608,7 +608,7 @@
608608 }
609609
610610 @Override
611- Request copy() {
611+ protected Request copyInternal() {
612612 return new Register(eventTypes);
613613 }
614614
@@ -641,7 +641,7 @@
641641 }
642642
643643 @Override
644- Request copy() {
644+ protected Request copyInternal() {
645645 return new AuthResponse(token);
646646 }
647647 }
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