mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 07:11:11 -05:00
test(appconfig): reuse named stores in race fixtures (#7026)
Apply the separate follow-up requested in upstream #6791. Register named backing stores through InMemoryStorageFactory and preserve existing AppConfig update, delete and tagging race assertions and synchronization. Source projection from fork #271; original source and metadata preserved. Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
a4d609a37a
commit
71f18f5ff3
4 files changed
+69
-28
No files matched your search
+1
-14
@@ -1,10 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.core.storage.WriteProfile;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Application;
|
||||
import io.github.hectorvent.floci.testing.InMemoryStorageFactory;
|
||||
import io.github.hectorvent.floci.testing.ParkingStore;
|
||||
@@ -94,15 +90,6 @@ class AppConfigServiceTaggingTest {
|
||||
|
||||
/** An AppConfig service whose application store is {@code store} and every other store in memory. */
|
||||
private static AppConfigService serviceWithApplicationStore(StorageBackend<String, Application> store) {
|
||||
return new AppConfigService(new StorageFactory(null, null) {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
|
||||
TypeReference<Map<String, V>> typeReference, WriteProfile profile) {
|
||||
return fileName.equals(APPLICATIONS)
|
||||
? new AccountAwareStorageBackend<>((StorageBackend<String, V>) (Object) store, null, ACCOUNT)
|
||||
: AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
}
|
||||
}, null);
|
||||
return new AppConfigService(new InMemoryStorageFactory(ACCOUNT).withStore(APPLICATIONS, store), null);
|
||||
}
|
||||
}
|
||||
+2
-14
@@ -1,14 +1,11 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.core.storage.WriteProfile;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Application;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.DeploymentStrategy;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Environment;
|
||||
import io.github.hectorvent.floci.testing.InMemoryStorageFactory;
|
||||
import io.github.hectorvent.floci.testing.ParkingStore;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -132,15 +129,6 @@ class AppConfigServiceUpdateRaceTest {
|
||||
|
||||
/** An AppConfig service whose {@code fileName} store is {@code store} and every other store in memory. */
|
||||
private static AppConfigService serviceWithStore(String fileName, StorageBackend<String, ?> store) {
|
||||
return new AppConfigService(new StorageFactory(null, null) {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName, String file,
|
||||
TypeReference<Map<String, V>> typeReference, WriteProfile profile) {
|
||||
return file.equals(fileName)
|
||||
? new AccountAwareStorageBackend<>((StorageBackend<String, V>) (Object) store, null, ACCOUNT)
|
||||
: AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
}
|
||||
}, null);
|
||||
return new AppConfigService(new InMemoryStorageFactory(ACCOUNT).withStore(fileName, store), null);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,13 @@ public final class InMemoryStorageFactory extends StorageFactory {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
/** Registers a backing store before constructing the services that use this factory. */
|
||||
public <V> InMemoryStorageFactory withStore(String fileName, StorageBackend<String, V> store) {
|
||||
stores.put(fileName, store instanceof AccountAwareStorageBackend<V> scoped
|
||||
? scoped : new AccountAwareStorageBackend<>(store, null, accountId));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
|
||||
TypeReference<Map<String, V>> typeReference) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package io.github.hectorvent.floci.testing;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.WriteProfile;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
class InMemoryStorageFactoryTest {
|
||||
|
||||
private static final String ACCOUNT = "123456789012";
|
||||
private static final TypeReference<Map<String, String>> TYPE = new TypeReference<>() {};
|
||||
|
||||
@Test
|
||||
void suppliedBackingStoreUsesTheFactoryAccountAndBothCreateOverloads() {
|
||||
InMemoryStorage<String, String> backing = new InMemoryStorage<>();
|
||||
InMemoryStorageFactory factory = new InMemoryStorageFactory(ACCOUNT).withStore("items.json", backing);
|
||||
AccountAwareStorageBackend<String> store = factory.create("service", "items.json", TYPE);
|
||||
|
||||
store.put("item", "value");
|
||||
|
||||
assertEquals("value", new AccountAwareStorageBackend<>(backing, null, ACCOUNT).get("item").orElseThrow());
|
||||
assertSame(store, factory.create("service", "items.json", TYPE, WriteProfile.DEFAULT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountAwareOverridesRetainIdentityAndDoNotWrapTwice() {
|
||||
AccountAwareStorageBackend<String> first = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
AccountAwareStorageBackend<String> second = AccountAwareStorageBackend.inMemory(ACCOUNT);
|
||||
InMemoryStorageFactory factory = new InMemoryStorageFactory(ACCOUNT)
|
||||
.withStore("first.json", first).withStore("second.json", second);
|
||||
|
||||
factory.create("service", "first.json", TYPE).put("item", "first");
|
||||
factory.create("service", "second.json", TYPE, WriteProfile.DEFAULT).put("item", "second");
|
||||
|
||||
assertSame(first, factory.create("service", "first.json", TYPE));
|
||||
assertSame(second, factory.create("service", "second.json", TYPE));
|
||||
assertEquals("first", first.get("item").orElseThrow());
|
||||
assertEquals("second", second.get("item").orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unrelatedStoresRemainSharedByFileName() {
|
||||
InMemoryStorageFactory factory = new InMemoryStorageFactory(ACCOUNT)
|
||||
.withStore("overridden.json", new InMemoryStorage<String, String>());
|
||||
AccountAwareStorageBackend<String> store = factory.create("one", "other.json", TYPE);
|
||||
store.put("item", "value");
|
||||
|
||||
AccountAwareStorageBackend<String> reused = factory.create("two", "other.json", TYPE, WriteProfile.DEFAULT);
|
||||
|
||||
assertSame(store, reused);
|
||||
assertEquals("value", reused.get("item").orElseThrow());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user