// Path: core/src/java/com/strategicgains/eventing/local/LocalEventBus.java
// public class LocalEventBus
// extends EventBus
// {
// 	public LocalEventBus(Collection<EventHandler> handlers, boolean shouldReraiseOnError, long pollDelayMillis)
// 	{
// 		super(new LocalEventTransport(handlers, shouldReraiseOnError, pollDelayMillis));
// 	}
// 
// 	/**
// 	 * @param value
// 	 */
//     public void retryOnError(boolean value)
//     {
//     	((LocalEventTransport) getTransport()).retryOnError(value);
//     }
// }
// 
// Path: core/src/java/com/strategicgains/eventing/local/LocalEventBusBuilder.java
// public class LocalEventBusBuilder
// implements EventBusBuilder<LocalEventBus, LocalEventBusBuilder>
// {
// 	private static final long DEFAULT_POLL_DELAY = 0L;
// 
// 	private Set<EventHandler> subscribers = new LinkedHashSet<EventHandler>();
// 	private Set<Class<?>> publishableEventTypes = new HashSet<Class<?>>();
// 	private boolean shouldRepublishOnError = false;
// 	private long pollDelay = DEFAULT_POLL_DELAY;
// 
// 	public LocalEventBusBuilder()
// 	{
// 		super();
// 	}
// 
// 	@Override
// 	public LocalEventBus build()
// 	{
// 		assert(!subscribers.isEmpty());
// 
// 		LocalEventBus bus = new LocalEventBus(subscribers, shouldRepublishOnError, pollDelay);
// 		
// 		for (Class<?> eventType : publishableEventTypes)
// 		{
// 			bus.addPublishableEventType(eventType);
// 		}
// 		
// 		return bus;
// 	}
// 
//     public LocalEventBusBuilder shouldRepublishOnError(boolean value)
//     {
//     	this.shouldRepublishOnError = value;
// 	    return this;
//     }
//     
//     public LocalEventBusBuilder pollDelay(long millis)
//     {
//     	this.pollDelay = millis;
//     	return this;
//     }
// 
//     @Override
//     public LocalEventBusBuilder subscribe(EventHandler handler)
//     {
//     	if (!subscribers.contains(handler))
//     	{
//     		subscribers.add(handler);
//     	}
//     	
//     	return this;
//     }
// 
//     @Override
//     public LocalEventBusBuilder unsubscribe(EventHandler handler)
//     {
//     	subscribers.remove(handler);
//     	return this;
//     }
//     
//     public LocalEventBusBuilder addPublishableEventType(Class<?> eventType)
//     {
//     	publishableEventTypes.add(eventType);
//     	return this;
//     }
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.strategicgains.eventing.local.LocalEventBus;
import com.strategicgains.eventing.local.LocalEventBusBuilder;
	{
		assertEquals(0, handler.getCallCount());
		DomainEvents.publish(new ErroredEvent());
		Thread.sleep(150);
		assertEquals(1, handler.getCallCount());
		assertEquals(0, ignoredHandler.getCallCount());
		assertEquals(0, longHandler.getCallCount());
	}

	@Test
	public void shouldProcessInParallel()
	throws Exception
	{
		assertEquals(0, longHandler.getCallCount());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		Thread.sleep(150);
		assertEquals(0, handler.getCallCount());
		assertEquals(0, ignoredHandler.getCallCount());
		System.out.println("longHandler instance=" + longHandler.toString());
		assertEquals(5, longHandler.getCallCount());
	}

	@Test
	public void shouldOnlyPublishSelected()
	throws Exception
	{
// Path: core/src/java/com/strategicgains/eventing/local/LocalEventBus.java
// public class LocalEventBus
// extends EventBus
// {
// 	public LocalEventBus(Collection<EventHandler> handlers, boolean shouldReraiseOnError, long pollDelayMillis)
// 	{
// 		super(new LocalEventTransport(handlers, shouldReraiseOnError, pollDelayMillis));
// 	}
// 
// 	/**
// 	 * @param value
// 	 */
//     public void retryOnError(boolean value)
//     {
//     	((LocalEventTransport) getTransport()).retryOnError(value);
//     }
// }
// 
// Path: core/src/java/com/strategicgains/eventing/local/LocalEventBusBuilder.java
// public class LocalEventBusBuilder
// implements EventBusBuilder<LocalEventBus, LocalEventBusBuilder>
// {
// 	private static final long DEFAULT_POLL_DELAY = 0L;
// 
// 	private Set<EventHandler> subscribers = new LinkedHashSet<EventHandler>();
// 	private Set<Class<?>> publishableEventTypes = new HashSet<Class<?>>();
// 	private boolean shouldRepublishOnError = false;
// 	private long pollDelay = DEFAULT_POLL_DELAY;
// 
// 	public LocalEventBusBuilder()
// 	{
// 		super();
// 	}
// 
// 	@Override
// 	public LocalEventBus build()
// 	{
// 		assert(!subscribers.isEmpty());
// 
// 		LocalEventBus bus = new LocalEventBus(subscribers, shouldRepublishOnError, pollDelay);
// 		
// 		for (Class<?> eventType : publishableEventTypes)
// 		{
// 			bus.addPublishableEventType(eventType);
// 		}
// 		
// 		return bus;
// 	}
// 
//     public LocalEventBusBuilder shouldRepublishOnError(boolean value)
//     {
//     	this.shouldRepublishOnError = value;
// 	    return this;
//     }
//     
//     public LocalEventBusBuilder pollDelay(long millis)
//     {
//     	this.pollDelay = millis;
//     	return this;
//     }
// 
//     @Override
//     public LocalEventBusBuilder subscribe(EventHandler handler)
//     {
//     	if (!subscribers.contains(handler))
//     	{
//     		subscribers.add(handler);
//     	}
//     	
//     	return this;
//     }
// 
//     @Override
//     public LocalEventBusBuilder unsubscribe(EventHandler handler)
//     {
//     	subscribers.remove(handler);
//     	return this;
//     }
//     
//     public LocalEventBusBuilder addPublishableEventType(Class<?> eventType)
//     {
//     	publishableEventTypes.add(eventType);
//     	return this;
//     }
// }


// Path: core/test/java/com/strategicgains/eventing/DomainEventsTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.strategicgains.eventing.local.LocalEventBus;
import com.strategicgains.eventing.local.LocalEventBusBuilder;

	{
		assertEquals(0, handler.getCallCount());
		DomainEvents.publish(new ErroredEvent());
		Thread.sleep(150);
		assertEquals(1, handler.getCallCount());
		assertEquals(0, ignoredHandler.getCallCount());
		assertEquals(0, longHandler.getCallCount());
	}

	@Test
	public void shouldProcessInParallel()
	throws Exception
	{
		assertEquals(0, longHandler.getCallCount());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		DomainEvents.publish(new LongEvent());
		Thread.sleep(150);
		assertEquals(0, handler.getCallCount());
		assertEquals(0, ignoredHandler.getCallCount());
		System.out.println("longHandler instance=" + longHandler.toString());
		assertEquals(5, longHandler.getCallCount());
	}

	@Test
	public void shouldOnlyPublishSelected()
	throws Exception
	{
		((LocalEventBus) DomainEvents.getBus("primary")).addPublishableEventType(HandledEvent.class);