Skip to content

Commit

Permalink
Aliyun: Remove AssertHelpers (apache#7116)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiaocs7 authored Mar 20, 2023
1 parent 49fb12e commit e82ecf6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.aliyun.AliyunProperties;
import org.apache.iceberg.exceptions.ValidationException;
import org.apache.iceberg.io.InputFile;
import org.apache.iceberg.io.SeekableInputStream;
import org.apache.iceberg.metrics.MetricsContext;
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -61,13 +61,12 @@ public void testReadFile() throws Exception {
@Test
public void testOSSInputFile() {
OSSURI uri = randomURI();
AssertHelpers.assertThrows(
"File length should not be negative",
ValidationException.class,
"Invalid file length",
() ->
new OSSInputFile(
ossClient().get(), uri, aliyunProperties, -1, MetricsContext.nullMetrics()));
Assertions.assertThatThrownBy(
() ->
new OSSInputFile(
ossClient().get(), uri, aliyunProperties, -1, MetricsContext.nullMetrics()))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("Invalid file length");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.iceberg.aliyun.oss;

import static org.apache.iceberg.AssertHelpers.assertThrows;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

Expand All @@ -29,6 +28,7 @@
import java.util.concurrent.ThreadLocalRandom;
import org.apache.iceberg.io.SeekableInputStream;
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
import org.assertj.core.api.Assertions;
import org.junit.Test;

public class TestOSSInputStream extends AliyunOSSTestBase {
Expand Down Expand Up @@ -99,14 +99,9 @@ public void testClose() throws Exception {
OSSURI uri = new OSSURI(location("closed.dat"));
SeekableInputStream closed = new OSSInputStream(ossClient().get(), uri);
closed.close();
assertThrows(
"Cannot seek the input stream after closed.",
IllegalStateException.class,
"Cannot seek: already closed",
() -> {
closed.seek(0);
return null;
});
Assertions.assertThatThrownBy(() -> closed.seek(0))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Cannot seek: already closed");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.aliyun.AliyunProperties;
import org.apache.iceberg.exceptions.AlreadyExistsException;
import org.apache.iceberg.io.InputFile;
import org.apache.iceberg.io.OutputFile;
import org.apache.iceberg.metrics.MetricsContext;
import org.apache.iceberg.relocated.com.google.common.io.ByteStreams;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -63,11 +63,10 @@ public void testWriteFile() throws IOException {

@Test
public void testFromLocation() {
AssertHelpers.assertThrows(
"Should catch null location when creating oss output file",
NullPointerException.class,
"location cannot be null",
() -> OSSOutputFile.fromLocation(ossClient, null, aliyunProperties));
Assertions.assertThatThrownBy(
() -> OSSOutputFile.fromLocation(ossClient, null, aliyunProperties))
.isInstanceOf(NullPointerException.class)
.hasMessageContaining("location cannot be null");
}

@Test
Expand All @@ -79,11 +78,10 @@ public void testCreate() {
writeOSSData(uri, data);

OutputFile out = OSSOutputFile.fromLocation(ossClient, uri.location(), aliyunProperties);
AssertHelpers.assertThrows(
"Should complain about location already exists",
AlreadyExistsException.class,
"Location already exists",
out::create);

Assertions.assertThatThrownBy(out::create)
.isInstanceOf(AlreadyExistsException.class)
.hasMessageContaining("Location already exists");
}

@Test
Expand Down
48 changes: 22 additions & 26 deletions aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import static com.aliyun.oss.internal.OSSUtils.OSS_RESOURCE_MANAGER;

import org.apache.iceberg.AssertHelpers;
import org.apache.iceberg.exceptions.ValidationException;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -49,47 +49,43 @@ public void testEncodedString() {

@Test
public void invalidBucket() {
AssertHelpers.assertThrows(
"Invalid bucket",
IllegalArgumentException.class,
OSS_RESOURCE_MANAGER.getFormattedString("BucketNameInvalid", "test_bucket"),
() -> new OSSURI("https://test_bucket/path/to/file"));

Assertions.assertThatThrownBy(() -> new OSSURI("https://test_bucket/path/to/file"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
OSS_RESOURCE_MANAGER.getFormattedString("BucketNameInvalid", "test_bucket"));
}

@Test
public void missingKey() {
AssertHelpers.assertThrows(
"Missing key",
ValidationException.class,
"Missing key in OSS location",
() -> new OSSURI("https://bucket/"));

Assertions.assertThatThrownBy(() -> new OSSURI("https://bucket/"))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("Missing key in OSS location");
}

@Test
public void invalidKey() {
AssertHelpers.assertThrows(
"Invalid key",
IllegalArgumentException.class,
OSS_RESOURCE_MANAGER.getFormattedString("ObjectKeyInvalid", "\\path/to/file"),
() -> new OSSURI("https://bucket/\\path/to/file"));
Assertions.assertThatThrownBy(() -> new OSSURI("https://bucket/\\path/to/file"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
OSS_RESOURCE_MANAGER.getFormattedString("ObjectKeyInvalid", "\\path/to/file"));
}

@Test
public void relativePathing() {
AssertHelpers.assertThrows(
"Cannot use relative oss location.",
ValidationException.class,
"Invalid OSS location",
() -> new OSSURI("/path/to/file"));

Assertions.assertThatThrownBy(() -> new OSSURI("/path/to/file"))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("Invalid OSS location");
}

@Test
public void invalidScheme() {
AssertHelpers.assertThrows(
"Only support scheme: oss/https",
ValidationException.class,
"Invalid scheme",
() -> new OSSURI("invalid://bucket/"));

Assertions.assertThatThrownBy(() -> new OSSURI("invalid://bucket/"))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("Invalid scheme");
}

@Test
Expand Down

0 comments on commit e82ecf6

Please sign in to comment.