-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REFACTOR: methods in MemcachedConnectio invoked with updateReplConnec…
…tion.
- Loading branch information
Showing
4 changed files
with
133 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/net/spy/memcached/ArcusReplNodeAddressTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package net.spy.memcached; | ||
|
||
|
||
import java.net.InetSocketAddress; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
class ArcusReplNodeAddressTest { | ||
|
||
@Test | ||
void findChangedGroupsTest() { | ||
List<ArcusReplNodeAddress> g0 = createReplList("g0", "192.168.0.1"); | ||
List<ArcusReplNodeAddress> g1 = createReplList("g1", "192.168.0.2"); | ||
List<MemcachedNode> old = new ArrayList<>(); | ||
setReplGroup(g0, old); | ||
setReplGroup(g1, old); | ||
|
||
List<InetSocketAddress> update = new ArrayList<>(g0); | ||
|
||
Set<String> changedGroups = ArcusReplNodeAddress.findChangedGroups(update, old); | ||
Assertions.assertEquals(1, changedGroups.size()); | ||
Assertions.assertTrue(changedGroups.contains("g1")); | ||
} | ||
|
||
@Test | ||
void findAddrsOfChangedGroupsTest() { | ||
List<ArcusReplNodeAddress> g0 = createReplList("g0", "192.168.0.1"); | ||
List<ArcusReplNodeAddress> g1 = createReplList("g1", "192.168.0.2"); | ||
List<MemcachedNode> old = new ArrayList<>(); | ||
setReplGroup(g0, old); | ||
setReplGroup(g1, old); | ||
|
||
List<InetSocketAddress> update = new ArrayList<>(); | ||
update.addAll(g0.subList(0, 2)); | ||
update.addAll(g1.subList(0, 2)); | ||
|
||
Set<String> changedGroups = ArcusReplNodeAddress.findChangedGroups(update, old); | ||
List<InetSocketAddress> result | ||
= ArcusReplNodeAddress.findAddrsOfChangedGroups(update, changedGroups); | ||
|
||
Assertions.assertEquals(4, result.size()); | ||
Assertions.assertTrue(result.contains(g0.get(0))); | ||
Assertions.assertTrue(result.contains(g0.get(1))); | ||
Assertions.assertTrue(result.contains(g1.get(0))); | ||
Assertions.assertTrue(result.contains(g1.get(1))); | ||
} | ||
|
||
private static void setReplGroup(List<ArcusReplNodeAddress> group, List<MemcachedNode> old) { | ||
List<MockMemcachedNode> collect = group.stream() | ||
.map(MockMemcachedNode::new) | ||
.collect(Collectors.toList()); | ||
MemcachedReplicaGroupImpl impl = null; | ||
for (MockMemcachedNode node : collect) { | ||
if (impl == null) { | ||
impl = new MemcachedReplicaGroupImpl(node); | ||
} else { | ||
node.setReplicaGroup(impl); | ||
} | ||
} | ||
old.addAll(collect); | ||
} | ||
|
||
private List<ArcusReplNodeAddress> createReplList(String group, String ip) { | ||
List<ArcusReplNodeAddress> replList = new ArrayList<>(); | ||
replList.add(ArcusReplNodeAddress.create(group, true, ip + ":" + 11211)); | ||
replList.add(ArcusReplNodeAddress.create(group, false, ip + ":" + (11211 + 1))); | ||
replList.add(ArcusReplNodeAddress.create(group, false, ip + ":" + (11211 + 2))); | ||
return replList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters