package com.ctrip.xpipe.redis.meta.server.job;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.Test;

import com.ctrip.xpipe.api.command.Command;
import com.ctrip.xpipe.redis.core.entity.RedisMeta;
import com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest;

/**
 * @author wenchao.meng
 *
 * Dec 14, 2016
 */
public class DefaultSlaveOfJobTest extends AbstractMetaServerTest{
	
	@Test
	public void testNoneSlavesSuccess() throws Exception{
		
		List<RedisMeta> slaves = new LinkedList<>();
		Command<Void> command = new DefaultSlaveOfJob(slaves, "localhost", randomPort(), getXpipeNettyClientKeyedObjectPool(), scheduled);
		command.execute().get(1, TimeUnit.SECONDS);
	}
	
	
	@Test
	public void testSlavesSuccess() throws Exception{
		
		List<RedisMeta> slaves = new LinkedList<>();
		slaves.add(new RedisMeta().setIp("localhost").setPort(6479));
		slaves.add(new RedisMeta().setIp("localhost").setPort(6579));
		
		Command<Void> command = new DefaultSlaveOfJob(slaves, "localhost", randomPort(), getXpipeNettyClientKeyedObjectPool(), scheduled);
		command.execute().get(1, TimeUnit.SECONDS);
		
	}


}

@@ -844,16 +844,74 @@
 st%3C%3E();%0A
+%09%09List%3CInteger%3E ports = new LinkedList%3C%3E(randomPorts(2));%0A
 %09%09slaves
@@ -962,12 +962,20 @@
 ort(
-6479
+ports.get(0)
 ));%0A
@@ -1034,13 +1034,104 @@
 ort(
-6579)
+ports.get(1)));%0A%09%09%0A%09%09startServer(ports.get(0), %22+OK%5Cr%5Cn%22);%0A%09%09startServer(ports.get(1), %22+OK%5Cr%5Cn%22
 );%0A%09

test start redis