kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 37a0d01b83e2e2bdf57f51c6deb6b53beb9eb03ac7e7bb3976dbc5e3dcb0f7db |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2016-12-09 17:19 -06:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-12-09 15:19 -08:00 |
| Parents | d9f407b99370 |
5 files changed
modified changelog/README.md +5 −0
| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | ## Changelog |
| 2 | 2 | |
| 3 | +### 3.0.6 (in progress) | |
| 4 | + | |
| 5 | +- [bug] JAVA-1330: Add un/register for SchemaChangeListener in DelegatingCluster | |
| 6 | + | |
| 7 | + | |
| 3 | 8 | ### 3.0.5 |
| 4 | 9 | |
| 5 | 10 | - [bug] JAVA-1312: QueryBuilder modifies selected columns when manually selected. |
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(); |
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 |