Skip to content

Commit 47b93a2

Browse files
committed
Merge branch '2.0' into 2.1
2 parents f44b7be + 8236943 commit 47b93a2

7 files changed

Lines changed: 116 additions & 23 deletions

File tree

driver-core/CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Merged from 2.0 branch:
2424
- [improvement] Exclude Netty POM from META-INF in shaded JAR (JAVA-654)
2525
- [bug] Quote single quotes contained in table comments in asCQLQuery method
2626
(JAVA-655)
27+
- [bug] Empty TokenRange returned in a one token cluster (JAVA-684)
2728
- [bug] Prevent race between cancellation and query completion (JAVA-614)
2829
- [bug] Prevent cancel and timeout from cancelling unrelated ResponseHandler if
2930
streamId was already released and reused (JAVA-632).

driver-core/src/main/java/com/datastax/driver/core/Metadata.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,15 @@ private static Map<Token, Set<Host>> makeNonReplicatedMap(Map<Token, Host> input
577577

578578
private static Set<TokenRange> makeTokenRanges(List<Token> ring, Token.Factory factory) {
579579
ImmutableSet.Builder<TokenRange> builder = ImmutableSet.builder();
580-
for (int i = 0; i < ring.size(); i++) {
581-
Token start = ring.get(i);
582-
Token end = ring.get((i + 1) % ring.size());
583-
builder.add(new TokenRange(start, end, factory));
580+
// JAVA-684: if there is only one token, return the range ]minToken, minToken]
581+
if(ring.size() == 1) {
582+
builder.add(new TokenRange(factory.minToken(), factory.minToken(), factory));
583+
} else {
584+
for (int i = 0; i < ring.size(); i++) {
585+
Token start = ring.get(i);
586+
Token end = ring.get((i + 1) % ring.size());
587+
builder.add(new TokenRange(start, end, factory));
588+
}
584589
}
585590
return builder.build();
586591
}

driver-core/src/test/java/com/datastax/driver/core/TokenMapTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,26 @@
1616
package com.datastax.driver.core;
1717

1818
import java.nio.ByteBuffer;
19+
import java.util.Collection;
20+
import java.util.Map;
1921
import java.util.Set;
2022

23+
import com.google.common.collect.ImmutableMap;
24+
import com.google.common.collect.Lists;
25+
import com.google.common.collect.Sets;
2126
import org.testng.annotations.*;
2227

28+
import static org.mockito.Mockito.mock;
29+
import static org.testng.Assert.assertEquals;
2330
import static org.testng.Assert.assertFalse;
31+
import static org.assertj.core.api.Assertions.*;
2432

2533
import com.datastax.driver.core.CCMBridge.CCMCluster;
2634

35+
import static com.datastax.driver.core.Token.M3PToken.FACTORY;
36+
2737
/**
28-
* Tests that the token map is correctly initialized at startup (JAVA-415).
38+
* Tests for {@link com.datastax.driver.core.Metadata.TokenMap}.
2939
*/
3040
public class TokenMapTest {
3141
CCMCluster ccmCluster = null;
@@ -37,6 +47,9 @@ public void setup() {
3747
cluster = ccmCluster.cluster;
3848
}
3949

50+
/**
51+
* Tests that the token map is correctly initialized at startup (JAVA-415).
52+
*/
4053
@Test(groups = "short")
4154
public void initTest() {
4255
// If the token map is initialized correctly, we should get replicas for any partition key
@@ -45,6 +58,28 @@ public void initTest() {
4558
assertFalse(replicas.isEmpty());
4659
}
4760

61+
/**
62+
* DEVC-684: Empty TokenRange returned in a one token cluster
63+
*/
64+
@Test(groups = "unit")
65+
public void should_return_single_non_empty_range_when_cluster_has_one_single_token() {
66+
// given a single node cluster with one single token "1"
67+
// ("1" is purposely chosen because it is not the minimum token for the partitioner in use)
68+
Collection<String> tokens = Sets.newHashSet("1");
69+
Map<Host, Collection<String>> allTokens = ImmutableMap.of(mock(Host.class), tokens);
70+
// when the token map is built
71+
Metadata metadata = new Metadata(mock(Cluster.Manager.class));
72+
metadata.rebuildTokenMap("Murmur3Partitioner", allTokens);
73+
// then
74+
Set<TokenRange> tokenRanges = metadata.getTokenRanges();
75+
assertThat(tokenRanges).hasSize(1);
76+
TokenRange tokenRange = tokenRanges.iterator().next();
77+
assertThat(tokenRange.getStart()).isEqualTo(FACTORY.minToken());
78+
assertThat(tokenRange.getEnd()).isEqualTo(FACTORY.minToken());
79+
assertThat(tokenRange.isEmpty()).isFalse();
80+
assertThat(tokenRange.isWrappedAround()).isFalse();
81+
}
82+
4883
@AfterMethod(groups = "short")
4984
public void teardown() {
5085
ccmCluster.discard();

driver-core/src/test/java/com/datastax/driver/core/TokenRangeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void should_compute_intersection() {
8989
}
9090

9191
@Test(groups = "unit")
92-
public void should_could_intersection_with_ranges_around_ring() {
92+
public void should_compute_intersection_with_ranges_around_ring() {
9393
// If a range wraps the ring like 10, -10 does this will produce two separate
9494
// intersected ranges.
9595
assertThat(tokenRange(10, -10).intersectWith(tokenRange(-20, 20)))

driver-examples/osgi/pom.xml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@
122122

123123
<build>
124124
<plugins>
125+
<plugin>
126+
<groupId>org.apache.maven.plugins</groupId>
127+
<artifactId>maven-failsafe-plugin</artifactId>
128+
<version>2.18.1</version>
129+
<executions>
130+
<execution>
131+
<goals>
132+
<goal>integration-test</goal>
133+
<goal>verify</goal>
134+
</goals>
135+
</execution>
136+
</executions>
137+
</plugin>
125138
<plugin>
126139
<groupId>org.apache.felix</groupId>
127140
<artifactId>maven-bundle-plugin</artifactId>
@@ -172,7 +185,14 @@
172185
<artifactId>maven-surefire-plugin</artifactId>
173186
<version>2.14</version>
174187
<configuration>
175-
<skipTests>true</skipTests>
188+
</configuration>
189+
</plugin>
190+
<plugin>
191+
<groupId>org.apache.maven.plugins</groupId>
192+
<artifactId>maven-failsafe-plugin</artifactId>
193+
<version>2.18.1</version>
194+
<configuration>
195+
<skip>true</skip>
176196
</configuration>
177197
</plugin>
178198
<plugin>
@@ -207,6 +227,19 @@
207227
</systemPropertyVariables>
208228
</configuration>
209229
</plugin>
230+
<plugin>
231+
<groupId>org.apache.maven.plugins</groupId>
232+
<artifactId>maven-failsafe-plugin</artifactId>
233+
<version>2.18.1</version>
234+
<configuration>
235+
<groups>unit,short</groups>
236+
<useFile>false</useFile>
237+
<systemPropertyVariables>
238+
<cassandra.version>${cassandra.version}</cassandra.version>
239+
<ipprefix>${ipprefix}</ipprefix>
240+
</systemPropertyVariables>
241+
</configuration>
242+
</plugin>
210243
</plugins>
211244
</build>
212245
</profile>
@@ -231,6 +264,19 @@
231264
</systemPropertyVariables>
232265
</configuration>
233266
</plugin>
267+
<plugin>
268+
<groupId>org.apache.maven.plugins</groupId>
269+
<artifactId>maven-failsafe-plugin</artifactId>
270+
<version>2.18.1</version>
271+
<configuration>
272+
<groups>unit,short,long</groups>
273+
<useFile>false</useFile>
274+
<systemPropertyVariables>
275+
<cassandra.version>${cassandra.version}</cassandra.version>
276+
<ipprefix>${ipprefix}</ipprefix>
277+
</systemPropertyVariables>
278+
</configuration>
279+
</plugin>
234280
</plugins>
235281
</build>
236282
</profile>

driver-examples/osgi/src/main/java/com/datastax/driver/osgi/impl/MailboxImpl.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,24 @@ public synchronized void init() {
7575

7676
retrieveStatement = session.prepare(select()
7777
.from(keyspace, TABLE)
78-
.where(eq("recipient", bindMarker("recipient"))));
78+
.where(eq("recipient", bindMarker())));
7979

8080
insertStatement = session.prepare(insertInto(keyspace, TABLE)
81-
.value("recipient", bindMarker("recipient"))
82-
.value("time", bindMarker("time"))
83-
.value("sender", bindMarker("sender"))
84-
.value("body", bindMarker("body")));
81+
.value("recipient", bindMarker())
82+
.value("time", bindMarker())
83+
.value("sender", bindMarker())
84+
.value("body", bindMarker()));
8585

8686
deleteStatement = session.prepare(delete().from(keyspace, TABLE)
87-
.where(eq("recipient", bindMarker("recipient"))));
87+
.where(eq("recipient", bindMarker())));
8888

8989
initialized = true;
9090
}
9191

9292
@Override public Collection<MailboxMessage> getMessages(String recipient) throws MailboxException {
9393
try {
9494
BoundStatement statement = new BoundStatement(retrieveStatement);
95-
statement.setString("recipient", recipient);
95+
statement.setString(0, recipient);
9696
ResultSet result = session.execute(statement);
9797

9898
Collection<MailboxMessage> messages = new ArrayList<MailboxMessage>();
@@ -114,10 +114,10 @@ public synchronized void init() {
114114
UUID time = UUIDs.startOf(message.getDate().getTime());
115115

116116
BoundStatement statement = new BoundStatement(insertStatement);
117-
statement.setString("recipient", message.getRecipient());
118-
statement.setUUID("time", time);
119-
statement.setString("sender", message.getSender());
120-
statement.setString("body", message.getBody());
117+
statement.setString(0, message.getRecipient());
118+
statement.setUUID(1, time);
119+
statement.setString(2, message.getSender());
120+
statement.setString(3, message.getBody());
121121

122122
session.execute(statement);
123123
return time;
@@ -129,7 +129,7 @@ public synchronized void init() {
129129
@Override public void clearMailbox(String recipient) throws MailboxException {
130130
try {
131131
BoundStatement statement = new BoundStatement(deleteStatement);
132-
statement.setString("recipient", recipient);
132+
statement.setString(0, recipient);
133133
session.execute(statement);
134134
} catch(Exception e) {
135135
throw new MailboxException(e);

driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceTest.java renamed to driver-examples/osgi/src/test/java/com/datastax/driver/osgi/MailboxServiceIT.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.ops4j.pax.exam.Option;
2525
import org.ops4j.pax.exam.options.CompositeOption;
2626
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
27+
import org.ops4j.pax.exam.options.UrlProvisionOption;
2728
import org.ops4j.pax.exam.testng.listener.PaxExam;
2829
import org.testng.annotations.Listeners;
2930
import org.testng.annotations.Test;
@@ -40,11 +41,16 @@
4041

4142
@Listeners({CCMBridgeListener.class, PaxExam.class})
4243
@Test(groups="short")
43-
public class MailboxServiceTest {
44+
public class MailboxServiceIT {
4445
@Inject MailboxService service;
4546

46-
private MavenArtifactProvisionOption driverBundle() {
47-
return mavenBundle("com.datastax.cassandra", "cassandra-driver-core", projectVersion());
47+
private UrlProvisionOption driverBundle() {
48+
return driverBundle(false);
49+
}
50+
51+
private UrlProvisionOption driverBundle(boolean useShaded) {
52+
String classifier = useShaded ? "-shaded" : "";
53+
return bundle("reference:file:../../driver-core/target/cassandra-driver-core-" + projectVersion() + classifier + ".jar");
4854
}
4955

5056
private MavenArtifactProvisionOption guavaBundle() {
@@ -75,7 +81,7 @@ private CompositeOption defaultOptions() {
7581
@Configuration
7682
public Option[] shadedConfig() {
7783
return options(
78-
driverBundle().classifier("shaded"),
84+
driverBundle(true),
7985
guavaBundle(),
8086
defaultOptions()
8187
);

0 commit comments

Comments
 (0)