SortArrayMapConsistentHash extends AbstractConsistentHash { @Override public void add(long key, String value) { sortArrayMap.clear(); for (int i = 0; i < VIRTUAL_NODE_SIZE; i++) { Long hash = super.hash("vir" + key + i); sortArrayMap.add(hash,value); } sortArrayMap.add(key, value); }  @Override void add(long key, String value); @Override void sort(); @Override String getFirstNodeValue(String value);  }
@Test public void getFirstNodeValue2() { AbstractConsistentHash map = new SortArrayMapConsistentHash() ; List<String> strings = new ArrayList<String>(); for (int i = 0; i < 10; i++) { strings.add("127.0.0." + i) ; } String process = map.process(strings,"zhangsan2"); System.out.println(process); Assert.assertEquals("127.0.0.3",process); }
@Test public void getFirstNodeValue3() { AbstractConsistentHash map = new SortArrayMapConsistentHash() ; List<String> strings = new ArrayList<String>(); for (int i = 0; i < 10; i++) { strings.add("127.0.0." + i) ; } String process = map.process(strings,"1551253899106"); System.out.println(process); Assert.assertEquals("127.0.0.6",process); }
@Test public void getFirstNodeValue4() { AbstractConsistentHash map = new SortArrayMapConsistentHash() ; List<String> strings = new ArrayList<String>(); strings.add("45.78.28.220:9000:8081") ; strings.add("45.78.28.220:9100:9081") ; String process = map.process(strings,"1551253899106"); System.out.println(process); Assert.assertEquals("45.78.28.220:9000:8081",process); }
@Test public void getFirstNodeValue5() { AbstractConsistentHash map = new SortArrayMapConsistentHash() ; List<String> strings = new ArrayList<String>(); strings.add("45.78.28.220:9000:8081") ; strings.add("45.78.28.220:9100:9081") ; strings.add("45.78.28.220:9100:10081") ; String process = map.process(strings,"1551253899106"); System.out.println(process); Assert.assertEquals("45.78.28.220:9000:8081",process); }
@Test public void getFirstNodeValue6() { AbstractConsistentHash map = new SortArrayMapConsistentHash() ; List<String> strings = new ArrayList<String>(); strings.add("45.78.28.220:9000:8081") ; strings.add("45.78.28.220:9100:9081") ; strings.add("45.78.28.220:9100:10081") ; String process = map.process(strings,"1551253899106"); System.out.println(process); Assert.assertEquals("45.78.28.220:9000:8081",process); }
@Test public void getFirstNodeValue7() { AbstractConsistentHash map = new SortArrayMapConsistentHash() ; List<String> strings = new ArrayList<String>(); strings.add("45.78.28.220:9000:8081") ; strings.add("45.78.28.220:9100:9081") ; strings.add("45.78.28.220:9100:10081") ; strings.add("45.78.28.220:9100:00081") ; String process = map.process(strings,"1551253899106"); System.out.println(process); Assert.assertEquals("45.78.28.220:9000:8081",process); }