Skip to content

Commit ee971a1

Browse files
committed
Log and assert actually processed permutations
Currently we log the actual number of permutation removed from the stack and also assert the counts for the individual permutation types added. Now as we have the Backlog actually filtering out candidates that are likely not good solutions the actual number of processed permutations becomes much more interesting. This now adds a new logger method for that case and uses it in the tests to assert that no more than a certain number of permutations are actually processed in the resolver loop.
1 parent 36c1f08 commit ee971a1

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,17 +1982,17 @@ public void testUses4() throws BundleException, IOException {
19821982
*/
19831983
@Test
19841984
public void testUses5Importer() throws BundleException, IOException {
1985-
doTestUses5("uses.k.importer.MF", 3, 0, 3, 0);
1985+
doTestUses5("uses.k.importer.MF", 2, 0, 3, 0);
19861986
}
19871987

19881988
@Test
19891989
public void testUses5ReqCap() throws BundleException, IOException {
1990-
doTestUses5("uses.k.reqCap.MF", 3, 0, 3, 0);
1990+
doTestUses5("uses.k.reqCap.MF", 2, 0, 3, 0);
19911991
}
19921992

19931993
@Test
19941994
public void testUses5Requirer() throws BundleException, IOException {
1995-
doTestUses5("uses.k.requirer.MF", 3, 0, 3, 0);
1995+
doTestUses5("uses.k.requirer.MF", 2, 0, 3, 0);
19961996
}
19971997

19981998
public void doTestUses5(String kManifest, int maxTotal, int maxSub, int maxUse, int maxPkg)
@@ -3939,14 +3939,13 @@ public void testSubstitutionWithMoreThan2Providers() throws BundleException, IOE
39393939
modules.add(installDummyModule(manifest, manifest, container));
39403940
}
39413941
report = container.resolve(modules, true);
3942-
assertSucessfulWith(report, 114, 62, 47, 5);
3942+
assertSucessfulWith(report, 15, 62, 47, 5);
39433943
}
39443944

3945-
protected void assertSucessfulWith(ResolutionReport report, int maxTotalPermutations, int maxSubstitution,
3945+
protected void assertSucessfulWith(ResolutionReport report, int maxProcessed, int maxSubstitution,
39463946
int maxUses, int maxImport) {
39473947
assertNull("Failed to resolve test.", report.getResolutionException());
3948-
assertNotMoreThanPermutationCreated(report, ResolutionReport::getTotalPermutations, maxTotalPermutations,
3949-
"total");
3948+
assertNotMoreThanPermutationCreated(report, ResolutionReport::getProcessedPermutations, maxProcessed, "processed");
39503949
assertNotMoreThanPermutationCreated(report, ResolutionReport::getSubstitutionPermutations, maxSubstitution,
39513950
"substitution");
39523951
assertNotMoreThanPermutationCreated(report, ResolutionReport::getUsesPermutations, maxUses, "uses");
@@ -4369,29 +4368,26 @@ private static void assertWires(List<ModuleWire> required, List<ModuleWire>... p
43694368
@Test
43704369
public void testLocalUseConstraintViolations() throws Exception {
43714370
ResolutionReport result = resolveTestSet("set1");
4372-
// TODO get down permutation count!
4373-
assertSucessfulWith(result, 49, 20, 23, 6);
4371+
assertSucessfulWith(result, 6, 20, 23, 6);
43744372
}
43754373

43764374
@Test
43774375

43784376
public void testLocalUseConstraintViolations2() throws Exception {
43794377
ResolutionReport result = resolveTestSet("set2");
4380-
// TODO get down permutation count!
4381-
assertSucessfulWith(result, 7, 3, 1, 3);
4378+
assertSucessfulWith(result, 3, 3, 1, 3);
43824379
}
43834380

43844381
@Test
43854382
public void testSubstitutionPackageResolution() throws Exception {
43864383
ResolutionReport result = resolveTestSet("set3");
4387-
// TODO get down permutation count
43884384
// In this example we see the following:
43894385
// - libg has two possible choices for its substitution package, the internal one is chosen in first iteration -> resolved
43904386
// - util has two possible choices for its substitution package, the external one is chosen in first iteration -> libg
43914387
// - now util has to be removed as a provider only having libg as the only one left
43924388
// - bndlib now can only use libg for exceptions package but this conflicts with result from util that has use constraint on exceptions package
43934389
// - on second iteration now libg chose external and drops it exports removing it from util+bndlib -> resolved state
4394-
assertSucessfulWith(result, 3, 2, 1, 0);
4390+
assertSucessfulWith(result, 1, 2, 1, 0);
43954391
}
43964392

43974393
private ResolutionReport resolveTestSet(String testSetName) throws Exception {

bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolver.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,11 @@ class ResolveProcess extends ResolveContext implements Comparator<Capability>, E
477477
class ResolveLogger extends Logger {
478478
private Map<Resource, ResolutionException> errors = null;
479479
public int totalPerm;
480-
public int processedPerm;
480+
public int totalProcessedPerm;
481481
public int usesPerm;
482482
public int importPerm;
483483
public int subPerm;
484+
public int processedPerm;
484485

485486
public ResolveLogger() {
486487
super(DEBUG_USES ? Logger.LOG_DEBUG : 0);
@@ -609,6 +610,11 @@ public void logPermutationAdded(PermutationType type) {
609610

610611
@Override
611612
public void logProcessPermutation(PermutationType type) {
613+
totalProcessedPerm++;
614+
}
615+
616+
@Override
617+
public void logPermutationProcessed(ResolutionError error) {
612618
processedPerm++;
613619
}
614620

bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/Logger.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,20 @@ public void logProcessPermutation(PermutationType type)
185185
{
186186
// do nothing by default
187187
}
188+
189+
/**
190+
* Called whenever a permutation was processed and if processing yields any
191+
* error (usually a uses-contraint violation but also unresolved resources),
192+
* this reflects actual work to be performed, while
193+
* {@link #logPermutationAdded(PermutationType)} and
194+
* {@link #logProcessPermutation(PermutationType)} indicate that a permutations
195+
* is added for later examination or pulled from the stack for further
196+
* processing.
197+
*
198+
* @param error if this permutation resulted in an error or was successful in
199+
* which case the value is <code>null</code>
200+
*/
201+
public void logPermutationProcessed(ResolutionError error) {
202+
203+
}
188204
}

bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/ResolverImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ private Candidates findValidCandidates(ResolveSession session, Map<Resource, Res
289289
ResolutionError currentError = session.getCurrentError();
290290
if (currentError == null && report.getUnresolvedRequirements().isEmpty()) {
291291
// Success!
292+
m_logger.logPermutationProcessed(null);
292293
break;
293294
}
295+
m_logger.logPermutationProcessed(currentError == null ? report : currentError);
294296
if (bestCandidate == null || report.isBetterThan(bestCandidate.getFaultyResources())) {
295297
bestCandidate = current;
296298
if (currentError == null && report.isMissingMandatory()) {

0 commit comments

Comments
 (0)