fix: fall back to tool pods when redis is unavailable
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 2m14s
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 2m14s
This commit is contained in:
@@ -113,11 +113,16 @@ public class McpRouterController {
|
||||
}
|
||||
|
||||
private List<ToolMetadata> fetchAllActiveTools() {
|
||||
List<ToolMetadata> activeTools = redisRegistryService.getAllTools()
|
||||
.stream()
|
||||
.filter(ToolMetadata::getVisible)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<ToolMetadata> activeTools = new ArrayList<>();
|
||||
try {
|
||||
activeTools.addAll(redisRegistryService.getAllTools()
|
||||
.stream()
|
||||
.filter(ToolMetadata::getVisible)
|
||||
.collect(Collectors.toList()));
|
||||
} catch (org.springframework.data.redis.RedisConnectionFailureException exception) {
|
||||
log.warn("Redis is unavailable. Fetching tools from configured fallback Tool Pods instead.");
|
||||
}
|
||||
|
||||
Set<String> knownTools = activeTools.stream()
|
||||
.map(ToolMetadata::getUid)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.shinhanlife.dap.mcg.presentation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.shinhanlife.dap.lib.mcp.security.SecurityProperties;
|
||||
import io.shinhanlife.dap.lib.adapter.dto.JsonRpcResponse;
|
||||
import io.shinhanlife.dap.mcg.config.GatewayFallbackProperties;
|
||||
import io.shinhanlife.dap.mcg.registry.RedisRegistryService;
|
||||
import io.shinhanlife.dap.mcg.service.ExecuteService;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
class McpRouterControllerTest {
|
||||
|
||||
@Test
|
||||
void returnsEmptyToolListWhenRedisIsUnavailableAndNoFallbackIsConfigured() {
|
||||
RedisRegistryService registryService = org.mockito.Mockito.mock(RedisRegistryService.class);
|
||||
when(registryService.getAllTools()).thenThrow(new RedisConnectionFailureException("Redis unavailable"));
|
||||
|
||||
McpRouterController controller = new McpRouterController(
|
||||
registryService,
|
||||
org.mockito.Mockito.mock(ExecuteService.class),
|
||||
org.mockito.Mockito.mock(SecurityProperties.class),
|
||||
new ObjectMapper(),
|
||||
new GatewayFallbackProperties());
|
||||
|
||||
ResponseEntity<JsonRpcResponse> response = assertDoesNotThrow(() -> controller.listTools(null));
|
||||
Map<?, ?> result = (Map<?, ?>) response.getBody().getResult();
|
||||
|
||||
assertEquals(List.of(), result.get("tools"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user