summaryrefslogtreecommitdiffstats
path: root/container-di/src/test/java/com
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2019-10-26 02:04:18 +0200
committergjoranv <gv@verizonmedia.com>2019-10-28 14:09:03 +0100
commit38ab0914bb97438ea8ddbe03089155192154580c (patch)
tree37036f4c68f44b2ccf0255c7a5818e56b7d16fcc /container-di/src/test/java/com
parentea149387f4e94edefdd8a4677075a1531e2357d0 (diff)
Support safe component deconstruction in jdisc container.
- Add allowDuplicates to all Osgi classes - Uninstall bundles in Deconstructor - We no longer refresh bundles because we uninstall old bundles at a later point than the new bundles are installed. Hence, the user must version app bundles that are dependencies used by other app bundles.
Diffstat (limited to 'container-di/src/test/java/com')
-rw-r--r--container-di/src/test/java/com/yahoo/container/di/ContainerTest.java22
-rw-r--r--container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java6
2 files changed, 18 insertions, 10 deletions
diff --git a/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java b/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java
index 9c4891c7db2..90bda0ef8a8 100644
--- a/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java
+++ b/container-di/src/test/java/com/yahoo/container/di/ContainerTest.java
@@ -14,6 +14,8 @@ import com.yahoo.container.di.componentgraph.core.Node;
import com.yahoo.container.di.config.RestApiContext;
import org.junit.Ignore;
import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
import java.util.Collection;
import java.util.concurrent.ExecutionException;
@@ -283,13 +285,16 @@ public class ContainerTest extends ContainerTestBase {
public void providers_are_destructed() {
writeBootstrapConfigs("id1", DestructableProvider.class);
- ComponentDeconstructor deconstructor = components -> components.forEach(component -> {
- if (component instanceof AbstractComponent) {
- ((AbstractComponent) component).deconstruct();
- } else if (component instanceof Provider) {
- ((Provider<?>) component).deconstruct();
- }
- });
+ ComponentDeconstructor deconstructor = (components, bundles) -> {
+ components.forEach(component -> {
+ if (component instanceof AbstractComponent) {
+ ((AbstractComponent) component).deconstruct();
+ } else if (component instanceof Provider) {
+ ((Provider<?>) component).deconstruct();
+ }
+ });
+ if (! bundles.isEmpty()) throw new IllegalArgumentException("This test should not use bundles");
+ };
Container container = newContainer(dirConfigSource, deconstructor);
@@ -373,13 +378,14 @@ public class ContainerTest extends ContainerTestBase {
public static class TestDeconstructor implements ComponentDeconstructor {
@Override
- public void deconstruct(Collection<Object> components) {
+ public void deconstruct(Collection<Object> components, Collection<Bundle> bundles) {
components.forEach(component -> {
if (component instanceof DestructableComponent) {
DestructableComponent vespaComponent = (DestructableComponent) component;
vespaComponent.deconstruct();
}
});
+ if (! bundles.isEmpty()) throw new IllegalArgumentException("This test should not use bundles");
}
}
diff --git a/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java b/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java
index 79cb080dfa4..18236a6bde9 100644
--- a/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java
+++ b/container-di/src/test/java/com/yahoo/container/di/ContainerTestBase.java
@@ -5,7 +5,6 @@ import com.google.inject.Guice;
import com.yahoo.component.ComponentSpecification;
import com.yahoo.config.FileReference;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
-import com.yahoo.container.di.CloudSubscriberFactory;
import com.yahoo.container.di.ContainerTest.ComponentTakingConfig;
import com.yahoo.container.di.componentgraph.core.ComponentGraph;
import com.yahoo.container.di.osgi.BundleClasses;
@@ -16,6 +15,8 @@ import org.osgi.framework.Bundle;
import java.util.Collection;
import java.util.Set;
+import static java.util.Collections.emptySet;
+
/**
* @author Tony Vaagenes
* @author gjoranv
@@ -60,7 +61,8 @@ public class ContainerTestBase {
}
@Override
- public void useBundles(Collection<FileReference> bundles) {
+ public Set<Bundle> useBundles(Collection<FileReference> bundles) {
+ return emptySet();
}
@Override