aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rotty3...@apache.org
Subject svn commit: r1829162 - in /aries/trunk/cdi: cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/bean/ cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ cdi-extender/src/main/java/org/apache/aries/cdi/container...
Date Sat, 14 Apr 2018 18:27:55 GMT
Author: rotty3000
Date: Sat Apr 14 18:27:55 2018
New Revision: 1829162

URL: http://svn.apache.org/viewvc?rev=1829162&view=rev
Log:
[CDI] further stabilizations and bug fixes

Signed-off-by: Raymond Augé <rotty3000@apache.org>

Added:
    aries/trunk/cdi/cdi-itests/bnd/tb11.bnd
    aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/OptionalReluctantReferenceTests.java
    aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/interfaces/BeanId.java
    aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/
    aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_AS.java
    aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_FC.java
    aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_SC.java
Modified:
    aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/bean/ReferenceBean.java
    aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ContainerState.java
    aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java
    aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java
    aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/FactoryActivator.java
    aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/InstanceActivator.java
    aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/SingleActivator.java
    aries/trunk/cdi/cdi-itests/bnd.bnd
    aries/trunk/cdi/cdi-itests/logback.xml
    aries/trunk/cdi/cdi-itests/pom.xml

Modified: aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/bean/ReferenceBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/bean/ReferenceBean.java?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/bean/ReferenceBean.java
(original)
+++ aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/bean/ReferenceBean.java
Sat Apr 14 18:27:55 2018
@@ -26,6 +26,7 @@ import java.util.SortedMap;
 import java.util.stream.Collectors;
 
 import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Default;
 import javax.enterprise.inject.spi.Bean;
