From 832574f43720c877e0d7c2aa3fcda6af95a96520 Mon Sep 17 00:00:00 2001 From: Artem Vysochyn Date: Fri, 12 Jul 2024 17:26:50 +0300 Subject: [PATCH] WIP --- .../cluster2/gossip/MemberSelectorTest.java | 60 +++++++++++++++++-- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/cluster2/src/test/java/io/scalecube/cluster2/gossip/MemberSelectorTest.java b/cluster2/src/test/java/io/scalecube/cluster2/gossip/MemberSelectorTest.java index 92cde589..6ca39800 100644 --- a/cluster2/src/test/java/io/scalecube/cluster2/gossip/MemberSelectorTest.java +++ b/cluster2/src/test/java/io/scalecube/cluster2/gossip/MemberSelectorTest.java @@ -44,7 +44,7 @@ void testSelectWhenLessThanFanout() { for (int i = 0; i < 10; i++) { memberSelector.nextGossipMembers(); - assertEquals(3, gossipMembers.size()); + assertEquals(remoteMembers.size(), gossipMembers.size()); assertThat(gossipMembers, hasItems(isOneOf(fooMember, barMember, bazMember))); } } @@ -59,7 +59,7 @@ void testSelectWhenEqualToFanout() { for (int i = 0; i < 10; i++) { memberSelector.nextGossipMembers(); - assertEquals(3, gossipMembers.size()); + assertEquals(remoteMembers.size(), gossipMembers.size()); assertThat(gossipMembers, hasItems(isOneOf(fooMember, barMember, bazMember))); } } @@ -76,13 +76,61 @@ void testSelectWhenGreaterThanFanout() { remoteMembers.add(abcMember); remoteMembers.add(xyzMember); - final MemberSelector memberSelector = new MemberSelector(3, remoteMembers, gossipMembers); + final int gossipFanout = 3; + final MemberSelector memberSelector = + new MemberSelector(gossipFanout, remoteMembers, gossipMembers); + + for (int i = 0; i < 10; i++) { + memberSelector.nextGossipMembers(); + assertEquals(gossipFanout, gossipMembers.size()); + assertThat( + gossipMembers, + hasItems( + isOneOf( + fooMember, + barMember, + bazMember, + aliceMember, + bobMember, + johnMember, + eveMember, + abcMember, + xyzMember))); + } + } + + @Test + void testSelectWhenGreaterThanFanoutWithReminder() { + remoteMembers.add(fooMember); + remoteMembers.add(barMember); + remoteMembers.add(bazMember); + remoteMembers.add(aliceMember); + remoteMembers.add(bobMember); + remoteMembers.add(johnMember); + remoteMembers.add(eveMember); + remoteMembers.add(abcMember); + remoteMembers.add(xyzMember); + + final int gossipFanout = 4; + final MemberSelector memberSelector = + new MemberSelector(gossipFanout, remoteMembers, gossipMembers); for (int i = 0; i < 10; i++) { memberSelector.nextGossipMembers(); - assertEquals(3, gossipMembers.size()); - System.err.println(gossipMembers); - // assertThat(gossipMembers, hasItems(isOneOf(fooMember, barMember, bazMember))); + assertEquals(gossipFanout, gossipMembers.size()); + assertThat( + gossipMembers, + hasItems( + isOneOf( + fooMember, + barMember, + bazMember, + aliceMember, + bobMember, + johnMember, + eveMember, + abcMember, + xyzMember))); } } }