<commit_before>package com.cardshifter.server.main;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.function.Predicate;

import com.cardshifter.api.outgoing.*;
import org.apache.log4j.PropertyConfigurator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.cardshifter.ai.AIs;
import com.cardshifter.ai.ScoringAI;
import com.cardshifter.api.ClientIO;
import com.cardshifter.api.both.ChatMessage;
import com.cardshifter.api.both.PlayerConfigMessage;
import com.cardshifter.api.incoming.LoginMessage;
import com.cardshifter.api.incoming.ServerQueryMessage;
import com.cardshifter.api.incoming.ServerQueryMessage.Request;
import com.cardshifter.api.incoming.StartGameRequest;
import com.cardshifter.api.incoming.UseAbilityMessage;
import com.cardshifter.api.outgoing.UserStatusMessage.Status;
import com.cardshifter.core.game.ServerGame;
import com.cardshifter.core.game.TCGGame;
import com.cardshifter.modapi.actions.ECSAction;
import com.cardshifter.modapi.ai.AIComponent;
import com.cardshifter.modapi.ai.CardshifterAI;
import com.cardshifter.modapi.base.ECSGameState;
import com.cardshifter.modapi.base.Entity;
import com.cardshifter.modapi.base.PlayerComponent;
import com.cardshifter.server.model.MainServer;
import com.cardshifter.server.model.Server;

public class ServerConnectionTest {

	private String getTestMod() {
        return mods.getMods()[0];
    }

	private TestClient createTestClient() throws IOException {
		return new TestClient(socketPort);
	}
	
	private MainServer main;
	private Server server;
	private int socketPort;
	private TestClient client1;
	private int userId;
    private AvailableModsMessage mods;

	private final int MAX_SERVER_PORT_TRY = 10;

    @Before
	public void setup() throws IOException, InterruptedException {
		PropertyConfigurator.configure(getClass().getResourceAsStream("log4j.properties"));
		ServerConfiguration config = ServerConfiguration.defaults();

		// The ports might be in use by another instance or application
		// Could use port = 0, but would need access to the ServerSocket to get the real port number
		for (int i = 0; i < MAX_SERVER_PORT_TRY; i++) {
			config.setPortSocket(config.getPortSocket() + i * 10);
			config.setPortWebsocket(config.getPortWebsocket() + i * 10);

			main = new MainServer(config);
			main.getMods().loadExternal(Paths.get("../extra-resources/groovy"));
			server = main.start();<commit_msg>Pick ports to try more sensibly<commit_after>package com.cardshifter.server.main;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.function.Predicate;

import com.cardshifter.api.outgoing.*;
import org.apache.log4j.PropertyConfigurator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.cardshifter.ai.AIs;
import com.cardshifter.ai.ScoringAI;
import com.cardshifter.api.ClientIO;
import com.cardshifter.api.both.ChatMessage;
import com.cardshifter.api.both.PlayerConfigMessage;
import com.cardshifter.api.incoming.LoginMessage;
import com.cardshifter.api.incoming.ServerQueryMessage;
import com.cardshifter.api.incoming.ServerQueryMessage.Request;
import com.cardshifter.api.incoming.StartGameRequest;
import com.cardshifter.api.incoming.UseAbilityMessage;
import com.cardshifter.api.outgoing.UserStatusMessage.Status;
import com.cardshifter.core.game.ServerGame;
import com.cardshifter.core.game.TCGGame;
import com.cardshifter.modapi.actions.ECSAction;
import com.cardshifter.modapi.ai.AIComponent;
import com.cardshifter.modapi.ai.CardshifterAI;
import com.cardshifter.modapi.base.ECSGameState;
import com.cardshifter.modapi.base.Entity;
import com.cardshifter.modapi.base.PlayerComponent;
import com.cardshifter.server.model.MainServer;
import com.cardshifter.server.model.Server;

public class ServerConnectionTest {

	private String getTestMod() {
        return mods.getMods()[0];
    }

	private TestClient createTestClient() throws IOException {
		return new TestClient(socketPort);
	}
	
	private MainServer main;
	private Server server;
	private int socketPort;
	private TestClient client1;
	private int userId;
    private AvailableModsMessage mods;

	private final int MAX_SERVER_PORT_TRY = 10;

    @Before
	public void setup() throws IOException, InterruptedException {
		PropertyConfigurator.configure(getClass().getResourceAsStream("log4j.properties"));
		ServerConfiguration config = ServerConfiguration.defaults();

		int basePortSocket = config.getPortSocket();
		int basePortWebsocket = config.getPortWebsocket();

		// The ports might be in use by another instance or application
		// Could use port = 0, but would need access to the ServerSocket to get the real port number
		for (int i = 0; i < MAX_SERVER_PORT_TRY; i++) {
			config.setPortSocket(basePortSocket + i * 10);
			config.setPortWebsocket(basePortWebsocket + i * 10);

			main = new MainServer(config);
			main.getMods().loadExternal(Paths.get("../extra-resources/groovy"));
			server = main.start();
{'fraction_non_alphanumeric': 0.10009132420091324, 'fraction_numerical': 0.004383561643835616, 'mean_word_length': 5.542413381123058, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6082178', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1678, 'n_words': 358}