DispatcherCache { public Dispatcher dispatcherFor(final InjectionPoint injectionPoint) { return createDispatcherIfAbsent(new DispatcherKey( componentNameExtractor.componentFrom(injectionPoint), componentLocationFrom(injectionPoint))); } @Inject  DispatcherCache(final DispatcherFactory dispatcherFactory,
                           final ComponentNameExtractor componentNameExtractor);  DispatcherCache(); Dispatcher dispatcherFor(final InjectionPoint injectionPoint); Dispatcher dispatcherFor(final ServiceComponentFoundEvent event); Dispatcher dispatcherFor(final String component, final ServiceComponentLocation location);  }
@Test public void shouldReturnTheSameDispatcherForTwoInjectionPoints() throws Exception { Dispatcher resultA = dispatcherCache.dispatcherFor(adaptorCommandApiInjectionPointA); Dispatcher resultB = dispatcherCache.dispatcherFor(adaptorCommandApiInjectionPointB); assertThat(resultA, is(sameInstance(resultB))); }
@Test public void shouldReturnDifferentDispatchersForCommandApiAndQueryApiInjectionPoints() throws Exception { Dispatcher resultA = dispatcherCache.dispatcherFor(adaptorCommandApiInjectionPointA); Dispatcher resultB = dispatcherCache.dispatcherFor(adaptorQueryApiInjectionPoint); assertThat(resultA, is(not(sameInstance(resultB)))); }
@Test public void shouldReturnTheSameDispatcherForTwoEventsConcerningSameComponent() throws Exception { final ServiceComponentFoundEvent foundEvent = new ServiceComponentFoundEvent("COMMAND_API", null, LOCAL); final ServiceComponentFoundEvent foundEvent2 = new ServiceComponentFoundEvent("COMMAND_API", null, LOCAL); final Dispatcher dispatcher1 = dispatcherCache.dispatcherFor(foundEvent); final Dispatcher dispatcher2 = dispatcherCache.dispatcherFor(foundEvent2); assertThat(dispatcher1, is(sameInstance(dispatcher2))); }
@Test public void shouldReturnDifferentDispatchersForLocalAndRemoteEvent() throws Exception { final ServiceComponentFoundEvent foundEvent = new ServiceComponentFoundEvent("COMMAND_API", null, LOCAL); final ServiceComponentFoundEvent foundEvent2 = new ServiceComponentFoundEvent("COMMAND_API", null, REMOTE); final Dispatcher dispatcher1 = dispatcherCache.dispatcherFor(foundEvent); final Dispatcher dispatcher2 = dispatcherCache.dispatcherFor(foundEvent2); assertThat(dispatcher1, is(not(sameInstance(dispatcher2)))); }
@Test public void shouldReturnDifferentDispatchersForDifferentComponents() throws Exception { final ServiceComponentFoundEvent foundEvent = new ServiceComponentFoundEvent("COMMAND_API", null, LOCAL); final ServiceComponentFoundEvent foundEvent2 = new ServiceComponentFoundEvent("QUERY_API", null, LOCAL); final Dispatcher dispatcher1 = dispatcherCache.dispatcherFor(foundEvent); final Dispatcher dispatcher2 = dispatcherCache.dispatcherFor(foundEvent2); assertThat(dispatcher1, is(not(sameInstance(dispatcher2)))); }
@Test public void shouldFindDispatchersByComponentAndLocation() throws Exception { final Dispatcher dispatcher1 = dispatcherCache.dispatcherFor(COMMAND_API, LOCAL); final Dispatcher dispatcher2 = dispatcherCache.dispatcherFor(COMMAND_API, LOCAL); assertThat(dispatcher1, is(notNullValue())); assertThat(dispatcher1, is(sameInstance(dispatcher2))); }