{
final String factoryPid = "single_test_ManagedServiceFactory_race_condition_test." + counter;
final ConfigureThread ct = new ConfigureThread( getConfigurationAdmin(), factoryPid, true );
final ManagedServiceFactoryThread mt = new ManagedServiceFactoryThread( bundleContext, factoryPid );
try
{
// start threads -- both are waiting to be triggered
ct.start();
mt.start();
// trigger for action
ct.trigger();
mt.trigger();
// wait for threads to terminate
ct.join();
mt.join();
// wait for all tasks to terminate
delay();
final boolean isConfigured = mt.isConfigured();
final ArrayList<Dictionary> configs = mt.getConfigs();
// terminate mt to ensure no further config updates
mt.cleanup();
TestCase.assertTrue( "Last update call must have been with configuration", isConfigured);
if ( configs.size() == 0 )
{
TestCase.fail( "No configuration provided to ManagedServiceFactory at all" );
}
else if ( configs.size() == 1 )
{
final Dictionary props = configs.get( 0 );
TestCase.assertNotNull( "Expected non-null configuration: " + props, props );
}
else
{
TestCase.fail( "Unexpectedly got " + configs.size() + " updated" );
}
}
finally
{
mt.cleanup();
ct.cleanup();
}
}