<commit_before>/***************************************************************************
 * Copyright 2017 Kieker Project (http://kieker-monitoring.net)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ***************************************************************************/

package kieker.monitoring.core.controller;

import java.lang.Thread.State;

import org.hamcrest.CoreMatchers;
import org.jctools.queues.MpscArrayQueue;
import org.junit.Assert;
import org.junit.Test;

import kieker.Await;
import kieker.common.configuration.Configuration;
import kieker.common.record.misc.EmptyRecord;
import kieker.monitoring.core.configuration.ConfigurationFactory;
import kieker.monitoring.writer.dump.DumpWriter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
 *
 * @author <NAME>
 *
 * @since 1.13
 */
public class WriterControllerTest {

	private static final int THREAD_STATE_CHANGE_TIMEOUT_IN_MS = 1000;
	private static final long CONTROLLER_TIMEOUT_IN_MS = 1000;

	public WriterControllerTest() {
		super();
	}

	@Test(expected = ClassNotFoundException.class)
	public void testInvalidWriterQueueConfiguration() {
		final Configuration configuration = new Configuration();
		configuration.setProperty(ConfigurationFactory.WRITER_CLASSNAME, "invalid writer queue fully qualified name");

		new WriterController(configuration);
	}

	@Test
	@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON")
	// @SuppressFBWarnings("SIC")
	public void testBlockOnFailedInsertBehavior() throws Exception {
		final Configuration configuration = new Configuration();
		configuration.setProperty(ConfigurationFactory.WRITER_CLASSNAME, DumpWriter.class.getName());
		configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_FQN,
				MpscArrayQueue.class.getName());
		configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_SIZE, "1");
		configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_INSERT_BEHAVIOR, "1");

		final WriterController writerController = new WriterController(configuration);

		final Thread thread = new Thread(new Runnable() {
			@Override<commit_msg>fixed test<commit_after>/***************************************************************************
 * Copyright 2017 Kieker Project (http://kieker-monitoring.net)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ***************************************************************************/

package kieker.monitoring.core.controller;

import java.lang.Thread.State;

import org.hamcrest.CoreMatchers;
import org.jctools.queues.MpscArrayQueue;
import org.junit.Assert;
import org.junit.Test;

import kieker.Await;
import kieker.common.configuration.Configuration;
import kieker.common.record.misc.EmptyRecord;
import kieker.monitoring.core.configuration.ConfigurationFactory;
import kieker.monitoring.writer.dump.DumpWriter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
 *
 * @author <NAME>
 *
 * @since 1.13
 */
public class WriterControllerTest {

	private static final int THREAD_STATE_CHANGE_TIMEOUT_IN_MS = 1000;
	private static final long CONTROLLER_TIMEOUT_IN_MS = 1000;

	public WriterControllerTest() {
		super();
	}

	@Test(expected = IllegalStateException.class)
	public void testInvalidWriterQueueConfiguration() {
		final Configuration configuration = new Configuration();
		configuration.setProperty(ConfigurationFactory.WRITER_CLASSNAME, "invalid writer queue fully qualified name");

		new WriterController(configuration);
	}

	@Test
	@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON")
	// @SuppressFBWarnings("SIC")
	public void testBlockOnFailedInsertBehavior() throws Exception {
		final Configuration configuration = new Configuration();
		configuration.setProperty(ConfigurationFactory.WRITER_CLASSNAME, DumpWriter.class.getName());
		configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_FQN,
				MpscArrayQueue.class.getName());
		configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_SIZE, "1");
		configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_INSERT_BEHAVIOR, "1");

		final WriterController writerController = new WriterController(configuration);

		final Thread thread = new Thread(new Runnable() {
			@Override
{'fraction_non_alphanumeric': 0.13840960240060016, 'fraction_numerical': 0.007876969242310577, 'mean_word_length': 6.091755319148936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1698222', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1399, 'n_words': 370}