Skip to content

Commit 150eda4

Browse files
committed
fix: typo in HttpClient.Factory scoring system logic
Signed-off-by: Marc Nuri <[email protected]>
1 parent 4a90f42 commit 150eda4

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Fix #4891: address vertx not completely reading exec streams
2020
* Fix #4899: BuildConfigs.instantiateBinary().fromFile() does not time out
2121
* Fix #4908: using the response headers in the vertx response
22+
* Fix #4947: typo in HttpClient.Factory scoring system logic
2223

2324
#### Improvements
2425
* Fix #4675: adding a fully client side timeout for informer watches

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private static HttpClient.Factory getFactory(ServiceLoader<HttpClient.Factory> l
157157
+ "You should exclude dependencies that aren't needed or use an explicit association of the HttpClient.Factory.");
158158
}
159159
if (factory == null || (factory.isDefault() && !possible.isDefault())
160-
|| (!factory.isDefault()) && factory.priority() < possible.priority()) {
160+
|| (!factory.isDefault() && factory.priority() < possible.priority())) {
161161
factory = possible;
162162
}
163163
}

kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -247,52 +247,69 @@ void withDefault() {
247247
@Test
248248
@DisplayName("With default and other implementation, should return other")
249249
void withDefaultAndOther() {
250-
factories.add(new OtherHttpClientFactory());
250+
factories.add(new ScoredHttpClientFactory("other", 0));
251251
factories.add(new DefaultHttpClientFactory());
252-
assertEquals(OtherHttpClientFactory.class, HttpClientUtils.getHttpClientFactory().getClass());
252+
assertEquals(ScoredHttpClientFactory.class, HttpClientUtils.getHttpClientFactory().getClass());
253253
}
254254

255255
@Test
256-
@DisplayName("With default and other implementation, should return Priority")
256+
@DisplayName("With default, other, and priority implementations; should return Priority")
257257
void withDefaultAndPriorityAndOther() {
258-
factories.add(new OtherHttpClientFactory());
259-
factories.add(new PriorityHttpClientFactory());
258+
factories.add(new ScoredHttpClientFactory("other", 0));
259+
factories.add(new ScoredHttpClientFactory("priority", Integer.MAX_VALUE));
260260
factories.add(new DefaultHttpClientFactory());
261-
assertEquals(PriorityHttpClientFactory.class, HttpClientUtils.getHttpClientFactory().getClass());
261+
final HttpClient.Factory result = HttpClientUtils.getHttpClientFactory();
262+
assertEquals(ScoredHttpClientFactory.class, result.getClass());
263+
assertEquals(Integer.MAX_VALUE, result.priority());
264+
assertEquals("priority", ((ScoredHttpClientFactory) result).id);
262265
}
263266

264-
private final class DefaultHttpClientFactory implements HttpClient.Factory {
267+
@Test
268+
@DisplayName("With multiple implementations and several with max priority, should return first of max priority")
269+
void withMultipleAndCollision() {
270+
factories.add(new DefaultHttpClientFactory());
271+
factories.add(new ScoredHttpClientFactory("other", 0));
272+
factories.add(new ScoredHttpClientFactory("priority-1", Integer.MAX_VALUE));
273+
factories.add(new ScoredHttpClientFactory("priority-2", Integer.MAX_VALUE));
274+
factories.add(new DefaultHttpClientFactory());
275+
final HttpClient.Factory result = HttpClientUtils.getHttpClientFactory();
276+
assertEquals(ScoredHttpClientFactory.class, result.getClass());
277+
assertEquals(Integer.MAX_VALUE, result.priority());
278+
assertEquals("priority-1", ((ScoredHttpClientFactory) result).id);
279+
}
265280

266-
@Override
267-
public HttpClient.Builder newBuilder() {
268-
return null;
269-
}
281+
private final class ScoredHttpClientFactory implements HttpClient.Factory {
282+
private final String id;
283+
private final int priority;
270284

271-
@Override
272-
public boolean isDefault() {
273-
return true;
285+
public ScoredHttpClientFactory(String id, int priority) {
286+
this.id = id;
287+
this.priority = priority;
274288
}
275-
}
276-
277-
private final class OtherHttpClientFactory implements HttpClient.Factory {
278289

279290
@Override
280291
public HttpClient.Builder newBuilder() {
281292
return null;
282293
}
294+
295+
@Override
296+
public int priority() {
297+
return priority;
298+
}
283299
}
284300

285-
private final class PriorityHttpClientFactory implements HttpClient.Factory {
301+
private final class DefaultHttpClientFactory implements HttpClient.Factory {
286302

287303
@Override
288304
public HttpClient.Builder newBuilder() {
289305
return null;
290306
}
291307

292308
@Override
293-
public int priority() {
294-
return Integer.MAX_VALUE;
309+
public boolean isDefault() {
310+
return true;
295311
}
296312
}
313+
297314
}
298315
}

0 commit comments

Comments
 (0)