|
|
|
package com.crossoverjie.cim.common.route.algorithm.consistenthash;
|
|
|
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
...
|
...
|
@@ -14,13 +15,14 @@ public class SortArrayMapConsistentHashTest { |
|
|
|
AbstractConsistentHash map = new SortArrayMapConsistentHash() ;
|
|
|
|
|
|
|
|
List<String> strings = new ArrayList<String>();
|
|
|
|
strings.add("zhangsan") ;
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
strings.add("127.0.0." + i) ;
|
|
|
|
}
|
|
|
|
map.process(strings);
|
|
|
|
String process = map.process(strings);
|
|
|
|
System.out.println(process);
|
|
|
|
Assert.assertEquals("127.0.0.8",process);
|
|
|
|
|
|
|
|
String firstNodeValue = map.getFirstNodeValue("zhangsan");
|
|
|
|
System.out.println(firstNodeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
...
|
...
|
@@ -28,12 +30,28 @@ public class SortArrayMapConsistentHashTest { |
|
|
|
AbstractConsistentHash map = new SortArrayMapConsistentHash() ;
|
|
|
|
|
|
|
|
List<String> strings = new ArrayList<String>();
|
|
|
|
strings.add("zhangsan2");
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
strings.add("127.0.0." + i) ;
|
|
|
|
}
|
|
|
|
map.process(strings);
|
|
|
|
String process = map.process(strings);
|
|
|
|
System.out.println(process);
|
|
|
|
|
|
|
|
String firstNodeValue = map.getFirstNodeValue("zhangsan2");
|
|
|
|
System.out.println(firstNodeValue);
|
|
|
|
Assert.assertEquals("127.0.0.4",process);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getFirstNodeValue3() {
|
|
|
|
AbstractConsistentHash map = new SortArrayMapConsistentHash() ;
|
|
|
|
|
|
|
|
List<String> strings = new ArrayList<String>();
|
|
|
|
strings.add("1551253899106") ;
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
strings.add("127.0.0." + i) ;
|
|
|
|
}
|
|
|
|
String process = map.process(strings);
|
|
|
|
|
|
|
|
System.out.println(process);
|
|
|
|
Assert.assertEquals("127.0.0.6",process);
|
|
|
|
}
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|