|
|
|
@ -14,16 +14,16 @@
|
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.server.master.dispatch.host.assign; |
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.StringUtils; |
|
|
|
|
import org.apache.dolphinscheduler.remote.utils.Host; |
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* round robin selector |
|
|
|
@ -33,43 +33,59 @@ public class RoundRobinSelectorTest {
|
|
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
|
public void testSelectWithIllegalArgumentException() { |
|
|
|
|
RoundRobinSelector selector = new RoundRobinSelector(); |
|
|
|
|
selector.select(Collections.EMPTY_LIST); |
|
|
|
|
selector.select(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testSelect1() { |
|
|
|
|
RoundRobinSelector selector = new RoundRobinSelector(); |
|
|
|
|
Host result = null; |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
Host result; |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.2", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
// add new host
|
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.2", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"), |
|
|
|
|
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"), |
|
|
|
|
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.3", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"), |
|
|
|
|
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"), |
|
|
|
|
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.2", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"), new Host("192.168.1.3", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"), new Host("192.168.1.3", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.3",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"), new Host("192.168.1.3", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"), new Host("192.168.1.3", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.2",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"), new Host("192.168.1.3", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"), new Host("192.168.1.3", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.3",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"), |
|
|
|
|
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"), |
|
|
|
|
new Host("192.168.1.3", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.3", result.getIp()); |
|
|
|
|
// remove host3
|
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.2",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, "kris"), new Host("192.168.1.2", 80, 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1",result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.2", result.getIp()); |
|
|
|
|
result = selector.select(Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis(), "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis(), "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.1", result.getIp()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testWarmUpRoundRobinSelector() { |
|
|
|
|
RoundRobinSelector selector = new RoundRobinSelector(); |
|
|
|
|
Host result; |
|
|
|
|
result = selector.select( |
|
|
|
|
Arrays.asList(new Host("192.168.1.1", 80, 20, System.currentTimeMillis() - 60 * 1000 * 2, "kris"), new Host("192.168.1.2", 80, 10, System.currentTimeMillis() - 60 * 1000 * 10, "kris"))); |
|
|
|
|
Assert.assertEquals("192.168.1.2", result.getIp()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|