-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LazyServiceComponentActivationDeadLockTest
Reproducer test for: https://github.com/eclipse-equinox/equinox.framework/issues/55
- Loading branch information
1 parent
48152cb
commit 331931a
Showing
6 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/bundle_tests/ | ||
/inner/ | ||
.DS_Store | ||
/OSGI-INF/org.eclipse.osgi.*.xml |
8 changes: 8 additions & 0 deletions
8
bundles/org.eclipse.osgi.tests/.settings/org.eclipse.pde.ds.annotations.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
classpath=true | ||
dsVersion=V1_3 | ||
eclipse.preferences.version=1 | ||
enabled=true | ||
generateBundleActivationPolicyLazy=true | ||
path=OSGI-INF | ||
validationErrorLevel=error | ||
validationErrorLevel.missingImplicitUnbindMethod=error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
.../org/eclipse/osgi/tests/services/resolver/LazyServiceComponentActivationDeadLockTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022, 2022 Hannes Wellmann and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Hannes Wellmann - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.osgi.tests.services.resolver; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.Test; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.FrameworkUtil; | ||
import org.osgi.framework.ServiceReference; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
import org.osgi.service.component.annotations.ReferenceCardinality; | ||
import org.osgi.service.component.annotations.ReferencePolicy; | ||
|
||
public class LazyServiceComponentActivationDeadLockTest { | ||
|
||
// TODO: add test cases for dead-lock due to lazy activation in different | ||
// bundles?! | ||
|
||
@Test | ||
public void testLateBindingInSameBundleDeadLock() throws Exception { | ||
BundleContext ctx = FrameworkUtil.getBundle(LazyServiceComponentActivationDeadLockTest.class) | ||
.getBundleContext(); | ||
ServiceReference<ProjectConfigurationManager> reference = ctx | ||
.getServiceReference(ProjectConfigurationManager.class); | ||
|
||
ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
try { | ||
Future<ProjectConfigurationManager> service = executor.submit(() -> ctx.getService(reference)); | ||
assertNotNull(service.get(5, TimeUnit.SECONDS)); // times out in case of dead-lock | ||
} finally { | ||
executor.shutdown(); | ||
// ctx.ungetService(reference); | ||
} | ||
} | ||
|
||
@Component(service = ProjectConfigurationManager.class) | ||
public static class ProjectConfigurationManager { | ||
|
||
@Reference | ||
MavenImpl maven; | ||
|
||
@Reference | ||
MavenModelManager mavenModelManager; | ||
|
||
} | ||
|
||
@Component(service = MavenModelManager.class) | ||
public static class MavenModelManager { | ||
|
||
@Reference | ||
private MavenProjectManager projectManager; | ||
|
||
// The nested component below ensures that the activation of this component | ||
// starts after the activation of MavenProjectManager has started in the SCR | ||
// Actor thread. | ||
|
||
@Reference | ||
HeavyComponent AAA; // Capital letters are important to ensure this reference is handled first | ||
|
||
@Component(service = HeavyComponent.class) | ||
public static class HeavyComponent { | ||
|
||
@Activate | ||
public void activated() throws InterruptedException { | ||
MavenProjectManager.HeavyComponent.ACTIVATED.await(); | ||
} | ||
} | ||
} | ||
|
||
@Component(service = MavenProjectManager.class) | ||
public static class MavenProjectManager { | ||
|
||
private final List<ProjectConfigurationManager> listenerManager = new ArrayList<>(); | ||
|
||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) | ||
public void addMavenProjectChangedListener(ProjectConfigurationManager listener) { | ||
listenerManager.add(listener); | ||
} | ||
|
||
public void removeMavenProjectChangedListener(ProjectConfigurationManager listener) { | ||
listenerManager.remove(listener); | ||
} | ||
|
||
// The nested component below ensures that the activation of this component | ||
// starts after the activation of MavenModelManager has started in the main | ||
// thread. | ||
|
||
@Reference | ||
HeavyComponent AAA; // Capital letters are important to ensure this reference is handled first | ||
|
||
@Component(service = HeavyComponent.class) | ||
public static class HeavyComponent { | ||
public static final CountDownLatch ACTIVATED = new CountDownLatch(1); | ||
|
||
@Activate | ||
public void activated() { | ||
ACTIVATED.countDown(); | ||
} | ||
} | ||
} | ||
|
||
@Component(service = MavenImpl.class) | ||
public static class MavenImpl { | ||
|
||
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) | ||
private final List<RepositoryRegistry> settingsListeners = new CopyOnWriteArrayList<>(); | ||
} | ||
|
||
@Component(service = RepositoryRegistry.class) | ||
public static class RepositoryRegistry { | ||
|
||
@Reference | ||
private MavenImpl maven; | ||
|
||
@Reference | ||
MavenProjectManager projectManager; | ||
} | ||
|
||
} |