Skip to content

Commit

Permalink
Merge pull request #2336 from ahgittin/kind-conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
fusesource-ci authored Jul 9, 2020
2 parents 7868b41 + f6ce84f commit df36613
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.fabric8.kubernetes.client;


import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public class KubernetesListHandler implements ResourceHandler<KubernetesList, Ku

private static final Logger LOGGER = LoggerFactory.getLogger(KubernetesListHandler.class);

private static final String KIND = new KubernetesList().getKind();

@Override
public String getKind() {
return Service.class.getSimpleName();
return KIND;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
*/
package io.fabric8.kubernetes.client;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.function.Consumer;

import io.fabric8.kubernetes.client.ResourceHandler.Key;
import io.fabric8.kubernetes.client.handlers.KubernetesListHandler;
import io.fabric8.kubernetes.client.handlers.core.v1.ServiceHandler;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;


public class ResourceHandlerTest {
Expand Down Expand Up @@ -52,4 +60,20 @@ public void testKeyEquals() {
assertNotEquals(k1, k2);
}

@Test
public void testAllRegisteredResourceHandlersKeysDiffer() {
Map<Key,ResourceHandler<?,?>> keys = new LinkedHashMap<>();
@SuppressWarnings("rawtypes")
Consumer<ResourceHandler> check = h -> {
ResourceHandler<?, ?> conflict = keys.put(new Key(h.getKind(), h.getApiVersion()), h);
assertTrue(conflict==null || conflict.getClass().equals(h.getClass()),
"Identical keys for different handlers "+h+" and "+conflict);
};
ServiceLoader.load(ResourceHandler.class).forEach(check);
// explicitly test KubernetesList because it is not included above in pojo, but it is a service in OSGi
check.accept(new KubernetesListHandler());
// and ServiceHandler which should already have been included above, but is known to conflict with KubernetesList
check.accept(new ServiceHandler());
}

}

0 comments on commit df36613

Please sign in to comment.