<commit_before>package com.j256.simplejmx.server;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.lang.reflect.Field;
import java.net.InetAddress;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.concurrent.atomic.AtomicInteger;

import javax.management.JMException;
import javax.management.ObjectName;
import javax.management.ReflectionException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.j256.simplejmx.client.JmxClient;
import com.j256.simplejmx.common.JmxAttributeField;
import com.j256.simplejmx.common.JmxAttributeFieldInfo;
import com.j256.simplejmx.common.JmxAttributeMethod;
import com.j256.simplejmx.common.JmxAttributeMethodInfo;
import com.j256.simplejmx.common.JmxFolderName;
import com.j256.simplejmx.common.JmxOperation;
import com.j256.simplejmx.common.JmxOperationInfo;
import com.j256.simplejmx.common.JmxOperationInfo.OperationAction;
import com.j256.simplejmx.common.JmxResource;
import com.j256.simplejmx.common.JmxSelfNaming;
import com.j256.simplejmx.common.ObjectNameUtil;

public class JmxServerTest {

	private static final int DEFAULT_PORT = 5256;
	private static final String DOMAIN_NAME = "j256";
	private static final String OBJECT_NAME = "testObject";
	private static final int FOO_VALUE = 1459243;
	private static final String FOLDER_FIELD_NAME = "00";
	private static final String FOLDER_VALUE_NAME = "FolderName";
	private static final String FOLDER_NAME = FOLDER_FIELD_NAME + "=" + FOLDER_VALUE_NAME;

	private static JmxServer server;
	private static InetAddress serverAddress;
	private static AtomicInteger differentPost = new AtomicInteger(DEFAULT_PORT);

	@BeforeClass
	public static void beforeClass() throws Exception {
		serverAddress = InetAddress.getByName("127.0.0.1");
		server = new JmxServer(serverAddress, DEFAULT_PORT);
		server.start();
	}

	@AfterClass
	public static void afterClass() {
		server.stop();
	}

	@Test
	public void testJmxServerStartStopStart() throws Exception {
		server = new JmxServer(serverAddress, differentPost.incrementAndGet());
		server.stop();
		server.start();
	}

	@Test(expected = JMException.class)
	public void testJmxServerDoubleInstance() throws Exception {
		int port = differentPost.incrementAndGet();
		JmxServer first = new JmxServer(serverAddress, port);
		try {
			first.start();
			new JmxServer(serverAddress, port).start();
		} finally {
			first.stop();
		}
	}

	@Test(expected = IllegalArgumentException.class)
	public void testJmxServerWildPort() throws Exception {
		JmxServer server = new JmxServer(serverAddress, -10);
		try {
			server.start();
		} finally {
			server.stop();
		}
	}

	@Test(expected = JMException.class)
	public void testDoubleClose() throws Exception {
		JmxServer server = new JmxServer(serverAddress, differentPost.incrementAndGet());
		try {
			server.start();
		} finally {
			Field field = server.getClass().getDeclaredField("rmiRegistry");
			field.setAccessible(true);
			Registry rmiRegistry = (Registry) field.get(server);
			// close the rmi registry through trickery!
			UnicastRemoteObject.unexportObject(rmiRegistry, true);
			try {
				server.stopThrow();
			} finally {
				server.stop();<commit_msg>Found a server i didn't stop.<commit_after>package com.j256.simplejmx.server;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.lang.reflect.Field;
import java.net.InetAddress;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.concurrent.atomic.AtomicInteger;

import javax.management.JMException;
import javax.management.ObjectName;
import javax.management.ReflectionException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.j256.simplejmx.client.JmxClient;
import com.j256.simplejmx.common.JmxAttributeField;
import com.j256.simplejmx.common.JmxAttributeFieldInfo;
import com.j256.simplejmx.common.JmxAttributeMethod;
import com.j256.simplejmx.common.JmxAttributeMethodInfo;
import com.j256.simplejmx.common.JmxFolderName;
import com.j256.simplejmx.common.JmxOperation;
import com.j256.simplejmx.common.JmxOperationInfo;
import com.j256.simplejmx.common.JmxOperationInfo.OperationAction;
import com.j256.simplejmx.common.JmxResource;
import com.j256.simplejmx.common.JmxSelfNaming;
import com.j256.simplejmx.common.ObjectNameUtil;

public class JmxServerTest {

	private static final int DEFAULT_PORT = 5256;
	private static final String DOMAIN_NAME = "j256";
	private static final String OBJECT_NAME = "testObject";
	private static final int FOO_VALUE = 1459243;
	private static final String FOLDER_FIELD_NAME = "00";
	private static final String FOLDER_VALUE_NAME = "FolderName";
	private static final String FOLDER_NAME = FOLDER_FIELD_NAME + "=" + FOLDER_VALUE_NAME;

	private static JmxServer server;
	private static InetAddress serverAddress;
	private static AtomicInteger differentPost = new AtomicInteger(DEFAULT_PORT);

	@BeforeClass
	public static void beforeClass() throws Exception {
		serverAddress = InetAddress.getByName("127.0.0.1");
		server = new JmxServer(serverAddress, DEFAULT_PORT);
		server.start();
	}

	@AfterClass
	public static void afterClass() {
		server.stop();
	}

	@Test
	public void testJmxServerStartStopStart() throws Exception {
		server = new JmxServer(serverAddress, differentPost.incrementAndGet());
		try {
			server.stop();
			server.start();
		} finally {
			server.stop();
		}
	}

	@Test(expected = JMException.class)
	public void testJmxServerDoubleInstance() throws Exception {
		int port = differentPost.incrementAndGet();
		JmxServer first = new JmxServer(serverAddress, port);
		JmxServer second = new JmxServer(serverAddress, port);
		try {
			first.start();
			second.start();
		} finally {
			first.stop();
			second.stop();
		}
	}

	@Test(expected = IllegalArgumentException.class)
	public void testJmxServerWildPort() throws Exception {
		JmxServer server = new JmxServer(serverAddress, -10);
		try {
			server.start();
		} finally {
			server.stop();
		}
	}

	@Test(expected = JMException.class)
	public void testDoubleClose() throws Exception {
		JmxServer server = new JmxServer(serverAddress, differentPost.incrementAndGet());
		try {
			server.start();
		} finally {
			Field field = server.getClass().getDeclaredField("rmiRegistry");
			field.setAccessible(true);
			Registry rmiRegistry = (Registry) field.get(server);
			// close the rmi registry through trickery!
			UnicastRemoteObject.unexportObject(rmiRegistry, true);
			try {
				server.stopThrow();
			} finally {
				server.stop();
{'fraction_non_alphanumeric': 0.10130376142664468, 'fraction_numerical': 0.018882062041060993, 'mean_word_length': 5.3260663507109, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4937565', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2067, 'n_words': 449}