Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Assertions;

import static org.apache.hadoop.hdds.StringUtils.string2Bytes;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

/**
* Test OzoneFSInputStream by reading through multiple interfaces.
Expand Down Expand Up @@ -147,11 +148,11 @@ public void testO3FSSingleByteRead() throws IOException {
break;
}
value[i] = (byte) val;
Assertions.assertEquals(value[i], data[i], "value mismatch at:" + i);
assertEquals(value[i], data[i], "value mismatch at:" + i);
i++;
}
Assertions.assertEquals(i, data.length);
Assertions.assertArrayEquals(value, data);
assertEquals(i, data.length);
assertArrayEquals(value, data);
}
}

Expand All @@ -169,8 +170,8 @@ public void testO3FSMultiByteRead() throws IOException {
System.arraycopy(tmp, 0, value, i * tmp.length, tmp.length);
i++;
}
Assertions.assertEquals((long) i * tmp.length, data.length);
Assertions.assertArrayEquals(value, data);
assertEquals((long) i * tmp.length, data.length);
assertArrayEquals(value, data);
}
}

Expand All @@ -181,12 +182,12 @@ public void testO3FSByteBufferRead() throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
int byteRead = inputStream.read(buffer);

Assertions.assertEquals(byteRead, 1024 * 1024);
assertEquals(byteRead, 1024 * 1024);

byte[] value = new byte[1024 * 1024];
System.arraycopy(data, 0, value, 0, value.length);

Assertions.assertArrayEquals(value, buffer.array());
assertArrayEquals(value, buffer.array());
}
}

Expand All @@ -208,7 +209,7 @@ public void testSequenceFileReaderSync() throws IOException {
in.sync(0);
blockStart = in.getPosition();
// The behavior should be consistent with HDFS
Assertions.assertEquals(srcfile.length(), blockStart);
assertEquals(srcfile.length(), blockStart);
in.close();
}

Expand All @@ -230,7 +231,7 @@ public void testSequenceFileReaderSyncEC() throws IOException {
in.sync(0);
blockStart = in.getPosition();
// The behavior should be consistent with HDFS
Assertions.assertEquals(srcfile.length(), blockStart);
assertEquals(srcfile.length(), blockStart);
in.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Assertions;

import java.io.IOException;
import java.net.URI;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Test Ozone Prefix Parser.
*/
Expand Down Expand Up @@ -115,18 +116,12 @@ public void testPrefixParsePath() throws Exception {
private void assertPrefixStats(PrefixParser parser, int volumeCount,
int bucketCount, int intermediateDirCount, int nonExistentDirCount,
int fileCount, int dirCount) {
Assertions.assertEquals(volumeCount,
parser.getParserStats(PrefixParser.Types.VOLUME));
Assertions.assertEquals(bucketCount,
parser.getParserStats(PrefixParser.Types.BUCKET));
Assertions.assertEquals(intermediateDirCount,
parser.getParserStats(PrefixParser.Types.INTERMEDIATE_DIRECTORY));
Assertions.assertEquals(nonExistentDirCount,
parser.getParserStats(PrefixParser.Types.NON_EXISTENT_DIRECTORY));
Assertions.assertEquals(fileCount,
parser.getParserStats(PrefixParser.Types.FILE));
Assertions.assertEquals(dirCount,
parser.getParserStats(PrefixParser.Types.DIRECTORY));
assertEquals(volumeCount, parser.getParserStats(PrefixParser.Types.VOLUME));
assertEquals(bucketCount, parser.getParserStats(PrefixParser.Types.BUCKET));
assertEquals(intermediateDirCount, parser.getParserStats(PrefixParser.Types.INTERMEDIATE_DIRECTORY));
assertEquals(nonExistentDirCount, parser.getParserStats(PrefixParser.Types.NON_EXISTENT_DIRECTORY));
assertEquals(fileCount, parser.getParserStats(PrefixParser.Types.FILE));
assertEquals(dirCount, parser.getParserStats(PrefixParser.Types.DIRECTORY));
}

private void testPrefixParseWithInvalidPaths() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.hadoop.ozone.client.io.SelectorOutputStream;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand All @@ -55,6 +54,9 @@
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

/**
* Ozone file system tests with Streaming.
Expand Down Expand Up @@ -152,7 +154,7 @@ static void createFile(FileSystem fs, Path path, boolean overwrite,

final OutputStream wrapped = out.getWrappedStream();
LOG.info("wrapped: {}", wrapped.getClass());
Assertions.assertEquals(SelectorOutputStream.class, wrapped.getClass());
assertEquals(SelectorOutputStream.class, wrapped.getClass());
final SelectorOutputStream<?> selector = (SelectorOutputStream<?>) wrapped;
final boolean belowThreshold = data.length <= AUTO_THRESHOLD;
LOG.info("data.length={}, threshold={}, belowThreshold? {}",
Expand All @@ -161,13 +163,12 @@ static void createFile(FileSystem fs, Path path, boolean overwrite,

out.close();
final OutputStream underlying = selector.getUnderlying();
Assertions.assertNotNull(underlying);
assertNotNull(underlying);
LOG.info("underlying after close: {}", underlying.getClass());
if (belowThreshold) {
Assertions.assertTrue(underlying instanceof OzoneFSOutputStream);
assertInstanceOf(OzoneFSOutputStream.class, underlying);
} else {
Assertions.assertEquals(OzoneFSDataStreamOutput.class,
underlying.getClass());
assertEquals(OzoneFSDataStreamOutput.class, underlying.getClass());
}
}

Expand All @@ -177,10 +178,10 @@ static void assertUnderlying(SelectorOutputStream<?> selector,
LOG.info("underlying before close: {}", underlying != null ?
underlying.getClass() : null);
if (belowThreshold) {
Assertions.assertNull(underlying);
assertNull(underlying);
} else {
Assertions.assertNotNull(underlying);
Assertions.assertEquals(OzoneFSDataStreamOutput.class,
assertNotNull(underlying);
assertEquals(OzoneFSDataStreamOutput.class,
underlying.getClass());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.util.UUID;
import java.util.stream.Stream;

import com.google.common.base.Strings;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand All @@ -39,7 +37,6 @@
import org.apache.hadoop.util.ToolRunner;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand All @@ -56,6 +53,8 @@
import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_INDICATOR;
import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPath;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Test client-side CRUD snapshot operations with Ozone Manager.
Expand Down Expand Up @@ -120,13 +119,13 @@ private static void createVolBuckKey()
// Create volume and bucket
int res = ToolRunner.run(shell,
new String[]{"-mkdir", "-p", BUCKET_PATH});
Assertions.assertEquals(0, res);
assertEquals(0, res);
// Create key
res = ToolRunner.run(shell, new String[]{"-touch", KEY_PATH});
Assertions.assertEquals(0, res);
assertEquals(0, res);
// List the bucket to make sure that bucket exists.
res = ToolRunner.run(shell, new String[]{"-ls", BUCKET_PATH});
Assertions.assertEquals(0, res);
assertEquals(0, res);

}

Expand All @@ -137,12 +136,12 @@ void testCreateSnapshotDuplicateName() throws Exception {
int res = ToolRunner.run(shell,
new String[]{"-createSnapshot", BUCKET_PATH, snapshotName});
// Asserts that create request succeeded
Assertions.assertEquals(0, res);
assertEquals(0, res);

res = ToolRunner.run(shell,
new String[]{"-createSnapshot", BUCKET_PATH, snapshotName});
// Asserts that create request fails since snapshot name provided twice
Assertions.assertEquals(1, res);
assertEquals(1, res);
}

@Test
Expand All @@ -162,19 +161,19 @@ void testCreateSnapshotWithSubDirInput() throws Exception {

int res = ToolRunner.run(shell, new String[] {
"-mkdir", "-p", dirPath});
Assertions.assertEquals(0, res);
assertEquals(0, res);

try (GenericTestUtils.SystemOutCapturer capture =
new GenericTestUtils.SystemOutCapturer()) {
res = ToolRunner.run(shell, new String[] {
"-createSnapshot", dirPath, snapshotName});
// Asserts that create request succeeded
Assertions.assertEquals(0, res);
assertEquals(0, res);

String expectedSnapshotPath = Paths.get(
BUCKET_PATH, OM_SNAPSHOT_INDICATOR, snapshotName).toString();
String out = capture.getOutput().trim();
Assertions.assertTrue(out.endsWith(expectedSnapshotPath));
assertThat(out).endsWith(expectedSnapshotPath);
}
}

Expand All @@ -192,7 +191,7 @@ void testCreateSnapshotSuccess(String snapshotName)
int res = ToolRunner.run(shell,
new String[]{"-createSnapshot", BUCKET_PATH, snapshotName});
// Asserts that create request succeeded
Assertions.assertEquals(0, res);
assertEquals(0, res);

SnapshotInfo snapshotInfo = ozoneManager
.getMetadataManager()
Expand All @@ -202,7 +201,7 @@ void testCreateSnapshotSuccess(String snapshotName)
// Assert that snapshot exists in RocksDB.
// We can't use list or valid if snapshot directory exists because DB
// transaction might not be flushed by the time.
Assertions.assertNotNull(snapshotInfo);
assertNotNull(snapshotInfo);
}

private static Stream<Arguments> createSnapshotFailureScenarios() {
Expand Down Expand Up @@ -252,8 +251,7 @@ void testCreateSnapshotFailure(String description,
String errorMessage = execShellCommandAndGetOutput(expectedResponse,
new String[]{"-createSnapshot", paramBucketPath, snapshotName});

Assertions.assertTrue(errorMessage
.contains(expectedMessage));
assertThat(errorMessage).contains(expectedMessage);
}

/**
Expand Down Expand Up @@ -291,7 +289,7 @@ void testFsLsSnapshot(@TempDir Path tempDir) throws Exception {
int res = ToolRunner.run(shell,
new String[]{"-deleteSnapshot", BUCKET_PATH, snapshotName1});
// Asserts that delete request succeeded
Assertions.assertEquals(0, res);
assertEquals(0, res);

// Wait for the snapshot to be marked deleted.
GenericTestUtils.waitFor(() -> {
Expand Down Expand Up @@ -339,24 +337,22 @@ void testDeleteBucketWithSnapshot() throws Exception {
String deleteKeyOut = execShellCommandAndGetOutput(0,
new String[]{"-rm", "-r", "-skipTrash", KEY_PATH});

Assertions.assertTrue(deleteKeyOut
.contains("Deleted " + BUCKET_PATH));
assertThat(deleteKeyOut).contains("Deleted " + BUCKET_PATH);

// Delete bucket should fail due to existing snapshot
String deleteBucketOut = execShellCommandAndGetOutput(1,
new String[]{"-rm", "-r", "-skipTrash", BUCKET_PATH});
Assertions.assertTrue(deleteBucketOut
.contains(BUCKET + " can't be deleted when it has snapshots"));
assertThat(deleteBucketOut).contains(BUCKET + " can't be deleted when it has snapshots");

// Key shouldn't exist under bucket
String listKeyOut = execShellCommandAndGetOutput(0,
new String[]{"-ls", BUCKET_PATH});
Assertions.assertTrue(Strings.isNullOrEmpty(listKeyOut));
assertThat(listKeyOut).isNullOrEmpty();

// Key should still exist under snapshot
String listSnapKeyOut = execShellCommandAndGetOutput(0,
new String[]{"-ls", snapshotPath});
Assertions.assertTrue(listSnapKeyOut.contains(snapshotKeyPath));
assertThat(listSnapKeyOut).contains(snapshotKeyPath);
}

@Test
Expand All @@ -366,7 +362,7 @@ void testSnapshotDeleteSuccess() throws Exception {
int res = ToolRunner.run(shell,
new String[]{"-deleteSnapshot", BUCKET_PATH, snapshotName});
// Asserts that delete request succeeded
Assertions.assertEquals(0, res);
assertEquals(0, res);

// Wait for the snapshot to be marked deleted.
GenericTestUtils.waitFor(() -> {
Expand Down Expand Up @@ -417,8 +413,7 @@ void testSnapshotDeleteFailure(String description,
String errorMessage = execShellCommandAndGetOutput(expectedResponse,
new String[]{"-deleteSnapshot", paramBucketPath, snapshotName});

Assertions.assertTrue(errorMessage
.contains(expectedMessage), errorMessage);
assertThat(errorMessage).contains(expectedMessage);
}

/**
Expand All @@ -438,7 +433,7 @@ private String execShellCommandAndGetOutput(

// Execute command
int res = ToolRunner.run(shell, args);
Assertions.assertEquals(response, res);
assertEquals(response, res);

// Store command output to a string,
// if command should succeed then
Expand Down Expand Up @@ -467,7 +462,7 @@ private String createSnapshot() throws Exception {
int res = ToolRunner.run(shell,
new String[]{"-createSnapshot", BUCKET_PATH, snapshotName});
// Asserts that create request succeeded
Assertions.assertEquals(0, res);
assertEquals(0, res);

OzoneConfiguration conf = ozoneManager.getConfiguration();

Expand Down
Loading