mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 05:04:52 +00:00
HHH-10427 - Modify test
This commit is contained in:
parent
1beb6ec27b
commit
93a1a1f531
@ -21,10 +21,11 @@
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@TestForIssue( jiraKey = "HHH-10427")
|
@TestForIssue(jiraKey = "HHH-10427")
|
||||||
public class ServiceRegistryTest {
|
public class ServiceRegistryTest {
|
||||||
private final ServiceRegistry registry = buildRegistry();
|
private final ServiceRegistry registry = buildRegistry();
|
||||||
private final static int NUMBER_OF_THREADS = 100;
|
private final static int NUMBER_OF_THREADS = 100;
|
||||||
|
private StandardServiceRegistryBuilder standardServiceRegistryBuilder;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnlyOneInstanceOfTheServiceShouldBeCreated() throws InterruptedException, ExecutionException {
|
public void testOnlyOneInstanceOfTheServiceShouldBeCreated() throws InterruptedException, ExecutionException {
|
||||||
@ -40,15 +41,16 @@ public void testOnlyOneInstanceOfTheServiceShouldBeCreated() throws InterruptedE
|
|||||||
else {
|
else {
|
||||||
assertTrue( "There are more than one instance of the service", result == previousResult );
|
assertTrue( "There are more than one instance of the service", result == previousResult );
|
||||||
}
|
}
|
||||||
assertTrue( "The service is not initialized", result.isInitialized() );
|
|
||||||
assertTrue( "The service is not configured", result.isConfigured() );
|
|
||||||
assertTrue( "The service is not started", result.isStarted() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
standardServiceRegistryBuilder.destroy( registry );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServiceRegistry buildRegistry() {
|
private ServiceRegistry buildRegistry() {
|
||||||
return new StandardServiceRegistryBuilder()
|
standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
|
||||||
.addInitiator( new SlowServiceInitiator() ).build();
|
return standardServiceRegistryBuilder.addInitiator( new SlowServiceInitiator() ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FutureTask<SlowInitializationService>[] execute()
|
private FutureTask<SlowInitializationService>[] execute()
|
||||||
@ -56,7 +58,7 @@ private FutureTask<SlowInitializationService>[] execute()
|
|||||||
FutureTask<SlowInitializationService>[] results = new FutureTask[NUMBER_OF_THREADS];
|
FutureTask<SlowInitializationService>[] results = new FutureTask[NUMBER_OF_THREADS];
|
||||||
ExecutorService executor = Executors.newFixedThreadPool( NUMBER_OF_THREADS );
|
ExecutorService executor = Executors.newFixedThreadPool( NUMBER_OF_THREADS );
|
||||||
for ( int i = 0; i < NUMBER_OF_THREADS; i++ ) {
|
for ( int i = 0; i < NUMBER_OF_THREADS; i++ ) {
|
||||||
results[i] = new FutureTask<SlowInitializationService>( new ServiceCallable( registry ) );
|
results[i] = new FutureTask<>( new ServiceCallable( registry ) );
|
||||||
executor.execute( results[i] );
|
executor.execute( results[i] );
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
@ -71,7 +73,11 @@ public ServiceCallable(ServiceRegistry registry) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SlowInitializationService call() throws Exception {
|
public SlowInitializationService call() throws Exception {
|
||||||
return registry.getService( SlowInitializationService.class );
|
final SlowInitializationService service = registry.getService( SlowInitializationService.class );
|
||||||
|
assertTrue( "The service is not initialized", service.isInitialized() );
|
||||||
|
assertTrue( "The service is not configured", service.isConfigured() );
|
||||||
|
assertTrue( "The service is not started", service.isStarted() );
|
||||||
|
return service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user