@Override public LuceneWorkSerializer getWorkSerializer() { if ( workSerializer == null ) { workSerializer = serviceManager.requestService( LuceneWorkSerializer.class ); } return workSerializer; }
private LuceneWorkSerializer requestSerializer() { try { return serviceManager.requestService( LuceneWorkSerializer.class ); } catch (SearchException se) { throw log.serializationProviderNotFoundException( se ); } }
private SerializationProvider requestSerializationProvider() { try { return serviceManager.requestService( SerializationProvider.class ); } catch (SearchException se) { throw LOG.serializationProviderNotFoundException( se ); } }
private SerializationProvider requestSerializationProvider() { try { return serviceManager.requestService( SerializationProvider.class ); } catch (SearchException se) { throw log.serializationProviderNotFoundException( se ); } }
private static LockFactory getLockFactory(Path indexDir, Properties properties, ServiceManager serviceManager) { try { return serviceManager.requestService( LockFactoryCreator.class ).createLockFactory( indexDir, properties ); } finally { serviceManager.releaseService( LockFactoryCreator.class ); } }
protected DirectoryProvider<?> createDirectoryProvider(String indexName, Properties cfg, WorkerBuildContext buildContext) { try { DirectoryProviderService directoryProviderService = serviceManager.requestService( DirectoryProviderService.class ); return directoryProviderService.create( cfg, indexName, buildContext ); } finally { serviceManager.releaseService( DirectoryProviderService.class ); } }
@Override public void start(Properties properties, BuildContext context) { ServiceManager serviceManager = context.getServiceManager(); // requesting service in a circular way serviceManager.requestService( FooService.class ); } }
private static NestingContextFactory getNestingContextFactory(ConfigContext context) { try { NestingContextFactoryProvider nestingContextFactoryProvider = context.getServiceManager().requestService( NestingContextFactoryProvider.class ); return nestingContextFactoryProvider.getNestingContextFactory(); } catch (Exception e) { return DefaultNestingContextFactory.INSTANCE; } finally { context.getServiceManager().releaseService( NestingContextFactoryProvider.class ); } }
@Before public void setUp() { ServiceManager serviceManager = getTestServiceManager(); workSerializer = serviceManager.requestService( LuceneWorkSerializer.class ); }
@Before public void setUp() { ServiceManager serviceManager = getTestServiceManager(); workSerializer = serviceManager.requestService( LuceneWorkSerializer.class ); }
@Test public void testNullParameterForRequestServiceThrowsException() { thrown.expect( IllegalArgumentException.class ); serviceManagerUnderTest.requestService( null ); }
@Test public void testRetrieveService() { SimpleService simpleService = serviceManagerUnderTest.requestService( SimpleService.class ); assertNotNull( "The service should be created", simpleService ); assertTrue( simpleService instanceof SimpleServiceImpl ); }
@Test public void testUnavailableServiceThrowsException() { thrown.expect( SearchException.class ); thrown.expectMessage( JUnitMatchers.containsString( "HSEARCH000196" ) ); serviceManagerUnderTest.requestService( NonExistentService.class ); }
@Test public void testCircularServiceDependencyThrowsException() { thrown.expect( SearchException.class ); thrown.expectMessage( JUnitMatchers.containsString( "HSEARCH000198" ) ); serviceManagerUnderTest.requestService( FooService.class ); }
@Before public void setUp() { ServiceManager serviceManager = new StandardServiceManager( new SearchConfigurationForTest(), null ); serializationProvider = serviceManager.requestService( SerializationProvider.class ); }
@Test @TestForIssue(jiraKey = "HSEARCH-1547") public void testRequestingServiceAfterReleaseAllThrowsException() { SimpleService simpleService1 = serviceManagerUnderTest.requestService( SimpleService.class ); assertNotNull( "The service should be created", simpleService1 ); serviceManagerUnderTest.releaseService( SimpleService.class ); serviceManagerUnderTest.releaseAllServices(); thrown.expect( IllegalStateException.class ); thrown.expectMessage( JUnitMatchers.containsString( "HSEARCH000209" ) ); serviceManagerUnderTest.requestService( SimpleService.class ); }
@Test public void testStartServiceIsPerformed() { StartableService service = serviceManagerUnderTest.requestService( StartableService.class ); assertNotNull( "The service should be created", service ); assertTrue( service instanceof StartableServiceImpl ); assertTrue( "Service should have been started", ( (StartableServiceImpl) service ).isStarted() ); }
@Test public void testExceptionMessage() { thrown.expect( SearchException.class ); thrown.expectMessage( "HSEARCH000275" ); thrown.expectMessage( "hibernate-search-serialization-avro" ); ExtendedSearchIntegrator searchFactory = factoryHolder.getSearchFactory(); searchFactory.getServiceManager().requestService( LuceneWorkSerializer.class ); }
@Test public void testInjectionHappened() throws Exception { SearchIntegrator searchFactory = getSearchFactory().unwrap( SearchIntegrator.class ); MessageSenderService sender = searchFactory.getServiceManager().requestService( MessageSenderService.class ); Assert.assertTrue( masterChannel.getAddress().equals( sender.getAddress() ) ); searchFactory.getServiceManager().releaseService( MessageSenderService.class ); }
@Test @TestForIssue(jiraKey = "HSEARCH-1589") public void testStopServiceIsPerformedLazily() { StoppableService service = serviceManagerUnderTest.requestService( StoppableService.class ); assertNotNull( "The service should be created", service ); assertTrue( service instanceof StoppableServiceImpl ); serviceManagerUnderTest.releaseService( StoppableService.class ); assertFalse( "Service should not be stopped yet", ( (StoppableServiceImpl) service ).isStopped() ); serviceManagerUnderTest.releaseAllServices(); assertTrue( "Service should have been stopped", ( (StoppableServiceImpl) service ).isStopped() ); }