forked from apache/incubator-retired-tamaya
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TAMAYA-326: Fix bug in ordinal comparison in ServiceContextManager
While adding some test coverage on the api, I found that org.apache.tamaya.spi.ServiceContextManager has a bug as it searches for the default service provider in loadDefaultServiceProvider. Namely, the "highestOrdinal" is not set after the first service provider is found, so any following service provider with an ordinal higher than 0 will be used, even if that ordinal is lower than the first one's. This patch fixes the logic, and adds tests to cover the case.
- Loading branch information
Showing
4 changed files
with
67 additions
and
5 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
62 changes: 62 additions & 0 deletions
62
code/api/src/test/java/org/apache/tamaya/spi/TestLowerOrdinalServiceContext.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,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.tamaya.spi; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.*; | ||
|
||
/** | ||
* This class implements the (default) | ||
* {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the | ||
* JDK {@link java.util.ServiceLoader} to load the services required. | ||
*/ | ||
public final class TestLowerOrdinalServiceContext implements ServiceContext { | ||
|
||
@Override | ||
public int ordinal() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public <T> T getService(Class<T> serviceType) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> T create(Class<T> serviceType) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T> List<T> getServices(Class<T> serviceType) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public Enumeration<URL> getResources(String resource, ClassLoader cl) throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public URL getResource(String resource, ClassLoader cl) { | ||
return null; | ||
} | ||
|
||
} |
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