mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(storage): make scan() return mutable list for non-InMemory backends (#517)
PersistentStorage, HybridStorage, and WalStorage used Stream.toList(), which returns an unmodifiable list in Java 16+. InMemoryStorage built an ArrayList, so callers that mutate the scan result work in unit tests (all using in-memory backend) but fail at runtime on persistent backends. This was the root cause of #482: CloudWatchLogsService.describeLogGroups calls result.sort(...) on the scan result, which throws UnsupportedOperationException when running against any non-memory store. Same latent bug at CloudWatchLogsService.getLogEvents and CognitoService.listGroups (callers copy into ArrayList first, so they happen to work). Rather than patch the two call sites, align all StorageBackend implementations on a documented "returns a new mutable list" contract. Tests added to each backend to lock in the behavior.
This commit is contained in:
8 files changed
+49
-3
No files matched your search
@@ -67,6 +67,15 @@ class HybridStorageTest {
|
||||
assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanReturnsMutableList() {
|
||||
storage.put("a", "1");
|
||||
storage.put("b", "2");
|
||||
var result = storage.scan(key -> true);
|
||||
assertDoesNotThrow(() -> result.sort(String::compareTo));
|
||||
assertDoesNotThrow(() -> result.add("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearRemovesAll() {
|
||||
storage.put("key1", "value1");
|
||||
|
||||
@@ -61,6 +61,15 @@ class InMemoryStorageTest {
|
||||
assertTrue(dbValues.contains("5432"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanReturnsMutableList() {
|
||||
storage.put("a", "1");
|
||||
storage.put("b", "2");
|
||||
List<String> result = storage.scan(k -> true);
|
||||
assertDoesNotThrow(() -> result.sort(String::compareTo));
|
||||
assertDoesNotThrow(() -> result.add("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanWithNoMatchesReturnsEmptyList() {
|
||||
storage.put("key1", "value1");
|
||||
|
||||
@@ -60,6 +60,15 @@ class PersistentStorageTest {
|
||||
assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanReturnsMutableList() {
|
||||
storage.put("a", "1");
|
||||
storage.put("b", "2");
|
||||
List<String> result = storage.scan(key -> true);
|
||||
assertDoesNotThrow(() -> result.sort(String::compareTo));
|
||||
assertDoesNotThrow(() -> result.add("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clear() {
|
||||
storage.put("key1", "value1");
|
||||
|
||||
@@ -65,6 +65,15 @@ class WalStorageTest {
|
||||
assertEquals(2, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanReturnsMutableList() {
|
||||
storage.put("a", "1");
|
||||
storage.put("b", "2");
|
||||
var result = storage.scan(key -> true);
|
||||
assertDoesNotThrow(() -> result.sort(String::compareTo));
|
||||
assertDoesNotThrow(() -> result.add("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearRemovesAllEntries() {
|
||||
storage.put("key1", "value1");
|
||||
|
||||
Reference in new issue
Block a user