Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return both read and route endpoints in shuffled order.
- Loading branch information
Max Sumrall
committed
Oct 21, 2016
1 parent
47d7646
commit 46167dd
Showing
3 changed files
with
119 additions
and
55 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
118 changes: 118 additions & 0 deletions
118
.../java/org/neo4j/causalclustering/discovery/procedures/GetServersProcedureRoutingTest.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,118 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.procedures; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameter; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import org.neo4j.causalclustering.core.consensus.LeaderLocator; | ||
import org.neo4j.causalclustering.discovery.CoreAddresses; | ||
import org.neo4j.causalclustering.discovery.CoreTopology; | ||
import org.neo4j.causalclustering.discovery.CoreTopologyService; | ||
import org.neo4j.causalclustering.discovery.ReadReplicaTopology; | ||
import org.neo4j.causalclustering.identity.ClusterId; | ||
import org.neo4j.causalclustering.identity.MemberId; | ||
import org.neo4j.kernel.configuration.Config; | ||
|
||
import static java.util.Collections.emptySet; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.runners.Parameterized.Parameters; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.neo4j.causalclustering.discovery.procedures.GetServersProcedureTest.coreAddresses; | ||
import static org.neo4j.causalclustering.identity.RaftTestMember.member; | ||
import static org.neo4j.helpers.collection.Iterators.asList; | ||
import static org.neo4j.logging.NullLogProvider.getInstance; | ||
|
||
@RunWith( Parameterized.class ) | ||
public class GetServersProcedureRoutingTest | ||
{ | ||
@Parameters | ||
public static Collection<Object> data() | ||
{ | ||
return Arrays.asList( 1, 2 ); | ||
} //the write endpoints are always index 0 | ||
|
||
@Parameter | ||
public int serverClass; | ||
|
||
private ClusterId clusterId = new ClusterId( UUID.randomUUID() ); | ||
private Config config = Config.defaults(); | ||
|
||
@Test | ||
public void shouldReturnEndpointsInDifferentOrders() throws Exception | ||
{ | ||
// given | ||
final CoreTopologyService coreTopologyService = mock( CoreTopologyService.class ); | ||
|
||
LeaderLocator leaderLocator = mock( LeaderLocator.class ); | ||
when( leaderLocator.getLeader() ).thenReturn( member( 0 ) ); | ||
|
||
Map<MemberId,CoreAddresses> coreMembers = new HashMap<>(); | ||
coreMembers.put( member( 0 ), coreAddresses( 0 ) ); | ||
coreMembers.put( member( 1 ), coreAddresses( 1 ) ); | ||
coreMembers.put( member( 2 ), coreAddresses( 2 ) ); | ||
|
||
final CoreTopology clusterTopology = new CoreTopology( clusterId, false, coreMembers ); | ||
when( coreTopologyService.coreServers() ).thenReturn( clusterTopology ); | ||
when( coreTopologyService.readReplicas() ).thenReturn( new ReadReplicaTopology( clusterId, emptySet() ) ); | ||
|
||
final GetServersProcedure proc = | ||
new GetServersProcedure( coreTopologyService, leaderLocator, config, getInstance() ); | ||
|
||
// when | ||
Object[] endpoints = getEndpoints( proc ); | ||
|
||
//then | ||
Object[] endpointsInDifferentOrder = getEndpoints( proc ); | ||
for ( int i = 0; i < 100; i++ ) | ||
{ | ||
if ( Arrays.deepEquals( endpointsInDifferentOrder, endpoints ) ) | ||
{ | ||
endpointsInDifferentOrder = getEndpoints( proc ); | ||
} | ||
else | ||
{ | ||
//Different order of servers, no need to retry. | ||
break; | ||
} | ||
} | ||
assertFalse( Arrays.deepEquals( endpoints, endpointsInDifferentOrder ) ); | ||
} | ||
|
||
private Object[] getEndpoints( GetServersProcedure proc ) | ||
throws org.neo4j.kernel.api.exceptions.ProcedureException | ||
{ | ||
List<Object[]> results = asList( proc.apply( null, new Object[0] ) ); | ||
Object[] rows = results.get( 0 ); | ||
List<Map<String,Object[]>> servers = (List<Map<String,Object[]>>) rows[1]; | ||
Map<String,Object[]> endpoints = servers.get( serverClass ); | ||
return endpoints.get( "addresses" ); | ||
} | ||
} |
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