Elffuss BraidHub

kikocis/java-driver public

Merge branch '2.0' into 2.1
Changeset5cc80eb128f8b1801e7225fd095a85abbd66a65288caa80f984b5f08a22e5e08
Authorolim7t <omichallat+github@gmail.com> · 2015-03-06 15:25 -08:00
Committerolim7t <omichallat+github@gmail.com> · 2015-03-06 15:25 -08:00
Parents7cfd979a815e, c24f41b39166

Browse the files at this changeset

4 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -17,6 +17,7 @@
1717 - [bug] Fix handling of DROP events when ks name is case-sensitive (JAVA-678)
1818 - [improvement] Use List<?> instead of List<Object> in QueryBuilder API
1919 (JAVA-631)
20+- [improvement] Exclude Netty POM from META-INF in shaded JAR (JAVA-654)
2021 - [bug] Prevent race between cancellation and query completion (JAVA-614)
2122 - [bug] Prevent cancel and timeout from cancelling unrelated ResponseHandler if
2223 streamId was already released and reused (JAVA-632).
modified driver-core/pom.xml +5 −1
@@ -196,7 +196,11 @@
196196 </relocations>
197197 <transformers>
198198 <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
199- <resource>META-INF/MANIFEST.MF</resource>
199+ <resources>
200+ <resource>META-INF/MANIFEST.MF</resource>
201+ <resource>META-INF/maven/io.netty/netty/pom.properties</resource>
202+ <resource>META-INF/maven/io.netty/netty/pom.xml</resource>
203+ </resources>
200204 </transformer>
201205 <!-- Pick up the alternate manifest that was generated by the alternate execution of the bundle plugin -->
202206 <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
modified driver-core/src/main/java/com/datastax/driver/core/TokenRange.java +34 −6
@@ -16,10 +16,12 @@
1616 package com.datastax.driver.core;
1717
1818 import java.util.ArrayList;
19+import java.util.Iterator;
1920 import java.util.List;
2021
2122 import com.google.common.base.Objects;
2223 import com.google.common.collect.ImmutableList;
24+import com.google.common.collect.Lists;
2325
2426 /**
2527 * A range of tokens on the Cassandra ring.
@@ -166,21 +168,47 @@
166168 /**
167169 * Computes the intersection of this range with another one.
168170 * <p>
171+ * If either of these ranges overlap the the ring, they are unwrapped and the unwrapped
172+ * tokens are compared with one another.
173+ * <p>
169174 * This call will fail if the two ranges do not intersect, you must check by calling
170175 * {@link #intersects(TokenRange)} beforehand.
171176 *
172177 * @param that the other range.
173- * @return the range resulting from the intersection.
178+ * @return the range(s) resulting from the intersection.
174179 * @throws IllegalArgumentException if the ranges do not intersect.
175180 */
176- public TokenRange intersectWith(TokenRange that) {
181+ public List<TokenRange> intersectWith(TokenRange that) {
177182 if (!this.intersects(that))
178183 throw new IllegalArgumentException("The two ranges do not intersect, use intersects() before calling this method");
179184
180- return new TokenRange(
181- (this.contains(that.start, true)) ? that.start : this.start,
182- (this.contains(that.end, false)) ? that.end : this.end,
183- factory);
185+ List<TokenRange> intersected = Lists.newArrayList();
186+
187+ // Compare the unwrapped ranges to one another.
188+ List<TokenRange> unwrappedForThis = this.unwrap();
189+ List<TokenRange> unwrappedForThat = that.unwrap();
190+ for(TokenRange t1 : unwrappedForThis) {
191+ for(TokenRange t2 : unwrappedForThat) {
192+ if(t1.intersects(t2)) {
193+ intersected.add(new TokenRange(
194+ (t1.contains(t2.start, true)) ? t2.start : t1.start,
195+ (t1.contains(t2.end, false)) ? t2.end : t1.end,
196+ factory));
197+ }
198+ }
199+ }
200+
201+ // If two intersecting ranges were produced, merge them if they are adjacent.
202+ // This could happen in the case that two wrapped ranges intersected.
203+ if(intersected.size() == 2) {
204+ TokenRange t1 = intersected.get(0);
205+ TokenRange t2 = intersected.get(1);
206+ if (t1.end.equals(t2.start) || t2.end.equals(t1.start)) {
207+ return ImmutableList.of(t1.mergeWith(t2));
208+ }
209+ }
210+
211+ return intersected;
184212 }
185213
186214 // isStart handles the case where the token is the start of another range, for example:
modified driver-core/src/test/java/com/datastax/driver/core/TokenRangeTest.java +21 −5
@@ -2,6 +2,7 @@
22
33 import java.util.List;
44
5+import com.google.common.collect.ImmutableList;
56 import org.testng.annotations.Test;
67
78 import static org.testng.Assert.fail;
@@ -76,15 +77,30 @@
7677 @Test(groups = "unit")
7778 public void should_compute_intersection() {
7879 assertThat(tokenRange(3, 9).intersectWith(tokenRange(2, 4)))
79- .isEqualTo(tokenRange(3, 4));
80+ .isEqualTo(ImmutableList.of(tokenRange(3, 4)));
8081 assertThat(tokenRange(3, 9).intersectWith(tokenRange(3, 5)))
81- .isEqualTo(tokenRange(3, 5));
82+ .isEqualTo(ImmutableList.of(tokenRange(3, 5)));
8283 assertThat(tokenRange(3, 9).intersectWith(tokenRange(4, 6)))
83- .isEqualTo(tokenRange(4, 6));
84+ .isEqualTo(ImmutableList.of(tokenRange(4, 6)));
8485 assertThat(tokenRange(3, 9).intersectWith(tokenRange(7, 9)))
85- .isEqualTo(tokenRange(7, 9));
86+ .isEqualTo(ImmutableList.of(tokenRange(7, 9)));
8687 assertThat(tokenRange(3, 9).intersectWith(tokenRange(8, 10)))
87- .isEqualTo(tokenRange(8, 9));
88+ .isEqualTo(ImmutableList.of(tokenRange(8, 9)));
89+ }
90+
91+ @Test(groups = "unit")
92+ public void should_could_intersection_with_ranges_around_ring() {
93+ // If a range wraps the ring like 10, -10 does this will produce two separate
94+ // intersected ranges.
95+ assertThat(tokenRange(10, -10).intersectWith(tokenRange(-20, 20)))
96+ .isEqualTo(ImmutableList.of(tokenRange(10, 20), tokenRange(-20, -10)));
97+ assertThat(tokenRange(-20, 20).intersectWith(tokenRange(10, -10)))
98+ .isEqualTo(ImmutableList.of(tokenRange(10, 20), tokenRange(-20, -10)));
99+
100+ // If both ranges wrap the ring, they should be merged together wrapping across
101+ // the range.
102+ assertThat(tokenRange(10, -30).intersectWith(tokenRange(20, -20)))
103+ .isEqualTo(ImmutableList.of(tokenRange(20, -30)));
88104 }
89105
90106 @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)