-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from guoshiqiufeng/dev
0.4.0
- Loading branch information
Showing
18 changed files
with
466 additions
and
14 deletions.
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
15 changes: 15 additions & 0 deletions
15
.../guoshiqiufeng/cloud/stream/binder/redis/support/converter/MessagingMessageConverter.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 |
---|---|---|
@@ -1,3 +1,18 @@ | ||
/* | ||
* Copyright (c) 2023-2024, fubluesky ([email protected]) | ||
* | ||
* 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 io.github.guoshiqiufeng.cloud.stream.binder.redis.support.converter; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
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
48 changes: 48 additions & 0 deletions
48
...oshiqiufeng/cloud/stream/binder/redis/config/RedisBinderHealthIndicatorConfiguration.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,48 @@ | ||
/* | ||
* Copyright (c) 2023-2024, fubluesky ([email protected]) | ||
* | ||
* 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 io.github.guoshiqiufeng.cloud.stream.binder.redis.config; | ||
|
||
import io.github.guoshiqiufeng.cloud.stream.binder.redis.health.RedisBinderHealth; | ||
import io.github.guoshiqiufeng.cloud.stream.binder.redis.health.RedisBinderHealthIndicator; | ||
import io.github.guoshiqiufeng.cloud.stream.binder.redis.properties.RedisBinderConfigurationProperties; | ||
import io.github.guoshiqiufeng.cloud.stream.binder.redis.utils.RedisConnectionFactoryUtil; | ||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
|
||
/** | ||
* Configuration for Redis binder health indicators. | ||
* | ||
* @author yanghq | ||
* @version 1.0 | ||
* @since 2024/11/17 10:55 | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator") | ||
@ConditionalOnEnabledHealthIndicator("binders") | ||
@ConditionalOnMissingBean(RedisBinderHealth.class) | ||
public class RedisBinderHealthIndicatorConfiguration { | ||
|
||
@Bean | ||
public RedisBinderHealthIndicator redisBinderHealthIndicator(RedisBinderConfigurationProperties configurationProperties) { | ||
RedisConnectionFactory connectionFactory = RedisConnectionFactoryUtil.getRedisConnectionFactory( | ||
configurationProperties.getConfiguration()); | ||
return new RedisBinderHealthIndicator(connectionFactory); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealth.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,12 @@ | ||
package io.github.guoshiqiufeng.cloud.stream.binder.redis.health; | ||
|
||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
|
||
/** | ||
* Health indicator for Redis binder. | ||
* @author yanghq | ||
* @version 1.0 | ||
* @since 2024/11/18 15:07 | ||
*/ | ||
public interface RedisBinderHealth extends HealthIndicator { | ||
} |
33 changes: 33 additions & 0 deletions
33
.../io/github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicator.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,33 @@ | ||
/* | ||
* Copyright (c) 2023-2024, fubluesky ([email protected]) | ||
* | ||
* 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 io.github.guoshiqiufeng.cloud.stream.binder.redis.health; | ||
|
||
import org.springframework.boot.actuate.data.redis.RedisHealthIndicator; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
|
||
/** | ||
* Health indicator for Redis binder. | ||
* | ||
* @author yanghq | ||
* @version 1.0 | ||
* @since 2024/11/17 10:00 | ||
*/ | ||
public class RedisBinderHealthIndicator extends RedisHealthIndicator { | ||
|
||
public RedisBinderHealthIndicator(RedisConnectionFactory connectionFactory) { | ||
super(connectionFactory); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...hiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorIntegrationTest.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,45 @@ | ||
/* | ||
* Copyright (c) 2023-2024, fubluesky ([email protected]) | ||
* | ||
* 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 io.github.guoshiqiufeng.cloud.stream.binder.redis.health; | ||
|
||
import io.github.guoshiqiufeng.cloud.stream.binder.redis.RedisContainerTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.Status; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author yanghq | ||
* @version 1.0 | ||
* @since 2024/11/17 17:04 | ||
*/ | ||
class RedisBinderHealthIndicatorIntegrationTest implements RedisContainerTest { | ||
|
||
@Test | ||
void shouldReportHealthWithRealRedis() { | ||
RedisConnectionFactory connectionFactory = RedisContainerTest.connectionFactory(); | ||
|
||
RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); | ||
Health health = healthIndicator.health(); | ||
|
||
assertThat(health.getStatus()).isEqualTo(Status.UP); | ||
assertThat(health.getDetails()) | ||
.containsKey("version") | ||
.containsKey("mode"); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...github/guoshiqiufeng/cloud/stream/binder/redis/health/RedisBinderHealthIndicatorTest.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,101 @@ | ||
/* | ||
* Copyright (c) 2023-2024, fubluesky ([email protected]) | ||
* | ||
* 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 io.github.guoshiqiufeng.cloud.stream.binder.redis.health; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.Status; | ||
import org.springframework.data.redis.connection.RedisConnection; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisServerCommands; | ||
|
||
import java.util.Properties; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* @author yanghq | ||
* @version 1.0 | ||
* @since 2024/11/17 17:04 | ||
*/ | ||
class RedisBinderHealthIndicatorTest { | ||
|
||
private static final String REDIS_PONG_RESPONSE = "PONG"; | ||
private static final String REDIS_VERSION_KEY = "redis_version"; | ||
|
||
@Test | ||
void healthUp() { | ||
RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); | ||
RedisConnection redisConnection = mock(RedisConnection.class); | ||
RedisServerCommands serverCommands = mock(RedisServerCommands.class); | ||
|
||
when(connectionFactory.getConnection()).thenReturn(redisConnection); | ||
when(redisConnection.ping()).thenReturn(REDIS_PONG_RESPONSE); | ||
when(redisConnection.serverCommands()).thenReturn(serverCommands); | ||
|
||
// Mock Redis info command response | ||
Properties serverInfo = new Properties(); | ||
serverInfo.setProperty(REDIS_VERSION_KEY, "7.0.2"); | ||
when(serverCommands.info()).thenReturn(serverInfo); | ||
|
||
RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); | ||
Health health = healthIndicator.health(); | ||
|
||
assertThat(health.getStatus()).isEqualTo(Status.UP); | ||
assertThat(health.getDetails()) | ||
.containsEntry("version", "7.0.2"); | ||
|
||
verify(redisConnection).close(); | ||
} | ||
|
||
@Test | ||
void healthDown() { | ||
RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); | ||
RedisConnection redisConnection = mock(RedisConnection.class); | ||
RedisServerCommands serverCommands = mock(RedisServerCommands.class); | ||
|
||
when(connectionFactory.getConnection()).thenReturn(redisConnection); | ||
when(redisConnection.ping()).thenReturn("ERROR"); | ||
when(redisConnection.serverCommands()).thenReturn(serverCommands); | ||
when(serverCommands.info()).thenThrow(new RuntimeException("Redis is down")); | ||
|
||
RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); | ||
Health health = healthIndicator.health(); | ||
|
||
assertThat(health.getStatus()).isEqualTo(Status.DOWN); | ||
assertThat(health.getDetails()) | ||
.containsKey("error") | ||
.containsValue("java.lang.RuntimeException: Redis is down"); | ||
|
||
verify(redisConnection).close(); | ||
} | ||
|
||
@Test | ||
void healthDownOnException() { | ||
RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); | ||
when(connectionFactory.getConnection()) | ||
.thenThrow(new RuntimeException("Connection failed")); | ||
|
||
RedisBinderHealthIndicator healthIndicator = new RedisBinderHealthIndicator(connectionFactory); | ||
Health health = healthIndicator.health(); | ||
|
||
assertThat(health.getStatus()).isEqualTo(Status.DOWN); | ||
assertThat(health.getDetails()) | ||
.containsKey("error") | ||
.containsValue("java.lang.RuntimeException: Connection failed"); | ||
} | ||
} |
Oops, something went wrong.