<commit_before>package grails.plugin.asyncevents

import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import org.codehaus.groovy.grails.support.MockApplicationContext
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.springframework.context.ApplicationEvent
import org.springframework.util.ErrorHandler
import static grails.plugin.asyncevents.RetryPolicy.DEFAULT_BACKOFF_MULTIPLIER
import static grails.test.MockUtils.mockLogging
import static java.util.concurrent.TimeUnit.MILLISECONDS
import static java.util.concurrent.TimeUnit.SECONDS
import static org.hamcrest.CoreMatchers.*
import static org.junit.Assert.*

class EventPublisherServiceTests {

	static final long RETRY_DELAY_MILLIS = 250

	MockApplicationContext applicationContext = new MockApplicationContext()
	EventPublisherService service = new EventPublisherService()
	ApplicationEvent event = new DummyEvent()

	@Test
	void shutsDownCleanly() {
		service.shutdownExecutors()
		assertTrue "Worker thread has not stopped", service.executor.awaitTermination(1, SECONDS)
	}

	@Test
	void publishesEventToAllListeners() {
		int numListeners = 2
		def latch = new CountDownLatch(numListeners)

		numListeners.times {
			service.addListener new CountingListener(latch)
		}

		service.publishEvent(event)<commit_msg>remove unused field in test<commit_after>package grails.plugin.asyncevents

import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import org.codehaus.groovy.grails.support.MockApplicationContext
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.springframework.context.ApplicationEvent
import org.springframework.util.ErrorHandler
import static grails.plugin.asyncevents.RetryPolicy.DEFAULT_BACKOFF_MULTIPLIER
import static grails.test.MockUtils.mockLogging
import static java.util.concurrent.TimeUnit.MILLISECONDS
import static java.util.concurrent.TimeUnit.SECONDS
import static org.hamcrest.CoreMatchers.*
import static org.junit.Assert.*

class EventPublisherServiceTests {

	static final long RETRY_DELAY_MILLIS = 250

	EventPublisherService service = new EventPublisherService()
	ApplicationEvent event = new DummyEvent()

	@Test
	void shutsDownCleanly() {
		service.shutdownExecutors()
		assertTrue "Worker thread has not stopped", service.executor.awaitTermination(1, SECONDS)
	}

	@Test
	void publishesEventToAllListeners() {
		int numListeners = 2
		def latch = new CountDownLatch(numListeners)

		numListeners.times {
			service.addListener new CountingListener(latch)
		}

		service.publishEvent(event)
{'fraction_non_alphanumeric': 0.07185854025583145, 'fraction_numerical': 0.003762227238525207, 'mean_word_length': 6.284931506849315, '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': '7151739', 'n_tokens_mistral': 818, 'n_tokens_neox': 768, 'n_words': 167}