Skip to content

Commit e405010

Browse files
authored
Stop the container in the shutdown method (#1525)
* How flaky is this test? * stop the server
1 parent a60ebd1 commit e405010

File tree

1 file changed

+26
-46
lines changed

1 file changed

+26
-46
lines changed

maven-resolver-transport-minio/src/test/java/org/eclipse/aether/transport/minio/MinioTransporterIT.java

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.eclipse.aether.util.FileUtils;
4040
import org.eclipse.aether.util.repository.AuthenticationBuilder;
4141
import org.junit.jupiter.api.AfterEach;
42-
import org.junit.jupiter.api.Assertions;
4342
import org.junit.jupiter.api.BeforeEach;
4443
import org.junit.jupiter.api.Test;
4544
import org.testcontainers.containers.MinIOContainer;
@@ -62,7 +61,6 @@ class MinioTransporterIT {
6261
private MinIOContainer minioContainer;
6362
private MinioClient minioClient;
6463
private RepositorySystemSession session;
65-
private RemoteRepository repository;
6664
private ObjectNameMapperFactory objectNameMapperFactory;
6765

6866
@BeforeEach
@@ -87,13 +85,12 @@ void startSuite() throws Exception {
8785
}
8886

8987
session = new DefaultRepositorySystemSession(h -> true);
90-
repository = newRepo(RepositoryAuth.WITH);
9188
objectNameMapperFactory = new RepositoryIdObjectNameMapperFactory();
9289
}
9390

9491
@AfterEach
95-
public void stopSuite() {
96-
minioContainer.start();
92+
void stopSuite() {
93+
minioContainer.stop();
9794
}
9895

9996
enum RepositoryAuth {
@@ -120,19 +117,17 @@ protected RemoteRepository newRepo(RepositoryAuth auth) {
120117
}
121118

122119
@Test
123-
void peekWithoutAuth() {
120+
void peekWithoutAuth() throws NoTransporterException {
124121
try {
125122
new MinioTransporter(session, newRepo(RepositoryAuth.WITHOUT), objectNameMapperFactory);
126123
fail("Should throw");
127-
} catch (NoTransporterException e) {
128-
fail("Should not throw this");
129124
} catch (IllegalStateException e) {
130125
assertTrue(e.getMessage().contains("No accessKey and/or secretKey provided"));
131126
}
132127
}
133128

134129
@Test
135-
void peekWithWrongAuth() throws Exception {
130+
void peekWithWrongAuth() throws NoTransporterException {
136131
try (MinioTransporter transporter =
137132
new MinioTransporter(session, newRepo(RepositoryAuth.WRONG), objectNameMapperFactory)) {
138133
try {
@@ -146,7 +141,7 @@ void peekWithWrongAuth() throws Exception {
146141
}
147142

148143
@Test
149-
void peekNonexistent() throws Exception {
144+
void peekNonexistent() throws NoTransporterException {
150145
try (MinioTransporter transporter =
151146
new MinioTransporter(session, newRepo(RepositoryAuth.WITH), objectNameMapperFactory)) {
152147
try {
@@ -163,16 +158,13 @@ void peekNonexistent() throws Exception {
163158
void peekExistent() throws Exception {
164159
try (MinioTransporter transporter =
165160
new MinioTransporter(session, newRepo(RepositoryAuth.WITH), objectNameMapperFactory)) {
166-
try {
167-
transporter.peek(new PeekTask(URI.create(OBJECT_NAME)));
168-
} catch (Exception e) {
169-
Assertions.fail("Should not throw");
170-
}
161+
transporter.peek(new PeekTask(URI.create(OBJECT_NAME)));
162+
// Should not throw
171163
}
172164
}
173165

174166
@Test
175-
void getNonexistent() throws Exception {
167+
void getNonexistent() throws NoTransporterException {
176168
try (MinioTransporter transporter =
177169
new MinioTransporter(session, newRepo(RepositoryAuth.WITH), objectNameMapperFactory)) {
178170
try {
@@ -189,50 +181,38 @@ void getNonexistent() throws Exception {
189181
void getExistent() throws Exception {
190182
try (MinioTransporter transporter =
191183
new MinioTransporter(session, newRepo(RepositoryAuth.WITH), objectNameMapperFactory)) {
192-
try {
193-
GetTask task = new GetTask(URI.create(OBJECT_NAME));
194-
transporter.get(task);
195-
assertEquals(OBJECT_CONTENT, new String(task.getDataBytes(), StandardCharsets.UTF_8));
196-
} catch (Exception e) {
197-
Assertions.fail("Should not throw");
198-
}
184+
GetTask task = new GetTask(URI.create(OBJECT_NAME));
185+
transporter.get(task);
186+
assertEquals(OBJECT_CONTENT, new String(task.getDataBytes(), StandardCharsets.UTF_8));
199187
}
200188
}
201189

202190
@Test
203191
void putNonexistent() throws Exception {
204192
try (MinioTransporter transporter =
205193
new MinioTransporter(session, newRepo(RepositoryAuth.WITH), objectNameMapperFactory)) {
206-
try {
207-
URI uri = URI.create("test");
208-
transporter.put(new PutTask(uri).setDataBytes(OBJECT_CONTENT.getBytes(StandardCharsets.UTF_8)));
209-
GetTask task = new GetTask(uri);
210-
transporter.get(task);
211-
assertEquals(OBJECT_CONTENT, new String(task.getDataBytes(), StandardCharsets.UTF_8));
212-
} catch (Exception e) {
213-
Assertions.fail("Should not throw");
214-
}
194+
URI uri = URI.create("test");
195+
transporter.put(new PutTask(uri).setDataBytes(OBJECT_CONTENT.getBytes(StandardCharsets.UTF_8)));
196+
GetTask task = new GetTask(uri);
197+
transporter.get(task);
198+
assertEquals(OBJECT_CONTENT, new String(task.getDataBytes(), StandardCharsets.UTF_8));
215199
}
216200
}
217201

218202
@Test
219203
void putExistent() throws Exception {
220204
try (MinioTransporter transporter =
221205
new MinioTransporter(session, newRepo(RepositoryAuth.WITH), objectNameMapperFactory)) {
222-
try {
223-
URI uri = URI.create(OBJECT_NAME);
224-
GetTask task = new GetTask(uri);
225-
transporter.get(task);
226-
assertEquals(OBJECT_CONTENT, new String(task.getDataBytes(), StandardCharsets.UTF_8));
227-
228-
String altContent = "altContent";
229-
transporter.put(new PutTask(uri).setDataBytes(altContent.getBytes(StandardCharsets.UTF_8)));
230-
task = new GetTask(uri);
231-
transporter.get(task);
232-
assertEquals(altContent, new String(task.getDataBytes(), StandardCharsets.UTF_8));
233-
} catch (Exception e) {
234-
Assertions.fail("Should not throw");
235-
}
206+
URI uri = URI.create(OBJECT_NAME);
207+
GetTask task = new GetTask(uri);
208+
transporter.get(task);
209+
assertEquals(OBJECT_CONTENT, new String(task.getDataBytes(), StandardCharsets.UTF_8));
210+
211+
String altContent = "altContent";
212+
transporter.put(new PutTask(uri).setDataBytes(altContent.getBytes(StandardCharsets.UTF_8)));
213+
task = new GetTask(uri);
214+
transporter.get(task);
215+
assertEquals(altContent, new String(task.getDataBytes(), StandardCharsets.UTF_8));
236216
}
237217
}
238218
}

0 commit comments

Comments
 (0)