-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into nls-use-utf8-by-default
- Loading branch information
Showing
14 changed files
with
273 additions
and
135 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
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
138 changes: 138 additions & 0 deletions
138
...org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/IllegalStateExceptionTests.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,138 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation 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: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.osgi.tests.bundles; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.junit.Test; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.BundleEvent; | ||
import org.osgi.framework.BundleListener; | ||
import org.osgi.framework.Constants; | ||
import org.osgi.framework.Filter; | ||
import org.osgi.framework.FrameworkEvent; | ||
import org.osgi.framework.FrameworkListener; | ||
import org.osgi.framework.ServiceEvent; | ||
import org.osgi.framework.ServiceListener; | ||
import org.osgi.framework.ServiceObjects; | ||
import org.osgi.framework.ServiceReference; | ||
import org.osgi.framework.ServiceRegistration; | ||
import org.osgi.service.condition.Condition; | ||
|
||
public class IllegalStateExceptionTests extends AbstractBundleTests { | ||
|
||
@Test | ||
public void testUninstall() throws Exception { | ||
Bundle bundle = installer.installBundle("test"); | ||
bundle.uninstall(); | ||
// uninstall again should not throw an exception | ||
bundle.uninstall(); | ||
} | ||
|
||
@Test | ||
public void testCreateFilter() throws Exception { | ||
Filter testFilter = getInvalidContext().createFilter("(test=illegalstateexception)"); | ||
assertNotNull("Null filter returned", testFilter); | ||
} | ||
|
||
@Test | ||
public void testGetBundle() throws Exception { | ||
BundleContext invalidContext = getInvalidContext(); | ||
|
||
assertNotNull("Null bundle returned", invalidContext.getBundle()); | ||
assertNotNull("Null system bundle returned", invalidContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION)); | ||
assertNotNull("Null system bundle returned", invalidContext.getBundle(Constants.SYSTEM_BUNDLE_ID)); | ||
} | ||
|
||
@Test | ||
public void testGetProperty() throws Exception { | ||
BundleContext invalidContext = getInvalidContext(); | ||
|
||
assertNotNull("Null UUID Property", invalidContext.getProperty(Constants.FRAMEWORK_UUID)); | ||
} | ||
|
||
@Test | ||
public void testRemoveServiceListener() throws Exception { | ||
BundleContext invalidContext = getInvalidContext(); | ||
|
||
invalidContext.removeServiceListener(new ServiceListener() { | ||
@Override | ||
public void serviceChanged(ServiceEvent event) { | ||
// nothing | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRemoveBundleListener() throws Exception { | ||
BundleContext invalidContext = getInvalidContext(); | ||
|
||
invalidContext.removeBundleListener(new BundleListener() { | ||
@Override | ||
public void bundleChanged(BundleEvent event) { | ||
// nothing | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testFrameworkListener() throws Exception { | ||
BundleContext invalidContext = getInvalidContext(); | ||
|
||
invalidContext.removeFrameworkListener(new FrameworkListener() { | ||
@Override | ||
public void frameworkEvent(FrameworkEvent event) { | ||
// nothing | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testContextUngetService() throws Exception { | ||
BundleContext invalidContext = getInvalidContext(); | ||
|
||
invalidContext.ungetService(getContext().getServiceReference("org.osgi.service.condition.Condition")); | ||
} | ||
|
||
@Test | ||
public void testServiceObjectsUngetService() throws Exception { | ||
Bundle bundle = installer.installBundle("test"); | ||
bundle.start(); | ||
BundleContext context = bundle.getBundleContext(); | ||
ServiceReference<Condition> ref = context.getServiceReference(Condition.class); | ||
ServiceObjects<Condition> serviceObjects = context.getServiceObjects(ref); | ||
Condition c = serviceObjects.getService(); | ||
bundle.stop(); | ||
serviceObjects.ungetService(c); | ||
} | ||
|
||
@Test | ||
public void testUnregister() throws Exception { | ||
Bundle bundle = installer.installBundle("test"); | ||
bundle.start(); | ||
BundleContext context = bundle.getBundleContext(); | ||
ServiceRegistration<Condition> reg = context.registerService(Condition.class, Condition.INSTANCE, null); | ||
reg.unregister(); | ||
reg.unregister(); | ||
} | ||
|
||
public BundleContext getInvalidContext() throws Exception { | ||
Bundle bundle = installer.installBundle("test"); | ||
bundle.start(); | ||
BundleContext context = bundle.getBundleContext(); | ||
bundle.stop(); | ||
return context; | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
...org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/KeyBasedLockStore.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,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022, 2024 IBM Corporation 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: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.osgi.internal.container; | ||
|
||
import java.lang.ref.ReferenceQueue; | ||
import java.lang.ref.WeakReference; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Function; | ||
|
||
public final class KeyBasedLockStore<Key, Lock> { | ||
|
||
final ReferenceQueue<Lock> refQueue = new ReferenceQueue<>(); | ||
private final ConcurrentHashMap<Key, LockWeakRef> lockMap = new ConcurrentHashMap<>(); | ||
private final Function<Key, Lock> lockCreator; | ||
|
||
public KeyBasedLockStore(Function<Key, Lock> lockCreator) { | ||
this.lockCreator = lockCreator; | ||
} | ||
|
||
private final class LockWeakRef extends WeakReference<Lock> { | ||
final Key key; | ||
|
||
public LockWeakRef(Lock referent, Key keyValue) { | ||
super(referent, refQueue); | ||
key = keyValue; | ||
} | ||
} | ||
|
||
public final Lock getLock(Key key) { | ||
poll(); | ||
LockWeakRef lockRef = lockMap.get(key); | ||
Lock lock = lockRef != null ? lockRef.get() : null; | ||
if (lock != null) { | ||
return lock; | ||
} | ||
|
||
lock = lockCreator.apply(key); | ||
|
||
while (true) { | ||
LockWeakRef retVal = lockMap.putIfAbsent(key, new LockWeakRef(lock, key)); | ||
if (retVal == null) { | ||
return lock; | ||
} | ||
|
||
Lock retLock = retVal.get(); | ||
if (retLock != null) { | ||
return retLock; | ||
} | ||
lockMap.remove(key, retVal); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private final void poll() { | ||
LockWeakRef lockRef; | ||
while ((lockRef = (LockWeakRef) refQueue.poll()) != null) { | ||
lockMap.remove(lockRef.key, lockRef); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.