Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more logging to make it easier to see what's happening in membership …
…land
- Loading branch information
Mark Needham
committed
Jan 25, 2017
1 parent
fb5b3dc
commit 800e17c
Showing
7 changed files
with
282 additions
and
10 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
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
130 changes: 130 additions & 0 deletions
130
...ausal-clustering/src/test/java/org/neo4j/causalclustering/discovery/CoreTopologyTest.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,130 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.causalclustering.discovery; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
||
import org.neo4j.causalclustering.identity.ClusterId; | ||
import org.neo4j.causalclustering.identity.MemberId; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class CoreTopologyTest | ||
{ | ||
@Test | ||
public void identicalTopologiesShouldHaveNoDifference() throws Exception | ||
{ | ||
// given | ||
UUID one = UUID.randomUUID(); | ||
UUID two = UUID.randomUUID(); | ||
|
||
Map<MemberId, CoreAddresses> coreMembers = new HashMap<>(); | ||
coreMembers.put( new MemberId( one ), mock(CoreAddresses.class) ); | ||
coreMembers.put( new MemberId( two ), mock(CoreAddresses.class) ); | ||
|
||
CoreTopology topology = new CoreTopology( new ClusterId( UUID.randomUUID() ), true, coreMembers ); | ||
|
||
// when | ||
CoreTopology.TopologyDifference diff = topology.difference(topology); | ||
|
||
// then | ||
assertThat( diff.added().size(), Matchers.equalTo( 0 ) ); | ||
assertThat( diff.removed().size(), Matchers.equalTo( 0 ) ); | ||
} | ||
|
||
@Test | ||
public void shouldDetectAddedMembers() throws Exception | ||
{ | ||
// given | ||
UUID one = UUID.randomUUID(); | ||
UUID two = UUID.randomUUID(); | ||
|
||
Map<MemberId, CoreAddresses> initialMembers = new HashMap<>(); | ||
initialMembers.put( new MemberId( one ), mock(CoreAddresses.class) ); | ||
initialMembers.put( new MemberId( two ), mock(CoreAddresses.class) ); | ||
|
||
Map<MemberId, CoreAddresses> newMembers = new HashMap<>(); | ||
newMembers.put( new MemberId( one ), mock(CoreAddresses.class) ); | ||
newMembers.put( new MemberId( two ), mock(CoreAddresses.class) ); | ||
newMembers.put( new MemberId( UUID.randomUUID() ), mock(CoreAddresses.class) ); | ||
|
||
CoreTopology topology = new CoreTopology( new ClusterId( UUID.randomUUID() ), true, initialMembers ); | ||
|
||
// when | ||
CoreTopology.TopologyDifference diff = topology.difference(new CoreTopology( new ClusterId( UUID.randomUUID() ), true, newMembers )); | ||
|
||
// then | ||
assertThat( diff.added().size(), Matchers.equalTo( 1 ) ); | ||
assertThat( diff.removed().size(), Matchers.equalTo( 0 ) ); | ||
} | ||
|
||
@Test | ||
public void shouldDetectRemovedMembers() throws Exception | ||
{ | ||
// given | ||
UUID one = UUID.randomUUID(); | ||
UUID two = UUID.randomUUID(); | ||
|
||
Map<MemberId, CoreAddresses> initialMembers = new HashMap<>(); | ||
initialMembers.put( new MemberId( one ), mock(CoreAddresses.class) ); | ||
initialMembers.put( new MemberId( two ), mock(CoreAddresses.class) ); | ||
|
||
Map<MemberId, CoreAddresses> newMembers = new HashMap<>(); | ||
newMembers.put( new MemberId( two ), mock(CoreAddresses.class) ); | ||
|
||
CoreTopology topology = new CoreTopology( new ClusterId( UUID.randomUUID() ), true, initialMembers ); | ||
|
||
// when | ||
CoreTopology.TopologyDifference diff = topology.difference(new CoreTopology( new ClusterId( UUID.randomUUID() ), true, newMembers )); | ||
|
||
// then | ||
assertThat( diff.added().size(), Matchers.equalTo( 0 ) ); | ||
assertThat( diff.removed().size(), Matchers.equalTo( 1 ) ); | ||
} | ||
|
||
@Test | ||
public void shouldDetectAddedAndRemovedMembers() throws Exception | ||
{ | ||
// given | ||
|
||
Map<MemberId, CoreAddresses> initialMembers = new HashMap<>(); | ||
initialMembers.put( new MemberId( UUID.randomUUID() ), mock(CoreAddresses.class) ); | ||
initialMembers.put( new MemberId( UUID.randomUUID() ), mock(CoreAddresses.class) ); | ||
|
||
Map<MemberId, CoreAddresses> newMembers = new HashMap<>(); | ||
newMembers.put( new MemberId( UUID.randomUUID() ), mock(CoreAddresses.class) ); | ||
newMembers.put( new MemberId( UUID.randomUUID() ), mock(CoreAddresses.class) ); | ||
|
||
CoreTopology topology = new CoreTopology( new ClusterId( UUID.randomUUID() ), true, initialMembers ); | ||
|
||
// when | ||
CoreTopology.TopologyDifference diff = topology.difference(new CoreTopology( new ClusterId( UUID.randomUUID() ), true, newMembers )); | ||
|
||
// then | ||
assertThat( diff.added().size(), Matchers.equalTo( 2 ) ); | ||
assertThat( diff.removed().size(), Matchers.equalTo( 2 ) ); | ||
} | ||
} |
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
Oops, something went wrong.