feat(brand-check): 品牌检测按任务归属用户取代理并计用量——三处调用接入
- BrandCheckClient 契约扩展:构造器收 UserApiSecretService,check/checkAll/ checkTitleText(s) 全系带 userId,请求体新增 user_id + proxy_url(proxy 取自 用户密钥库 module=proxy);响应新增 reason/retryable,retryable=false(供应商 拒付、用户没配代理)当场停重试阶梯并短路整批 - 三处调用方接入:CollectDataService 品牌过滤、CollectDataBrandRecheckScheduler 补测(markAttempted 带真实原因)、AppearancePatentLlmClient 标题查标(取 SecretUsageContext 归属用户) - 用户未配置代理:整批本地定论「用户未配置代理」,零 HTTP,不再有平台钥匙兜底 - 测试迁移:15 支测试文件按新契约迁移(3 参构造、userId 实参、BrandCheckBatchResult 第 4 位 reason、Mockito 匹配器加宽);HTTP 类测试 stub findPlainValue 非空代理 以绕开零 HTTP 短路。13 类 119 例全绿(1 skip 为既有快照写盘门),test-compile 零错误
This commit is contained in:
+8
-8
@@ -96,8 +96,8 @@ class HttpClientConnectionReuseTest {
|
||||
void test_task_077_brand_normal_default_path() throws Exception {
|
||||
// 默认路径:品牌检查客户端通过共享池创建单例 RestClient,
|
||||
// 工厂为带 keep-alive 连接池的 JdkClientHttpRequestFactory。
|
||||
BrandCheckClient client = new BrandCheckClient(new BrandCheckProperties(), null);
|
||||
BrandCheckBatchResult result = client.checkTitleText(" ");
|
||||
BrandCheckClient client = new BrandCheckClient(new BrandCheckProperties(), null, null);
|
||||
BrandCheckBatchResult result = client.checkTitleText(" ", null, null);
|
||||
|
||||
assertTrue(result.brands().isEmpty(), "空标题安全跳过,不创建无效资源");
|
||||
assertPooled(factoryOf(restClientOf(client)));
|
||||
@@ -108,7 +108,7 @@ class HttpClientConnectionReuseTest {
|
||||
// 批量场景:LLM/品牌/紫鸟三个客户端各自持有独立 RestClient,
|
||||
// 但底层连接池共用同一 HttpClient 实例,不重复创建。
|
||||
SimilarAsinLlmClient llm = new SimilarAsinLlmClient(new SimilarAsinProperties(), new ObjectMapper(), null, null);
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null);
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
|
||||
ZiniaoClientImpl ziniao = new ZiniaoClientImpl(new ZiniaoProperties(), new ObjectMapper());
|
||||
|
||||
HttpClient llmClient = clientOf(factoryOf(restClientOf(llm)));
|
||||
@@ -124,7 +124,7 @@ class HttpClientConnectionReuseTest {
|
||||
void test_task_077_brand_normal_repeated_operation_is_idempotent() throws Exception {
|
||||
// 幂等:同一客户端重复触发请求创建逻辑只产生一个 RestClient,
|
||||
// 重复调用返回同一实例,不重复创建客户端对象。
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null);
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
|
||||
assertSame(restClientOf(brand), restClientOf(brand), "品牌客户端复用同一 RestClient");
|
||||
|
||||
ZiniaoClientImpl ziniao = new ZiniaoClientImpl(new ZiniaoProperties(), new ObjectMapper());
|
||||
@@ -134,8 +134,8 @@ class HttpClientConnectionReuseTest {
|
||||
@Test
|
||||
void test_task_077_brand_boundary_empty_input() throws Exception {
|
||||
// 空输入:空品牌列表不发起任何 HTTP 请求、不创建客户端资源。
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null);
|
||||
BrandCheckBatchResult result = brand.checkAll(List.of(), "Terms");
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
|
||||
BrandCheckBatchResult result = brand.checkAll(List.of(), "Terms", null);
|
||||
|
||||
assertTrue(result.brands().isEmpty());
|
||||
assertTrue(result.faildData().isEmpty());
|
||||
@@ -145,7 +145,7 @@ class HttpClientConnectionReuseTest {
|
||||
@Test
|
||||
void test_task_077_brand_boundary_single_item() throws Exception {
|
||||
// 单元素:单客户端单请求走共享池,工厂带连接池,行为与批量一致。
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null);
|
||||
BrandCheckClient brand = new BrandCheckClient(new BrandCheckProperties(), null, null);
|
||||
assertPooled(factoryOf(restClientOf(brand)));
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ class HttpClientConnectionReuseTest {
|
||||
// 不随实例数量线性增长连接资源。
|
||||
int instances = 8;
|
||||
for (int i = 0; i < instances; i++) {
|
||||
restClientOf(new BrandCheckClient(new BrandCheckProperties(), null));
|
||||
restClientOf(new BrandCheckClient(new BrandCheckProperties(), null, null));
|
||||
restClientOf(new ZiniaoClientImpl(new ZiniaoProperties(), new ObjectMapper()));
|
||||
}
|
||||
assertSame(HttpClientPool.sharedHttpClient(), HttpClientPool.sharedHttpClient(),
|
||||
|
||||
Reference in New Issue
Block a user