kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a30aaa55e581b3345cdc852cafd22100080e879d6d9c8ea225b032b38b8f4553 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-03-11 09:05 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-03-11 09:05 +01:00 |
| Parents | ed2d579048cd |
3 files changed
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +5 −3
| @@ -513,9 +513,11 @@ | ||
| 513 | 513 | |
| 514 | 514 | Map<Host, Set<TokenRange>> ksRanges; |
| 515 | 515 | if (ring.size() == 1) { |
| 516 | - // The single range is ]minToken,minToken] which does not necessarily match the host's token | |
| 517 | - assert hosts.size() == 1; | |
| 518 | - ksRanges = ImmutableMap.of(hosts.iterator().next(), tokenRanges); | |
| 516 | + // We forced the single range to ]minToken,minToken], make sure to use that instead of relying on the host's token | |
| 517 | + ImmutableMap.Builder<Host, Set<TokenRange>> builder = ImmutableMap.builder(); | |
| 518 | + for (Host host : allTokens.keySet()) | |
| 519 | + builder.put(host, tokenRanges); | |
| 520 | + ksRanges = builder.build(); | |
| 519 | 521 | } else { |
| 520 | 522 | ksRanges = computeHostsToRangesMap(tokenRanges, ksTokens, hosts.size()); |
| 521 | 523 | } |
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +1 −1
| @@ -178,7 +178,7 @@ | ||
| 178 | 178 | |
| 179 | 179 | public void bootstrapNode(int n, String dc) { |
| 180 | 180 | if (dc == null) |
| 181 | - execute("ccm add node%d -i %s%d -j %d -b -s", n, IP_PREFIX, n, 7000 + 100*n); | |
| 181 | + execute("ccm add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100*n, 8000 + 100*n); | |
| 182 | 182 | else |
| 183 | 183 | execute("ccm add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100*n, dc); |
| 184 | 184 | execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n); |
modified driver-core/src/test/java/com/datastax/driver/core/SingleTokenIntegrationTest.java +16 −5
| @@ -15,10 +15,13 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import java.nio.ByteBuffer; | |
| 18 | 19 | import java.util.Set; |
| 19 | 20 | |
| 20 | 21 | import org.testng.annotations.Test; |
| 21 | 22 | |
| 23 | +import com.datastax.driver.core.utils.Bytes; | |
| 24 | + | |
| 22 | 25 | import static com.datastax.driver.core.Assertions.assertThat; |
| 23 | 26 | |
| 24 | 27 | public class SingleTokenIntegrationTest { |
| @@ -32,7 +35,7 @@ | ||
| 32 | 35 | |
| 33 | 36 | try { |
| 34 | 37 | ccm = CCMBridge.create("test"); |
| 35 | - // Set an initial token that is not the minimum | |
| 38 | + // force the initial token to a non-min value to validate that the single range will always be ]minToken, minToken] | |
| 36 | 39 | ccm.updateConfig("initial_token", "1"); |
| 37 | 40 | ccm.bootstrapNode(1); |
| 38 | 41 | ccm.start(); |
| @@ -42,7 +45,9 @@ | ||
| 42 | 45 | Session session = cluster.connect(); |
| 43 | 46 | session.execute("create keyspace test with replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"); |
| 44 | 47 | |
| 45 | - Set<TokenRange> tokenRanges = cluster.getMetadata().getTokenRanges(); | |
| 48 | + Metadata metadata = cluster.getMetadata(); | |
| 49 | + | |
| 50 | + Set<TokenRange> tokenRanges = metadata.getTokenRanges(); | |
| 46 | 51 | assertThat(tokenRanges).hasSize(1); |
| 47 | 52 | TokenRange tokenRange = tokenRanges.iterator().next(); |
| 48 | 53 | assertThat(tokenRange) |
| @@ -51,10 +56,16 @@ | ||
| 51 | 56 | .isNotEmpty() |
| 52 | 57 | .isNotWrappedAround(); |
| 53 | 58 | |
| 54 | - Set<Host> rangeHosts = cluster.getMetadata().getReplicas("test", tokenRange); | |
| 55 | - assertThat(rangeHosts) | |
| 56 | - .containsOnly(TestUtils.findHost(cluster, 1)); | |
| 59 | + Set<Host> hostsForRange = metadata.getReplicas("test", tokenRange); | |
| 60 | + Host host1 = TestUtils.findHost(cluster, 1); | |
| 61 | + assertThat(hostsForRange).containsOnly(host1); | |
| 62 | + | |
| 63 | + ByteBuffer randomPartitionKey = Bytes.fromHexString("0xCAFEBABE"); | |
| 64 | + Set<Host> hostsForKey = metadata.getReplicas("test", randomPartitionKey); | |
| 65 | + assertThat(hostsForKey).containsOnly(host1); | |
| 57 | 66 | |
| 67 | + Set<TokenRange> rangesForHost = metadata.getTokenRanges("test", host1); | |
| 68 | + assertThat(rangesForHost).containsOnly(tokenRange); | |
| 58 | 69 | } finally { |
| 59 | 70 | if (cluster != null) |
| 60 | 71 | cluster.close(); |