Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit cbed477

Browse files
olenagerasimovaolenagerasimova
andauthored
fix: verification base tests corrected and file storage fixed (#479)
* fix: verification base tests corrected and file storage fixed * disable redis on win * s3 storage test disable on win * fixed vertx file storage Co-authored-by: olenagerasimova <olena.gereasimova@gmail.com>
1 parent 60cba06 commit cbed477

File tree

8 files changed

+83
-100
lines changed

8 files changed

+83
-100
lines changed

asto-core/src/main/java/com/artipie/asto/fs/FileStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public CompletableFuture<Collection<Key>> list(final Key prefix) {
8888
if (Key.ROOT.equals(prefix)) {
8989
dirnamelen = path.toString().length() + 1;
9090
} else {
91-
dirnamelen = path.toString().length() - prefix.string().length() + 1;
91+
dirnamelen = path.toString().length() - prefix.string().length();
9292
}
9393
try {
9494
keys = Files.walk(path)

asto-core/src/main/java/com/artipie/asto/test/StorageWhiteboxVerification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import org.hamcrest.Matchers;
3131
import org.hamcrest.core.IsEqual;
3232
import org.hamcrest.core.IsInstanceOf;
33-
import org.junit.Test;
3433
import org.junit.jupiter.api.Assertions;
34+
import org.junit.jupiter.api.Test;
3535
import org.junit.jupiter.api.Timeout;
3636

3737
/**

asto-core/src/test/java/com/artipie/asto/FileStorageWhiteboxVerificationTest.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66

77
import com.artipie.asto.fs.FileStorage;
88
import com.artipie.asto.test.StorageWhiteboxVerification;
9-
import java.io.File;
10-
import java.nio.file.Files;
119
import java.nio.file.Path;
1210
import java.util.Optional;
13-
import java.util.stream.Stream;
14-
import org.junit.After;
15-
import org.junit.Before;
11+
import org.junit.jupiter.api.io.TempDir;
1612

1713
/**
1814
* File storage verification test.
@@ -26,21 +22,9 @@ public final class FileStorageWhiteboxVerificationTest extends StorageWhiteboxVe
2622
/**
2723
* Temp test dir.
2824
*/
25+
@TempDir
2926
private Path temp;
3027

31-
@Before
32-
public void setUp() throws Exception {
33-
this.temp = Files.createTempDirectory("junit");
34-
}
35-
36-
@After
37-
public void tearDown() throws Exception {
38-
try (Stream<Path> walk = Files.walk(this.temp)) {
39-
walk.map(Path::toFile)
40-
.forEach(File::delete);
41-
}
42-
}
43-
4428
@Override
4529
protected Storage newStorage() {
4630
return new FileStorage(this.temp.resolve("base"));

asto-etcd/src/test/java/com/artipie/asto/etcd/EtcdStorageVerificationTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import io.etcd.jetcd.Client;
1010
import io.etcd.jetcd.test.EtcdClusterExtension;
1111
import java.util.Optional;
12-
import org.junit.AfterClass;
13-
import org.junit.BeforeClass;
12+
import org.junit.jupiter.api.AfterAll;
13+
import org.junit.jupiter.api.BeforeAll;
1414
import org.junit.jupiter.api.condition.DisabledOnOs;
1515
import org.junit.jupiter.api.condition.OS;
1616

@@ -28,23 +28,6 @@ public final class EtcdStorageVerificationTest extends StorageWhiteboxVerificati
2828
*/
2929
private static EtcdClusterExtension etcd;
3030

31-
@BeforeClass
32-
public static void beforeClass() throws Exception {
33-
EtcdStorageVerificationTest.etcd = new EtcdClusterExtension(
34-
"test-etcd",
35-
1,
36-
false,
37-
"--data-dir",
38-
"/data.etcd0"
39-
);
40-
EtcdStorageVerificationTest.etcd.beforeAll(null);
41-
}
42-
43-
@AfterClass
44-
public static void afterClass() throws Exception {
45-
EtcdStorageVerificationTest.etcd.afterAll(null);
46-
}
47-
4831
@Override
4932
protected Storage newStorage() throws Exception {
5033
return new EtcdStorage(
@@ -58,4 +41,21 @@ protected Storage newStorage() throws Exception {
5841
protected Optional<Storage> newBaseForRootSubStorage() {
5942
return Optional.empty();
6043
}
44+
45+
@BeforeAll
46+
static void beforeClass() throws Exception {
47+
EtcdStorageVerificationTest.etcd = new EtcdClusterExtension(
48+
"test-etcd",
49+
1,
50+
false,
51+
"--data-dir",
52+
"/data.etcd0"
53+
);
54+
EtcdStorageVerificationTest.etcd.beforeAll(null);
55+
}
56+
57+
@AfterAll
58+
static void afterClass() throws Exception {
59+
EtcdStorageVerificationTest.etcd.afterAll(null);
60+
}
6161
}

asto-redis/src/test/java/com/artipie/asto/redis/RedisStorageWhiteboxVerificationTest.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import com.artipie.asto.Storage;
1010
import com.artipie.asto.factory.Storages;
1111
import com.artipie.asto.test.StorageWhiteboxVerification;
12-
import org.junit.After;
13-
import org.junit.Before;
12+
import org.junit.jupiter.api.AfterAll;
13+
import org.junit.jupiter.api.BeforeAll;
14+
import org.junit.jupiter.api.condition.DisabledOnOs;
15+
import org.junit.jupiter.api.condition.OS;
1416
import org.testcontainers.containers.GenericContainer;
1517

1618
/**
@@ -20,6 +22,7 @@
2022
* @since 0.1
2123
*/
2224
@SuppressWarnings({"PMD.TestClassWithoutTestCases", "PMD.AvoidDuplicateLiterals"})
25+
@DisabledOnOs(OS.WINDOWS)
2326
public final class RedisStorageWhiteboxVerificationTest extends StorageWhiteboxVerification {
2427

2528
/**
@@ -30,30 +33,31 @@ public final class RedisStorageWhiteboxVerificationTest extends StorageWhiteboxV
3033
/**
3134
* Redis test container.
3235
*/
33-
private GenericContainer<?> redis;
36+
private static GenericContainer<?> redis;
3437

3538
/**
3639
* Redis storage.
3740
*/
38-
private Storage storage;
41+
private static Storage storage;
3942

40-
@Before
41-
public void setUp() {
42-
this.redis = new GenericContainer<>("redis:3-alpine")
43-
.withExposedPorts(RedisStorageWhiteboxVerificationTest.DEF_PORT);
44-
this.redis.start();
45-
this.storage = new Storages()
46-
.newStorage("redis", config(this.redis.getFirstMappedPort()));
43+
@Override
44+
protected Storage newStorage() {
45+
return RedisStorageWhiteboxVerificationTest.storage;
4746
}
4847

49-
@After
50-
public void tearDown() {
51-
this.redis.stop();
48+
@BeforeAll
49+
static void setUp() {
50+
RedisStorageWhiteboxVerificationTest.redis = new GenericContainer<>("redis:3-alpine")
51+
.withExposedPorts(RedisStorageWhiteboxVerificationTest.DEF_PORT);
52+
RedisStorageWhiteboxVerificationTest.redis.start();
53+
RedisStorageWhiteboxVerificationTest.storage = new Storages().newStorage(
54+
"redis", config(RedisStorageWhiteboxVerificationTest.redis.getFirstMappedPort())
55+
);
5256
}
5357

54-
@Override
55-
protected Storage newStorage() {
56-
return this.storage;
58+
@AfterAll
59+
static void tearDown() {
60+
RedisStorageWhiteboxVerificationTest.redis.stop();
5761
}
5862

5963
private static YamlMapping config(final Integer port) {

asto-s3/src/test/java/com/artipie/asto/S3StorageWhiteboxVerificationTest.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import com.artipie.asto.test.StorageWhiteboxVerification;
1010
import java.net.URI;
1111
import java.util.UUID;
12-
import org.junit.After;
13-
import org.junit.Before;
12+
import org.junit.jupiter.api.AfterAll;
13+
import org.junit.jupiter.api.BeforeAll;
14+
import org.junit.jupiter.api.condition.DisabledOnOs;
15+
import org.junit.jupiter.api.condition.OS;
1416
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
1517
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
1618
import software.amazon.awssdk.regions.Region;
@@ -24,24 +26,14 @@
2426
* @since 0.1
2527
*/
2628
@SuppressWarnings("PMD.TestClassWithoutTestCases")
29+
@DisabledOnOs(OS.WINDOWS)
2730
public final class S3StorageWhiteboxVerificationTest extends StorageWhiteboxVerification {
2831

2932
/**
3033
* S3 mock server extension.
3134
*/
32-
private final S3MockExtension mock = S3MockExtension.builder()
33-
.withSecureConnection(false)
34-
.build();
35-
36-
@Before
37-
public void setUp() throws Exception {
38-
this.mock.beforeAll(null);
39-
}
40-
41-
@After
42-
public void tearDown() {
43-
this.mock.afterAll(null);
44-
}
35+
private static final S3MockExtension MOCK = S3MockExtension.builder()
36+
.withSecureConnection(false).build();
4537

4638
@Override
4739
protected Storage newStorage() {
@@ -53,11 +45,22 @@ protected Storage newStorage() {
5345
)
5446
)
5547
.endpointOverride(
56-
URI.create(String.format("http://localhost:%d", this.mock.getHttpPort()))
48+
URI.create(String.format("http://localhost:%d", MOCK.getHttpPort()))
5749
)
5850
.build();
5951
final String bucket = UUID.randomUUID().toString();
6052
client.createBucket(CreateBucketRequest.builder().bucket(bucket).build()).join();
6153
return new S3Storage(client, bucket);
6254
}
55+
56+
@BeforeAll
57+
static void setUp() throws Exception {
58+
S3StorageWhiteboxVerificationTest.MOCK.beforeAll(null);
59+
}
60+
61+
@AfterAll
62+
static void tearDown() {
63+
S3StorageWhiteboxVerificationTest.MOCK.afterAll(null);
64+
}
65+
6366
}

asto-vertx-file/src/main/java/com/artipie/asto/fs/VertxFileStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public CompletableFuture<Collection<Key>> list(final Key prefix) {
8888
if (Key.ROOT.equals(prefix)) {
8989
dirnamelen = path.toString().length() + 1;
9090
} else {
91-
dirnamelen = path.toString().length() - prefix.string().length() + 1;
91+
dirnamelen = path.toString().length() - prefix.string().length();
9292
}
9393
try {
9494
keys = Files.walk(path)

asto-vertx-file/src/test/java/com/artipie/asto/VertxFileStorageVerificationTest.java

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
import com.artipie.asto.fs.VertxFileStorage;
88
import com.artipie.asto.test.StorageWhiteboxVerification;
99
import io.vertx.reactivex.core.Vertx;
10-
import java.io.File;
11-
import java.nio.file.Files;
1210
import java.nio.file.Path;
1311
import java.util.Optional;
14-
import java.util.stream.Stream;
15-
import org.junit.After;
16-
import org.junit.Before;
12+
import org.junit.jupiter.api.AfterAll;
13+
import org.junit.jupiter.api.io.TempDir;
1714

1815
/**
1916
* Vertx file storage verification test.
@@ -25,50 +22,45 @@
2522
public final class VertxFileStorageVerificationTest extends StorageWhiteboxVerification {
2623

2724
/**
28-
* Temp dir.
25+
* Vert.x file System.
2926
*/
30-
private Path temp;
27+
private static final Vertx VERTX = Vertx.vertx();
3128

3229
/**
33-
* Vert.x file System.
30+
* Temp dir.
3431
*/
35-
private Vertx vertx;
36-
37-
@Before
38-
public void setUp() throws Exception {
39-
this.vertx = Vertx.vertx();
40-
this.temp = Files.createTempDirectory("vtx_junit");
41-
}
42-
43-
@After
44-
public void tearDown() throws Exception {
45-
this.vertx.close();
46-
try (Stream<Path> walk = Files.walk(this.temp)) {
47-
walk.map(Path::toFile)
48-
.forEach(File::delete);
49-
}
50-
}
32+
@TempDir
33+
private Path temp;
5134

5235
@Override
5336
protected Storage newStorage() throws Exception {
5437
return new VertxFileStorage(
5538
this.temp.resolve("base"),
56-
this.vertx
39+
VertxFileStorageVerificationTest.VERTX
5740
);
5841
}
5942

6043
@Override
6144
protected Optional<Storage> newBaseForRootSubStorage() {
6245
return Optional.of(
63-
new VertxFileStorage(this.temp.resolve("root-sub-storage"), this.vertx)
46+
new VertxFileStorage(
47+
this.temp.resolve("root-sub-storage"), VertxFileStorageVerificationTest.VERTX
48+
)
6449
);
6550
}
6651

6752
@Override
6853
protected Optional<Storage> newBaseForSubStorage() {
6954
return Optional.of(
70-
new VertxFileStorage(this.temp.resolve("sub-storage"), this.vertx)
55+
new VertxFileStorage(
56+
this.temp.resolve("sub-storage"), VertxFileStorageVerificationTest.VERTX
57+
)
7158
);
7259
}
7360

61+
@AfterAll
62+
static void tearDown() throws Exception {
63+
VertxFileStorageVerificationTest.VERTX.close();
64+
}
65+
7466
}

0 commit comments

Comments
 (0)