mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(storage): migrate legacy entries by exact key (#3408)
* fix(storage): migrate legacy entries by exact key * fix(storage): use legacy migrator for bulk scans * chore: retrigger CI
This commit is contained in:
1 parent
ebe9cf2264
commit
d92211d1c1
2 files changed
+138
-15
No files matched your search
+73
@@ -15,6 +15,7 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -219,6 +220,78 @@ class AccountAwareStorageBackendTest {
|
||||
Set.copyOf(storage.scanAllAccountEntries(key -> key.startsWith("us-east-1::"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void migrateLegacyEntriesMovesGen0KeyAndDeletesExactSource() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
raw.put("legacy", "owned");
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(raw, null, "111111111111");
|
||||
|
||||
storage.migrateLegacyEntries("111111111111", "legacy"::equals,
|
||||
value -> "us-east-1/" + value, "owned"::equals);
|
||||
|
||||
assertEquals("owned", raw.get("111111111111/us-east-1/owned").orElseThrow());
|
||||
assertFalse(raw.get("legacy").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void migrateLegacyEntriesMovesGen1KeyAndDeletesExactSource() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
raw.put("111111111111/legacy", "owned");
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(raw, null, "000000000000");
|
||||
|
||||
storage.migrateLegacyEntries("111111111111", "legacy"::equals,
|
||||
value -> "us-east-1/" + value, "owned"::equals);
|
||||
|
||||
assertEquals("owned", raw.get("111111111111/us-east-1/owned").orElseThrow());
|
||||
assertFalse(raw.get("111111111111/legacy").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void migrateLegacyEntriesIsIdempotent() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
raw.put("legacy", "owned");
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(raw, null, "111111111111");
|
||||
|
||||
storage.migrateLegacyEntries("111111111111", "legacy"::equals,
|
||||
value -> "us-east-1/" + value, "owned"::equals);
|
||||
storage.migrateLegacyEntries("111111111111", "legacy"::equals,
|
||||
value -> "us-east-1/" + value, "owned"::equals);
|
||||
|
||||
assertEquals(Set.of("111111111111/us-east-1/owned"), raw.keys());
|
||||
}
|
||||
|
||||
@Test
|
||||
void migrateLegacyEntriesLeavesNonOwnerUntouched() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
raw.put("legacy", "foreign");
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(raw, null, "111111111111");
|
||||
|
||||
storage.migrateLegacyEntries("111111111111", "legacy"::equals,
|
||||
value -> "us-east-1/" + value, "owned"::equals);
|
||||
|
||||
assertEquals("foreign", raw.get("legacy").orElseThrow());
|
||||
assertTrue(raw.get("111111111111/us-east-1/foreign").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void migrateLegacyEntriesDeletesSourceWhenDestinationAlreadyExists() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
raw.put("111111111111/legacy", "stale");
|
||||
raw.put("111111111111/us-east-1/current", "current");
|
||||
AccountAwareStorageBackend<String> storage =
|
||||
new AccountAwareStorageBackend<>(raw, null, "000000000000");
|
||||
|
||||
storage.migrateLegacyEntries("111111111111", "legacy"::equals,
|
||||
value -> "us-east-1/current", "stale"::equals);
|
||||
|
||||
assertEquals("current", raw.get("111111111111/us-east-1/current").orElseThrow());
|
||||
assertFalse(raw.get("111111111111/legacy").isPresent());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code get} and {@code getForAccountMigratingLegacy} both migrate a pre-multi-account entry, and
|
||||
* both delete the legacy key once they have copied it. Unless they hold the same monitor, two readers
|
||||
|
||||
Reference in new issue
Block a user