<commit_before>package nl.tudelft.ewi.dea;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.ServerSocket;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.eclipse.jetty.server.Server;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DevHubServerTest {

	private static final Logger LOG = LoggerFactory.getLogger(DevHubServerTest.class);

	private static final int PORT = 10_000;

	private Server server;

	@Before
	public void setUp() throws Exception {
		assertThat("Port is available", available(PORT), is(true));
		server = new Server(PORT);
		server.setHandler(DevHubServer.buildWebAppContext());
		server.start();
	}

	@After
	public void tearDown() throws Exception {
		server.stop();
	}

	@Test
	public void testThatTheServerCanBeRunAndRootIsGettable() throws Exception {

		HttpClient client = new DefaultHttpClient();
		HttpGet get = new HttpGet("http://localhost:" + PORT + "/");

		LOG.info("Executing GET for url: {}", get.getURI());
		HttpResponse response = client.execute(get);

		if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
			fail("GET response not 200, but: " + response.getStatusLine());
		}

		client.getConnectionManager().shutdown();

	}

	/**
	 * Checks to see if a specific port is available.
	 * 
	 * @param port the port to check for availability
	 */
	public static boolean available(int port) {
		ServerSocket ss = null;
		DatagramSocket ds = null;
		try {
			ss = new ServerSocket(port);
			ss.setReuseAddress(true);
			ds = new DatagramSocket(port);
			ds.setReuseAddress(true);
			return true;
		} catch (IOException e) {
		} finally {
			if (ds != null) {
				ds.close();
			}
			if (ss != null) {
				try {
					ss.close();
				} catch (IOException e) {
					/* should not be thrown */
				}
			}
		}
		return false;
	}

}<commit_msg>DevhubServertest now grabs a random available port<commit_after>package nl.tudelft.ewi.dea;

import static org.junit.Assert.fail;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DevHubServerTest {

	private static final Logger LOG = LoggerFactory.getLogger(DevHubServerTest.class);

	private Server server;

	private int port;

	@Before
	public void setUp() throws Exception {
		server = new Server(0);
		server.setHandler(DevHubServer.buildWebAppContext());
		server.start();
		this.port = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
	}

	@After
	public void tearDown() throws Exception {
		server.stop();
	}

	@Test
	public void testThatTheServerCanBeRunAndRootIsGettable() throws Exception {

		HttpClient client = new DefaultHttpClient();
		HttpGet get = new HttpGet("http://localhost:" + port + "/");

		LOG.info("Executing GET for url: {}", get.getURI());
		HttpResponse response = client.execute(get);

		if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
			fail("GET response not 200, but: " + response.getStatusLine());
		}

		client.getConnectionManager().shutdown();

	}

}
{'fraction_non_alphanumeric': 0.12329134280353793, 'fraction_numerical': 0.004556419190565532, 'mean_word_length': 4.440233236151603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5630413', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1165, 'n_words': 278}