FELIX-4401 fix tests and test assumptions
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1602640 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java b/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
index 624035a..14a2462 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
@@ -120,6 +120,7 @@
A a = getServiceFromConfiguration(componentA, A.class);
assertEquals( 1, a.getBs().size());
+ delay(); //async binding of a to b after circular ref detected
B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
}
@@ -130,7 +131,7 @@
public void test_A11_B0n_delayed_B_first() throws InvalidSyntaxException
{
String componentNameA = "4.A.1.1.dynamic";
- final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
+ ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
String componentNameB = "4.B.0.n.dynamic";
final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED);
@@ -166,6 +167,8 @@
// Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
// assertNotNull( serviceA1 );
+ //new component.id, refetch configuration.
+ componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
a = getServiceFromConfiguration(componentA, A.class);
assertEquals( 1, a.getBs().size());
b = getServiceFromConfiguration(componentB, B.class);
@@ -237,7 +240,7 @@
public void test_A11_B01_delayed_B_first() throws InvalidSyntaxException
{
String componentNameA = "7.A.1.1.dynamic";
- final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
+ ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
String componentNameB = "7.B.0.1.dynamic";
final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED );
@@ -274,6 +277,8 @@
// Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
// assertNotNull( serviceA1 );
+ //new component.id, refetch configuration.
+ componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
a = getServiceFromConfiguration(componentA, A.class);
assertEquals( 1, a.getBs().size());
b = getServiceFromConfiguration(componentB, B.class);
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
index 4d0a7c5..9e1bf32 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
@@ -31,11 +31,15 @@
// paxRunnerVmOption = DEBUG_VM_OPTION;
descriptorFile = "/integration_test_component_concurrency.xml";
COMPONENT_PACKAGE = COMPONENT_PACKAGE + ".concurrency";
+ restrictedLogging = true;
+ ignoredWarnings = new String[] {"FrameworkEvent: ERROR",
+ "FrameworkEvent ERROR",
+ "Could not get service from ref",
+ "Failed creating the component instance; see log for reason",
+ "Cannot create component instance due to failure to bind reference"};
+ DS_LOGLEVEL = "warn";
}
- @Inject
- protected BundleContext bundleContext;
-
protected static void delay(int secs)
{
try
@@ -56,16 +60,12 @@
ComponentConfigurationDTO ccC = getDisabledConfigurationAndEnable( "org.apache.felix.scr.integration.components.concurrency.CFactory", ComponentConfigurationDTO.ACTIVE );
delay( 30 );
- for ( Iterator it = log.foundWarnings().iterator(); it.hasNext();)
+ if ( ! log.foundWarnings().isEmpty() )
{
- String message = ( String ) it.next();
- if ( message.contains( "FrameworkEvent ERROR" ) ||
- message.contains( "Could not get service from ref" ) ||
- message.contains( "Failed creating the component instance; see log for reason" ) ||
- message.contains( "Cannot create component instance due to failure to bind reference" ))
- {
- continue;
- }
+ TestCase.fail( "unexpected warning or error logged: " + log.foundWarnings() );
+ }
+ for ( String message: log.foundWarnings() )
+ {
TestCase.fail( "unexpected warning or error logged: " + message );
}
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
index 1d92d4f..ff29be8 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
@@ -127,6 +127,8 @@
protected static boolean NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR = false;
protected volatile Log log;
+
+ protected static String[] ignoredWarnings; //null unless you need it.
//set to true to only get last 1000 lines of log.
protected static boolean restrictedLogging;
@@ -186,7 +188,7 @@
@Before
public void setUp() throws BundleException
{
- log = new Log(restrictedLogging);
+ log = new Log(restrictedLogging, ignoredWarnings);
log.start();
bundleContext.addFrameworkListener( log );
bundleContext.registerService( LogService.class.getName(), log, null );
@@ -253,16 +255,16 @@
{
TestCase.fail("no ServiceComponentRuntime");
}
- ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(bundle, name);
- Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
- if (expected != -1)
+ ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(b, name);
+ Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
+ if (expected != -1)
+ {
+ for (ComponentConfigurationDTO cc: ccs)
{
- for (ComponentConfigurationDTO cc: ccs)
- {
- Assert.assertEquals( "for ComponentConfiguration name: " + cc.description.name + " properties" + cc.properties + "Expected state " + STATES.get(expected) + " but was " + STATES.get(cc.state), expected, cc.state);
- }
+ Assert.assertEquals( "for ComponentConfiguration name: " + cc.description.name + " properties" + cc.properties + "Expected state " + STATES.get(expected) + " but was " + STATES.get(cc.state), expected, cc.state);
}
- return ccs;
+ }
+ return ccs;
}
protected Collection<ComponentConfigurationDTO> findComponentConfigurationsByName( String name, int expected )
@@ -895,6 +897,7 @@
private volatile Thread m_logThread;
private volatile PrintStream m_realOut;
private volatile PrintStream m_realErr;
+ private String[] ignoredWarnings;
protected Throwable firstFrameworkThrowable;
@@ -902,9 +905,10 @@
private final String[] log = new String[1000];
private int i = 0;
- public Log( boolean restrictedLogging )
+ public Log( boolean restrictedLogging, String[] ignoredWarnings )
{
this.restrictedLogging = restrictedLogging;
+ this.ignoredWarnings = ignoredWarnings;
}
public void start()
@@ -971,7 +975,7 @@
entry = m_logQueue.take();
if ( entry.getLevel() <= 2 )
{
- if ( m_warnings.size() < 1024 )
+ if ( m_warnings.size() < 1024 && acceptWarning( entry.getMessage() ) )
{
m_warnings.add( entry.getMessage() );
}
@@ -1017,7 +1021,19 @@
// ------------- FrameworkListener -----------------------------------------------------------
- public void frameworkEvent( final FrameworkEvent event )
+ private boolean acceptWarning(String message) {
+ if ( ignoredWarnings != null )
+ {
+ for (String ignore : ignoredWarnings) {
+ if (message.contains(ignore)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public void frameworkEvent( final FrameworkEvent event )
{
int eventType = event.getType();
String msg = getFrameworkEventMessage( eventType );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java
index da1eab9..a5b18f7 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java
@@ -110,7 +110,8 @@
theConfig.put("ref.target", "(value=srv1)");
configure( pid );
-
+ delay();//all cm event to complete
+
getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
@@ -212,7 +213,8 @@
theConfig.put("ref.target", "(value=srv1)");
configure( pid );
-
+ delay();//let cm thread finish before enabling.
+
getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java b/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java
index 79ad028..f3913a2 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java
@@ -49,9 +49,9 @@
static
{
// uncomment to enable debugging of this test class
- // paxRunnerVmOption = DEBUG_VM_OPTION;
+// paxRunnerVmOption = DEBUG_VM_OPTION;
descriptorFile = "/integration_test_FELIX_4188.xml";
- restrictedLogging = true;
+// restrictedLogging = true;
//comment to get debug logging if the test fails.
// DS_LOGLEVEL = "warn";
}
@@ -62,19 +62,19 @@
@Test
public void test_concurrent_deactivation() throws Exception
{
- final Bundle bundle1 = installBundle("/integration_test_FELIX_4188_1.xml", "", "simplecomponent1");
+ final Bundle bundle1 = installBundle("/integration_test_FELIX_4188_1.xml", "org.apache.felix.scr.integration.components", "simplecomponent1");
bundle1.start();
- final Bundle bundle2 = installBundle("/integration_test_FELIX_4188_2.xml", "", "simplecomponent2");
+ final Bundle bundle2 = installBundle("/integration_test_FELIX_4188_2.xml", "org.apache.felix.scr.integration.components", "simplecomponent2");
bundle2.start();
final ComponentConfigurationDTO aComp1 =
- findComponentConfigurationByName( bundle1, "org.apache.felix.scr.integration.components.Felix4188Component-1", ComponentConfigurationDTO.ACTIVE);
- final Felix4188Component aInst1 = getServiceFromConfiguration(aComp1, Felix4188Component.class);
+ findComponentConfigurationByName( bundle1, "org.apache.felix.scr.integration.components.Felix4188Component-1", ComponentConfigurationDTO.SATISFIED);
+ final Object aInst1 = getServiceFromConfiguration(aComp1, Felix4188Component.class);
final ComponentConfigurationDTO aComp2 =
- findComponentConfigurationByName( bundle1, "org.apache.felix.scr.integration.components.Felix4188Component-2", ComponentConfigurationDTO.ACTIVE);
- final Felix4188Component aInst2 = getServiceFromConfiguration(aComp2, Felix4188Component.class);
+ findComponentConfigurationByName( bundle2, "org.apache.felix.scr.integration.components.Felix4188Component-2", ComponentConfigurationDTO.SATISFIED);
+ final Object aInst2 = getServiceFromConfiguration(aComp2, Felix4188Component.class);
final CountDownLatch latch = new CountDownLatch(1);
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java b/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java
index b4339d0..43e4caa 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java
@@ -88,6 +88,8 @@
Configuration configSNVL = configure( pidSNVL );
configSNVL.setBundleLocation( REGION );
+ delay();
+
//Add more and more specific components to check that they pick up the appropriate configuration
Set<ComponentConfigurationDTO> known = new HashSet<ComponentConfigurationDTO>();
diff --git a/scr/src/test/resources/integration_test_FELIX_4188_1.xml b/scr/src/test/resources/integration_test_FELIX_4188_1.xml
index 2b5c631..29bad0c 100644
--- a/scr/src/test/resources/integration_test_FELIX_4188_1.xml
+++ b/scr/src/test/resources/integration_test_FELIX_4188_1.xml
@@ -14,7 +14,7 @@
name='org.apache.felix.scr.integration.components.Felix4188Component-1' activate='start' deactivate='stop'>
<implementation class="org.apache.felix.scr.integration.components.felix4188.Felix4188Component" />
<service>
- <provide>org.apache.felix.scr.integration.components.felix4188.Felix4188Component</provide>
+ <provide interface="org.apache.felix.scr.integration.components.felix4188.Felix4188Component"/>
</service>
</scr:component>
</components>
diff --git a/scr/src/test/resources/integration_test_FELIX_4188_2.xml b/scr/src/test/resources/integration_test_FELIX_4188_2.xml
index 8eccbf7..ef8bbad 100644
--- a/scr/src/test/resources/integration_test_FELIX_4188_2.xml
+++ b/scr/src/test/resources/integration_test_FELIX_4188_2.xml
@@ -14,7 +14,7 @@
name='org.apache.felix.scr.integration.components.Felix4188Component-2' activate='start' deactivate='stop'>
<implementation class="org.apache.felix.scr.integration.components.felix4188.Felix4188Component" />
<service>
- <provide>org.apache.felix.scr.integration.components.felix4188.Felix4188Component</provide>
+ <provide interface="org.apache.felix.scr.integration.components.felix4188.Felix4188Component"/>
</service>
</scr:component>
</components>
diff --git a/scr/src/test/resources/integration_test_component_concurrency.xml b/scr/src/test/resources/integration_test_component_concurrency.xml
index 3f1dfe8..aeb7c7f 100644
--- a/scr/src/test/resources/integration_test_component_concurrency.xml
+++ b/scr/src/test/resources/integration_test_component_concurrency.xml
@@ -12,7 +12,7 @@
<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
<scr:component
name='org.apache.felix.scr.integration.components.concurrency.A'
- factory='AFactory' activate='start' enabled='false'>
+ factory='AFactory' activate='start'>
<implementation
class='org.apache.felix.scr.integration.components.concurrency.A' />
<reference name='b'