http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/dht/RangeFetchMapCalculatorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/dht/RangeFetchMapCalculatorTest.java b/test/unit/org/apache/cassandra/dht/RangeFetchMapCalculatorTest.java index 1b3fe03..78e87c1 100644 --- a/test/unit/org/apache/cassandra/dht/RangeFetchMapCalculatorTest.java +++ b/test/unit/org/apache/cassandra/dht/RangeFetchMapCalculatorTest.java @@ -18,7 +18,6 @@ package org.apache.cassandra.dht; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; @@ -34,6 +33,7 @@ import org.junit.Test; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.locator.AbstractNetworkTopologySnitch; +import org.apache.cassandra.locator.InetAddressAndPort; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -50,13 +50,13 @@ public class RangeFetchMapCalculatorTest //Odd IPs are in DC1 and Even are in DC2. Endpoints upto .14 will have unique racks and // then will be same for a set of three. @Override - public String getRack(InetAddress endpoint) + public String getRack(InetAddressAndPort endpoint) { return "RAC1"; } @Override - public String getDatacenter(InetAddress endpoint) + public String getDatacenter(InetAddressAndPort endpoint) { if (getIPLastPart(endpoint) <= 50) return DatabaseDescriptor.getLocalDataCenter(); @@ -66,9 +66,9 @@ public class RangeFetchMapCalculatorTest return DatabaseDescriptor.getLocalDataCenter() + "Remote"; } - private int getIPLastPart(InetAddress endpoint) + private int getIPLastPart(InetAddressAndPort endpoint) { - String str = endpoint.toString(); + String str = endpoint.address.toString(); int index = str.lastIndexOf("."); return Integer.parseInt(str.substring(index + 1).trim()); } @@ -78,7 +78,7 @@ public class RangeFetchMapCalculatorTest @Test public void testWithSingleSource() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.1"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.2"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.3"); @@ -86,7 +86,7 @@ public class RangeFetchMapCalculatorTest addNonTrivialRangeAndSources(rangesWithSources, 41, 50, "127.0.0.5"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, new ArrayList<RangeStreamer.ISourceFilter>(), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); Assert.assertEquals(4, map.asMap().keySet().size()); @@ -95,7 +95,7 @@ public class RangeFetchMapCalculatorTest @Test public void testWithNonOverlappingSource() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.1", "127.0.0.2"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.3", "127.0.0.4"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.5", "127.0.0.6"); @@ -103,7 +103,7 @@ public class RangeFetchMapCalculatorTest addNonTrivialRangeAndSources(rangesWithSources, 41, 50, "127.0.0.9", "127.0.0.10"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, new ArrayList<RangeStreamer.ISourceFilter>(), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); Assert.assertEquals(5, map.asMap().keySet().size()); @@ -112,13 +112,13 @@ public class RangeFetchMapCalculatorTest @Test public void testWithRFThreeReplacement() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.1", "127.0.0.2"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.2", "127.0.0.3"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.3", "127.0.0.4"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, new ArrayList<RangeStreamer.ISourceFilter>(), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); //We should validate that it streamed from 3 unique sources @@ -128,7 +128,7 @@ public class RangeFetchMapCalculatorTest @Test public void testForMultipleRoundsComputation() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.3"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.3"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.3"); @@ -136,21 +136,21 @@ public class RangeFetchMapCalculatorTest addNonTrivialRangeAndSources(rangesWithSources, 41, 50, "127.0.0.3", "127.0.0.2"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, new ArrayList<RangeStreamer.ISourceFilter>(), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); //We should validate that it streamed from 2 unique sources Assert.assertEquals(2, map.asMap().keySet().size()); assertArrays(Arrays.asList(generateNonTrivialRange(1, 10), generateNonTrivialRange(11, 20), generateNonTrivialRange(21, 30), generateNonTrivialRange(31, 40)), - map.asMap().get(InetAddress.getByName("127.0.0.3"))); - assertArrays(Arrays.asList(generateNonTrivialRange(41, 50)), map.asMap().get(InetAddress.getByName("127.0.0.2"))); + map.asMap().get(InetAddressAndPort.getByName("127.0.0.3"))); + assertArrays(Arrays.asList(generateNonTrivialRange(41, 50)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.2"))); } @Test public void testForMultipleRoundsComputationWithLocalHost() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.1"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.1"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.1"); @@ -158,19 +158,19 @@ public class RangeFetchMapCalculatorTest addNonTrivialRangeAndSources(rangesWithSources, 41, 50, "127.0.0.1", "127.0.0.2"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, new ArrayList<RangeStreamer.ISourceFilter>(), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); //We should validate that it streamed from only non local host and only one range Assert.assertEquals(1, map.asMap().keySet().size()); - assertArrays(Arrays.asList(generateNonTrivialRange(41, 50)), map.asMap().get(InetAddress.getByName("127.0.0.2"))); + assertArrays(Arrays.asList(generateNonTrivialRange(41, 50)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.2"))); } @Test public void testForEmptyGraph() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.1"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.1"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.1"); @@ -178,7 +178,7 @@ public class RangeFetchMapCalculatorTest addNonTrivialRangeAndSources(rangesWithSources, 41, 50, "127.0.0.1"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, new ArrayList<RangeStreamer.ISourceFilter>(), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); //All ranges map to local host so we will not stream anything. assertTrue(map.isEmpty()); } @@ -186,7 +186,7 @@ public class RangeFetchMapCalculatorTest @Test public void testWithNoSourceWithLocal() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.1", "127.0.0.5"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.2"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.3"); @@ -194,11 +194,11 @@ public class RangeFetchMapCalculatorTest //Return false for all except 127.0.0.5 final RangeStreamer.ISourceFilter filter = new RangeStreamer.ISourceFilter() { - public boolean shouldInclude(InetAddress endpoint) + public boolean shouldInclude(InetAddressAndPort endpoint) { try { - if (endpoint.equals(InetAddress.getByName("127.0.0.5"))) + if (endpoint.equals(InetAddressAndPort.getByName("127.0.0.5"))) return false; else return true; @@ -211,28 +211,28 @@ public class RangeFetchMapCalculatorTest }; RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, Arrays.asList(filter), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); //We should validate that it streamed from only non local host and only one range Assert.assertEquals(2, map.asMap().keySet().size()); - assertArrays(Arrays.asList(generateNonTrivialRange(11, 20)), map.asMap().get(InetAddress.getByName("127.0.0.2"))); - assertArrays(Arrays.asList(generateNonTrivialRange(21, 30)), map.asMap().get(InetAddress.getByName("127.0.0.3"))); + assertArrays(Arrays.asList(generateNonTrivialRange(11, 20)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.2"))); + assertArrays(Arrays.asList(generateNonTrivialRange(21, 30)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.3"))); } @Test (expected = IllegalStateException.class) public void testWithNoLiveSource() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.5"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.2"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.3"); final RangeStreamer.ISourceFilter allDeadFilter = new RangeStreamer.ISourceFilter() { - public boolean shouldInclude(InetAddress endpoint) + public boolean shouldInclude(InetAddressAndPort endpoint) { return false; } @@ -245,25 +245,25 @@ public class RangeFetchMapCalculatorTest @Test public void testForLocalDC() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.1", "127.0.0.3", "127.0.0.53"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.1", "127.0.0.3", "127.0.0.57"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.2", "127.0.0.59", "127.0.0.61"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, new ArrayList<>(), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); Assert.assertEquals(2, map.asMap().size()); //Should have streamed from local DC endpoints - assertArrays(Arrays.asList(generateNonTrivialRange(21, 30)), map.asMap().get(InetAddress.getByName("127.0.0.2"))); - assertArrays(Arrays.asList(generateNonTrivialRange(1, 10), generateNonTrivialRange(11, 20)), map.asMap().get(InetAddress.getByName("127.0.0.3"))); + assertArrays(Arrays.asList(generateNonTrivialRange(21, 30)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.2"))); + assertArrays(Arrays.asList(generateNonTrivialRange(1, 10), generateNonTrivialRange(11, 20)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.3"))); } @Test public void testForRemoteDC() throws Exception { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.3", "127.0.0.51"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.3", "127.0.0.55"); addNonTrivialRangeAndSources(rangesWithSources, 21, 30, "127.0.0.2", "127.0.0.59"); @@ -271,11 +271,11 @@ public class RangeFetchMapCalculatorTest //Reject only 127.0.0.3 and accept everyone else final RangeStreamer.ISourceFilter localHostFilter = new RangeStreamer.ISourceFilter() { - public boolean shouldInclude(InetAddress endpoint) + public boolean shouldInclude(InetAddressAndPort endpoint) { try { - if (endpoint.equals(InetAddress.getByName("127.0.0.3"))) + if (endpoint.equals(InetAddressAndPort.getByName("127.0.0.3"))) return false; else return true; @@ -288,20 +288,20 @@ public class RangeFetchMapCalculatorTest }; RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, Arrays.asList(localHostFilter), "Test"); - Multimap<InetAddress, Range<Token>> map = calculator.getRangeFetchMap(); + Multimap<InetAddressAndPort, Range<Token>> map = calculator.getRangeFetchMap(); validateRange(rangesWithSources, map); Assert.assertEquals(3, map.asMap().size()); //Should have streamed from remote DC endpoint - assertArrays(Arrays.asList(generateNonTrivialRange(1, 10)), map.asMap().get(InetAddress.getByName("127.0.0.51"))); - assertArrays(Arrays.asList(generateNonTrivialRange(11, 20)), map.asMap().get(InetAddress.getByName("127.0.0.55"))); - assertArrays(Arrays.asList(generateNonTrivialRange(21, 30)), map.asMap().get(InetAddress.getByName("127.0.0.2"))); + assertArrays(Arrays.asList(generateNonTrivialRange(1, 10)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.51"))); + assertArrays(Arrays.asList(generateNonTrivialRange(11, 20)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.55"))); + assertArrays(Arrays.asList(generateNonTrivialRange(21, 30)), map.asMap().get(InetAddressAndPort.getByName("127.0.0.2"))); } @Test public void testTrivialRanges() throws UnknownHostException { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); // add non-trivial ranges addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.3", "127.0.0.51"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.3", "127.0.0.55"); @@ -309,17 +309,17 @@ public class RangeFetchMapCalculatorTest // and a trivial one: addTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.3", "127.0.0.51"); RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, Collections.emptyList(), "Test"); - Multimap<InetAddress, Range<Token>> optMap = calculator.getRangeFetchMapForNonTrivialRanges(); - Multimap<InetAddress, Range<Token>> trivialMap = calculator.getRangeFetchMapForTrivialRanges(optMap); - assertTrue(trivialMap.get(InetAddress.getByName("127.0.0.3")).contains(generateTrivialRange(1,10)) ^ - trivialMap.get(InetAddress.getByName("127.0.0.51")).contains(generateTrivialRange(1,10))); + Multimap<InetAddressAndPort, Range<Token>> optMap = calculator.getRangeFetchMapForNonTrivialRanges(); + Multimap<InetAddressAndPort, Range<Token>> trivialMap = calculator.getRangeFetchMapForTrivialRanges(optMap); + assertTrue(trivialMap.get(InetAddressAndPort.getByName("127.0.0.3")).contains(generateTrivialRange(1,10)) ^ + trivialMap.get(InetAddressAndPort.getByName("127.0.0.51")).contains(generateTrivialRange(1,10))); assertFalse(optMap.containsKey(generateTrivialRange(1, 10))); } @Test(expected = IllegalStateException.class) public void testNotEnoughEndpointsForTrivialRange() throws UnknownHostException { - Multimap<Range<Token>, InetAddress> rangesWithSources = HashMultimap.create(); + Multimap<Range<Token>, InetAddressAndPort> rangesWithSources = HashMultimap.create(); // add non-trivial ranges addNonTrivialRangeAndSources(rangesWithSources, 1, 10, "127.0.0.3", "127.0.0.51"); addNonTrivialRangeAndSources(rangesWithSources, 11, 20, "127.0.0.3", "127.0.0.55"); @@ -329,11 +329,11 @@ public class RangeFetchMapCalculatorTest RangeStreamer.ISourceFilter filter = new RangeStreamer.ISourceFilter() { - public boolean shouldInclude(InetAddress endpoint) + public boolean shouldInclude(InetAddressAndPort endpoint) { try { - if (endpoint.equals(InetAddress.getByName("127.0.0.3"))) + if (endpoint.equals(InetAddressAndPort.getByName("127.0.0.3"))) return false; } catch (UnknownHostException e) @@ -344,8 +344,8 @@ public class RangeFetchMapCalculatorTest } }; RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(rangesWithSources, Collections.singleton(filter), "Test"); - Multimap<InetAddress, Range<Token>> optMap = calculator.getRangeFetchMapForNonTrivialRanges(); - Multimap<InetAddress, Range<Token>> trivialMap = calculator.getRangeFetchMapForTrivialRanges(optMap); + Multimap<InetAddressAndPort, Range<Token>> optMap = calculator.getRangeFetchMapForNonTrivialRanges(); + Multimap<InetAddressAndPort, Range<Token>> trivialMap = calculator.getRangeFetchMapForTrivialRanges(optMap); } @@ -355,35 +355,35 @@ public class RangeFetchMapCalculatorTest assertTrue(result.containsAll(expected)); } - private void validateRange(Multimap<Range<Token>, InetAddress> rangesWithSources, Multimap<InetAddress, Range<Token>> result) + private void validateRange(Multimap<Range<Token>, InetAddressAndPort> rangesWithSources, Multimap<InetAddressAndPort, Range<Token>> result) { - for (Map.Entry<InetAddress, Range<Token>> entry : result.entries()) + for (Map.Entry<InetAddressAndPort, Range<Token>> entry : result.entries()) { assertTrue(rangesWithSources.get(entry.getValue()).contains(entry.getKey())); } } - private void addNonTrivialRangeAndSources(Multimap<Range<Token>, InetAddress> rangesWithSources, int left, int right, String... hosts) throws UnknownHostException + private void addNonTrivialRangeAndSources(Multimap<Range<Token>, InetAddressAndPort> rangesWithSources, int left, int right, String... hosts) throws UnknownHostException { - for (InetAddress endpoint : makeAddrs(hosts)) + for (InetAddressAndPort endpoint : makeAddrs(hosts)) { rangesWithSources.put(generateNonTrivialRange(left, right), endpoint); } } - private void addTrivialRangeAndSources(Multimap<Range<Token>, InetAddress> rangesWithSources, int left, int right, String... hosts) throws UnknownHostException + private void addTrivialRangeAndSources(Multimap<Range<Token>, InetAddressAndPort> rangesWithSources, int left, int right, String... hosts) throws UnknownHostException { - for (InetAddress endpoint : makeAddrs(hosts)) + for (InetAddressAndPort endpoint : makeAddrs(hosts)) { rangesWithSources.put(generateTrivialRange(left, right), endpoint); } } - private Collection<InetAddress> makeAddrs(String... hosts) throws UnknownHostException + private Collection<InetAddressAndPort> makeAddrs(String... hosts) throws UnknownHostException { - ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(hosts.length); + ArrayList<InetAddressAndPort> addrs = new ArrayList<>(hosts.length); for (String host : hosts) - addrs.add(InetAddress.getByName(host)); + addrs.add(InetAddressAndPort.getByName(host)); return addrs; }
http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/dht/StreamStateStoreTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/dht/StreamStateStoreTest.java b/test/unit/org/apache/cassandra/dht/StreamStateStoreTest.java index b5f8036..ad5f8f5 100644 --- a/test/unit/org/apache/cassandra/dht/StreamStateStoreTest.java +++ b/test/unit/org/apache/cassandra/dht/StreamStateStoreTest.java @@ -17,13 +17,13 @@ */ package org.apache.cassandra.dht; -import java.net.InetAddress; import java.util.Collections; import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.streaming.DefaultConnectionFactory; import org.apache.cassandra.streaming.PreviewKind; import org.apache.cassandra.streaming.StreamEvent; @@ -50,7 +50,7 @@ public class StreamStateStoreTest Token.TokenFactory factory = p.getTokenFactory(); Range<Token> range = new Range<>(factory.fromString("0"), factory.fromString("100")); - InetAddress local = FBUtilities.getBroadcastAddress(); + InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort(); StreamSession session = new StreamSession(local, local, new DefaultConnectionFactory(), 0, true, null, PreviewKind.NONE); session.addStreamRequest("keyspace1", Collections.singleton(range), Collections.singleton("cf")); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java b/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java index 511511b..ea59300 100644 --- a/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java +++ b/test/unit/org/apache/cassandra/gms/ArrivalWindowTest.java @@ -25,9 +25,8 @@ import static org.junit.Assert.*; import org.junit.Test; -import java.lang.RuntimeException; -import java.net.InetAddress; -import java.net.UnknownHostException; +import org.apache.cassandra.locator.InetAddressAndPort; +import org.apache.cassandra.utils.FBUtilities; public class ArrivalWindowTest { @@ -36,15 +35,7 @@ public class ArrivalWindowTest { final ArrivalWindow windowWithNano = new ArrivalWindow(4); final long toNano = 1000000L; - InetAddress ep; - try - { - ep = InetAddress.getLocalHost(); - } - catch (UnknownHostException e) - { - throw new RuntimeException(e); - } + InetAddressAndPort ep = FBUtilities.getLocalAddressAndPort(); windowWithNano.add(111 * toNano, ep); windowWithNano.add(222 * toNano, ep); windowWithNano.add(333 * toNano, ep); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/gms/EndpointStateTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/gms/EndpointStateTest.java b/test/unit/org/apache/cassandra/gms/EndpointStateTest.java index 2453fe8..6e0cc75 100644 --- a/test/unit/org/apache/cassandra/gms/EndpointStateTest.java +++ b/test/unit/org/apache/cassandra/gms/EndpointStateTest.java @@ -72,7 +72,7 @@ public class EndpointStateTest public void run() { state.addApplicationState(ApplicationState.TOKENS, valueFactory.tokens(tokens)); - state.addApplicationState(ApplicationState.STATUS, valueFactory.normal(tokens)); + state.addApplicationState(ApplicationState.STATUS_WITH_PORT, valueFactory.normal(tokens)); } }); @@ -86,7 +86,7 @@ public class EndpointStateTest for (Map.Entry<ApplicationState, VersionedValue> entry : state.states()) values.put(entry.getKey(), entry.getValue()); - if (values.containsKey(ApplicationState.STATUS) && !values.containsKey(ApplicationState.TOKENS)) + if (values.containsKey(ApplicationState.STATUS_WITH_PORT) && !values.containsKey(ApplicationState.TOKENS)) { numFailures.incrementAndGet(); System.out.println(String.format("Failed: %s", values)); @@ -129,7 +129,7 @@ public class EndpointStateTest { Map<ApplicationState, VersionedValue> states = new EnumMap<>(ApplicationState.class); states.put(ApplicationState.TOKENS, valueFactory.tokens(tokens)); - states.put(ApplicationState.STATUS, valueFactory.normal(tokens)); + states.put(ApplicationState.STATUS_WITH_PORT, valueFactory.normal(tokens)); state.addApplicationStates(states); } }); @@ -158,7 +158,7 @@ public class EndpointStateTest for (Map.Entry<ApplicationState, VersionedValue> entry : states) values.put(entry.getKey(), entry.getValue()); - assertTrue(values.containsKey(ApplicationState.STATUS)); + assertTrue(values.containsKey(ApplicationState.STATUS_WITH_PORT)); assertTrue(values.containsKey(ApplicationState.TOKENS)); assertTrue(values.containsKey(ApplicationState.INTERNAL_IP)); assertTrue(values.containsKey(ApplicationState.HOST_ID)); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/gms/FailureDetectorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/gms/FailureDetectorTest.java b/test/unit/org/apache/cassandra/gms/FailureDetectorTest.java index dca00b1..554e894 100644 --- a/test/unit/org/apache/cassandra/gms/FailureDetectorTest.java +++ b/test/unit/org/apache/cassandra/gms/FailureDetectorTest.java @@ -18,7 +18,6 @@ package org.apache.cassandra.gms; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; @@ -33,6 +32,7 @@ import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.RandomPartitioner; import org.apache.cassandra.dht.Token; +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.locator.TokenMetadata; import org.apache.cassandra.service.StorageService; @@ -60,7 +60,7 @@ public class FailureDetectorTest ArrayList<Token> endpointTokens = new ArrayList<>(); ArrayList<Token> keyTokens = new ArrayList<>(); - List<InetAddress> hosts = new ArrayList<>(); + List<InetAddressAndPort> hosts = new ArrayList<>(); List<UUID> hostIds = new ArrayList<>(); // we want to convict if there is any heartbeat data present in the FD @@ -69,12 +69,12 @@ public class FailureDetectorTest // create a ring of 2 nodes Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 3); - InetAddress leftHost = hosts.get(1); + InetAddressAndPort leftHost = hosts.get(1); FailureDetector.instance.report(leftHost); // trigger handleStateLeft in StorageService - ss.onChange(leftHost, ApplicationState.STATUS, + ss.onChange(leftHost, ApplicationState.STATUS_WITH_PORT, valueFactory.left(Collections.singleton(endpointTokens.get(1)), Gossiper.computeExpireTime())); // confirm that handleStateLeft was called and leftEndpoint was removed from TokenMetadata http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/gms/GossipDigestTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/gms/GossipDigestTest.java b/test/unit/org/apache/cassandra/gms/GossipDigestTest.java index 3191b03..cb67a54 100644 --- a/test/unit/org/apache/cassandra/gms/GossipDigestTest.java +++ b/test/unit/org/apache/cassandra/gms/GossipDigestTest.java @@ -26,8 +26,7 @@ import org.apache.cassandra.io.util.DataInputBuffer; import org.apache.cassandra.io.util.DataInputPlus; import org.apache.cassandra.io.util.DataOutputBuffer; -import java.net.InetAddress; - +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.net.MessagingService; import org.junit.Test; @@ -36,7 +35,7 @@ public class GossipDigestTest @Test public void test() throws IOException { - InetAddress endpoint = InetAddress.getByName("127.0.0.1"); + InetAddressAndPort endpoint = InetAddressAndPort.getByName("127.0.0.1"); int generation = 0; int maxVersion = 123; GossipDigest expected = new GossipDigest(endpoint, generation, maxVersion); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/gms/GossiperTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/gms/GossiperTest.java b/test/unit/org/apache/cassandra/gms/GossiperTest.java index 83f12d1..8c65cb4 100644 --- a/test/unit/org/apache/cassandra/gms/GossiperTest.java +++ b/test/unit/org/apache/cassandra/gms/GossiperTest.java @@ -18,7 +18,6 @@ package org.apache.cassandra.gms; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; @@ -33,6 +32,7 @@ import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.RandomPartitioner; import org.apache.cassandra.dht.Token; +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.locator.TokenMetadata; import org.apache.cassandra.service.StorageService; @@ -49,7 +49,7 @@ public class GossiperTest TokenMetadata tmd = StorageService.instance.getTokenMetadata(); ArrayList<Token> endpointTokens = new ArrayList<>(); ArrayList<Token> keyTokens = new ArrayList<>(); - List<InetAddress> hosts = new ArrayList<>(); + List<InetAddressAndPort> hosts = new ArrayList<>(); List<UUID> hostIds = new ArrayList<>(); @Before @@ -62,7 +62,7 @@ public class GossiperTest public void testLargeGenerationJump() throws UnknownHostException, InterruptedException { Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 2); - InetAddress remoteHostAddress = hosts.get(1); + InetAddressAndPort remoteHostAddress = hosts.get(1); EndpointState initialRemoteState = Gossiper.instance.getEndpointStateForEndpoint(remoteHostAddress); HeartBeatState initialRemoteHeartBeat = initialRemoteState.getHeartBeatState(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/gms/PendingRangeCalculatorServiceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/gms/PendingRangeCalculatorServiceTest.java b/test/unit/org/apache/cassandra/gms/PendingRangeCalculatorServiceTest.java index 0939db0..833ee8b 100644 --- a/test/unit/org/apache/cassandra/gms/PendingRangeCalculatorServiceTest.java +++ b/test/unit/org/apache/cassandra/gms/PendingRangeCalculatorServiceTest.java @@ -18,7 +18,6 @@ package org.apache.cassandra.gms; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collection; @@ -35,6 +34,7 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.dht.ByteOrderedPartitioner; import org.apache.cassandra.dht.Token; import org.apache.cassandra.exceptions.ConfigurationException; +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.service.StorageService; import org.jboss.byteman.contrib.bmunit.BMRule; import org.jboss.byteman.contrib.bmunit.BMUnitRunner; @@ -66,7 +66,7 @@ public class PendingRangeCalculatorServiceTest action = "org.apache.cassandra.gms.PendingRangeCalculatorServiceTest.calculationLock.lock()") public void testDelayedResponse() throws UnknownHostException, InterruptedException { - InetAddress otherNodeAddr = InetAddress.getByName("127.0.0.2"); + InetAddressAndPort otherNodeAddr = InetAddressAndPort.getByName("127.0.0.2"); UUID otherHostId = UUID.randomUUID(); // introduce node for first major state change @@ -112,7 +112,7 @@ public class PendingRangeCalculatorServiceTest } } - private Map<InetAddress, EndpointState> getStates(InetAddress otherNodeAddr, UUID hostId, int ver, boolean bootstrapping) + private Map<InetAddressAndPort, EndpointState> getStates(InetAddressAndPort otherNodeAddr, UUID hostId, int ver, boolean bootstrapping) { HeartBeatState hb = new HeartBeatState(1, ver); EndpointState state = new EndpointState(hb); @@ -125,7 +125,7 @@ public class PendingRangeCalculatorServiceTest state.addApplicationState(ApplicationState.HOST_ID, StorageService.instance.valueFactory.hostId(hostId)); state.addApplicationState(ApplicationState.NET_VERSION, StorageService.instance.valueFactory.networkVersion()); - Map<InetAddress, EndpointState> states = new HashMap<>(); + Map<InetAddressAndPort, EndpointState> states = new HashMap<>(); states.put(otherNodeAddr, state); return states; } http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/gms/SerializationsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/gms/SerializationsTest.java b/test/unit/org/apache/cassandra/gms/SerializationsTest.java index 0df266f..90ce10b 100644 --- a/test/unit/org/apache/cassandra/gms/SerializationsTest.java +++ b/test/unit/org/apache/cassandra/gms/SerializationsTest.java @@ -24,6 +24,7 @@ import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.Token; import org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus; import org.apache.cassandra.io.util.DataOutputStreamPlus; +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.FBUtilities; @@ -31,7 +32,6 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.IOException; -import java.net.InetAddress; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -78,9 +78,9 @@ public class SerializationsTest extends AbstractSerializationsTester private void testGossipDigestWrite() throws IOException { - Map<InetAddress, EndpointState> states = new HashMap<InetAddress, EndpointState>(); - states.put(InetAddress.getByName("127.0.0.1"), Statics.EndpointSt); - states.put(InetAddress.getByName("127.0.0.2"), Statics.EndpointSt); + Map<InetAddressAndPort, EndpointState> states = new HashMap<>(); + states.put(InetAddressAndPort.getByName("127.0.0.1"), Statics.EndpointSt); + states.put(InetAddressAndPort.getByName("127.0.0.2"), Statics.EndpointSt); GossipDigestAck ack = new GossipDigestAck(Statics.Digests, states); GossipDigestAck2 ack2 = new GossipDigestAck2(states); GossipDigestSyn syn = new GossipDigestSyn("Not a real cluster name", @@ -132,9 +132,9 @@ public class SerializationsTest extends AbstractSerializationsTester { HeartbeatSt.updateHeartBeat(); EndpointSt.addApplicationState(ApplicationState.LOAD, vv0); - EndpointSt.addApplicationState(ApplicationState.STATUS, vv1); + EndpointSt.addApplicationState(ApplicationState.STATUS_WITH_PORT, vv1); for (int i = 0; i < 100; i++) - Digests.add(new GossipDigest(FBUtilities.getBroadcastAddress(), 100 + i, 1000 + 2 * i)); + Digests.add(new GossipDigest(FBUtilities.getBroadcastAddressAndPort(), 100 + i, 1000 + 2 * i)); } } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/hints/HintTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/HintTest.java b/test/unit/org/apache/cassandra/hints/HintTest.java index 23189e1..e8960f5 100644 --- a/test/unit/org/apache/cassandra/hints/HintTest.java +++ b/test/unit/org/apache/cassandra/hints/HintTest.java @@ -18,7 +18,6 @@ package org.apache.cassandra.hints; import java.io.IOException; -import java.net.InetAddress; import java.util.Collections; import java.util.UUID; @@ -39,6 +38,7 @@ import org.apache.cassandra.dht.BootStrapper; import org.apache.cassandra.io.util.DataInputBuffer; import org.apache.cassandra.io.util.DataInputPlus; import org.apache.cassandra.io.util.DataOutputBuffer; +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.locator.TokenMetadata; import org.apache.cassandra.metrics.StorageMetrics; import org.apache.cassandra.net.MessageIn; @@ -81,7 +81,7 @@ public class HintTest public void resetGcGraceSeconds() { TokenMetadata tokenMeta = StorageService.instance.getTokenMetadata(); - InetAddress local = FBUtilities.getBroadcastAddress(); + InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort(); tokenMeta.clearUnsafe(); tokenMeta.updateHostId(UUID.randomUUID(), local); tokenMeta.updateNormalTokens(BootStrapper.getRandomTokens(tokenMeta, 1), local); @@ -230,8 +230,8 @@ public class HintTest // Prepare metadata with injected stale endpoint serving the mutation key. TokenMetadata tokenMeta = StorageService.instance.getTokenMetadata(); - InetAddress local = FBUtilities.getBroadcastAddress(); - InetAddress endpoint = InetAddress.getByName("1.1.1.1"); + InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort(); + InetAddressAndPort endpoint = InetAddressAndPort.getByName("1.1.1.1"); UUID localId = StorageService.instance.getLocalHostUUID(); UUID targetId = UUID.randomUUID(); tokenMeta.updateHostId(targetId, endpoint); @@ -271,8 +271,8 @@ public class HintTest // Prepare metadata with injected stale endpoint. TokenMetadata tokenMeta = StorageService.instance.getTokenMetadata(); - InetAddress local = FBUtilities.getBroadcastAddress(); - InetAddress endpoint = InetAddress.getByName("1.1.1.1"); + InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort(); + InetAddressAndPort endpoint = InetAddressAndPort.getByName("1.1.1.1"); UUID localId = StorageService.instance.getLocalHostUUID(); UUID targetId = UUID.randomUUID(); tokenMeta.updateHostId(targetId, endpoint); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/hints/HintsServiceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/hints/HintsServiceTest.java b/test/unit/org/apache/cassandra/hints/HintsServiceTest.java index 2da8993..b71140f 100644 --- a/test/unit/org/apache/cassandra/hints/HintsServiceTest.java +++ b/test/unit/org/apache/cassandra/hints/HintsServiceTest.java @@ -17,7 +17,6 @@ */ package org.apache.cassandra.hints; -import java.net.InetAddress; import java.util.Collections; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -34,6 +33,7 @@ import org.junit.Test; import com.datastax.driver.core.utils.MoreFutures; import org.apache.cassandra.SchemaLoader; +import org.apache.cassandra.locator.InetAddressAndPort; import org.apache.cassandra.schema.TableMetadata; import org.apache.cassandra.schema.Schema; import org.apache.cassandra.db.DecoratedKey; @@ -182,7 +182,7 @@ public class HintsServiceTest private MockMessagingSpy sendHintsAndResponses(int noOfHints, int noOfResponses) { // create spy for hint messages, but only create responses for noOfResponses hints - MessageIn<HintResponse> messageIn = MessageIn.create(FBUtilities.getBroadcastAddress(), + MessageIn<HintResponse> messageIn = MessageIn.create(FBUtilities.getBroadcastAddressAndPort(), HintResponse.instance, Collections.emptyMap(), MessagingService.Verb.REQUEST_RESPONSE, @@ -217,17 +217,17 @@ public class HintsServiceTest { private boolean isAlive = true; - public boolean isAlive(InetAddress ep) + public boolean isAlive(InetAddressAndPort ep) { return isAlive; } - public void interpret(InetAddress ep) + public void interpret(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } - public void report(InetAddress ep) + public void report(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } @@ -242,12 +242,12 @@ public class HintsServiceTest throw new UnsupportedOperationException(); } - public void remove(InetAddress ep) + public void remove(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } - public void forceConviction(InetAddress ep) + public void forceConviction(InetAddressAndPort ep) { throw new UnsupportedOperationException(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java b/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java index d63d6c3..dbb929d 100644 --- a/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java @@ -650,7 +650,7 @@ public class CQLSSTableWriterTest { this.keyspace = keyspace; for (Range<Token> range : StorageService.instance.getLocalRanges(ks)) - addRangeForEndpoint(range, FBUtilities.getBroadcastAddress()); + addRangeForEndpoint(range, FBUtilities.getBroadcastAddressAndPort()); } public TableMetadataRef getTableMetadata(String cfName) http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java index 6e7d173..8fc69bf 100644 --- a/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/LegacySSTableTest.java @@ -215,7 +215,7 @@ public class LegacySSTableTest details.add(new StreamSession.SSTableStreamingSections(sstable.ref(), sstable.getPositionsForRanges(ranges), sstable.estimatedKeysForRanges(ranges))); - new StreamPlan(StreamOperation.OTHER).transferFiles(FBUtilities.getBroadcastAddress(), details) + new StreamPlan(StreamOperation.OTHER).transferFiles(FBUtilities.getBroadcastAddressAndPort(), details) .execute().get(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/io/sstable/SSTableLoaderTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/io/sstable/SSTableLoaderTest.java b/test/unit/org/apache/cassandra/io/sstable/SSTableLoaderTest.java index 4f3739f..430b7c2 100644 --- a/test/unit/org/apache/cassandra/io/sstable/SSTableLoaderTest.java +++ b/test/unit/org/apache/cassandra/io/sstable/SSTableLoaderTest.java @@ -104,7 +104,7 @@ public class SSTableLoaderTest { this.keyspace = keyspace; for (Range<Token> range : StorageService.instance.getLocalRanges(KEYSPACE1)) - addRangeForEndpoint(range, FBUtilities.getBroadcastAddress()); + addRangeForEndpoint(range, FBUtilities.getBroadcastAddressAndPort()); } public TableMetadataRef getTableMetadata(String tableName) http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java index 34f8204..391f789 100644 --- a/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java +++ b/test/unit/org/apache/cassandra/locator/CloudstackSnitchTest.java @@ -19,7 +19,6 @@ package org.apache.cassandra.locator; import java.io.IOException; -import java.net.InetAddress; import java.util.EnumMap; import java.util.Map; @@ -77,8 +76,8 @@ public class CloudstackSnitchTest { az = "ch-gva-1"; CloudstackSnitch snitch = new TestCloudstackSnitch(); - InetAddress local = InetAddress.getByName("127.0.0.1"); - InetAddress nonlocal = InetAddress.getByName("127.0.0.7"); + InetAddressAndPort local = InetAddressAndPort.getByName("127.0.0.1"); + InetAddressAndPort nonlocal = InetAddressAndPort.getByName("127.0.0.7"); Gossiper.instance.addSavedEndpoint(nonlocal); Map<ApplicationState, VersionedValue> stateMap = new EnumMap<>(ApplicationState.class); @@ -99,7 +98,7 @@ public class CloudstackSnitchTest { az = "ch-gva-1"; CloudstackSnitch snitch = new TestCloudstackSnitch(); - InetAddress local = InetAddress.getByName("127.0.0.1"); + InetAddressAndPort local = InetAddressAndPort.getByName("127.0.0.1"); assertEquals("ch-gva", snitch.getDatacenter(local)); assertEquals("1", snitch.getRack(local)); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java b/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java index 8a59a4a..bf1e4c2 100644 --- a/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java +++ b/test/unit/org/apache/cassandra/locator/DynamicEndpointSnitchTest.java @@ -19,7 +19,6 @@ package org.apache.cassandra.locator; import java.io.IOException; -import java.net.InetAddress; import java.util.*; import org.junit.BeforeClass; @@ -41,7 +40,7 @@ public class DynamicEndpointSnitchTest DatabaseDescriptor.daemonInitialization(); } - private static void setScores(DynamicEndpointSnitch dsnitch, int rounds, List<InetAddress> hosts, Integer... scores) throws InterruptedException + private static void setScores(DynamicEndpointSnitch dsnitch, int rounds, List<InetAddressAndPort> hosts, Integer... scores) throws InterruptedException { for (int round = 0; round < rounds; round++) { @@ -58,16 +57,16 @@ public class DynamicEndpointSnitchTest StorageService.instance.unsafeInitialize(); SimpleSnitch ss = new SimpleSnitch(); DynamicEndpointSnitch dsnitch = new DynamicEndpointSnitch(ss, String.valueOf(ss.hashCode())); - InetAddress self = FBUtilities.getBroadcastAddress(); - InetAddress host1 = InetAddress.getByName("127.0.0.2"); - InetAddress host2 = InetAddress.getByName("127.0.0.3"); - InetAddress host3 = InetAddress.getByName("127.0.0.4"); - InetAddress host4 = InetAddress.getByName("127.0.0.5"); - List<InetAddress> hosts = Arrays.asList(host1, host2, host3); + InetAddressAndPort self = FBUtilities.getBroadcastAddressAndPort(); + InetAddressAndPort host1 = InetAddressAndPort.getByName("127.0.0.2"); + InetAddressAndPort host2 = InetAddressAndPort.getByName("127.0.0.3"); + InetAddressAndPort host3 = InetAddressAndPort.getByName("127.0.0.4"); + InetAddressAndPort host4 = InetAddressAndPort.getByName("127.0.0.5"); + List<InetAddressAndPort> hosts = Arrays.asList(host1, host2, host3); // first, make all hosts equal setScores(dsnitch, 1, hosts, 10, 10, 10); - List<InetAddress> order = Arrays.asList(host1, host2, host3); + List<InetAddressAndPort> order = Arrays.asList(host1, host2, host3); assertEquals(order, dsnitch.getSortedListByProximity(self, Arrays.asList(host1, host2, host3))); // make host1 a little worse http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java index 09973a8..182ff1a 100644 --- a/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java +++ b/test/unit/org/apache/cassandra/locator/EC2SnitchTest.java @@ -20,7 +20,7 @@ package org.apache.cassandra.locator; import java.io.IOException; -import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.EnumMap; import java.util.Map; @@ -72,8 +72,8 @@ public class EC2SnitchTest { az = "us-east-1d"; Ec2Snitch snitch = new TestEC2Snitch(); - InetAddress local = InetAddress.getByName("127.0.0.1"); - InetAddress nonlocal = InetAddress.getByName("127.0.0.7"); + InetAddressAndPort local = InetAddressAndPort.getByName("127.0.0.1"); + InetAddressAndPort nonlocal = InetAddressAndPort.getByName("127.0.0.7"); Gossiper.instance.addSavedEndpoint(nonlocal); Map<ApplicationState, VersionedValue> stateMap = new EnumMap<>(ApplicationState.class); @@ -93,7 +93,7 @@ public class EC2SnitchTest { az = "us-east-2d"; Ec2Snitch snitch = new TestEC2Snitch(); - InetAddress local = InetAddress.getByName("127.0.0.1"); + InetAddressAndPort local = InetAddressAndPort.getByName("127.0.0.1"); assertEquals("us-east-2", snitch.getDatacenter(local)); assertEquals("2d", snitch.getRack(local)); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/GoogleCloudSnitchTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/GoogleCloudSnitchTest.java b/test/unit/org/apache/cassandra/locator/GoogleCloudSnitchTest.java index c63044c..ea6fa2d 100644 --- a/test/unit/org/apache/cassandra/locator/GoogleCloudSnitchTest.java +++ b/test/unit/org/apache/cassandra/locator/GoogleCloudSnitchTest.java @@ -20,7 +20,6 @@ package org.apache.cassandra.locator; import java.io.IOException; -import java.net.InetAddress; import java.util.EnumMap; import java.util.Map; @@ -72,8 +71,8 @@ public class GoogleCloudSnitchTest { az = "us-central1-a"; GoogleCloudSnitch snitch = new TestGoogleCloudSnitch(); - InetAddress local = InetAddress.getByName("127.0.0.1"); - InetAddress nonlocal = InetAddress.getByName("127.0.0.7"); + InetAddressAndPort local = InetAddressAndPort.getByName("127.0.0.1"); + InetAddressAndPort nonlocal = InetAddressAndPort.getByName("127.0.0.7"); Gossiper.instance.addSavedEndpoint(nonlocal); Map<ApplicationState, VersionedValue> stateMap = new EnumMap<>(ApplicationState.class); @@ -93,7 +92,7 @@ public class GoogleCloudSnitchTest { az = "asia-east1-a"; GoogleCloudSnitch snitch = new TestGoogleCloudSnitch(); - InetAddress local = InetAddress.getByName("127.0.0.1"); + InetAddressAndPort local = InetAddressAndPort.getByName("127.0.0.1"); assertEquals("asia-east1", snitch.getDatacenter(local)); assertEquals("a", snitch.getRack(local)); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/GossipingPropertyFileSnitchTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/GossipingPropertyFileSnitchTest.java b/test/unit/org/apache/cassandra/locator/GossipingPropertyFileSnitchTest.java index 77734f7..da26003 100644 --- a/test/unit/org/apache/cassandra/locator/GossipingPropertyFileSnitchTest.java +++ b/test/unit/org/apache/cassandra/locator/GossipingPropertyFileSnitchTest.java @@ -18,9 +18,8 @@ package org.apache.cassandra.locator; -import java.net.InetAddress; +import java.net.UnknownHostException; -import com.google.common.net.InetAddresses; import org.junit.BeforeClass; import org.junit.Test; @@ -45,7 +44,15 @@ public class GossipingPropertyFileSnitchTest final String endpointString, final String expectedDatacenter, final String expectedRack) { - final InetAddress endpoint = InetAddresses.forString(endpointString); + final InetAddressAndPort endpoint; + try + { + endpoint = InetAddressAndPort.getByName(endpointString); + } + catch (UnknownHostException e) + { + throw new RuntimeException(e); + } assertEquals(expectedDatacenter, snitch.getDatacenter(endpoint)); assertEquals(expectedRack, snitch.getRack(endpoint)); } @@ -54,6 +61,6 @@ public class GossipingPropertyFileSnitchTest public void testLoadConfig() throws Exception { final GossipingPropertyFileSnitch snitch = new GossipingPropertyFileSnitch(); - checkEndpoint(snitch, FBUtilities.getBroadcastAddress().getHostAddress(), "DC1", "RAC1"); + checkEndpoint(snitch, FBUtilities.getBroadcastAddressAndPort().toString(), "DC1", "RAC1"); } } http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/InetAddressAndPortTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/InetAddressAndPortTest.java b/test/unit/org/apache/cassandra/locator/InetAddressAndPortTest.java new file mode 100644 index 0000000..c32b9a9 --- /dev/null +++ b/test/unit/org/apache/cassandra/locator/InetAddressAndPortTest.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.locator; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class InetAddressAndPortTest +{ + private static interface ThrowingRunnable + { + public void run() throws Throwable; + } + + @Test + public void getByNameIPv4Test() throws Exception + { + //Negative port + shouldThrow(() -> InetAddressAndPort.getByName("127.0.0.1:-1"), IllegalArgumentException.class); + //Too large port + shouldThrow(() -> InetAddressAndPort.getByName("127.0.0.1:65536"), IllegalArgumentException.class); + + //bad address, caught by InetAddress + shouldThrow(() -> InetAddressAndPort.getByName("127.0.0.1.0"), UnknownHostException.class); + + //Test default port + InetAddressAndPort address = InetAddressAndPort.getByName("127.0.0.1"); + assertEquals(InetAddress.getByName("127.0.0.1"), address.address); + assertEquals(InetAddressAndPort.defaultPort, address.port); + + //Test overriding default port + address = InetAddressAndPort.getByName("127.0.0.1:42"); + assertEquals(InetAddress.getByName("127.0.0.1"), address.address); + assertEquals(42, address.port); + } + + @Test + public void getByNameIPv6Test() throws Exception + { + //Negative port + shouldThrow(() -> InetAddressAndPort.getByName("[2001:0db8:0000:0000:0000:ff00:0042:8329]:-1"), IllegalArgumentException.class); + //Too large port + shouldThrow(() -> InetAddressAndPort.getByName("[2001:0db8:0000:0000:0000:ff00:0042:8329]:65536"), IllegalArgumentException.class); + + //bad address, caught by InetAddress + shouldThrow(() -> InetAddressAndPort.getByName("2001:0db8:0000:0000:0000:ff00:0042:8329:8329"), UnknownHostException.class); + + //Test default port + InetAddressAndPort address = InetAddressAndPort.getByName("2001:0db8:0000:0000:0000:ff00:0042:8329"); + assertEquals(InetAddress.getByName("2001:0db8:0000:0000:0000:ff00:0042:8329"), address.address); + assertEquals(InetAddressAndPort.defaultPort, address.port); + + //Test overriding default port + address = InetAddressAndPort.getByName("[2001:0db8:0000:0000:0000:ff00:0042:8329]:42"); + assertEquals(InetAddress.getByName("2001:0db8:0000:0000:0000:ff00:0042:8329"), address.address); + assertEquals(42, address.port); + } + + @Test + public void compareAndEqualsAndHashCodeTest() throws Exception + { + InetAddressAndPort address1 = InetAddressAndPort.getByName("127.0.0.1:42"); + InetAddressAndPort address4 = InetAddressAndPort.getByName("127.0.0.1:43"); + InetAddressAndPort address5 = InetAddressAndPort.getByName("127.0.0.1:41"); + InetAddressAndPort address6 = InetAddressAndPort.getByName("127.0.0.2:42"); + InetAddressAndPort address7 = InetAddressAndPort.getByName("127.0.0.0:42"); + + assertEquals(0, address1.compareTo(address1)); + assertEquals(-1, address1.compareTo(address4)); + assertEquals(1, address1.compareTo(address5)); + assertEquals(-1, address1.compareTo(address6)); + assertEquals(1, address1.compareTo(address7)); + + assertEquals(address1, address1); + assertEquals(address1.hashCode(), address1.hashCode()); + assertEquals(address1, InetAddressAndPort.getByName("127.0.0.1:42")); + assertEquals(address1.hashCode(), InetAddressAndPort.getByName("127.0.0.1:42").hashCode()); + assertEquals(address1, InetAddressAndPort.getByNameOverrideDefaults("127.0.0.1", 42)); + assertEquals(address1.hashCode(), InetAddressAndPort.getByNameOverrideDefaults("127.0.0.1", 42).hashCode()); + int originalPort = InetAddressAndPort.defaultPort; + InetAddressAndPort.initializeDefaultPort(42); + try + { + assertEquals(address1, InetAddressAndPort.getByName("127.0.0.1")); + assertEquals(address1.hashCode(), InetAddressAndPort.getByName("127.0.0.1").hashCode()); + } + finally + { + InetAddressAndPort.initializeDefaultPort(originalPort); + } + assertTrue(!address1.equals(address4)); + assertTrue(!address1.equals(address5)); + assertTrue(!address1.equals(address6)); + assertTrue(!address1.equals(address7)); + } + + @Test + public void toStringTest() throws Exception + { + String ipv4 = "127.0.0.1:42"; + String ipv6 = "[2001:db8:0:0:0:ff00:42:8329]:42"; + assertEquals(ipv4, InetAddressAndPort.getByName(ipv4).toString()); + assertEquals(ipv6, InetAddressAndPort.getByName(ipv6).toString()); + } + + + private void shouldThrow(ThrowingRunnable t, Class expectedClass) + { + try + { + t.run(); + } + catch (Throwable thrown) + { + assertEquals(thrown.getClass(), expectedClass); + return; + } + fail("Runnable didn't throw"); + } + +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java b/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java index f64b84a..ab6c6cd 100644 --- a/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java +++ b/test/unit/org/apache/cassandra/locator/NetworkTopologyStrategyTest.java @@ -19,7 +19,6 @@ package org.apache.cassandra.locator; import java.io.IOException; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.*; import java.util.stream.Collectors; @@ -73,9 +72,9 @@ public class NetworkTopologyStrategyTest assert strategy.getReplicationFactor("DC2") == 2; assert strategy.getReplicationFactor("DC3") == 1; // Query for the natural hosts - ArrayList<InetAddress> endpoints = strategy.getNaturalEndpoints(new StringToken("123")); + ArrayList<InetAddressAndPort> endpoints = strategy.getNaturalEndpoints(new StringToken("123")); assert 6 == endpoints.size(); - assert 6 == new HashSet<InetAddress>(endpoints).size(); // ensure uniqueness + assert 6 == new HashSet<>(endpoints).size(); // ensure uniqueness } @Test @@ -97,9 +96,9 @@ public class NetworkTopologyStrategyTest assert strategy.getReplicationFactor("DC2") == 3; assert strategy.getReplicationFactor("DC3") == 0; // Query for the natural hosts - ArrayList<InetAddress> endpoints = strategy.getNaturalEndpoints(new StringToken("123")); + ArrayList<InetAddressAndPort> endpoints = strategy.getNaturalEndpoints(new StringToken("123")); assert 6 == endpoints.size(); - assert 6 == new HashSet<InetAddress>(endpoints).size(); // ensure uniqueness + assert 6 == new HashSet<>(endpoints).size(); // ensure uniqueness } @Test @@ -113,7 +112,7 @@ public class NetworkTopologyStrategyTest DatabaseDescriptor.setEndpointSnitch(snitch); TokenMetadata metadata = new TokenMetadata(); Map<String, String> configOptions = new HashMap<String, String>(); - Multimap<InetAddress, Token> tokens = HashMultimap.create(); + Multimap<InetAddressAndPort, Token> tokens = HashMultimap.create(); int totalRF = 0; for (int dc = 0; dc < dcRacks.length; ++dc) @@ -125,7 +124,7 @@ public class NetworkTopologyStrategyTest for (int ep = 1; ep <= dcEndpoints[dc]/dcRacks[dc]; ++ep) { byte[] ipBytes = new byte[]{10, (byte)dc, (byte)rack, (byte)ep}; - InetAddress address = InetAddress.getByAddress(ipBytes); + InetAddressAndPort address = InetAddressAndPort.getByAddress(ipBytes); StringToken token = new StringToken(String.format("%02x%02x%02x", ep, rack, dc)); logger.debug("adding node {} at {}", address, token); tokens.put(address, token); @@ -138,8 +137,8 @@ public class NetworkTopologyStrategyTest for (String testToken : new String[]{"123456", "200000", "000402", "ffffff", "400200"}) { - List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(new StringToken(testToken), metadata); - Set<InetAddress> epSet = new HashSet<InetAddress>(endpoints); + List<InetAddressAndPort> endpoints = strategy.calculateNaturalEndpoints(new StringToken(testToken), metadata); + Set<InetAddressAndPort> epSet = new HashSet<>(endpoints); Assert.assertEquals(totalRF, endpoints.size()); Assert.assertEquals(totalRF, epSet.size()); @@ -172,7 +171,7 @@ public class NetworkTopologyStrategyTest public void tokenFactory(TokenMetadata metadata, String token, byte[] bytes) throws UnknownHostException { Token token1 = new StringToken(token); - InetAddress add1 = InetAddress.getByAddress(bytes); + InetAddressAndPort add1 = InetAddressAndPort.getByAddress(bytes); metadata.updateNormalToken(token1, add1); } @@ -184,9 +183,9 @@ public class NetworkTopologyStrategyTest final int RUNS = 10; StorageService.instance.setPartitionerUnsafe(Murmur3Partitioner.instance); Map<String, Integer> datacenters = ImmutableMap.of("rf1", 1, "rf3", 3, "rf5_1", 5, "rf5_2", 5, "rf5_3", 5); - List<InetAddress> nodes = new ArrayList<>(NODES); + List<InetAddressAndPort> nodes = new ArrayList<>(NODES); for (byte i=0; i<NODES; ++i) - nodes.add(InetAddress.getByAddress(new byte[]{127, 0, 0, i})); + nodes.add(InetAddressAndPort.getByAddress(new byte[]{ 127, 0, 0, i})); for (int run=0; run<RUNS; ++run) { Random rand = new Random(); @@ -209,8 +208,8 @@ public class NetworkTopologyStrategyTest for (int i=0; i<1000; ++i) { Token token = Murmur3Partitioner.instance.getRandomToken(rand); - List<InetAddress> expected = calculateNaturalEndpoints(token, tokenMetadata, datacenters, snitch); - List<InetAddress> actual = nts.calculateNaturalEndpoints(token, tokenMetadata); + List<InetAddressAndPort> expected = calculateNaturalEndpoints(token, tokenMetadata, datacenters, snitch); + List<InetAddressAndPort> actual = nts.calculateNaturalEndpoints(token, tokenMetadata); if (endpointsDiffer(expected, actual)) { System.err.println("Endpoints mismatch for token " + token); @@ -221,7 +220,7 @@ public class NetworkTopologyStrategyTest } } - private boolean endpointsDiffer(List<InetAddress> ep1, List<InetAddress> ep2) + private boolean endpointsDiffer(List<InetAddressAndPort> ep1, List<InetAddressAndPort> ep2) { // Because the old algorithm does not put the nodes in the correct order in the case where more replicas // are required than there are racks in a dc, we accept different order as long as the primary @@ -230,15 +229,15 @@ public class NetworkTopologyStrategyTest return false; if (!ep1.get(0).equals(ep2.get(0))) return true; - Set<InetAddress> s1 = new HashSet<>(ep1); - Set<InetAddress> s2 = new HashSet<>(ep2); + Set<InetAddressAndPort> s1 = new HashSet<>(ep1); + Set<InetAddressAndPort> s2 = new HashSet<>(ep2); return !s1.equals(s2); } - IEndpointSnitch generateSnitch(Map<String, Integer> datacenters, Collection<InetAddress> nodes, Random rand) + IEndpointSnitch generateSnitch(Map<String, Integer> datacenters, Collection<InetAddressAndPort> nodes, Random rand) { - final Map<InetAddress, String> nodeToRack = new HashMap<>(); - final Map<InetAddress, String> nodeToDC = new HashMap<>(); + final Map<InetAddressAndPort, String> nodeToRack = new HashMap<>(); + final Map<InetAddressAndPort, String> nodeToDC = new HashMap<>(); Map<String, List<String>> racksPerDC = new HashMap<>(); datacenters.forEach((dc, rf) -> racksPerDC.put(dc, randomRacks(rf, rand))); int rf = datacenters.values().stream().mapToInt(x -> x).sum(); @@ -250,7 +249,7 @@ public class NetworkTopologyStrategyTest dcs[pos++] = dce.getKey(); } - for (InetAddress node : nodes) + for (InetAddressAndPort node : nodes) { String dc = dcs[rand.nextInt(rf)]; List<String> racks = racksPerDC.get(dc); @@ -261,12 +260,12 @@ public class NetworkTopologyStrategyTest return new AbstractNetworkTopologySnitch() { - public String getRack(InetAddress endpoint) + public String getRack(InetAddressAndPort endpoint) { return nodeToRack.get(endpoint); } - public String getDatacenter(InetAddress endpoint) + public String getDatacenter(InetAddressAndPort endpoint) { return nodeToDC.get(endpoint); } @@ -283,20 +282,20 @@ public class NetworkTopologyStrategyTest } // Copy of older endpoints calculation algorithm for comparison - public static List<InetAddress> calculateNaturalEndpoints(Token searchToken, TokenMetadata tokenMetadata, Map<String, Integer> datacenters, IEndpointSnitch snitch) + public static List<InetAddressAndPort> calculateNaturalEndpoints(Token searchToken, TokenMetadata tokenMetadata, Map<String, Integer> datacenters, IEndpointSnitch snitch) { // we want to preserve insertion order so that the first added endpoint becomes primary - Set<InetAddress> replicas = new LinkedHashSet<>(); + Set<InetAddressAndPort> replicas = new LinkedHashSet<>(); // replicas we have found in each DC - Map<String, Set<InetAddress>> dcReplicas = new HashMap<>(datacenters.size()); + Map<String, Set<InetAddressAndPort>> dcReplicas = new HashMap<>(datacenters.size()); for (Map.Entry<String, Integer> dc : datacenters.entrySet()) - dcReplicas.put(dc.getKey(), new HashSet<InetAddress>(dc.getValue())); + dcReplicas.put(dc.getKey(), new HashSet<InetAddressAndPort>(dc.getValue())); Topology topology = tokenMetadata.getTopology(); // all endpoints in each DC, so we can check when we have exhausted all the members of a DC - Multimap<String, InetAddress> allEndpoints = topology.getDatacenterEndpoints(); + Multimap<String, InetAddressAndPort> allEndpoints = topology.getDatacenterEndpoints(); // all racks in a DC so we can check when we have exhausted all racks in a DC - Map<String, Multimap<String, InetAddress>> racks = topology.getDatacenterRacks(); + Map<String, Multimap<String, InetAddressAndPort>> racks = topology.getDatacenterRacks(); assert !allEndpoints.isEmpty() && !racks.isEmpty() : "not aware of any cluster members"; // tracks the racks we have already placed replicas in @@ -306,15 +305,15 @@ public class NetworkTopologyStrategyTest // tracks the endpoints that we skipped over while looking for unique racks // when we relax the rack uniqueness we can append this to the current result so we don't have to wind back the iterator - Map<String, Set<InetAddress>> skippedDcEndpoints = new HashMap<>(datacenters.size()); + Map<String, Set<InetAddressAndPort>> skippedDcEndpoints = new HashMap<>(datacenters.size()); for (Map.Entry<String, Integer> dc : datacenters.entrySet()) - skippedDcEndpoints.put(dc.getKey(), new LinkedHashSet<InetAddress>()); + skippedDcEndpoints.put(dc.getKey(), new LinkedHashSet<InetAddressAndPort>()); Iterator<Token> tokenIter = TokenMetadata.ringIterator(tokenMetadata.sortedTokens(), searchToken, false); while (tokenIter.hasNext() && !hasSufficientReplicas(dcReplicas, allEndpoints, datacenters)) { Token next = tokenIter.next(); - InetAddress ep = tokenMetadata.getEndpoint(next); + InetAddressAndPort ep = tokenMetadata.getEndpoint(next); String dc = snitch.getDatacenter(ep); // have we already found all replicas for this dc? if (!datacenters.containsKey(dc) || hasSufficientReplicas(dc, dcReplicas, allEndpoints, datacenters)) @@ -341,10 +340,10 @@ public class NetworkTopologyStrategyTest // if we've run out of distinct racks, add the hosts we skipped past already (up to RF) if (seenRacks.get(dc).size() == racks.get(dc).keySet().size()) { - Iterator<InetAddress> skippedIt = skippedDcEndpoints.get(dc).iterator(); + Iterator<InetAddressAndPort> skippedIt = skippedDcEndpoints.get(dc).iterator(); while (skippedIt.hasNext() && !hasSufficientReplicas(dc, dcReplicas, allEndpoints, datacenters)) { - InetAddress nextSkipped = skippedIt.next(); + InetAddressAndPort nextSkipped = skippedIt.next(); dcReplicas.get(dc).add(nextSkipped); replicas.add(nextSkipped); } @@ -353,15 +352,15 @@ public class NetworkTopologyStrategyTest } } - return new ArrayList<InetAddress>(replicas); + return new ArrayList<InetAddressAndPort>(replicas); } - private static boolean hasSufficientReplicas(String dc, Map<String, Set<InetAddress>> dcReplicas, Multimap<String, InetAddress> allEndpoints, Map<String, Integer> datacenters) + private static boolean hasSufficientReplicas(String dc, Map<String, Set<InetAddressAndPort>> dcReplicas, Multimap<String, InetAddressAndPort> allEndpoints, Map<String, Integer> datacenters) { return dcReplicas.get(dc).size() >= Math.min(allEndpoints.get(dc).size(), getReplicationFactor(dc, datacenters)); } - private static boolean hasSufficientReplicas(Map<String, Set<InetAddress>> dcReplicas, Multimap<String, InetAddress> allEndpoints, Map<String, Integer> datacenters) + private static boolean hasSufficientReplicas(Map<String, Set<InetAddressAndPort>> dcReplicas, Multimap<String, InetAddressAndPort> allEndpoints, Map<String, Integer> datacenters) { for (String dc : datacenters.keySet()) if (!hasSufficientReplicas(dc, dcReplicas, allEndpoints, datacenters)) http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java b/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java index e6e17cd..9c90d57 100644 --- a/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java +++ b/test/unit/org/apache/cassandra/locator/OldNetworkTopologyStrategyTest.java @@ -17,7 +17,6 @@ */ package org.apache.cassandra.locator; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; @@ -45,7 +44,7 @@ public class OldNetworkTopologyStrategyTest { private List<Token> keyTokens; private TokenMetadata tmd; - private Map<String, ArrayList<InetAddress>> expectedResults; + private Map<String, ArrayList<InetAddressAndPort>> expectedResults; @BeforeClass public static void setupDD() @@ -58,7 +57,7 @@ public class OldNetworkTopologyStrategyTest { keyTokens = new ArrayList<Token>(); tmd = new TokenMetadata(); - expectedResults = new HashMap<String, ArrayList<InetAddress>>(); + expectedResults = new HashMap<String, ArrayList<InetAddressAndPort>>(); } /** @@ -136,12 +135,12 @@ public class OldNetworkTopologyStrategyTest testGetEndpoints(strategy, keyTokens.toArray(new Token[0])); } - private ArrayList<InetAddress> buildResult(String... addresses) throws UnknownHostException + private ArrayList<InetAddressAndPort> buildResult(String... addresses) throws UnknownHostException { - ArrayList<InetAddress> result = new ArrayList<InetAddress>(); + ArrayList<InetAddressAndPort> result = new ArrayList<>(); for (String address : addresses) { - result.add(InetAddress.getByName(address)); + result.add(InetAddressAndPort.getByName(address)); } return result; } @@ -153,7 +152,7 @@ public class OldNetworkTopologyStrategyTest BigIntegerToken keyToken = new BigIntegerToken(keyTokenID); keyTokens.add(keyToken); - InetAddress ep = InetAddress.getByName(endpointAddress); + InetAddressAndPort ep = InetAddressAndPort.getByName(endpointAddress); tmd.updateNormalToken(endpointToken, ep); } @@ -161,10 +160,10 @@ public class OldNetworkTopologyStrategyTest { for (Token keyToken : keyTokens) { - List<InetAddress> endpoints = strategy.getNaturalEndpoints(keyToken); + List<InetAddressAndPort> endpoints = strategy.getNaturalEndpoints(keyToken); for (int j = 0; j < endpoints.size(); j++) { - ArrayList<InetAddress> hostsExpected = expectedResults.get(keyToken.toString()); + ArrayList<InetAddressAndPort> hostsExpected = expectedResults.get(keyToken.toString()); assertEquals(endpoints.get(j), hostsExpected.get(j)); } } @@ -340,7 +339,7 @@ public class OldNetworkTopologyStrategyTest int lastIPPart = 1; for (BigIntegerToken token : tokens) - tokenMetadataCurrent.updateNormalToken(token, InetAddress.getByName("254.0.0." + Integer.toString(lastIPPart++))); + tokenMetadataCurrent.updateNormalToken(token, InetAddressAndPort.getByName("254.0.0." + Integer.toString(lastIPPart++))); return tokenMetadataCurrent; } @@ -360,7 +359,7 @@ public class OldNetworkTopologyStrategyTest { RackInferringSnitch endpointSnitch = new RackInferringSnitch(); - InetAddress movingNode = InetAddress.getByName("254.0.0." + Integer.toString(movingNodeIdx + 1)); + InetAddressAndPort movingNode = InetAddressAndPort.getByName("254.0.0." + Integer.toString(movingNodeIdx + 1)); TokenMetadata tokenMetadataCurrent = initTokenMetadata(tokens); http://git-wip-us.apache.org/repos/asf/cassandra/blob/59b5b6be/test/unit/org/apache/cassandra/locator/PendingRangeMapsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/locator/PendingRangeMapsTest.java b/test/unit/org/apache/cassandra/locator/PendingRangeMapsTest.java index 7121550..56fd181 100644 --- a/test/unit/org/apache/cassandra/locator/PendingRangeMapsTest.java +++ b/test/unit/org/apache/cassandra/locator/PendingRangeMapsTest.java @@ -25,7 +25,6 @@ import org.apache.cassandra.dht.Range; import org.apache.cassandra.dht.Token; import org.junit.Test; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Collection; @@ -44,12 +43,12 @@ public class PendingRangeMapsTest { { PendingRangeMaps pendingRangeMaps = new PendingRangeMaps(); - pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddress.getByName("127.0.0.1")); - pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddress.getByName("127.0.0.2")); - pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddress.getByName("127.0.0.3")); - pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddress.getByName("127.0.0.4")); - pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddress.getByName("127.0.0.5")); - pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddress.getByName("127.0.0.6")); + pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddressAndPort.getByName("127.0.0.1")); + pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddressAndPort.getByName("127.0.0.2")); + pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddressAndPort.getByName("127.0.0.3")); + pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddressAndPort.getByName("127.0.0.4")); + pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddressAndPort.getByName("127.0.0.5")); + pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddressAndPort.getByName("127.0.0.6")); assertEquals(0, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("0")).size()); assertEquals(0, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("5")).size()); @@ -62,8 +61,8 @@ public class PendingRangeMapsTest { assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("55")).size()); assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("65")).size()); - Collection<InetAddress> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15")); - assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.1"))); + Collection<InetAddressAndPort> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("15")); + assertTrue(endpoints.contains(InetAddressAndPort.getByName("127.0.0.1"))); } @Test @@ -71,13 +70,13 @@ public class PendingRangeMapsTest { { PendingRangeMaps pendingRangeMaps = new PendingRangeMaps(); - pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddress.getByName("127.0.0.1")); - pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddress.getByName("127.0.0.2")); - pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddress.getByName("127.0.0.3")); - pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddress.getByName("127.0.0.4")); - pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddress.getByName("127.0.0.5")); - pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddress.getByName("127.0.0.6")); - pendingRangeMaps.addPendingRange(genRange("65", "7"), InetAddress.getByName("127.0.0.7")); + pendingRangeMaps.addPendingRange(genRange("5", "15"), InetAddressAndPort.getByName("127.0.0.1")); + pendingRangeMaps.addPendingRange(genRange("15", "25"), InetAddressAndPort.getByName("127.0.0.2")); + pendingRangeMaps.addPendingRange(genRange("25", "35"), InetAddressAndPort.getByName("127.0.0.3")); + pendingRangeMaps.addPendingRange(genRange("35", "45"), InetAddressAndPort.getByName("127.0.0.4")); + pendingRangeMaps.addPendingRange(genRange("45", "55"), InetAddressAndPort.getByName("127.0.0.5")); + pendingRangeMaps.addPendingRange(genRange("45", "65"), InetAddressAndPort.getByName("127.0.0.6")); + pendingRangeMaps.addPendingRange(genRange("65", "7"), InetAddressAndPort.getByName("127.0.0.7")); assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("0")).size()); assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("5")).size()); @@ -91,8 +90,8 @@ public class PendingRangeMapsTest { assertEquals(2, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("55")).size()); assertEquals(1, pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("65")).size()); - Collection<InetAddress> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("6")); - assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.1"))); - assertTrue(endpoints.contains(InetAddress.getByName("127.0.0.7"))); + Collection<InetAddressAndPort> endpoints = pendingRangeMaps.pendingEndpointsFor(new BigIntegerToken("6")); + assertTrue(endpoints.contains(InetAddressAndPort.getByName("127.0.0.1"))); + assertTrue(endpoints.contains(InetAddressAndPort.getByName("127.0.0.7"))); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org