use of com.artipie.asto.Storage in project artipie by artipie.
the class MetricSliceTest method shouldReturnMetricsInJsonArray.
@Test
void shouldReturnMetricsInJsonArray() {
final String keyone = "one";
final String keytwo = "two";
final String json = "[{\"key\":\"%s\",\"value\":%s},{\"key\":\"%s\",\"value\":%s}]";
final long valone = 1;
final long valtwo = 2;
final String dirorder = String.format(json, keyone, valone, keytwo, valtwo);
final String revorder = String.format(json, keytwo, valtwo, keyone, valone);
final Storage storage = new InMemoryStorage();
storage.save(new Key.From(keyone), this.getContent(valone));
storage.save(new Key.From(keytwo), this.getContent(valtwo));
MatcherAssert.assertThat(new MetricSlice(storage), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new AnyOf<>(Arrays.asList(new RsHasBody(dirorder, StandardCharsets.UTF_8), new RsHasBody(revorder, StandardCharsets.UTF_8))))), new RequestLine(RqMethod.GET, "/api/repositories/")));
}
use of com.artipie.asto.Storage in project artipie by artipie.
the class CachedStoragesTest method getsOriginForDifferentConfiguration.
@Test
void getsOriginForDifferentConfiguration() {
final CachedStorages storages = new CachedStorages(this.cache);
final Storage frst = storages.storage(CachedStoragesTest.config("first"));
final Storage scnd = storages.storage(CachedStoragesTest.config("second"));
MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
MatcherAssert.assertThat("Storage configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
use of com.artipie.asto.Storage in project artipie by artipie.
the class CachedStoragesTest method getsValueFromCache.
@Test
void getsValueFromCache() {
final String path = "same/path/for/storage";
final CachedStorages storages = new CachedStorages(this.cache);
final Storage strg = storages.storage(CachedStoragesTest.config(path));
final Storage same = storages.storage(CachedStoragesTest.config(path));
MatcherAssert.assertThat("Obtained configurations were different", strg.equals(same), new IsEqual<>(true));
MatcherAssert.assertThat("Storage configuration was not cached", this.cache.size(), new IsEqual<>(1L));
}
use of com.artipie.asto.Storage in project artipie by artipie.
the class YamlStorage method storage.
/**
* Provides a storage.
*
* @return Storage instance.
*/
public Storage storage() {
@SuppressWarnings("deprecation") final YamlMapping strict = new StrictYamlMapping(this.yaml);
final String type = strict.string("type");
final Storage storage;
if ("fs".equals(type)) {
storage = new FileStorage(Path.of(strict.string("path")));
} else if ("s3".equals(type)) {
storage = new S3Storage(this.s3Client(), strict.string("bucket"), !"false".equals(this.yaml.string("multipart")));
} else if ("etcd".equals(type)) {
storage = new EtcdStorage(YamlStorage.etcdClient(strict.yamlMapping("connection")));
} else {
throw new IllegalStateException(String.format("Unsupported storage type: '%s'", type));
}
return storage;
}
use of com.artipie.asto.Storage in project artipie by artipie.
the class ConfigFile method delete.
/**
* Deletes value from the storage.
* @param storage Storage where the file with different extensions is checked for existence
* @return Result of completion.
*/
public CompletionStage<Void> delete(final Storage storage) {
final CompletionStage<Void> res;
if (this.isYamlOrYml() || this.extension().isEmpty()) {
final String name = this.name();
final Key yaml = Extension.YAML.key(name);
res = storage.exists(yaml).thenCompose(exist -> {
final CompletionStage<Void> result;
if (exist) {
result = storage.delete(yaml);
} else {
result = storage.delete(Extension.YML.key(name));
}
return result;
});
} else {
res = CompletableFuture.allOf();
}
return res;
}
Aggregations