Instead of just sitting for a number of seconds we add a ConfigurationAdmin
scheduled task (assuming this would be the last after the expected
service update tasks) notifying the test of the end of asynchronous tasks
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@809570 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
index 8475f03..d4c4be7 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBindingTest.java
@@ -640,7 +640,6 @@
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation( locationB );
delay();
- delay();
// ==> configuration is bound to locationB
TestCase.assertEquals( locationB, config.getBundleLocation() );
@@ -717,7 +716,6 @@
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation( locationB );
delay();
- delay();
// ==> configuration is bound to locationB
TestCase.assertEquals( locationB, config.getBundleLocation() );
@@ -800,7 +798,6 @@
// 5. Call Configuration.setBundleLocation( "locationB" )
config.setBundleLocation( locationB );
delay();
- delay();
// ==> configuration is bound to locationB
TestCase.assertEquals( locationB, config.getBundleLocation() );
@@ -883,7 +880,6 @@
// 5. Uninstall bundle A
bundleA.uninstall();
delay();
- delay();
/*
* According to BJ Hargrave configuration is not re-dispatched
@@ -959,7 +955,6 @@
// 5. Uninstall bundle A
bundleA.uninstall();
delay();
- delay();
/*
* According to BJ Hargrave configuration is not re-dispatched
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
index 50117e3..eda056e 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
@@ -22,14 +22,18 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.Dictionary;
import java.util.Hashtable;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.felix.cm.integration.helper.BaseTestActivator;
import org.apache.felix.cm.integration.helper.ManagedServiceTestActivator;
import org.apache.felix.cm.integration.helper.MyTinyBundle;
+import org.apache.felix.cm.integration.helper.UpdateThreadSignalTask;
import org.junit.After;
import org.junit.Before;
import org.ops4j.pax.exam.CoreOptions;
@@ -163,8 +167,42 @@
}
- protected static void delay()
+ protected void delay()
{
+ Object ca = configAdminTracker.getService();
+ if ( ca != null )
+ {
+ try
+ {
+
+ Field caf = ca.getClass().getDeclaredField( "configurationManager" );
+ caf.setAccessible( true );
+ Object cm = caf.get( ca );
+
+ Field cmf = cm.getClass().getDeclaredField( "updateThread" );
+ cmf.setAccessible( true );
+ Object ut = cmf.get( cm );
+
+ Method utm = ut.getClass().getDeclaredMethod( "schedule" );
+ utm.setAccessible( true );
+
+ UpdateThreadSignalTask signalTask = new UpdateThreadSignalTask();
+ utm.invoke( ut, signalTask );
+ signalTask.waitSignal();
+
+ return;
+ }
+ catch ( AssertionFailedError afe )
+ {
+ throw afe;
+ }
+ catch ( Throwable t )
+ {
+ // ignore any problem and revert to timed delay (might log this)
+ }
+ }
+
+ // no configadmin or failure while setting up task
try
{
Thread.sleep( 300 );