mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): scope event reconciliation and prune history (#3533)
Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
34efd8957a
commit
04f0c3b7fd
4 files changed
+79
-5
No files matched your search
@@ -56,6 +56,39 @@ class RdsQueryHandlerTest {
|
||||
handler = new RdsQueryHandler(service, config, docDbHandler, neptuneHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeEvents_reconcilesOnlyTheRequestedDbInstance() {
|
||||
DbInstance requested = makeInstance("requested");
|
||||
when(service.listDbInstances("requested", null)).thenReturn(List.of(requested));
|
||||
when(service.describeEvents("requested", "db-instance", null, null, null))
|
||||
.thenReturn(List.of());
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("SourceIdentifier", "requested");
|
||||
p.add("SourceType", "db-instance");
|
||||
|
||||
Response response = handler.handle("DescribeEvents", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service).listDbInstances("requested", null);
|
||||
verify(service).refreshDbInstanceRuntimeHealth(requested);
|
||||
verify(service, never()).listDbInstances(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeEvents_doesNotReconcileInstancesForAnotherSourceType() {
|
||||
when(service.describeEvents("cluster", "db-cluster", null, null, null))
|
||||
.thenReturn(List.of());
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("SourceIdentifier", "cluster");
|
||||
p.add("SourceType", "db-cluster");
|
||||
|
||||
Response response = handler.handle("DescribeEvents", p);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service, never()).listDbInstances(any(), any());
|
||||
verify(service, never()).refreshDbInstanceRuntimeHealth(any());
|
||||
}
|
||||
|
||||
// ──────────────────────────── DBInstances XML tag ────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,6 +29,7 @@ import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.OptionGroupOption;
|
||||
import io.github.hectorvent.floci.services.rds.model.RdsEvent;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.RdsAuthProxy;
|
||||
import io.github.hectorvent.floci.services.rds.proxy.RdsProxyManager;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
@@ -39,6 +40,8 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -5541,6 +5544,28 @@ class RdsServiceTest {
|
||||
assertEquals(1, rdsService.describeEvents("dead-db", "db-instance", null, null, 60).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeEventsPrunesEventsOlderThanFourteenDays() throws Exception {
|
||||
InMemoryStorage<String, RdsEvent> eventStore = new InMemoryStorage<>();
|
||||
Field eventsField = RdsService.class.getDeclaredField("events");
|
||||
eventsField.setAccessible(true);
|
||||
eventsField.set(rdsService, eventStore);
|
||||
Instant now = Instant.now();
|
||||
RdsEvent expired = new RdsEvent("expired", "old-db", "db-instance", "old",
|
||||
List.of("availability"), now.minus(Duration.ofDays(15)), "old-arn");
|
||||
RdsEvent retained = new RdsEvent("retained", "recent-db", "db-instance", "recent",
|
||||
List.of("availability"), now.minus(Duration.ofDays(13)), "recent-arn");
|
||||
eventStore.put(expired.id(), expired);
|
||||
eventStore.put(retained.id(), retained);
|
||||
|
||||
List<RdsEvent> result = rdsService.describeEvents(
|
||||
null, null, now.minus(Duration.ofDays(20)), now.plusSeconds(1), null);
|
||||
|
||||
assertEquals(List.of(retained), result);
|
||||
assertTrue(eventStore.get("retained").isPresent());
|
||||
assertTrue(eventStore.get("expired").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void optionGroupsUseTheInjectedAccountAwareStorage() {
|
||||
String accountId = "123456789012";
|
||||
|
||||
Reference in new issue
Block a user