Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): fix enableRedisKeyspaceNotificationsInitializer bean creation issue during upgrade to spring boot 2.6.x #1766

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gate-api-tck/gate-api-tck.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ apply from: "${project.rootDir}/gradle/kotlin-test.gradle"

dependencies {
implementation(project(":gate-web"))
implementation("io.spinnaker.kork:kork-jedis-test")
implementation("org.springframework.session:spring-session-data-redis")

api("org.springframework.boot:spring-boot-starter-test")
api("dev.minutest:minutest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ import com.netflix.spinnaker.gate.Main
import dev.minutest.TestContextBuilder
import dev.minutest.TestDescriptor
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.test.context.TestContextManager
import org.springframework.test.context.TestPropertySource
import org.springframework.context.annotation.Bean
import com.netflix.spinnaker.kork.jedis.EmbeddedRedis
import org.springframework.context.annotation.Primary
import org.springframework.data.redis.connection.RedisStandaloneConfiguration
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory
import org.springframework.test.context.ContextConfiguration
import redis.clients.jedis.JedisPool

@SpringBootTest(classes = [Main::class])
@ContextConfiguration(classes = [GateFixtureConfiguration::class])
@TestPropertySource(properties = ["spring.config.location=classpath:gate-test-app.yml"])
abstract class GateFixture

Expand All @@ -39,3 +49,24 @@ inline fun <PF, reified F> TestContextBuilder<PF, F>.gateFixture(
}
}
}

@TestConfiguration
dbyron-sf marked this conversation as resolved.
Show resolved Hide resolved
internal open class GateFixtureConfiguration {
@Bean(destroyMethod = "destroy")
fun embeddedRedis(): EmbeddedRedis {
return EmbeddedRedis.embed().also { redis -> redis.jedis.connect() }.also { redis -> redis.jedis.ping() }
}

@Bean
@Primary
@SpringSessionRedisConnectionFactory
fun jedisConnectionFactory(embeddedRedis: EmbeddedRedis): JedisConnectionFactory {
return JedisConnectionFactory(RedisStandaloneConfiguration(embeddedRedis.host, embeddedRedis.port))
}

@Bean
@Primary
fun jedis(embeddedRedis: EmbeddedRedis): JedisPool {
return embeddedRedis.getPool();
}
}
2 changes: 2 additions & 0 deletions gate-plugins-test/gate-plugins-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies {

testImplementation("io.spinnaker.kork:kork-plugins")
testImplementation("io.spinnaker.kork:kork-plugins-tck")
testImplementation("io.spinnaker.kork:kork-jedis-test")
testImplementation("org.springframework.session:spring-session-data-redis")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import org.springframework.boot.test.context.TestConfiguration
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.web.servlet.MockMvc
import org.springframework.context.annotation.Bean
import com.netflix.spinnaker.kork.jedis.EmbeddedRedis
import org.springframework.context.annotation.Primary
import org.springframework.data.redis.connection.RedisStandaloneConfiguration
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory
import redis.clients.jedis.JedisPool

class GatePluginsFixture : PluginsTckFixture, GateTestService() {

Expand Down Expand Up @@ -75,4 +82,22 @@ class GatePluginsFixture : PluginsTckFixture, GateTestService() {
abstract class GateTestService

@TestConfiguration
internal open class PluginTestConfiguration
internal open class PluginTestConfiguration {
@Bean(destroyMethod = "destroy")
fun embeddedRedis(): EmbeddedRedis {
return EmbeddedRedis.embed().also { redis -> redis.jedis.connect() }.also { redis -> redis.jedis.ping() }
}

@Bean
@Primary
@SpringSessionRedisConnectionFactory
fun jedisConnectionFactory(embeddedRedis: EmbeddedRedis): JedisConnectionFactory {
return JedisConnectionFactory(RedisStandaloneConfiguration(embeddedRedis.host, embeddedRedis.port))
}

@Bean
@Primary
fun jedis(embeddedRedis: EmbeddedRedis): JedisPool {
return embeddedRedis.getPool();
}
}