Skip to content

Commit

Permalink
addressing the sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Apr 28, 2021
1 parent ff57558 commit ca3c363
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public synchronized <T> SharedIndexInformer<T> getExistingSharedIndexInformer(Cl
SharedIndexInformer<T> foundSharedIndexInformer = null;
for (Map.Entry<String, SharedIndexInformer> entry : this.informers.entrySet()) {
if (isKeyOfType(entry.getKey(), apiTypeClass)) {
foundSharedIndexInformer = entry.getValue();
foundSharedIndexInformer = (SharedIndexInformer<T>) entry.getValue();
}
}
return foundSharedIndexInformer;
Expand All @@ -284,7 +284,7 @@ public synchronized void startAllRegisteredInformers() {
if (!informerExecutor.isShutdown()) {
informers.forEach(
(informerType, informer) ->
startedInformers.computeIfAbsent(informerType, key -> informerExecutor.submit((Runnable)informer::run)));
startedInformers.computeIfAbsent(informerType, key -> informerExecutor.submit(informer::run)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* It basically saves and indexes all the entries.
Expand All @@ -51,7 +51,7 @@ public class Cache<T> implements Indexer<T> {
// indices stores objects' key by their indices
private Map<String, Map<String, Set<String>>> indices = new HashMap<>();

private Supplier<Boolean> isRunning = () -> false;
private BooleanSupplier isRunning = () -> false;

public Cache() {
this(NAMESPACE_INDEX, Cache::metaNamespaceIndexFunc, Cache::deletionHandlingMetaNamespaceKeyFunc);
Expand All @@ -63,7 +63,7 @@ public Cache(String indexName, Function<T, List<String>> indexFunc, Function<T,
this.indices.put(indexName, new HashMap<>());
}

public void setIsRunning(Supplier<Boolean> isRunning) {
public void setIsRunning(BooleanSupplier isRunning) {
this.isRunning = isRunning;
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public Map<String, Function<T, List<String>>> getIndexers() {

@Override
public void addIndexers(Map<String, Function<T, List<String>>> indexersNew) {
if (isRunning.get()) {
if (isRunning.getAsBoolean()) {
throw new IllegalStateException("Cannot add indexers to a running informer.");
}
if (!items.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@ public void onDelete(Pod oldObj, boolean deletedFinalStateUnknown) {
assertFalse(podInformer.isRunning());
}

@Test public void testRunAfterStop() {
@Test
void testRunAfterStop() {
SharedIndexInformer<Pod> podInformer = factory.sharedIndexInformerFor(Pod.class, 0);
podInformer.run();
podInformer.stop();
Expand Down

0 comments on commit ca3c363

Please sign in to comment.