Skip to content

Commit

Permalink
Created test for MultiClusterRouting procedures
Browse files Browse the repository at this point in the history
- Includes unit tests to verify that signatures of procedures remain
unchanged and consistent for consumers.

- Includes integration tests to verify that procedure behaves as
expected given a range of scenarios.
  • Loading branch information
hugofirth committed Mar 20, 2018
1 parent d09e708 commit 7a50fff
Show file tree
Hide file tree
Showing 5 changed files with 379 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import java.util.Map;
import java.util.Objects;

import org.neo4j.causalclustering.routing.*;
import org.neo4j.causalclustering.routing.RoutingResult;
import org.neo4j.causalclustering.routing.Endpoint;

/**
* Simple struct containing the the result of Get*ClusterRouting procedure execution.
Expand All @@ -33,7 +34,7 @@ public class MultiClusterRoutingResult implements RoutingResult
private final Map<String,List<Endpoint>> routers;
private final long ttl;

public MultiClusterRoutingResult( Map<String,List<Endpoint>> routers, long ttl)
public MultiClusterRoutingResult( Map<String,List<Endpoint>> routers, long ttl )
{
this.routers = routers;
this.ttl = ttl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public class GetSubClusterRoutersProcedure implements CallableProcedure
private final ProcedureSignature procedureSignature =
procedureSignature( GET_SUB_CLUSTER_ROUTERS.fullyQualifiedProcedureName() )
.in( DATABASE.parameterName(), Neo4jTypes.NTString )
.out( ROUTERS.parameterName(), Neo4jTypes.NTList( Neo4jTypes.NTString ) )
.out( TTL.parameterName(), Neo4jTypes.NTInteger )
.out( ROUTERS.parameterName(), Neo4jTypes.NTMap )
.description( DESCRIPTION )
.build();

private final TopologyService topologyService;
private final Config config;

public GetSubClusterRoutersProcedure(TopologyService topologyService, Config config )
public GetSubClusterRoutersProcedure( TopologyService topologyService, Config config )
{
this.topologyService = topologyService;
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2002-2018 "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.routing.multi_cluster.procedure;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.neo4j.internal.kernel.api.procs.FieldSignature;
import org.neo4j.internal.kernel.api.procs.Neo4jTypes;
import org.neo4j.internal.kernel.api.procs.ProcedureSignature;

import static org.junit.Assert.assertEquals;

public class MultiClusterRoutingProcedureTest
{

@Test
public void subClusterRoutingProcedureShouldHaveCorrectSignature()
{
GetSubClusterRoutersProcedure proc = new GetSubClusterRoutersProcedure( null, null );

ProcedureSignature procSig = proc.signature();

List<FieldSignature> input = Collections.singletonList( FieldSignature.inputField( "database", Neo4jTypes.NTString ) );
List<FieldSignature> output = Arrays.asList(
FieldSignature.outputField( "ttl", Neo4jTypes.NTInteger ),
FieldSignature.outputField( "routers", Neo4jTypes.NTMap ) );

assertEquals( "The input signature of the GetSubClusterRoutersProcedure should not change.", procSig.inputSignature(), input );

assertEquals( "The output signature of the GetSubClusterRoutersProcedure should not change.", procSig.outputSignature(), output );
}

@Test
public void superClusterRoutingProcedureShouldHaveCorrectSignature()
{
GetSuperClusterRoutersProcedure proc = new GetSuperClusterRoutersProcedure( null, null );

ProcedureSignature procSig = proc.signature();

List<FieldSignature> output = Arrays.asList(
FieldSignature.outputField( "ttl", Neo4jTypes.NTInteger ),
FieldSignature.outputField( "routers", Neo4jTypes.NTMap ) );

assertEquals( "The output signature of the GetSuperClusterRoutersProcedure should not change.", procSig.outputSignature(), output );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2002-2018 "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.routing.multi_cluster.procedure;

import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.neo4j.causalclustering.routing.Endpoint;
import org.neo4j.causalclustering.routing.multi_cluster.MultiClusterRoutingResult;
import org.neo4j.helpers.AdvertisedSocketAddress;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;

public class MultiClusterRoutingResultFormatTest
{

@Test
public void shouldSerializeToAndFromRecordFormat()
{
List<Endpoint> fooRouters = asList(
Endpoint.route( new AdvertisedSocketAddress( "host1", 1 ) ),
Endpoint.route( new AdvertisedSocketAddress( "host2", 1 ) ),
Endpoint.route( new AdvertisedSocketAddress( "host3", 1 ) )
);

List<Endpoint> barRouters = asList(
Endpoint.route( new AdvertisedSocketAddress( "host4", 1 ) ),
Endpoint.route( new AdvertisedSocketAddress( "host5", 1 ) ),
Endpoint.route( new AdvertisedSocketAddress( "host6", 1 ) )
);

Map<String,List<Endpoint>> routers = new HashMap<>();
routers.put( "foo", fooRouters );
routers.put( "bar", barRouters );

long ttlSeconds = 5;
MultiClusterRoutingResult original = new MultiClusterRoutingResult( routers, ttlSeconds * 1000 );

Object[] record = MultiClusterRoutingResultFormat.build( original );

MultiClusterRoutingResult parsed = MultiClusterRoutingResultFormat.parse( record );

assertEquals( original, parsed );
}
}

0 comments on commit 7a50fff

Please sign in to comment.