Search in sources :

Example 16 with Storage

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/")));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) AnyOf(org.hamcrest.core.AnyOf) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) RequestLine(com.artipie.http.rq.RequestLine) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Storage(com.artipie.asto.Storage) RsHasBody(com.artipie.http.hm.RsHasBody) Key(com.artipie.asto.Key) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 17 with Storage

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));
}
Also used : Storage(com.artipie.asto.Storage) Test(org.junit.jupiter.api.Test)

Example 18 with Storage

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));
}
Also used : Storage(com.artipie.asto.Storage) Test(org.junit.jupiter.api.Test)

Example 19 with Storage

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;
}
Also used : StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) S3Storage(com.artipie.asto.s3.S3Storage) FileStorage(com.artipie.asto.fs.FileStorage) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) S3Storage(com.artipie.asto.s3.S3Storage)

Example 20 with 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;
}
Also used : CompletionStage(java.util.concurrent.CompletionStage) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) Pattern(java.util.regex.Pattern) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

Storage (com.artipie.asto.Storage)24 Key (com.artipie.asto.Key)17 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)15 Test (org.junit.jupiter.api.Test)15 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)10 RsHasStatus (com.artipie.http.hm.RsHasStatus)6 Content (com.artipie.asto.Content)4 PublisherAs (com.artipie.asto.ext.PublisherAs)4 FileStorage (com.artipie.asto.fs.FileStorage)4 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)3 TestResource (com.artipie.asto.test.TestResource)3 RsHasBody (com.artipie.http.hm.RsHasBody)3 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletionStage (java.util.concurrent.CompletionStage)3 StrictYamlMapping (com.amihaiemil.eoyaml.StrictYamlMapping)2 SubStorage (com.artipie.asto.SubStorage)2 EtcdStorage (com.artipie.asto.etcd.EtcdStorage)2 S3Storage (com.artipie.asto.s3.S3Storage)2 Slice (com.artipie.http.Slice)2