Skip to content

Commit

Permalink
fix unit test issue in MergeableClusterInvokerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
beiwei30 committed Jun 7, 2016
1 parent af80dc5 commit 6bab637
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public class Menu {
public Menu() {}

public Menu( Map<String, List<String>> menus ) {
this.menus.putAll( menus );
for (String key : menus.keySet()) {
this.menus.put(key, new ArrayList<String>(menus.get(key)));
}
}

public void putMenuItem( String menu, String item ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.dubbo.rpc.cluster.Directory;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -31,6 +32,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -46,44 +49,23 @@ public class MergeableClusterInvokerTest {
private Invocation invocation = EasyMock.createMock( Invocation.class );

private MergeableClusterInvoker<MenuService> mergeableClusterInvoker;


private String[] list1 = {"10", "11", "12"};
private String[] list2 = {"20", "21", "22"};
private String[] list3 = {"23", "24", "25"};
private String[] list4 = {"30", "31", "32"};

private Map<String, List<String>> firstMenuMap = new HashMap<String, List<String>>() {
{
put( "1", new ArrayList<String>() {
{
add( "10" );
add( "11" );
add( "12" );
}
} );
put( "2", new ArrayList<String>() {

{
add( "20" );
add( "21" );
add( "22" );
}
} );
put( "1", Arrays.asList(list1));
put( "2", Arrays.asList(list2));
}
};

private Map<String, List<String>> secondMenuMap = new HashMap<String, List<String>>() {
{
put( "2", new ArrayList<String>() {

{
add( "23" );
add( "24" );
add( "25" );
}
} );
put( "3", new ArrayList<String>() {

{
add( "30" );
add( "31" );
add( "32" );
}
} );
put( "2", Arrays.asList(list3));
put( "3", Arrays.asList(list4));
}
};

Expand Down Expand Up @@ -170,8 +152,16 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
Map<String, List<String>> expected = new HashMap<String, List<String>>();
merge( expected, firstMenuMap );
merge( expected, secondMenuMap );
Assert.assertEquals( expected, menu.getMenus() );

TestCase.assertEquals(expected.keySet(), menu.getMenus().keySet());
for (String key : expected.keySet()) {
// FIXME: cannot guarantee the sequence of the merge result, check implementation in
// MergeableClusterInvoker#invoke
List<String> values1 = new ArrayList<String>(expected.get(key));
List<String> values2 = new ArrayList<String>(menu.getMenus().get(key));
Collections.sort(values1);
Collections.sort(values2);
TestCase.assertEquals(values1, values2);
}
}

@Test
Expand Down Expand Up @@ -235,7 +225,7 @@ static void merge( Map<String, List<String>> first, Map<String, List<String>> se
if ( value != null ) {
value.addAll( entry.getValue() );
} else {
first.put( entry.getKey(), entry.getValue() );
first.put( entry.getKey(), new ArrayList<String>(entry.getValue()) );
}
}
}
Expand Down

0 comments on commit 6bab637

Please sign in to comment.