use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testSelectionPolicy.
public void testSelectionPolicy() throws BundleException {
State state = buildEmptyState();
Resolver resolver = state.getResolver();
resolver.setSelectionPolicy(new Comparator() {
public int compare(Object o1, Object o2) {
if (!(o1 instanceof BaseDescription) || !(o2 instanceof BaseDescription))
throw new IllegalArgumentException();
Version v1 = null;
Version v2 = null;
v1 = ((BaseDescription) o1).getVersion();
v2 = ((BaseDescription) o2).getVersion();
// only take version in to account and use lower versions over higher ones
return v1.compareTo(v2);
}
});
Hashtable manifest = new Hashtable();
long bundleID = 0;
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.host; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
BundleDescription testHost100 = state.getFactory().createBundleDescription(state, manifest, "test.host100", bundleID++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.host; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.1");
// $NON-NLS-1$
BundleDescription testHost101 = state.getFactory().createBundleDescription(state, manifest, "test.host101", bundleID++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.frag; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
BundleDescription testFrag100 = state.getFactory().createBundleDescription(state, manifest, "test.frag100", bundleID++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.frag; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.1");
// $NON-NLS-1$
BundleDescription testFrag101 = state.getFactory().createBundleDescription(state, manifest, "test.frag101", bundleID++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.dependent; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
BundleDescription testDependent = state.getFactory().createBundleDescription(state, manifest, "test.frag101", bundleID++);
state.addBundle(testHost100);
state.addBundle(testFrag100);
state.addBundle(testHost101);
state.addBundle(testFrag101);
state.addBundle(testDependent);
state.resolve();
// $NON-NLS-1$
assertTrue("1.0", testHost100.isResolved());
// $NON-NLS-1$
assertFalse("1.1", testHost101.isResolved());
// $NON-NLS-1$
assertTrue("1.2", testFrag100.isResolved());
// $NON-NLS-1$
assertFalse("1.3", testFrag101.isResolved());
// $NON-NLS-1$
assertTrue("1.4", testDependent.isResolved());
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testFragmentConstraints05.
public void testFragmentConstraints05() throws BundleException {
// same as testFragmentConstraints04 but with a cycle
int id = 0;
State state = buildEmptyState();
Hashtable manifest = new Hashtable();
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "a");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "b");
// $NON-NLS-1$
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d, e");
// $NON-NLS-1$
BundleDescription aFrag1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d, f");
// $NON-NLS-1$
BundleDescription aFrag2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag3");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d");
// $NON-NLS-1$
BundleDescription aFrag3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "b1, b2, b3");
// $NON-NLS-1$
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "c");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "c1, c2, c3");
// $NON-NLS-1$
BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "d");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "a");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "d1, d2, d3");
// $NON-NLS-1$
BundleDescription d = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
state.addBundle(a);
state.addBundle(aFrag1);
state.addBundle(aFrag2);
state.addBundle(aFrag3);
state.addBundle(b);
state.addBundle(c);
state.addBundle(d);
state.resolve();
// $NON-NLS-1$
assertTrue("0.1", a.isResolved());
// $NON-NLS-1$
assertFalse("0.2", aFrag1.isResolved());
// $NON-NLS-1$
assertFalse("0.3", aFrag2.isResolved());
// $NON-NLS-1$
assertTrue("0.4", aFrag3.isResolved());
// $NON-NLS-1$
assertTrue("0.5", b.isResolved());
// $NON-NLS-1$
assertTrue("0.6", c.isResolved());
// $NON-NLS-1$
assertTrue("0.7", d.isResolved());
BundleDescription[] aResolvedRequires = a.getResolvedRequires();
// $NON-NLS-1$
assertEquals("1.0", 3, aResolvedRequires.length);
// $NON-NLS-1$
assertEquals("1.1", b, aResolvedRequires[0]);
// $NON-NLS-1$
assertEquals("1.2", c, aResolvedRequires[1]);
// $NON-NLS-1$
assertEquals("1.3", d, aResolvedRequires[2]);
BundleDescription[] dResolvedRequires = d.getResolvedRequires();
// $NON-NLS-1$
assertEquals("2.0", 1, dResolvedRequires.length);
// $NON-NLS-1$
assertEquals("2.1", a, dResolvedRequires[0]);
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testFragmentsMultipleVersion.
public void testFragmentsMultipleVersion() throws BundleException {
State state = buildEmptyState();
int bundleID = 0;
// test the selection algorithm of the resolver to pick the bundles which
// resolve the largest set of bundles; with fragments using Import-Package
Hashtable manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
BundleDescription a1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "AFrag");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "A");
BundleDescription aFrag1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "2.0");
BundleDescription a2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "AFrag");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "2.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "A");
BundleDescription aFrag2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + '_' + (String) manifest.get(Constants.BUNDLE_VERSION), bundleID++);
state.addBundle(a1);
state.addBundle(aFrag1);
state.addBundle(a2);
state.addBundle(aFrag2);
state.resolve();
// $NON-NLS-1$
assertTrue("0.1", a1.isResolved());
// $NON-NLS-1$
assertTrue("0.2", aFrag1.isResolved());
// $NON-NLS-1$
assertTrue("0.3", a2.isResolved());
// $NON-NLS-1$
assertTrue("0.4", aFrag2.isResolved());
state.removeBundle(a2);
state.resolve(false);
// $NON-NLS-1$
assertTrue("1.1", a1.isResolved());
// $NON-NLS-1$
assertTrue("1.2", aFrag2.isResolved());
// $NON-NLS-1$
assertFalse("1.3", aFrag1.isResolved());
// $NON-NLS-1$
assertEquals("1.4", a1, aFrag2.getHost().getSupplier());
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StatePerformanceTest method testResolution.
private void testResolution(int stateSize, int repetitions, String localName, String degradation) {
final State originalState = buildRandomState(stateSize);
PerformanceTestRunner runner = new PerformanceTestRunner() {
protected void test() {
originalState.resolve(false);
}
};
runner.setRegressionReason(degradation);
runner.run(this, localName, 10, repetitions);
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StatePerformanceTest method testStoreAndRetrieve.
public void testStoreAndRetrieve() {
int stateSize = 5000;
final State originalState = buildRandomState(stateSize);
PerformanceTestRunner runner = new PerformanceTestRunner() {
protected void test() {
try {
storeAndRetrieve(originalState);
} catch (IOException e) {
CoreTest.fail("", e);
}
}
};
runner.setRegressionReason(DEGREDATION_STORE_RETRIEVE);
runner.run(this, 10, 10);
}
Aggregations