@@ -217,6 +218,11 @@ public class ReferenceBean implements Be
 	@Override
 	public Class<? extends Annotation> getScope() {
 		if (_component.type == ComponentType.CONTAINER) {
+			// is it optional?
+			if ((_template.maximumCardinality == MaximumCardinality.ONE) &&
+				(_template.minimumCardinality == 0)) {
+				return Dependent.class;
+			}
 			return ApplicationScoped.class;
 		}
 		return ComponentScoped.class;

Modified: aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ContainerState.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ContainerState.java?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ContainerState.java
(original)
+++ aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ContainerState.java
Sat Apr 14 18:27:55 2018
@@ -270,7 +270,7 @@ public class ContainerState {
 			String query = "(service.pid=".concat(pid).concat(")");
 
 			if (factory) {
-				query = "(factory.pid=".concat(pid).concat(")");
+				query = "(service.factoryPid=".concat(pid).concat(")");
 			}
 
 			return Optional.ofNullable(

Modified: aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java
(original)
+++ aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java
Sat Apr 14 18:27:55 2018
@@ -103,10 +103,6 @@ public class ReferenceSync implements Se
 			if (requiresUpdate) {
 				InstanceActivator activator = _builder.setInstance(
 					_componentInstanceDTO
-				).setReferenceDTO(
-					_referenceDTO
-				).setReference(
-					reference
 				).build();
 
 				updateStatically(activator);
@@ -172,10 +168,6 @@ public class ReferenceSync implements Se
 			if (requiresUpdate) {
 				InstanceActivator activator = _builder.setInstance(
 					_componentInstanceDTO
-				).setReferenceDTO(
-					_referenceDTO
-				).setReference(
-					reference
 				).build();
 
 				updateStatically(activator);

Modified: aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java
(original)
+++ aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java
Sat Apr 14 18:27:55 2018
@@ -64,7 +64,7 @@ public class ExtendedComponentInstanceDT
 	}
 
 	public boolean close() {
-		_containerState.submit(Op.of(Mode.CLOSE, Type.REFERENCES, template.name),
+		_containerState.submit(Op.of(Mode.CLOSE, Type.REFERENCES, ident()),
 			() -> {
 				references.removeIf(
 					r -> {
@@ -186,7 +186,7 @@ public class ExtendedComponentInstanceDT
 		);
 
 		_containerState.submit(
-			Op.of(Mode.OPEN, Type.REFERENCES, template.name),
+			Op.of(Mode.OPEN, Type.REFERENCES, ident()),
 			() -> {
 				references.stream().map(ExtendedReferenceDTO.class::cast).forEach(
 					r -> r.serviceTracker.open()
@@ -249,7 +249,9 @@ public class ExtendedComponentInstanceDT
 			);
 		}
 
-		props.put(Constants.SERVICE_PID, servicePids);
+		if (!servicePids.isEmpty()) {
+			props.put(Constants.SERVICE_PID, servicePids);
+		}
 		props.put("component.id", _componentId);
 		props.put("component.name", template.name);
 

Modified: aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/FactoryActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/FactoryActivator.java?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/FactoryActivator.java
(original)
+++ aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/FactoryActivator.java
Sat Apr 14 18:27:55 2018
@@ -60,9 +60,11 @@ public class FactoryActivator extends In
 
 		@Override
 		public FactoryActivator build() {
-			return new FactoryActivator(this);
+			return _cache.computeIfAbsent(_instance, i -> new FactoryActivator(this));
 		}
 
+		private final Map<ExtendedComponentInstanceDTO, FactoryActivator> _cache = new ConcurrentHashMap<>();
+
 	}
 
 	private FactoryActivator(Builder builder) {
@@ -94,7 +96,7 @@ public class FactoryActivator extends In
 
 	@Override
 	public Op closeOp() {
-		return Op.of(Mode.CLOSE, Type.FACTORY_ACTIVATOR, instance.template.name);
+		return Op.of(Mode.CLOSE, Type.FACTORY_ACTIVATOR, instance.ident());
 	}
 
 	@Override
@@ -227,7 +229,7 @@ public class FactoryActivator extends In
 
 	@Override
 	public Op openOp() {
-		return Op.of(Mode.OPEN, Type.FACTORY_ACTIVATOR, instance.template.name);
+		return Op.of(Mode.OPEN, Type.FACTORY_ACTIVATOR, instance.ident());
 	}
 
 	@Override

Modified: aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/InstanceActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/InstanceActivator.java?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/InstanceActivator.java
(original)
+++ aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/InstanceActivator.java
Sat Apr 14 18:27:55 2018
@@ -17,7 +17,6 @@ package org.apache.aries.cdi.container.i
 import org.apache.aries.cdi.container.internal.container.ContainerState;
 import org.apache.aries.cdi.container.internal.container.Op;
 import org.apache.aries.cdi.container.internal.container.Phase;
-import org.osgi.framework.ServiceReference;
 
 public abstract class InstanceActivator extends Phase {
 
@@ -36,31 +35,15 @@ public abstract class InstanceActivator
 			return (T)this;
 		}
 
-		@SuppressWarnings("unchecked")
-		public T setReference(ServiceReference<Object> reference) {
-			_reference = reference;
-			return (T)this;
-		}
-
-		@SuppressWarnings("unchecked")
-		public T setReferenceDTO(ExtendedReferenceDTO referenceDTO) {
-			_referenceDTO = referenceDTO;
-			return (T)this;
-		}
-
 		private ContainerState _containerState;
-		private ExtendedComponentInstanceDTO _instance;
+		protected ExtendedComponentInstanceDTO _instance;
 		private Phase _next;
-		private ServiceReference<Object> _reference;
-		private ExtendedReferenceDTO _referenceDTO;
 	}
 
 	protected InstanceActivator(Builder<?> builder) {
 		super(builder._containerState, builder._next);
 
 		this.instance = builder._instance;
-		this.referenceDTO = builder._referenceDTO;
-		this.reference = builder._reference;
 	}
 
 	@Override
@@ -70,7 +53,5 @@ public abstract class InstanceActivator
 	public abstract Op openOp();
 
 	protected final ExtendedComponentInstanceDTO instance;
-	protected final ExtendedReferenceDTO referenceDTO;
-	protected final ServiceReference<Object> reference;
 
 }

Modified: aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/SingleActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/SingleActivator.java?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/SingleActivator.java
(original)
+++ aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/SingleActivator.java
Sat Apr 14 18:27:55 2018
@@ -59,9 +59,11 @@ public class SingleActivator extends Ins
 
 		@Override
 		public SingleActivator build() {
-			return new SingleActivator(this);
+			return _cache.computeIfAbsent(_instance, i -> new SingleActivator(this));
 		}
 
+		private final Map<ExtendedComponentInstanceDTO, SingleActivator> _cache = new ConcurrentHashMap<>();
+
 	}
 
 	private SingleActivator(Builder builder) {
@@ -93,7 +95,7 @@ public class SingleActivator extends Ins
 
 	@Override
 	public Op closeOp() {
-		return Op.of(Mode.CLOSE, Op.Type.SINGLE_ACTIVATOR, instance.template.name);
+		return Op.of(Mode.CLOSE, Op.Type.SINGLE_ACTIVATOR, instance.ident());
 	}
 
 	@Override
@@ -226,7 +228,7 @@ public class SingleActivator extends Ins
 
 	@Override
 	public Op openOp() {
-		return Op.of(Mode.OPEN, Op.Type.SINGLE_ACTIVATOR, instance.template.name);
+		return Op.of(Mode.OPEN, Op.Type.SINGLE_ACTIVATOR, instance.ident());
 	}
 
 	@Override

Modified: aries/trunk/cdi/cdi-itests/bnd.bnd
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/bnd.bnd?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-itests/bnd.bnd (original)
+++ aries/trunk/cdi/cdi-itests/bnd.bnd Sat Apr 14 18:27:55 2018
@@ -29,7 +29,8 @@ p = org.apache.aries.cdi.test
 	tb7.jar,\
 	tb8.jar,\
 	tb9.jar,\
-	tb10.jar
+	tb10.jar,\
+	tb11.jar
 
 # Don't forget that we had to coax the `maven-jar-plugin` NOT to include the `sub-bundle`
packages in
 # the root bundle:

Added: aries/trunk/cdi/cdi-itests/bnd/tb11.bnd
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/bnd/tb11.bnd?rev=1829162&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-itests/bnd/tb11.bnd (added)
+++ aries/trunk/cdi/cdi-itests/bnd/tb11.bnd Sat Apr 14 18:27:55 2018
@@ -0,0 +1,5 @@
+Export-Package: ${p}.tb11.*;-split-package:=first
+Require-Capability:\
+	osgi.extender;\
+		filter:='(&(osgi.extender=osgi.cdi)(version>=1.0.0)(!(version>=2.0.0)))';\
+		osgi.beans:List<String>='${classes;PUBLIC;CONCRETE;NAMED;${p}.tb11.*}'

Modified: aries/trunk/cdi/cdi-itests/logback.xml
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/logback.xml?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-itests/logback.xml (original)
+++ aries/trunk/cdi/cdi-itests/logback.xml Sat Apr 14 18:27:55 2018
@@ -6,16 +6,17 @@
 
 	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
 		<encoder>
-			<pattern>%d{HH:mm:ss.SSS} [%.15thread] %-5level %logger{36}:%line - %msg%n</pattern>
+			<!-- <pattern>%d{HH:mm:ss.SSS} [%.15thread] %-5level %logger{36}:%line - %msg%n</pattern>
-->
+			<pattern>[%.15thread] %-5level %logger{36}:%line - %msg%n</pattern>
 		</encoder>
 	</appender>
 
 	<logger name="Events.Bundle" level="ERROR"/>
 	<logger name="Events.Framework" level="ERROR"/>
-	<logger name="Events.Service" level="ERROR"/>
+	<logger name="Events.Service" level="INFO"/>
 	<logger name="LogService" level="ERROR"/>
 
-	<logger name="Events.Service.org" level="WARN"/>
+	<logger name="Events.Service.org" level="ERROR"/>
 	<logger name="Events.Service.cdi-itests" level="INFO"/>
 	<logger name="Events.Service.org.apache.aries" level="INFO"/>
 

Modified: aries/trunk/cdi/cdi-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/pom.xml?rev=1829162&r1=1829161&r2=1829162&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-itests/pom.xml (original)
+++ aries/trunk/cdi/cdi-itests/pom.xml Sat Apr 14 18:27:55 2018
@@ -252,6 +252,12 @@
 		</dependency>
 		<dependency>
 			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.service.cm</artifactId>
+			<version>1.6.0-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
 			<artifactId>org.osgi.service.component.annotations</artifactId>
 			<version>1.3.0</version>
 			<scope>provided</scope>

Added: aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/OptionalReluctantReferenceTests.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/OptionalReluctantReferenceTests.java?rev=1829162&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/OptionalReluctantReferenceTests.java
(added)
+++ aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/cases/OptionalReluctantReferenceTests.java
Sat Apr 14 18:27:55 2018
@@ -0,0 +1,225 @@
+package org.apache.aries.cdi.test.cases;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.Hashtable;
+
+import org.apache.aries.cdi.test.interfaces.Pojo;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cdi.runtime.dto.ContainerDTO;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class OptionalReluctantReferenceTests extends AbstractTestCase {
+
+	@Override
+	@Before
+	public void setUp() throws Exception {
+		testHeader();
+
+		cdiRuntime = runtimeTracker.waitForService(timeout);
+	}
+
+	@Override
+	@After
+	public void tearDown() throws Exception {
+	}
+
+	@Test
+	public void applicationScoped() throws Exception {
+		Bundle tb = installBundle("tb11.jar");
+
+		try {
+			ServiceTracker<Pojo, Pojo> tracker = track("(&(objectClass=%s)(bean.id=as))",
Pojo.class.getName());
+
+			Pojo pojo = tracker.waitForService(timeout);
+
+			assertEquals(-1, pojo.getCount());
+			assertEquals("-1", pojo.foo(""));
+
+			ContainerDTO containerDTO = cdiRuntime.getContainerDTO(tb);
+
+			long changeCount = containerDTO.changeCount;
+
+			ServiceRegistration<Integer> int1 = bundleContext.registerService(
+				Integer.class, new Integer(12),
+				new Hashtable<>(Collections.singletonMap("bean.id", "as")));
+
+			try {
+				for (long i = 10; i > 0 && (cdiRuntime.getContainerDTO(tb).changeCount ==
changeCount); i--) {
+					Thread.sleep(20);
+				}
+
+				assertEquals(-1, pojo.getCount());
+				assertEquals("-1", pojo.foo(""));
+
+				tb.stop();
+				tb.start();
+
+				pojo = tracker.waitForService(timeout);
+
+				assertEquals(12, pojo.getCount());
+				assertEquals("12", pojo.foo(""));
+			}
+			finally {
+				changeCount = cdiRuntime.getContainerDTO(tb).changeCount;
+
+				int1.unregister();
+
+				for (long i = 10; i > 0 && (cdiRuntime.getContainerDTO(tb).changeCount ==
changeCount); i--) {
+					Thread.sleep(20);
+				}
+
+				pojo = tracker.waitForService(timeout);
+
+				assertEquals(-1, pojo.getCount());
+				assertEquals("-1", pojo.foo(""));
+			}
+		}
+		finally {
+			tb.uninstall();
+		}
+	}
+
+	@Test
+	public void singleComponent() throws Exception {
+		Bundle tb = installBundle("tb11.jar");
+
+		try {
+			ServiceTracker<Pojo, Pojo> tracker = track("(&(objectClass=%s)(bean.id=sc))",
Pojo.class.getName());
+
+			Pojo pojo = tracker.waitForService(timeout);
+
+			assertEquals(-1, pojo.getCount());
+			assertEquals("-1", pojo.foo(""));
+
+			ContainerDTO containerDTO = cdiRuntime.getContainerDTO(tb);
+
+			long changeCount = containerDTO.changeCount;
+
+			ServiceRegistration<Integer> int1 = bundleContext.registerService(
+				Integer.class, new Integer(12),
+				new Hashtable<>(Collections.singletonMap("bean.id", "sc")));
+
+			try {
+				for (long i = 10; i > 0 && (cdiRuntime.getContainerDTO(tb).changeCount ==
changeCount); i--) {
+					Thread.sleep(20);
+				}
+
+				assertEquals(-1, pojo.getCount());
+				assertEquals("-1", pojo.foo(""));
+
+				tb.stop();
+				tb.start();
+
+				pojo = tracker.waitForService(timeout);
+
+				assertEquals(12, pojo.getCount());
+				assertEquals("12", pojo.foo(""));
+			}
+			finally {
+				changeCount = cdiRuntime.getContainerDTO(tb).changeCount;
+
+				int1.unregister();
+
+				for (long i = 10; i > 0 && (cdiRuntime.getContainerDTO(tb).changeCount ==
changeCount); i--) {
+					Thread.sleep(20);
+				}
+
+				pojo = tracker.waitForService(timeout);
+
+				assertEquals(-1, pojo.getCount());
+				assertEquals("-1", pojo.foo(""));
+			}
+		}
+		finally {
+			tb.uninstall();
+		}
+	}
+
+	@Test
+	public void factoryComponent() throws Exception {
+		adminTracker = new ServiceTracker<>(bundleContext, ConfigurationAdmin.class, null);
+		adminTracker.open();
+		configurationAdmin = adminTracker.getService();
+
+		Bundle tb = installBundle("tb11.jar");
+
+		try {
+			ServiceTracker<Pojo, Pojo> tracker = track("(&(objectClass=%s)(bean.id=fc))",
Pojo.class.getName());
+
+			Pojo pojo = tracker.waitForService(timeout);
+
+			assertNull(pojo);
+
+			int trackingCount = tracker.getTrackingCount();
+
+			Configuration configuration = configurationAdmin.createFactoryConfiguration("optionalReference_FC");
+			configuration.update(new Hashtable<>(Collections.singletonMap("foo", "bar")));
+
+			for (long i = 10; i > 0 && (tracker.getTrackingCount() == trackingCount); i--)
{
+				Thread.sleep(20);
+			}
+
+			pojo = tracker.waitForService(timeout);
+
+			assertEquals(-1, pojo.getCount());
+			assertEquals("-1", pojo.foo(""));
+
+			ContainerDTO containerDTO = cdiRuntime.getContainerDTO(tb);
+
+			long changeCount = containerDTO.changeCount;
+
+			ServiceRegistration<Integer> int1 = bundleContext.registerService(
+				Integer.class, new Integer(12),
+				new Hashtable<>(Collections.singletonMap("bean.id", "fc")));
+
+			try {
+				for (long i = 10; i > 0 && (cdiRuntime.getContainerDTO(tb).changeCount ==
changeCount); i--) {
+					Thread.sleep(20);
+				}
+
+				assertEquals(-1, pojo.getCount());
+				assertEquals("-1", pojo.foo(""));
+
+				tb.stop();
+				tb.start();
+
+				pojo = tracker.waitForService(timeout);
+
+				assertEquals(12, pojo.getCount());
+				assertEquals("12", pojo.foo(""));
+			}
+			finally {
+				changeCount = cdiRuntime.getContainerDTO(tb).changeCount;
+
+				int1.unregister();
+
+				for (long i = 10; i > 0 && (cdiRuntime.getContainerDTO(tb).changeCount ==
changeCount); i--) {
+					Thread.sleep(20);
+				}
+
+				pojo = tracker.waitForService(timeout);
+
+				assertEquals(-1, pojo.getCount());
+				assertEquals("-1", pojo.foo(""));
+
+				configuration.delete();
+			}
+		}
+		finally {
+			tb.uninstall();
+			adminTracker.close();
+		}
+	}
+
+	private ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> adminTracker;
+	private ConfigurationAdmin configurationAdmin;
+
+}

Added: aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/interfaces/BeanId.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/interfaces/BeanId.java?rev=1829162&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/interfaces/BeanId.java
(added)
+++ aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/interfaces/BeanId.java
Sat Apr 14 18:27:55 2018
@@ -0,0 +1,30 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.test.interfaces;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.osgi.service.cdi.annotations.ComponentPropertyType;
+
+@ComponentPropertyType
+@Retention(RUNTIME)
+@Target({FIELD, METHOD, TYPE})
+public @interface BeanId {
+	String value();
+}

Added: aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_AS.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_AS.java?rev=1829162&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_AS.java
(added)
+++ aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_AS.java
Sat Apr 14 18:27:55 2018
@@ -0,0 +1,47 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.test.tb11;
+
+import java.util.Optional;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import org.apache.aries.cdi.test.interfaces.BeanId;
+import org.apache.aries.cdi.test.interfaces.Pojo;
+import org.osgi.service.cdi.annotations.Reference;
+import org.osgi.service.cdi.annotations.Service;
+
+@BeanId("as")
+@ApplicationScoped
+@Service
+public class OptionalReference_AS implements Pojo {
+
+	@Inject
+	@Reference
+	@BeanId("as")
+	Optional<Integer> service;
+
+	@Override
+	public String foo(String fooInput) {
+		return fooInput + service.orElse(-1);
+	}
+
+	@Override
+	public int getCount() {
+		return service.orElse(-1);
+	}
+
+}

Added: aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_FC.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_FC.java?rev=1829162&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_FC.java
(added)
+++ aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_FC.java
Sat Apr 14 18:27:55 2018
@@ -0,0 +1,47 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.test.tb11;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.aries.cdi.test.interfaces.BeanId;
+import org.apache.aries.cdi.test.interfaces.Pojo;
+import org.osgi.service.cdi.annotations.FactoryComponent;
+import org.osgi.service.cdi.annotations.Reference;
+import org.osgi.service.cdi.annotations.Service;
+
+@BeanId("fc")
+@FactoryComponent
+@Service
+public class OptionalReference_FC implements Pojo {
+
+	@BeanId("fc")
+	@Inject
+	@Reference
+	Optional<Integer> service;
+
+	@Override
+	public String foo(String fooInput) {
+		return fooInput + service.orElse(-1);
+	}
+
+	@Override
+	public int getCount() {
+		return service.orElse(-1);
+	}
+
+}

Added: aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_SC.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_SC.java?rev=1829162&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_SC.java
(added)
+++ aries/trunk/cdi/cdi-itests/src/main/java/org/apache/aries/cdi/test/tb11/OptionalReference_SC.java
Sat Apr 14 18:27:55 2018
@@ -0,0 +1,47 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.test.tb11;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.aries.cdi.test.interfaces.BeanId;
+import org.apache.aries.cdi.test.interfaces.Pojo;
+import org.osgi.service.cdi.annotations.Reference;
+import org.osgi.service.cdi.annotations.Service;
+import org.osgi.service.cdi.annotations.SingleComponent;
+
+@BeanId("sc")
+@SingleComponent
+@Service
+public class OptionalReference_SC implements Pojo {
+
+	@BeanId("sc")
+	@Inject
+	@Reference
+	Optional<Integer> service;
+
+	@Override
+	public String foo(String fooInput) {
+		return fooInput + service.orElse(-1);
+	}
+
+	@Override
+	public int getCount() {
+		return service.orElse(-1);
+	}
+
+}



Mime
View raw message