use of org.osgi.resource.Wiring in project felix by apache.
the class Main method main.
public static void main(String[] args) throws ResolutionException {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory;
ResolveContextImpl rci;
Map<Resource, List<Wire>> wireMap;
System.out.println("\nSCENARIO 1\n");
mandatory = populateScenario1(wirings, candMap);
rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
wireMap = resolver.resolve(rci);
System.out.println("RESULT " + wireMap);
System.out.println("\nSCENARIO 2\n");
mandatory = populateScenario2(wirings, candMap);
rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
wireMap = resolver.resolve(rci);
System.out.println("RESULT " + wireMap);
System.out.println("\nSCENARIO 3\n");
mandatory = populateScenario3(wirings, candMap);
rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
wireMap = resolver.resolve(rci);
System.out.println("RESULT " + wireMap);
System.out.println("\nSCENARIO 4\n");
mandatory = populateScenario4(wirings, candMap);
rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
try {
wireMap = resolver.resolve(rci);
System.err.println("UNEXPECTED RESULT " + wireMap);
} catch (ResolutionException e) {
System.out.println("EXPECTED ResolutionException:");
e.printStackTrace(System.out);
}
System.out.println("\nSCENARIO 5\n");
mandatory = populateScenario5(wirings, candMap);
rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
try {
wireMap = resolver.resolve(rci);
System.err.println("UNEXPECTED RESULT " + wireMap);
} catch (ResolutionException e) {
System.out.println("EXPECTED ResolutionException:");
e.printStackTrace(System.out);
}
System.out.println("\nSCENARIO 6\n");
mandatory = populateScenario6(wirings, candMap);
rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
wireMap = resolver.resolve(rci);
System.out.println("RESULT " + wireMap);
System.out.println("\nSCENARIO 7\n");
mandatory = populateScenario7(wirings, candMap);
rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
wireMap = resolver.resolve(rci);
System.out.println("RESULT " + wireMap);
}
use of org.osgi.resource.Wiring in project felix by apache.
the class ResolverTest method testScenario14.
@Test
public void testScenario14() throws Exception {
ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
ResourceImpl a1 = new ResourceImpl("A", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("1.0.0"));
Capability a1_hostCap = addCap(a1, HostNamespace.HOST_NAMESPACE, "A");
Capability a1_pkgCap = addCap(a1, PackageNamespace.PACKAGE_NAMESPACE, "a");
Requirement a1_pkgReq = addReq(a1, PackageNamespace.PACKAGE_NAMESPACE, "a.impl");
ResourceImpl a2 = new ResourceImpl("A", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("2.0.0"));
Capability a2_hostCap = addCap(a2, HostNamespace.HOST_NAMESPACE, "A");
Capability a2_pkgCap = addCap(a2, PackageNamespace.PACKAGE_NAMESPACE, "a");
Requirement a2_pkgReq = addReq(a2, PackageNamespace.PACKAGE_NAMESPACE, "a.impl");
ResourceImpl a3 = new ResourceImpl("A", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("3.0.0"));
Capability a3_hostCap = addCap(a3, HostNamespace.HOST_NAMESPACE, "A");
Capability a3_pkgCap = addCap(a3, PackageNamespace.PACKAGE_NAMESPACE, "a");
Requirement a3_pkgReq = addReq(a3, PackageNamespace.PACKAGE_NAMESPACE, "a.impl");
ResourceImpl f1 = new ResourceImpl("F1", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
Requirement f1_hostReq = addReq(f1, HostNamespace.HOST_NAMESPACE, "A");
Capability f1_pkgCap = addCap(f1, PackageNamespace.PACKAGE_NAMESPACE, "a.impl");
Requirement f1_pkgReq = addReq(f1, PackageNamespace.PACKAGE_NAMESPACE, "a");
ResourceImpl b1 = new ResourceImpl("B");
Requirement b_pkgReq1 = addReq(b1, PackageNamespace.PACKAGE_NAMESPACE, "a");
candMap.put(a1_pkgReq, Collections.singletonList(f1_pkgCap));
candMap.put(a2_pkgReq, Collections.singletonList(f1_pkgCap));
candMap.put(a3_pkgReq, Collections.singletonList(f1_pkgCap));
candMap.put(b_pkgReq1, Arrays.asList(a3_pkgCap, a2_pkgCap, a1_pkgCap));
candMap.put(f1_pkgReq, Arrays.asList(a3_pkgCap, a2_pkgCap, a1_pkgCap));
candMap.put(f1_hostReq, Arrays.asList(a3_hostCap, a2_hostCap, a1_hostCap));
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, Arrays.<Resource>asList(b1, a1, a2, a3), Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
// all bundles should be resolved
assertEquals(5, wireMap.size());
List<Wire> wiresB = wireMap.get(b1);
assertNotNull(wiresB);
assertEquals(1, wiresB.size());
assertEquals(a3, wiresB.get(0).getProvider());
assertEquals(a3_pkgCap, wiresB.get(0).getCapability());
// There should be three hosts
List<Wire> wiresF1 = wireMap.get(f1);
assertNotNull(wiresF1);
assertEquals(3, wiresF1.size());
}
use of org.osgi.resource.Wiring in project felix by apache.
the class ResolverTest method testScenario8.
@Test
public void testScenario8() throws Exception {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory = populateScenario8(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
Resource res2 = findResource("res2", wireMap.keySet());
Resource res4 = findResource("res4", wireMap.keySet());
Resource res5 = findResource("res5", wireMap.keySet());
assertNotNull(res2);
assertNotNull(res4);
assertNotNull(res5);
List<Wire> wires2 = wireMap.get(res2);
assertEquals(2, wires2.size());
// should be wired to res4 and res5
List<Wire> wires4 = wireMap.get(res4);
assertEquals(1, wires4.size());
// should be wired to res5
List<Wire> wires5 = wireMap.get(res5);
assertEquals(0, wires5.size());
// should not be wired to any of its optional requirements to res6
assertEquals(3, wireMap.size());
}
use of org.osgi.resource.Wiring in project felix by apache.
the class ResolverTest method testScenario11.
/**
* Test dynamic resolution with an unresolved fragment
*/
@Test
public void testScenario11() throws Exception {
ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
ResourceImpl a1 = new ResourceImpl("A");
Capability a1_hostCap = addCap(a1, HostNamespace.HOST_NAMESPACE, "A");
ResourceImpl f1 = new ResourceImpl("F1", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
Requirement f1_hostReq = addReq(f1, HostNamespace.HOST_NAMESPACE, "A");
Capability f1_pkgCap = addCap(f1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
ResourceImpl b1 = new ResourceImpl("B");
Requirement b_pkgReq1 = addReq(b1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
candMap.put(b_pkgReq1, Collections.singletonList(f1_pkgCap));
candMap.put(f1_hostReq, Collections.singletonList(a1_hostCap));
Map<Resource, List<Wire>> wires = new HashMap<Resource, List<Wire>>();
wires.put(a1, new ArrayList<Wire>());
wires.put(b1, new ArrayList<Wire>());
Map<Resource, List<Wire>> invertedWires = new HashMap<Resource, List<Wire>>();
invertedWires.put(a1, new ArrayList<Wire>());
invertedWires.put(b1, new ArrayList<Wire>());
wirings.put(a1, new SimpleWiring(a1, Collections.<Capability>emptyList(), wires, invertedWires));
wirings.put(b1, new SimpleWiring(b1, Collections.<Capability>emptyList(), wires, invertedWires));
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, Collections.<Resource>emptyList(), Collections.<Resource>emptyList());
List<Capability> caps = new ArrayList<Capability>();
caps.add(f1_pkgCap);
try {
resolver.resolve(rci, b1, b_pkgReq1, caps);
fail("Should fail to dynamic requirement to fragment when host is resolved already.");
} catch (ResolutionException e) {
// expected
assertTrue(e.getUnresolvedRequirements().contains(b_pkgReq1));
}
// now remove host wiring
wirings.remove(a1);
caps.clear();
caps.add(f1_pkgCap);
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci, b1, b_pkgReq1, caps);
assertEquals(3, wireMap.size());
List<Wire> wiresB = wireMap.get(b1);
assertNotNull(wiresB);
assertEquals(1, wiresB.size());
// should be wired to A through the fragment capability
assertEquals(a1, wiresB.get(0).getProvider());
assertEquals(f1_pkgCap, wiresB.get(0).getCapability());
}
use of org.osgi.resource.Wiring in project felix by apache.
the class ResolverTest method testScenario4.
@Test
public void testScenario4() throws Exception {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory = populateScenario4(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
try {
resolver.resolve(rci);
fail("Should have thrown a resolution exception as bundle A in scenario 4 cannot be resolved due to constraint violations.");
} catch (ResolutionException re) {
// good
}
}
Aggregations