feat: separate api key and upstream concurrency

This commit is contained in:
wlx committed 2026-09-23 18:09:10 +08:00
1 parent 281849ceb8
commit f5f855c751
13 files changed
+74 -8

No files matched your search

@@ -29,6 +29,17 @@ class GatewayDeploymentTest {
verify(redis).execute(any(RedisScript.class), eq(List.of("moyi:test:gateway:rate:invoke:" + keyId)), any(Object[].class));
}
@Test
void keyConcurrencyUsesDedicatedRedisBucket() {
StringRedisTemplate redis = mock(StringRedisTemplate.class);
doReturn(1L).when(redis).execute(any(RedisScript.class), anyList(), any(Object[].class));
UUID keyId = UUID.randomUUID();
try (GatewayGuard.Slot ignored = new GatewayGuard(redis, 60, 300, 4, 2, "moyi:test:").acquireKey(keyId)) {
// The lease is intentionally held for the duration of this assertion.
}
verify(redis, atLeastOnce()).execute(any(RedisScript.class), eq(List.of("moyi:test:gateway:slots:key:" + keyId)), any(Object[].class));
}
@Test
void invalidRedisPrefixIsRejected() {
assertThrows(IllegalArgumentException.class, () -> new GatewayGuard(mock(StringRedisTemplate.class), 60, 300, 4, ""));