Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 48 additions & 10 deletions functional/TestMinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import io.minio.messages.AccessControlPolicy;
import io.minio.messages.CORSConfiguration;
import io.minio.messages.DeleteRequest;
import io.minio.messages.DeleteResult;
import io.minio.messages.ErrorResponse;
import io.minio.messages.EventType;
import io.minio.messages.Filter;
Expand Down Expand Up @@ -121,8 +122,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import okhttp3.Headers;
Expand All @@ -137,6 +140,12 @@
value = "REC",
justification = "Allow catching super class Exception since it's tests")
public class TestMinioClient extends TestArgs {
private static final int MAX_DELETE_ATTEMPTS = 5;
private static final Set<String> TRANSIENT_DELETE_CODES =
Collections.unmodifiableSet(
new HashSet<>(
Arrays.asList("InternalError", "RequestTimeout", "ServiceUnavailable", "SlowDown")));

private String bucketName = getRandomName();
private String bucketNameWithLock = getRandomName();
public boolean isQuickTest;
Expand Down Expand Up @@ -1030,15 +1039,46 @@ public List<ObjectWriteResponse> createObjects(String bucketName, int count, int
public void removeObjects(String bucketName, List<ObjectWriteResponse> results) throws Exception {
List<DeleteRequest.Object> objects =
results.stream()
.map(
result -> {
return new DeleteRequest.Object(result.object(), result.versionId());
})
.map(r -> new DeleteRequest.Object(r.object(), r.versionId()))
Comment thread
allanrogerr marked this conversation as resolved.
.collect(Collectors.toList());
for (Result<?> r :
client.removeObjects(
RemoveObjectsArgs.builder().bucket(bucketName).objects(objects).build())) {
ignore(r.get());
boolean anyTransient = false;
for (int attempt = 0; attempt < MAX_DELETE_ATTEMPTS; attempt++) {
if (attempt > 0) {
try {
Thread.sleep(500L << attempt); // 1s / 2s / 4s / 8s
} catch (InterruptedException ie) {
Comment thread
allanrogerr marked this conversation as resolved.
Thread.currentThread().interrupt();
throw ie;
}
}
anyTransient = false;
for (Result<DeleteResult.Error> r :
client.removeObjects(
RemoveObjectsArgs.builder().bucket(bucketName).objects(objects).build())) {
DeleteResult.Error err = r.get();
String code = err.code();
if (!TRANSIENT_DELETE_CODES.contains(code)) {
throw new Exception(
"non-transient delete error '"
+ code
+ "': "
+ err.message()
+ " on "
+ err.objectName()
+ " in bucket "
+ bucketName);
}
anyTransient = true;
}
if (!anyTransient) break;
}
if (anyTransient) {
throw new Exception(
results.size()
+ " object(s) not deleted after "
+ MAX_DELETE_ATTEMPTS
+ " attempts in bucket "
+ bucketName);
}
}

Expand Down Expand Up @@ -1191,8 +1231,6 @@ public void testRemoveObjects(String testTags, List<ObjectWriteResponse> results
mintSuccessLog(methodName, testTags, startTime);
} catch (Exception e) {
handleException(methodName, testTags, startTime, e);
} finally {
removeObjects(bucketName, results);
}
}

Expand Down
Loading