/
ChooserTest.java
61 lines (55 loc) · 1.59 KB
/
ChooserTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
***************************************************************************************
*
* @Title: ChooserTest.java
* @Package io.github.junxworks.junx.test.core
* @Description: (用一句话描述该文件做什么)
* @author: Michael
* @date: 2018-10-10 10:55:35
* @version V1.0
* @Copyright: 2018 JunxWorks. All rights reserved.
*
* ----------------------------------------------------------------------------------
* 文件修改记录
* 文件版本: 修改人: 修改原因:
***************************************************************************************
*/
package io.github.junxworks.junx.test.core;
import org.junit.Test;
import io.github.junxworks.junx.core.chooser.Chooser;
import io.github.junxworks.junx.core.chooser.strategy.Strategy;
/**
* 选择算法测试
*
* @ClassName: ChooserTest
* @author: Michael
* @date: 2018-10-10 10:53:30
* @since: v1.0
*/
public class ChooserTest {
private String[] aa = new String[] { "a", "b", "c", "d" };
/**
* 一致性哈希
*/
@Test
public void consistentHash() {
Chooser<String> c = new Chooser<String>(aa);
c.setStrategy(Strategy.CHash);
c.getContext().setChooseId("1234561123");
String s = null;
while ((s = c.next()) != null) {
System.out.println("ch:" + s);
}
}
/**
* 随机起点的顺序选择
*/
@Test
public void randomSequence() {
Chooser<String> c = new Chooser<String>(aa);
String s = null;
while ((s = c.next()) != null) {
System.out.println("rs:" + s);
}
}
}