Skip to content

Commit

Permalink
fix(tests): refactor tests and junit platform name to execute startup…
Browse files Browse the repository at this point in the history
… tests

Startup test under module keiko-mem-spring and keiko-redis-spring are not executing and throwing below error:

```
> Task :keiko-mem-spring:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':keiko-mem-spring:test'.
> No tests found for given includes: [com.netflix.spinnaker.q.mem.spring.SpringStartupTests](--tests filter)

```

```
> Task :keiko-redis-spring:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':keiko-redis-spring:test'.
> No tests found for given includes: [com.netflix.spinnaker.q.redis.spring.SpringStartupTests](--tests filter)

```
After fixing these issues by refactoring the junit platform as `junit-jupiter`, encountered below errors while execution:
```
Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.netflix.spectator.api.Registry' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
	at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1801)
	at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1357)
	at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
	at app//org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:911)
	at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:788)
	... 133 more
```

```
Failed to load ApplicationContext
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.spinnaker.q.redis.RedisQueue]: Factory method 'queue' threw exception; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
	at app//org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at app//org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
	... 120 more
```
To fix these errors refactored the test by adding `Registry` and `JedisPool` beans.
  • Loading branch information
j-sandy committed Jul 15, 2024
1 parent 968da95 commit 9576cef
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion keiko-mem-spring/keiko-mem-spring.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ dependencies {

test {
useJUnitPlatform {
includeEngines "jupiter"
includeEngines "junit-jupiter"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netflix.spinnaker.q.mem.spring

import com.netflix.spectator.api.NoopRegistry
import com.netflix.spinnaker.config.MemQueueConfiguration
import com.netflix.spinnaker.config.QueueConfiguration
import com.netflix.spinnaker.q.DeadMessageCallback
Expand All @@ -13,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.test.context.junit.jupiter.SpringExtension
import com.netflix.spectator.api.Registry

@ExtendWith(SpringExtension::class)
@SpringBootTest(
Expand All @@ -34,4 +36,7 @@ internal class SpringStartupTests {
internal class TestConfiguration {
@Bean
fun deadMessageCallback(): DeadMessageCallback = { _, _ -> }

@Bean
fun registry(): Registry = NoopRegistry()
}
3 changes: 2 additions & 1 deletion keiko-redis-spring/keiko-redis-spring.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ dependencies {
testImplementation "org.springframework:spring-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "org.assertj:assertj-core"
testImplementation("io.spinnaker.kork:kork-jedis-test")

testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
}

test {
useJUnitPlatform {
includeEngines "jupiter"
includeEngines "junit-jupiter"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.netflix.spinnaker.q.redis.spring

import com.netflix.spectator.api.NoopRegistry
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.config.QueueConfiguration
import com.netflix.spinnaker.config.RedisQueueConfiguration
import com.netflix.spinnaker.q.Queue
Expand All @@ -10,11 +12,15 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.test.context.junit.jupiter.SpringExtension
import com.netflix.spinnaker.kork.jedis.EmbeddedRedis
import redis.clients.jedis.JedisPool

@ExtendWith(SpringExtension::class)
@SpringBootTest(
classes = [QueueConfiguration::class, RedisQueueConfiguration::class],
classes = [QueueConfiguration::class, RedisQueueConfiguration::class, TestConfiguration::class],
webEnvironment = NONE
)
internal class SpringStartupTests {
Expand All @@ -27,3 +33,11 @@ internal class SpringStartupTests {
Assertions.assertThat(queue).isNotNull.isInstanceOf(RedisQueue::class.java)
}
}
@Configuration
internal class TestConfiguration {
@Bean
fun registry(): Registry = NoopRegistry()

@Bean
fun queueRedisPool(): JedisPool = EmbeddedRedis.embed().pool
}

0 comments on commit 9576cef

Please sign in to comment.