feat(unreachable-cooldown): 连接层不可达客户端级冷却,四家判定下沉共用

BACKLOG B24(窗长 300s 已拍板):连续 2 次连接未建立即对该 host 进
冷却窗,窗内调用零探针快速失败(归因文案与调用内短路逐字一致);到期
后下一条真实调用兼作探针,失败重进、成功恢复。isConnectFailure 四处
副本(BrandCheckClient/AppearancePatentLlmClient/SimilarAsinLlmClient/
TaskOwnerForwardService)下沉 common/retry 共用。三家客户端接入同一
冷却表(两个 LLM 客户端共用 ai.t8star.org 一格,16890 独立一格),
窗长可配(0=关闭退回调用内短路)。另修 CollectDataBrandBatchFilter
首批预算竞态(1ms 预算下 GC 停顿误切首批,照 BrandCheckClient 首轮
不掐契约补 start>0 守卫)。变异验证:冷却禁用 6 例判红;定向 47/47 绿。
This commit is contained in:
2026-10-23 20:58:32 +08:00
parent 6af19b51ba
commit 09dfb01f9c
22 changed files with 426 additions and 99 deletions
@@ -1,6 +1,7 @@
package com.nanri.aiimage.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nanri.aiimage.common.retry.UnreachableCooldown;
import com.nanri.aiimage.modules.brand.client.BrandCheckClient;
import com.nanri.aiimage.modules.brand.client.BrandCheckClient.BrandCheckBatchResult;
import com.nanri.aiimage.modules.similarasin.client.SimilarAsinLlmClient;
@@ -96,7 +97,7 @@ class HttpClientConnectionReuseTest {
void test_task_077_brand_normal_default_path() throws Exception {
// 默认路径:品牌检查客户端通过共享池创建单例 RestClient,
// 工厂为带 keep-alive 连接池的 JdkClientHttpRequestFactory。
BrandCheckClient client = new BrandCheckClient(new BrandCheckProperties(), null, null);
BrandCheckClient client = new BrandCheckClient(new BrandCheckProperties(), null, null, new UnreachableCooldown());
BrandCheckBatchResult result = client.checkTitleText(" ", null, null);
assertTrue(result.brands().isEmpty(), "空标题安全跳过,不创建无效资源");
@@ -107,8 +108,8 @@ class HttpClientConnectionReuseTest {
void test_task_077_brand_normal_multiple_items() throws Exception {
// 批量场景:LLM/品牌/紫鸟三个客户端各自持有独立 RestClient,
// 但底层连接池共用同一 HttpClient 实例,不重复创建。
SimilarAsinLlmClient llm = new SimilarAsinLlmClient(new SimilarAsinProperties(), new ObjectMapper(), null, null);
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
SimilarAsinLlmClient llm = new SimilarAsinLlmClient(new SimilarAsinProperties(), new ObjectMapper(), null, null, new UnreachableCooldown());
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null, new UnreachableCooldown());
ZiniaoClientImpl ziniao = new ZiniaoClientImpl(new ZiniaoProperties(), new ObjectMapper());
HttpClient llmClient = clientOf(factoryOf(restClientOf(llm)));
@@ -124,7 +125,7 @@ class HttpClientConnectionReuseTest {
void test_task_077_brand_normal_repeated_operation_is_idempotent() throws Exception {
// 幂等:同一客户端重复触发请求创建逻辑只产生一个 RestClient,
// 重复调用返回同一实例,不重复创建客户端对象。
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null, new UnreachableCooldown());
assertSame(restClientOf(brand), restClientOf(brand), "品牌客户端复用同一 RestClient");
ZiniaoClientImpl ziniao = new ZiniaoClientImpl(new ZiniaoProperties(), new ObjectMapper());
@@ -134,7 +135,7 @@ class HttpClientConnectionReuseTest {
@Test
void test_task_077_brand_boundary_empty_input() throws Exception {
// 空输入:空品牌列表不发起任何 HTTP 请求、不创建客户端资源。
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null, new UnreachableCooldown());
BrandCheckBatchResult result = brand.checkAll(List.of(), "Terms", null);
assertTrue(result.brands().isEmpty());
@@ -145,7 +146,7 @@ class HttpClientConnectionReuseTest {
@Test
void test_task_077_brand_boundary_single_item() throws Exception {
// 单元素:单客户端单请求走共享池,工厂带连接池,行为与批量一致。
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null, new UnreachableCooldown());
assertPooled(factoryOf(restClientOf(brand)));
}
@@ -155,7 +156,7 @@ class HttpClientConnectionReuseTest {
// 不随实例数量线性增长连接资源。
int instances = 8;
for (int i = 0; i < instances; i++) {
restClientOf(new BrandCheckClient(new BrandCheckProperties(), null, null));
restClientOf(new BrandCheckClient(new BrandCheckProperties(), null, null, new UnreachableCooldown()));
restClientOf(new ZiniaoClientImpl(new ZiniaoProperties(), new ObjectMapper()));
}
assertSame(HttpClientPool.sharedHttpClient(), HttpClientPool.sharedHttpClient(),