mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(s3tables): expose bucket storage class configuration (#8524)
Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
63124253f2
commit
dc7948013d
11 files changed
+353
-58
No files matched your search
+5
-17
@@ -3,12 +3,10 @@ package io.floci.aws.services.cloudwatch.metrics;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.HybridStorage;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.PersistentStorage;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.WalStorage;
|
||||
import io.floci.aws.services.cloudwatch.metrics.model.MetricDatum;
|
||||
import io.floci.aws.testing.StorageTestBackends;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
@@ -53,30 +51,20 @@ class CloudWatchMetricPublicationStorageFaultTest {
|
||||
statistics(metrics);
|
||||
assertEquals(3, actual.keys().size());
|
||||
actual.flush();
|
||||
} finally { close(actual); }
|
||||
} finally { StorageTestBackends.close(actual); }
|
||||
if (!mode.equals("memory")) {
|
||||
StorageBackend<String, MetricDatum> reloaded = backend(mode);
|
||||
try {
|
||||
reloaded.load();
|
||||
statistics(metrics(new AccountAwareStorageBackend<>(reloaded, null, ACCOUNT)));
|
||||
assertEquals(3, reloaded.keys().size());
|
||||
} finally { close(reloaded); }
|
||||
} finally { StorageTestBackends.close(reloaded); }
|
||||
}
|
||||
}
|
||||
|
||||
private StorageBackend<String, MetricDatum> backend(String mode) {
|
||||
return switch (mode) {
|
||||
case "memory" -> new InMemoryStorage<>();
|
||||
case "persistent" -> new PersistentStorage<>(directory.resolve("metrics.json"), TYPE);
|
||||
case "hybrid" -> new HybridStorage<>(directory.resolve("metrics.json"), TYPE, 3_600_000);
|
||||
case "wal" -> new WalStorage<>(directory.resolve("metrics-snapshot.json"), directory.resolve("metrics.wal"), TYPE, 3_600_000);
|
||||
default -> throw new IllegalArgumentException(mode);
|
||||
};
|
||||
}
|
||||
|
||||
private static void close(StorageBackend<String, MetricDatum> backend) {
|
||||
if (backend instanceof HybridStorage<?, ?> hybrid) { hybrid.shutdown(); }
|
||||
if (backend instanceof WalStorage<?, ?> wal) { wal.shutdown(); }
|
||||
Path snapshot = directory.resolve(mode.equals("wal") ? "metrics-snapshot.json" : "metrics.json");
|
||||
return StorageTestBackends.create(mode, snapshot, directory.resolve("metrics.wal"), TYPE, 3_600_000);
|
||||
}
|
||||
|
||||
private static CloudWatchMetricsService metrics(AccountAwareStorageBackend<MetricDatum> store) {
|
||||
|
||||
@@ -4,12 +4,10 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.HybridStorage;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.PersistentStorage;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.WalStorage;
|
||||
import io.floci.aws.services.kms.model.KmsKey;
|
||||
import io.floci.aws.testing.StorageTestBackends;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -159,7 +157,7 @@ class KmsRotationPublicationServiceTest {
|
||||
newCiphertext = service.encrypt(keyId, plaintext, primaryRegion);
|
||||
keys.flush();
|
||||
} finally {
|
||||
close(keys);
|
||||
StorageTestBackends.close(keys);
|
||||
}
|
||||
|
||||
StorageBackend<String, KmsKey> reopened = persistentKeys(mode);
|
||||
@@ -175,31 +173,18 @@ class KmsRotationPublicationServiceTest {
|
||||
assertEquals(service.describeKey(keyId, primaryRegion).getBackingKeys(),
|
||||
service.describeKey(keyId, replicaRegion).getBackingKeys());
|
||||
} finally {
|
||||
close(reopened);
|
||||
StorageTestBackends.close(reopened);
|
||||
}
|
||||
}
|
||||
|
||||
private StorageBackend<String, KmsKey> persistentKeys(String mode) {
|
||||
TypeReference<Map<String, KmsKey>> type = new TypeReference<>() {};
|
||||
Path snapshot = directory.resolve("keys.json");
|
||||
return switch (mode) {
|
||||
case "persistent" -> new PersistentStorage<>(snapshot, type);
|
||||
case "hybrid" -> new HybridStorage<>(snapshot, type, Long.MAX_VALUE);
|
||||
case "wal" -> new WalStorage<>(snapshot, directory.resolve("keys.wal"), type, Long.MAX_VALUE);
|
||||
default -> throw new IllegalArgumentException("Unsupported test storage mode: " + mode);
|
||||
};
|
||||
return StorageTestBackends.create(mode, directory.resolve("keys.json"), directory.resolve("keys.wal"),
|
||||
type, Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
private static KmsService service(StorageBackend<String, KmsKey> keys, String region) {
|
||||
return new KmsService(keys, new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new RegionResolver(region, "000000000000"));
|
||||
}
|
||||
|
||||
private static void close(StorageBackend<String, KmsKey> keys) {
|
||||
if (keys instanceof HybridStorage<String, KmsKey> hybrid) {
|
||||
hybrid.shutdown();
|
||||
} else if (keys instanceof WalStorage<String, KmsKey> wal) {
|
||||
wal.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package io.floci.aws.services.s3tables;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.floci.aws.testing.SignedIamEnforcementProfile;
|
||||
import io.floci.aws.testing.SignedIamUsers;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3tables.S3TablesClient;
|
||||
import software.amazon.awssdk.services.s3tables.model.S3TablesException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(SignedIamEnforcementProfile.class)
|
||||
class S3TablesStorageReadIamIntegrationTest {
|
||||
@TestHTTPResource
|
||||
URI endpoint;
|
||||
|
||||
@Test
|
||||
void storageReadbackRequiresPermissionOnTheRequestedBucket() throws Exception {
|
||||
try (S3TablesClient admin = AwsTestClients.create(S3TablesClient.builder(), "test", Region.US_EAST_1, endpoint)) {
|
||||
String bucket = admin.createTableBucket(request -> request.name(name())).arn();
|
||||
try {
|
||||
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3t-storage-");
|
||||
S3TablesClient client = client(user)) {
|
||||
denied(client, bucket);
|
||||
}
|
||||
String other = admin.createTableBucket(request -> request.name(name())).arn();
|
||||
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3t-storage-", "read",
|
||||
policy("Allow", bucket));
|
||||
S3TablesClient client = client(user)) {
|
||||
assertEquals("STANDARD", client.getTableBucketStorageClass(request -> request.tableBucketARN(bucket))
|
||||
.storageClassConfiguration().storageClassAsString());
|
||||
denied(client, other);
|
||||
} finally {
|
||||
admin.deleteTableBucket(request -> request.tableBucketARN(other));
|
||||
}
|
||||
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "s3t-storage-", "deny",
|
||||
explicitDeny(bucket));
|
||||
S3TablesClient client = client(user)) {
|
||||
denied(client, bucket);
|
||||
}
|
||||
} finally {
|
||||
admin.deleteTableBucket(request -> request.tableBucketARN(bucket));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String policy(String effect, String bucket) {
|
||||
return """
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "%s",
|
||||
"Action": "s3tables:GetTableBucketStorageClass",
|
||||
"Resource": "%s"
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(effect, bucket);
|
||||
}
|
||||
|
||||
private S3TablesClient client(SignedIamUsers.User user) {
|
||||
return AwsTestClients.create(S3TablesClient.builder(), user.accessKeyId(), user.secretAccessKey(),
|
||||
Region.US_EAST_1, endpoint);
|
||||
}
|
||||
|
||||
private static String explicitDeny(String bucket) {
|
||||
return """
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": "s3tables:GetTableBucketStorageClass",
|
||||
"Resource": "*"
|
||||
},
|
||||
{
|
||||
"Effect": "Deny",
|
||||
"Action": "s3tables:GetTableBucketStorageClass",
|
||||
"Resource": "%s"
|
||||
}
|
||||
]
|
||||
}
|
||||
""".formatted(bucket);
|
||||
}
|
||||
|
||||
private static void denied(S3TablesClient client, String bucket) {
|
||||
S3TablesException error = assertThrows(S3TablesException.class,
|
||||
() -> client.getTableBucketStorageClass(request -> request.tableBucketARN(bucket)));
|
||||
assertEquals(403, error.statusCode());
|
||||
assertTrue(error.getMessage().contains("not authorized to perform: s3tables:GetTableBucketStorageClass"),
|
||||
error.getMessage());
|
||||
}
|
||||
|
||||
private static String name() {
|
||||
return "storage-iam-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package io.floci.aws.services.s3tables;
|
||||
|
||||
import io.floci.aws.testing.AwsTestClients;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.s3tables.S3TablesClient;
|
||||
import software.amazon.awssdk.services.s3tables.model.NotFoundException;
|
||||
import software.amazon.awssdk.services.s3tables.model.StorageClassConfiguration;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@QuarkusTest
|
||||
class S3TablesStorageReadIntegrationTest {
|
||||
@TestHTTPResource
|
||||
URI endpoint;
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"us-east-1", "us-gov-west-1", "cn-north-1"})
|
||||
void sdkReadsDefaultAndExplicitBucketStorageClasses(String region) {
|
||||
try (S3TablesClient client = client(region, "111111111111")) {
|
||||
assertReadback(client, null, "STANDARD");
|
||||
assertReadback(client, "STANDARD", "STANDARD");
|
||||
assertReadback(client, "INTELLIGENT_TIERING", "INTELLIGENT_TIERING");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsStayWithinTheRequestedAccountRegionAndExactBucketArn() {
|
||||
String name = name();
|
||||
try (S3TablesClient first = client("us-east-1", "111111111111");
|
||||
S3TablesClient second = client("us-east-1", "222222222222");
|
||||
S3TablesClient otherRegion = client("us-west-2", "111111111111")) {
|
||||
String firstArn = first.createTableBucket(request -> request.name(name)).arn();
|
||||
try {
|
||||
String secondArn = second.createTableBucket(request -> request.name(name)
|
||||
.storageClassConfiguration(config -> config.storageClass("INTELLIGENT_TIERING"))).arn();
|
||||
try {
|
||||
assertEquals("STANDARD", read(first, firstArn).storageClassAsString());
|
||||
assertEquals("INTELLIGENT_TIERING", read(second, secondArn).storageClassAsString());
|
||||
assertThrows(NotFoundException.class, () -> read(first, secondArn));
|
||||
assertThrows(NotFoundException.class, () -> read(second, firstArn));
|
||||
assertThrows(NotFoundException.class, () -> read(otherRegion, firstArn));
|
||||
assertEquals("INTELLIGENT_TIERING", read(second, secondArn).storageClassAsString());
|
||||
} finally {
|
||||
second.deleteTableBucket(request -> request.tableBucketARN(secondArn));
|
||||
}
|
||||
} finally {
|
||||
first.deleteTableBucket(request -> request.tableBucketARN(firstArn));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingAndDeletedBucketsReturnTheModeledError() {
|
||||
try (S3TablesClient client = client("us-east-1", "test")) {
|
||||
String arn = client.createTableBucket(request -> request.name(name())).arn();
|
||||
try {
|
||||
assertThrows(NotFoundException.class, () -> read(client, arn + "-missing"));
|
||||
} finally {
|
||||
client.deleteTableBucket(request -> request.tableBucketARN(arn));
|
||||
}
|
||||
assertThrows(NotFoundException.class, () -> read(client, arn));
|
||||
}
|
||||
}
|
||||
|
||||
private void assertReadback(S3TablesClient client, String configured, String expected) {
|
||||
String arn = client.createTableBucket(request -> {
|
||||
request.name(name());
|
||||
if (configured != null) {
|
||||
request.storageClassConfiguration(config -> config.storageClass(configured));
|
||||
}
|
||||
}).arn();
|
||||
try {
|
||||
StorageClassConfiguration configuration = StorageClassConfiguration.builder().storageClass(expected).build();
|
||||
assertEquals(configuration, read(client, arn));
|
||||
} finally {
|
||||
client.deleteTableBucket(request -> request.tableBucketARN(arn));
|
||||
}
|
||||
}
|
||||
|
||||
private StorageClassConfiguration read(S3TablesClient client, String arn) {
|
||||
return client.getTableBucketStorageClass(request -> request.tableBucketARN(arn)).storageClassConfiguration();
|
||||
}
|
||||
|
||||
private String name() {
|
||||
return "storage-read-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
|
||||
private S3TablesClient client(String region, String account) {
|
||||
return AwsTestClients.create(S3TablesClient.builder(), account, Region.of(region), endpoint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.floci.aws.services.s3tables;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.s3.S3Service;
|
||||
import io.floci.aws.services.s3tables.model.TableBucket;
|
||||
import io.floci.aws.testing.StorageTestBackends;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class S3TablesStorageReadPersistenceTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
private static final Map<String, String> TIERED = Map.of("storageClass", "INTELLIGENT_TIERING");
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"persistent,false", "persistent,true", "hybrid,false", "hybrid,true", "wal,false", "wal,true"})
|
||||
void defaultAndConfiguredStorageClassReadBackAfterReload(String mode, boolean configured, @TempDir Path directory) {
|
||||
Path snapshot = directory.resolve("s3tables.json");
|
||||
String arn;
|
||||
Map<String, String> expected = configured ? TIERED : Map.of("storageClass", "STANDARD");
|
||||
StorageBackend<String, TableBucket> first = open(mode, snapshot);
|
||||
try {
|
||||
S3TablesService service = service(first);
|
||||
arn = service.createTableBucket("warehouse", null, configured ? TIERED : null, Map.of(), REGION).getArn();
|
||||
assertEquals(expected, service.getTableBucketStorageClass(arn, REGION));
|
||||
} finally {
|
||||
StorageTestBackends.close(first);
|
||||
}
|
||||
|
||||
StorageBackend<String, TableBucket> second = open(mode, snapshot);
|
||||
try {
|
||||
assertEquals(expected, service(second).getTableBucketStorageClass(arn, REGION));
|
||||
} finally {
|
||||
StorageTestBackends.close(second);
|
||||
}
|
||||
}
|
||||
|
||||
private static S3TablesService service(StorageBackend<String, TableBucket> backend) {
|
||||
StorageFactory factory = mock(StorageFactory.class);
|
||||
when(factory.<TableBucket>create(anyString(), anyString(), any()))
|
||||
.thenReturn(new AccountAwareStorageBackend<>(backend, null, ACCOUNT));
|
||||
return new S3TablesService(factory, new RegionResolver(REGION, ACCOUNT), mock(S3Service.class));
|
||||
}
|
||||
|
||||
private static StorageBackend<String, TableBucket> open(String mode, Path snapshot) {
|
||||
TypeReference<Map<String, TableBucket>> type = new TypeReference<>() {};
|
||||
StorageBackend<String, TableBucket> backend = StorageTestBackends.create(
|
||||
mode, snapshot, snapshot.resolveSibling("s3tables.wal"), type, 60_000);
|
||||
backend.load();
|
||||
return backend;
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,11 @@ package io.floci.aws.services.s3vectors;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.HybridStorage;
|
||||
import io.floci.aws.core.storage.PersistentStorage;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.core.storage.WalStorage;
|
||||
import io.floci.aws.services.s3vectors.model.VectorBucket;
|
||||
import io.floci.aws.services.s3vectors.model.VectorIndex;
|
||||
import io.floci.aws.testing.StorageTestBackends;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
@@ -79,7 +77,7 @@ class S3VectorsPersistenceTest {
|
||||
assertEquals(DEFAULT_ENCRYPTION, created.getEncryptionConfiguration());
|
||||
assertEquals(MIGRATION_TIME, created.getCreationTime());
|
||||
} finally {
|
||||
close(first);
|
||||
StorageTestBackends.close(first);
|
||||
}
|
||||
|
||||
StorageBackend<String, VectorBucket> second = open(mode, snapshot);
|
||||
@@ -98,7 +96,7 @@ class S3VectorsPersistenceTest {
|
||||
assertEquals(3, restarted.listIndexes("legacy", REGION).size());
|
||||
verify(second, never()).put(anyString(), any());
|
||||
} finally {
|
||||
close(second);
|
||||
StorageTestBackends.close(second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,23 +109,9 @@ class S3VectorsPersistenceTest {
|
||||
|
||||
private static StorageBackend<String, VectorBucket> open(String mode, Path snapshot) {
|
||||
TypeReference<Map<String, VectorBucket>> type = new TypeReference<>() {};
|
||||
StorageBackend<String, VectorBucket> backend = spy(switch (mode) {
|
||||
case "persistent" -> new PersistentStorage<>(snapshot, type);
|
||||
case "hybrid" -> new HybridStorage<>(snapshot, type, 60_000);
|
||||
case "wal" -> new WalStorage<>(snapshot, snapshot.resolveSibling("s3vectors.wal"), type, 60_000);
|
||||
default -> throw new IllegalArgumentException(mode);
|
||||
});
|
||||
StorageBackend<String, VectorBucket> backend = spy(StorageTestBackends.create(
|
||||
mode, snapshot, snapshot.resolveSibling("s3vectors.wal"), type, 60_000));
|
||||
backend.load();
|
||||
return backend;
|
||||
}
|
||||
|
||||
private static void close(StorageBackend<String, VectorBucket> backend) {
|
||||
if (backend instanceof HybridStorage<?, ?> hybrid) {
|
||||
hybrid.shutdown();
|
||||
} else if (backend instanceof WalStorage<?, ?> wal) {
|
||||
wal.shutdown();
|
||||
} else {
|
||||
backend.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.floci.aws.testing;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.floci.aws.core.storage.HybridStorage;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.PersistentStorage;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.WalStorage;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
/** Real storage backends for tests that exercise writes and reload persisted state. */
|
||||
public final class StorageTestBackends {
|
||||
private StorageTestBackends() {
|
||||
}
|
||||
|
||||
/** Creates an unloaded backend. The caller owns loading and closing it. */
|
||||
public static <V> StorageBackend<String, V> create(String mode, Path snapshot, Path journal,
|
||||
TypeReference<Map<String, V>> type, long intervalMillis) {
|
||||
return switch (mode) {
|
||||
case "memory" -> new InMemoryStorage<>();
|
||||
case "persistent" -> new PersistentStorage<>(snapshot, type);
|
||||
case "hybrid" -> new HybridStorage<>(snapshot, type, intervalMillis);
|
||||
case "wal" -> new WalStorage<>(snapshot, journal, type, intervalMillis);
|
||||
default -> throw new IllegalArgumentException("Unsupported test storage mode: " + mode);
|
||||
};
|
||||
}
|
||||
|
||||
/** Flushes pending state and stops any background storage worker. */
|
||||
public static void close(StorageBackend<?, ?> backend) {
|
||||
if (backend instanceof HybridStorage<?, ?> hybrid) {
|
||||
hybrid.shutdown();
|
||||
} else if (backend instanceof WalStorage<?, ?> wal) {
|
||||
wal.shutdown();
|
||||
} else {
|
||||
backend.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user