// Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
// 
//     public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//     
//     public static final String BASE_DIR = "config-data";
// 
//     public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
// 
//     public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
// 
//     public static final int DEFAULT_PORT = 54321;
// 
//     public static final String NULL = "";
// 
//     public static final String DATAID = "dataId";
// 
//     public static final String GROUP = "group";
// 
//     public static final String LAST_MODIFIED = "Last-Modified";
// 
//     public static final String ACCEPT_ENCODING = "Accept-Encoding";
// 
//     public static final String CONTENT_ENCODING = "Content-Encoding";
// 
//     public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
// 
//     public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
// 
//     public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
// 
//     public static final String CONTENT_MD5 = "Content-MD5";
// 
//     public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
// 
//     public static final String SPACING_INTERVAL = "client-spacing-interval";
//     
//     public static final String OPAQUE = "opaque";
// 
//     public static final int POLLING_INTERVAL_TIME = 15;// 秒
// 
//     public static final int ONCE_TIMEOUT = 5000;// 毫秒
// 
//     public static final int CONN_TIMEOUT = 5000;// 毫秒
// 
//     public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//     
//     public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//     
//     public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
// 
//     public static final String HTTP_URI_FILE = "/config.co";
//     
//     public static final String HTTP_PROTOCOL_PREFIX = "http://";
// 
//     public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
// 
//     public static final String ENCODE = "UTF-8";
//     
//     public static final String LINE_SEPARATOR = Character.toString((char) 1);
// 
//     public static final String WORD_SEPARATOR = Character.toString((char) 2);
//     
//     public static final int SC_OK = 200;
//     public static final int SC_REQUEST_TIMEOUT = 408;
// 
//     /*
//      * 批量操作时, 单条数据的状态码
//      */
//     // 发生异常
//     public static final int BATCH_OP_ERROR = -1;
//     // 查询成功, 数据存在
//     public static final int BATCH_QUERY_EXISTS = 1;
//     // 查询成功, 数据不存在
//     public static final int BATCH_QUERY_NONEXISTS = 2;
//     // 新增成功
//     public static final int BATCH_ADD_SUCCESS = 3;
//     // 更新成功
//     public static final int BATCH_UPDATE_SUCCESS = 4;
// 
// }


import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.taobao.diamond.common.Constants;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;

/**
 * 
 */
package com.taobao.diamond.httpclient;





/**
 * <pre>
 *
 * </pre>
 *
 * @author Wayne.Wang<5waynewang@gmail.com>
 * @since 4:36:56 PM Jun 20, 2016
 */
public class HttpClientTest {
	HttpClient httpClient;

	@Before
	public void before() {
		this.httpClient = new HttpClient();
		this.httpClient.start();
	}

	@After
	public void after() {
		this.httpClient.shutdown();
	}

