Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): provide a way to turn off cats search provider and kube…
…rnetes search provider (#5595) * feat(search): provide a way to turn off cats search provider * test(core): make sure that CatsSearchProviderTest works with spring 2.3 as mentioned here: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#applicationcontextrunner-disables-bean-overriding-by-default, tests should add: withAllowBeanDefinitionOverriding for backwards consistency * feat(search): provide a way to turn off kubernetes search provider * fix(search): ensure that search result==null is handled properly if any of the search providers return items.results as null, then we see: Ambiguous method overloading for method java.util.ArrayList#addAll. Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [interface java.util.Collection] [interface java.lang.Iterable] [interface java.util.Iterator] Therefore, let's default to an empty [] in such cases.
- Loading branch information
1 parent
9d3d51e
commit 4096e61
Showing
9 changed files
with
208 additions
and
1 deletion.
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
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
77 changes: 77 additions & 0 deletions
77
...er-core/src/test/java/com/netflix/spinnaker/clouddriver/cache/CatsSearchProviderTest.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,77 @@ | ||
/* | ||
* Copyright 2021 Salesforce.com, Inc. | ||
* | ||
* Licensed 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 com.netflix.spinnaker.clouddriver.cache; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.netflix.spectator.api.NoopRegistry; | ||
import com.netflix.spectator.api.Registry; | ||
import com.netflix.spinnaker.cats.cache.Cache; | ||
import com.netflix.spinnaker.cats.mem.InMemoryCache; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.context.annotation.UserConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
public class CatsSearchProviderTest { | ||
private final ApplicationContextRunner runner = | ||
new ApplicationContextRunner() | ||
.withPropertyValues("caching.write-enabled=false", "redis.enabled:false") | ||
.withConfiguration(UserConfigurations.of(CacheConfig.class, TestConfiguration.class)) | ||
.withAllowBeanDefinitionOverriding(true); | ||
|
||
@Test | ||
void testCatsSearchProviderBeanIsPresentByDefault() { | ||
runner.run(ctx -> assertThat(ctx).hasSingleBean(CatsSearchProvider.class)); | ||
} | ||
|
||
@Test | ||
void testCatsSearchProviderBeanIsPresentWhenConfiguredInSuchAWay() { | ||
runner | ||
.withPropertyValues("caching.search.enabled=true") | ||
.run(ctx -> assertThat(ctx).hasSingleBean(CatsSearchProvider.class)); | ||
} | ||
|
||
@Test | ||
void testCatsSearchProviderBeanIsNotPresentWhenConfiguredInSuchAWay() { | ||
runner | ||
.withPropertyValues("caching.search.enabled=false") | ||
.run(ctx -> assertThat(ctx).doesNotHaveBean(CatsSearchProvider.class)); | ||
} | ||
|
||
/** | ||
* test class that supplies the minimum set of beans needed to autowire the CatsSearchProvider | ||
* bean and other required beans in the CacheConfig class | ||
*/ | ||
static class TestConfiguration { | ||
@Bean | ||
CatsInMemorySearchProperties catsInMemorySearchProperties() { | ||
return new CatsInMemorySearchProperties(); | ||
} | ||
|
||
@Bean | ||
Cache cache() { | ||
return new InMemoryCache(); | ||
} | ||
|
||
@Bean | ||
Registry registry() { | ||
return new NoopRegistry(); | ||
} | ||
} | ||
} |
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
78 changes: 78 additions & 0 deletions
78
.../spinnaker/clouddriver/kubernetes/caching/view/provider/KubernetesSearchProviderTest.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,78 @@ | ||
/* | ||
* Copyright 2021 Salesforce.com, Inc. | ||
* | ||
* Licensed 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 com.netflix.spinnaker.clouddriver.kubernetes.caching.view.provider; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.description.KubernetesSpinnakerKindMap; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.context.annotation.UserConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
public class KubernetesSearchProviderTest { | ||
private final ApplicationContextRunner runner = | ||
new ApplicationContextRunner() | ||
.withConfiguration( | ||
UserConfigurations.of(KubernetesSearchProvider.class, TestConfiguration.class)); | ||
|
||
@Test | ||
void testKubernetesSearchProviderBeanIsPresentByDefault() { | ||
runner.run(ctx -> assertThat(ctx).hasSingleBean(KubernetesSearchProvider.class)); | ||
} | ||
|
||
@Test | ||
void testKubernetesSearchProviderBeanIsPresentWhenConfiguredInSuchAWay() { | ||
runner | ||
.withPropertyValues("kubernetes.search.enabled=true") | ||
.run(ctx -> assertThat(ctx).hasSingleBean(KubernetesSearchProvider.class)); | ||
} | ||
|
||
@Test | ||
void testKubernetesSearchProviderBeanIsNotPresentWhenConfiguredInSuchAWay() { | ||
runner | ||
.withPropertyValues("kubernetes.search.enabled=false") | ||
.run(ctx -> assertThat(ctx).doesNotHaveBean(KubernetesSearchProvider.class)); | ||
} | ||
|
||
/** test class that supplies beans needed to autowire the KubernetesSearchProvider bean */ | ||
static class TestConfiguration { | ||
@Bean | ||
ObjectMapper getObjectMapper() { | ||
return new ObjectMapper(); | ||
} | ||
|
||
@Bean | ||
KubernetesCacheUtils getKubernetesCacheUtils() { | ||
return mock(KubernetesCacheUtils.class); | ||
} | ||
|
||
@Bean | ||
KubernetesSpinnakerKindMap kubernetesSpinnakerKindMap() { | ||
return new KubernetesSpinnakerKindMap(List.of()); | ||
} | ||
|
||
@Bean | ||
KubernetesAccountResolver kubernetesAccountResolver() { | ||
return mock(KubernetesAccountResolver.class); | ||
} | ||
} | ||
} |
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