use of com.artipie.asto.Key in project artipie by artipie.
the class CachedCredsTest method getsOriginForSameConfigurationButDifferentStorages.
@Test
void getsOriginForSameConfigurationButDifferentStorages() {
final String path = "_credentials.yaml";
final Key key = new Key.From(path);
final CredsConfigCache configs = new CachedCreds(this.cache);
final Storage another = new InMemoryStorage();
new TestResource(path).saveTo(this.storage);
new BlockingStorage(another).save(key, "credentials: another val".getBytes(StandardCharsets.UTF_8));
final YamlMapping frst = configs.credentials(this.storage, key).toCompletableFuture().join();
final YamlMapping scnd = configs.credentials(another, key).toCompletableFuture().join();
MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class CachedCredsTest method getsValueFromCache.
@Test
void getsValueFromCache() {
final Key path = new Key.From("creds.yaml");
final CredsConfigCache configs = new CachedCreds(this.cache);
this.storage.save(path, Content.EMPTY).join();
final YamlMapping creds = configs.credentials(this.storage, path).toCompletableFuture().join();
final YamlMapping same = configs.credentials(this.storage, path).toCompletableFuture().join();
MatcherAssert.assertThat("Obtained configurations were different", creds.equals(same), new IsEqual<>(true));
MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(1L));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class CachedCredsTest method getsOriginForDifferentConfigurations.
@Test
void getsOriginForDifferentConfigurations() {
final CredsConfigCache configs = new CachedCreds(this.cache);
final Key onekey = new Key.From("first.yml");
final Key twokey = new Key.From("credentials.yml");
final BlockingStorage blck = new BlockingStorage(this.storage);
blck.save(onekey, "credentials: val".getBytes(StandardCharsets.UTF_8));
blck.save(twokey, "credentials: another val".getBytes(StandardCharsets.UTF_8));
final YamlMapping frst = configs.credentials(this.storage, onekey).toCompletableFuture().join();
final YamlMapping scnd = configs.credentials(this.storage, twokey).toCompletableFuture().join();
MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class RepositoriesFromStorageCacheTest method readAliasesFromCache.
@Test
void readAliasesFromCache() {
final Key alias = new Key.From("_storages.yaml");
final Key config = new Key.From("bin.yaml");
new TestResource(alias.string()).saveTo(this.storage);
new BlockingStorage(this.storage).save(config, "repo:\n storage: default".getBytes());
final ClientSlices http = new JettyClientSlices();
new RepositoriesFromStorage(http, this.storage).config(config.string()).toCompletableFuture().join();
this.storage.save(alias, Content.EMPTY).join();
MatcherAssert.assertThat(new RepositoriesFromStorage(http, this.storage).config(config.string()).toCompletableFuture().join().storageOpt().isPresent(), new IsEqual<>(true));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class VertxMain method startRepos.
/**
* Start repository servers.
*
* @param settings Settings.
* @param metrics Metrics.
*/
private void startRepos(final Settings settings, final Metrics metrics) {
final Storage storage = settings.repoConfigsStorage();
final Collection<RepoConfig> configs = storage.list(Key.ROOT).thenApply(keys -> keys.stream().map(key -> new ConfigFile(key)).filter(Predicate.not(ConfigFile::isSystem).and(ConfigFile::isYamlOrYml)).map(ConfigFile::name).map(name -> new RepositoriesFromStorage(this.http, storage).config(name)).map(stage -> stage.toCompletableFuture().join()).collect(Collectors.toList())).toCompletableFuture().join();
for (final RepoConfig repo : configs) {
try {
repo.port().ifPresent(prt -> {
final String name = new ConfigFile(repo.name()).name();
this.listenOn(new ArtipieRepositories(this.http, settings).slice(new Key.From(name), true), metrics, prt);
Logger.info(VertxMain.class, "Artipie repo '%s' was started on port %d", name, prt);
});
} catch (final IllegalStateException err) {
Logger.error(this, "Invalid repo config file %s: %[exception]s", repo.name(), err);
}
}
new QuartzScheduler(configs).start();
}
Aggregations