	@Test
	public void testInvoke() throws Exception {
		final String host = "config.ixiaopu.com";
		final int port = 54321;

		// Prepare the HTTP request.
		HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
				"/config.co?group=XIANGQU&dataId=GLOBAL");
		request.headers().set(HttpHeaders.Names.HOST, host);
		request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);

		final HttpInvokeResult result = this.httpClient.invokeSync(host + ":" + port, request, 5000);

		System.out.println(result);
	}

	@Test
	public void testPost() throws Exception {
		final String host = "config.ixiaopu.com";
		final int port = 54321;

		Collection<Pair<String, ?>> parameters = new ArrayList<Pair<String, ?>>();

// Path: diamond-utils/src/main/java/com/taobao/diamond/common/Constants.java
// public class Constants {
// 
//     public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
//     
//     public static final String BASE_DIR = "config-data";
// 
//     public static final String DEFAULT_DOMAINNAME = "config.ixiaopu.com";
// 
//     public static final String DAILY_DOMAINNAME = "config.ixiaopu.com";
// 
//     public static final int DEFAULT_PORT = 54321;
// 
//     public static final String NULL = "";
// 
//     public static final String DATAID = "dataId";
// 
//     public static final String GROUP = "group";
// 
//     public static final String LAST_MODIFIED = "Last-Modified";
// 
//     public static final String ACCEPT_ENCODING = "Accept-Encoding";
// 
//     public static final String CONTENT_ENCODING = "Content-Encoding";
// 
//     public static final String PROBE_MODIFY_REQUEST = "Probe-Modify-Request";
// 
//     public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
// 
//     public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
// 
//     public static final String CONTENT_MD5 = "Content-MD5";
// 
//     public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
// 
//     public static final String SPACING_INTERVAL = "client-spacing-interval";
//     
//     public static final String OPAQUE = "opaque";
// 
//     public static final int POLLING_INTERVAL_TIME = 15;// 秒
// 
//     public static final int ONCE_TIMEOUT = 5000;// 毫秒
// 
//     public static final int CONN_TIMEOUT = 5000;// 毫秒
// 
//     public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;// 毫秒
//     
//     public static final int CLIENT_CHANNEL_MAX_IDLE_TIME_SECONDS = 120;// 秒
//     
//     public static final int MAX_CONTENT_LENGTH = 1024 * 1024;// 1MB
// 
//     public static final String HTTP_URI_FILE = "/config.co";
//     
//     public static final String HTTP_PROTOCOL_PREFIX = "http://";
// 
//     public static final String CONFIG_HTTP_URI_FILE = "/ServerNodes";
// 
//     public static final String ENCODE = "UTF-8";
//     
//     public static final String LINE_SEPARATOR = Character.toString((char) 1);
// 
//     public static final String WORD_SEPARATOR = Character.toString((char) 2);
//     
//     public static final int SC_OK = 200;
//     public static final int SC_REQUEST_TIMEOUT = 408;
// 
//     /*
//      * 批量操作时, 单条数据的状态码
//      */
//     // 发生异常
//     public static final int BATCH_OP_ERROR = -1;
//     // 查询成功, 数据存在
//     public static final int BATCH_QUERY_EXISTS = 1;
//     // 查询成功, 数据不存在
//     public static final int BATCH_QUERY_NONEXISTS = 2;
//     // 新增成功
//     public static final int BATCH_ADD_SUCCESS = 3;
//     // 更新成功
//     public static final int BATCH_UPDATE_SUCCESS = 4;
// 
// }


// Path: diamond-utils/src/test/java/com/taobao/diamond/httpclient/HttpClientTest.java
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.taobao.diamond.common.Constants;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;

/**
 * 
 */
package com.taobao.diamond.httpclient;





/**
 * <pre>
 *
 * </pre>
 *
 * @author Wayne.Wang<5waynewang@gmail.com>
 * @since 4:36:56 PM Jun 20, 2016
 */
public class HttpClientTest {
	HttpClient httpClient;

	@Before
	public void before() {
		this.httpClient = new HttpClient();
		this.httpClient.start();
	}

	@After
	public void after() {
		this.httpClient.shutdown();
	}

	@Test
	public void testInvoke() throws Exception {
		final String host = "config.ixiaopu.com";
		final int port = 54321;

		// Prepare the HTTP request.
		HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
				"/config.co?group=XIANGQU&dataId=GLOBAL");
		request.headers().set(HttpHeaders.Names.HOST, host);
		request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);

		final HttpInvokeResult result = this.httpClient.invokeSync(host + ":" + port, request, 5000);

		System.out.println(result);
	}

	@Test
	public void testPost() throws Exception {
		final String host = "config.ixiaopu.com";
		final int port = 54321;

		Collection<Pair<String, ?>> parameters = new ArrayList<Pair<String, ?>>();

		parameters.add(Pair.of(Constants.PROBE_MODIFY_REQUEST, "MEMCACHEDXIANGQU3e433623c8761a1903e2882afd52377c"));
