summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2019-10-28 16:07:25 +0100
committergjoranv <gv@verizonmedia.com>2019-10-28 16:07:25 +0100
commit0846f9d3277ab1965f9718045a89ec2865128852 (patch)
treee9310421e7a90adc75766b3e7007fa14fc4df3a4 /container-core
parent376d9cbab6134843a42811eae910271139219d6f (diff)
Simplify testing by adding a combined interface for osgi wrapper.
- Add a MockOsgiWrapper for HandlerConfigurerTestWrapper
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java24
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java4
-rw-r--r--container-core/src/main/java/com/yahoo/container/core/config/testutil/MockOsgiWrapper.java44
-rw-r--r--container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java20
-rw-r--r--container-core/src/main/java/com/yahoo/osgi/OsgiWrapper.java16
5 files changed, 85 insertions, 23 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
index 2ca76535b34..ef132694e10 100644
--- a/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
+++ b/container-core/src/main/java/com/yahoo/container/core/config/HandlersConfigurerDi.java
@@ -9,6 +9,7 @@ import com.yahoo.component.ComponentSpecification;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.concurrent.ThreadFactoryFactory;
import com.yahoo.config.FileReference;
+import com.yahoo.container.core.config.testutil.MockOsgiWrapper;
import com.yahoo.container.di.ComponentDeconstructor;
import com.yahoo.container.di.Container;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
@@ -20,17 +21,15 @@ import com.yahoo.jdisc.application.OsgiFramework;
import com.yahoo.jdisc.handler.RequestHandler;
import com.yahoo.jdisc.service.ClientProvider;
import com.yahoo.jdisc.service.ServerProvider;
-import com.yahoo.language.Linguistics;
-import com.yahoo.language.simple.SimpleLinguistics;
import com.yahoo.log.LogLevel;
import com.yahoo.osgi.OsgiImpl;
+import com.yahoo.osgi.OsgiWrapper;
import com.yahoo.statistics.Statistics;
import org.osgi.framework.Bundle;
import org.osgi.framework.wiring.BundleWiring;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
@@ -82,19 +81,30 @@ public class HandlersConfigurerDi {
Injector discInjector,
OsgiFramework osgiFramework) {
- this.vespaContainer = vespaContainer;
- osgiWrapper = new OsgiWrapper(osgiFramework, new BundleLoader(new OsgiImpl(osgiFramework)));
+ this(subscriberFactory, vespaContainer, configId, deconstructor, discInjector,
+ new ContainerAndDiOsgi(osgiFramework, new BundleLoader(new OsgiImpl(osgiFramework))));
+ }
+ // Only public for testing
+ public HandlersConfigurerDi(SubscriberFactory subscriberFactory,
+ com.yahoo.container.Container vespaContainer,
+ String configId,
+ ComponentDeconstructor deconstructor,
+ Injector discInjector,
+ OsgiWrapper osgiWrapper) {
+
+ this.vespaContainer = vespaContainer;
+ this.osgiWrapper = osgiWrapper;
container = new Container(subscriberFactory, configId, deconstructor, osgiWrapper);
getNewComponentGraph(discInjector, false);
}
- private static class OsgiWrapper extends OsgiImpl implements com.yahoo.container.di.Osgi {
+ private static class ContainerAndDiOsgi extends OsgiImpl implements OsgiWrapper {
private final OsgiFramework osgiFramework;
private final BundleLoader bundleLoader;
- public OsgiWrapper(OsgiFramework osgiFramework, BundleLoader bundleLoader) {
+ public ContainerAndDiOsgi(OsgiFramework osgiFramework, BundleLoader bundleLoader) {
super(osgiFramework);
this.osgiFramework = osgiFramework;
this.bundleLoader = bundleLoader;
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java b/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java
index bc06aad76ec..9f49b016b68 100644
--- a/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java
+++ b/container-core/src/main/java/com/yahoo/container/core/config/testutil/HandlersConfigurerTestWrapper.java
@@ -89,7 +89,7 @@ public class HandlersConfigurerTestWrapper {
public HandlersConfigurerTestWrapper(Container container, String configId) {
createFiles(configId);
- MockOsgi mockOsgi = new MockOsgi();
+ MockOsgiWrapper mockOsgiWrapper = new MockOsgiWrapper();
ComponentDeconstructor testDeconstructor = getTestDeconstructor();
configurer = new HandlersConfigurerDi(
new CloudSubscriberFactory(configSources),
@@ -97,7 +97,7 @@ public class HandlersConfigurerTestWrapper {
configId,
testDeconstructor,
guiceInjector(),
- mockOsgi);
+ mockOsgiWrapper);
this.container = container;
}
diff --git a/container-core/src/main/java/com/yahoo/container/core/config/testutil/MockOsgiWrapper.java b/container-core/src/main/java/com/yahoo/container/core/config/testutil/MockOsgiWrapper.java
new file mode 100644
index 00000000000..a1f564f5682
--- /dev/null
+++ b/container-core/src/main/java/com/yahoo/container/core/config/testutil/MockOsgiWrapper.java
@@ -0,0 +1,44 @@
+package com.yahoo.container.core.config.testutil;
+
+import com.yahoo.component.ComponentSpecification;
+import com.yahoo.osgi.OsgiWrapper;
+import org.osgi.framework.Bundle;
+
+import java.util.Collection;
+import java.util.List;
+
+import static java.util.Collections.emptyList;
+
+/**
+ * @author gjoranv
+ */
+public class MockOsgiWrapper implements OsgiWrapper {
+
+ @Override
+ public List<Bundle> getInitialBundles() {
+ return emptyList();
+ }
+
+ @Override
+ public Bundle[] getBundles() {
+ return new Bundle[0];
+ }
+
+ @Override
+ public List<Bundle> getCurrentBundles() {
+ return emptyList();
+ }
+
+ @Override
+ public Bundle getBundle(ComponentSpecification bundleId) {
+ return null;
+ }
+
+ @Override
+ public List<Bundle> install(String absolutePath) {
+ return emptyList();
+ }
+
+ @Override
+ public void allowDuplicateBundles(Collection<Bundle> bundles) { }
+}
diff --git a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
index dcea9e55e63..5fa0e65463a 100644
--- a/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
+++ b/container-core/src/main/java/com/yahoo/osgi/OsgiImpl.java
@@ -5,13 +5,11 @@ import com.yahoo.component.ComponentSpecification;
import com.yahoo.component.Version;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.jdisc.application.OsgiFramework;
-import com.yahoo.jdisc.test.NonWorkingOsgiFramework;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
/**
@@ -31,19 +29,13 @@ public class OsgiImpl implements Osgi {
public OsgiImpl(OsgiFramework jdiscOsgi) {
this.jdiscOsgi = jdiscOsgi;
- if (jdiscOsgi instanceof NonWorkingOsgiFramework) {
- initialBundles = Collections.emptyList();
- alwaysCurrentBundle = null;
- } else {
-
- this.initialBundles = jdiscOsgi.bundles();
- if (initialBundles.isEmpty())
- throw new IllegalStateException("No initial bundles!");
+ this.initialBundles = jdiscOsgi.bundles();
+ if (initialBundles.isEmpty())
+ throw new IllegalStateException("No initial bundles!");
- alwaysCurrentBundle = firstNonFrameworkBundle(initialBundles);
- if (alwaysCurrentBundle == null)
- throw new IllegalStateException("The initial bundles only contained the framework bundle!");
- }
+ alwaysCurrentBundle = firstNonFrameworkBundle(initialBundles);
+ if (alwaysCurrentBundle == null)
+ throw new IllegalStateException("The initial bundles only contained the framework bundle!");
}
@Override
diff --git a/container-core/src/main/java/com/yahoo/osgi/OsgiWrapper.java b/container-core/src/main/java/com/yahoo/osgi/OsgiWrapper.java
new file mode 100644
index 00000000000..58e19e52ee3
--- /dev/null
+++ b/container-core/src/main/java/com/yahoo/osgi/OsgiWrapper.java
@@ -0,0 +1,16 @@
+package com.yahoo.osgi;
+
+import com.yahoo.component.ComponentSpecification;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author gjoranv
+ */
+public interface OsgiWrapper extends Osgi, com.yahoo.container.di.Osgi {
+
+ @Override
+ default Bundle getBundle(ComponentSpecification bundleId) {
+ return null;
+ }
+
+}