<commit_before>/**
 * Copyright (C) 2011-2013 Barchart, Inc. <http://www.barchart.com/>
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */
package com.barchart.netty.server.http;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import io.netty.channel.nio.NioEventLoopGroup;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.util.Queue;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.barchart.netty.server.Servers;
import com.barchart.netty.server.http.request.HttpServerRequest;
import com.barchart.netty.server.http.request.RequestHandlerBase;

public class TestHttpServer {

	private HttpServer server;
	private HttpClient client;

	private int port;

	private TestRequestHandler basic;
	private TestRequestHandler async;
	private TestRequestHandler asyncDelayed;
	private TestRequestHandler clientDisconnect;
	private TestRequestHandler error;
	private TestRequestHandler channelError;

	private TestRequestHandler serviceHandler;
	private TestRequestHandler infoHandler;

	private ChunkedRequestHandler chunkedHandler;

	@Before
	public void setUp() throws Exception {

		basic = new TestRequestHandler("basic", false, 0, 0, false, false);
		async = new TestRequestHandler("async", true, 0, 0, false, false);
		asyncDelayed =
				new TestRequestHandler("async-delayed", true, 50, 0, false,
						false);
		clientDisconnect =
				new TestRequestHandler("", true, 500, 500, false, false);
		error = new TestRequestHandler("error", false, 0, 0, true, false);
		channelError =
				new TestRequestHandler("channel-error", false, 0, 0, false,
						true);

		infoHandler = new TestRequestHandler("info", false, 0, 0, false, false);
		serviceHandler =
				new TestRequestHandler("service", false, 0, 0, false, false);

		chunkedHandler = new ChunkedRequestHandler("chunked");

		final ServerSocket s = new ServerSocket(0);
		port = s.getLocalPort();
		s.close();

		server =<commit_msg>Wait after closing socket to re-use, seems to be some timing issues?<commit_after>/**
 * Copyright (C) 2011-2013 Barchart, Inc. <http://www.barchart.com/>
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */
package com.barchart.netty.server.http;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import io.netty.channel.nio.NioEventLoopGroup;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.util.Queue;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.barchart.netty.server.Servers;
import com.barchart.netty.server.http.request.HttpServerRequest;
import com.barchart.netty.server.http.request.RequestHandlerBase;

public class TestHttpServer {

	private HttpServer server;
	private HttpClient client;

	private int port;

	private TestRequestHandler basic;
	private TestRequestHandler async;
	private TestRequestHandler asyncDelayed;
	private TestRequestHandler clientDisconnect;
	private TestRequestHandler error;
	private TestRequestHandler channelError;

	private TestRequestHandler serviceHandler;
	private TestRequestHandler infoHandler;

	private ChunkedRequestHandler chunkedHandler;

	@Before
	public void setUp() throws Exception {

		basic = new TestRequestHandler("basic", false, 0, 0, false, false);
		async = new TestRequestHandler("async", true, 0, 0, false, false);
		asyncDelayed =
				new TestRequestHandler("async-delayed", true, 50, 0, false,
						false);
		clientDisconnect =
				new TestRequestHandler("", true, 500, 500, false, false);
		error = new TestRequestHandler("error", false, 0, 0, true, false);
		channelError =
				new TestRequestHandler("channel-error", false, 0, 0, false,
						true);

		infoHandler = new TestRequestHandler("info", false, 0, 0, false, false);
		serviceHandler =
				new TestRequestHandler("service", false, 0, 0, false, false);

		chunkedHandler = new ChunkedRequestHandler("chunked");

		final ServerSocket s = new ServerSocket(0);
		port = s.getLocalPort();
		s.close();
		Thread.sleep(100);

		server =
{'fraction_non_alphanumeric': 0.10494675369288904, 'fraction_numerical': 0.01082102370319478, 'mean_word_length': 5.4485049833887045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '419922', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1699, 'n_words': 420}