felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1731988 - /felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/CFDependencyTest.java
Date Tue, 23 Feb 2016 22:48:10 GMT
Author: pderop
Date: Tue Feb 23 22:48:10 2016
New Revision: 1731988

URL: http://svn.apache.org/viewvc?rev=1731988&view=rev
Log:
FELIX-4689: Added test case for CompletableFuture dependency.

Added:
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/CFDependencyTest.java

Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/CFDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/CFDependencyTest.java?rev=1731988&view=auto
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/CFDependencyTest.java
(added)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/CFDependencyTest.java
Tue Feb 23 22:48:10 2016
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.felix.dm.lambda.itest;
+
+import static org.apache.felix.dm.lambda.DependencyManagerActivator.component;
+
+import java.util.concurrent.CompletableFuture;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.junit.Assert;
+
+/**
+ * CompletableFuture Dependency test.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class CFDependencyTest extends TestBase {
+    private final Ensure m_ensure = new Ensure();
+    
+    public void testComponentWithCFDependencyDefinedFromInit() throws Exception {
+        final DependencyManager dm = getDM();
+
+        // Create a consumer depending on a Provider and on the result of a CF.
+        // (the CF dependency is added from the Consumer.init() method).
+        CompletableFuture<String> cf = new CompletableFuture<>();
+        Component consumer = component(dm).impl(new Consumer(cf)).withSvc(Provider.class).build();
+                        
+        // Create provider
+        Component provider = component(dm).impl(new ProviderImpl()).provides(Provider.class).build();
+        
+        dm.add(consumer);
+        dm.add(provider);
+        
+        // Sets the result in the CF: this will normally trigger the activation of the Consumer
component.
+        cf.complete("cfFesult");
+            
+        m_ensure.waitForStep(3, 5000);
+        dm.clear();
+    }
+    
+    public static interface Provider {
+        void invoke();
+    }
+    
+    public class ProviderImpl implements Provider {
+        @Override
+        public void invoke() {
+            m_ensure.step(3);
+        }
+    }
+    
+    public class Consumer {
+        private Provider m_provider; // injected
+        private String m_cfResult; // injected
+        private final CompletableFuture<String> m_cf;
+        
+        Consumer(CompletableFuture<String> cf) {
+            m_cf = cf;
+        }
+
+        void init(Component c) {
+            component(c, comp -> comp.withFuture(m_cf, result -> result.complete(this::add)));
+        }
+        
+		void add(String cfResult) {
+		    m_cfResult = cfResult;
+            Assert.assertNotNull(m_cfResult);
+            Assert.assertEquals("cfFesult", m_cfResult);
+            m_ensure.step(1);
+        }
+        
+        void start() {
+            Assert.assertNotNull(m_provider);
+            m_ensure.step(2);
+            m_provider.invoke();
+        }
+    }
+}



Mime
View raw message