Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson-Wang-7 committed Aug 14, 2023
1 parent 8cdf8dd commit f579e0d
Show file tree
Hide file tree
Showing 40 changed files with 94 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
@ThreadSafe
public final class FileSystemTestUtils {
public static final WritePType DEFAULT_WRITE_TYPE = WritePType.CACHE_THROUGH;

/**
* Creates a simple file with {@code len} bytes.
*
Expand All @@ -45,6 +47,17 @@ public static void createByteFile(FileSystem fs, String fileName, int len,
createByteFile(fs, new AlluxioURI(fileName), options, len);
}

/**
* Creates a simple file with {@code len} bytes.
*
* @param fs a {@link FileSystem} handler
* @param fileName the name of the file to be created
* @param len file size
*/
public static void createByteFile(FileSystem fs, String fileName, int len) {
createByteFile(fs, new AlluxioURI(fileName), DEFAULT_WRITE_TYPE, len);
}

/**
* Creates a simple file with {@code len} bytes.
*
Expand All @@ -58,6 +71,17 @@ public static void createByteFile(FileSystem fs, String fileName,
createByteFile(fs, new AlluxioURI(fileName), writeType, len);
}

/**
* Creates a simple file with {@code len} bytes.
*
* @param fs a {@link FileSystem} handler
* @param fileURI URI of the file
* @param len file size
*/
public static void createByteFile(FileSystem fs, AlluxioURI fileURI, int len) {
createByteFile(fs, fileURI, DEFAULT_WRITE_TYPE, len);
}

/**
* Creates a simple file with {@code len} bytes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import alluxio.AuthenticatedUserRule;
import alluxio.Constants;
import alluxio.annotation.dora.DoraTestTodoItem;
import alluxio.client.WriteType;
import alluxio.conf.Configuration;
import alluxio.exception.AccessControlException;
import alluxio.exception.BlockInfoException;
Expand Down Expand Up @@ -70,7 +69,6 @@
import org.junit.runners.Parameterized;

import java.io.Closeable;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -90,18 +88,6 @@ public FileSystemMasterFsOptsTest(InodeStore.Factory factory) {
mInodeStoreFactory = factory;
}

@Test
public void createFileMustCacheThenCacheThrough() throws Exception {
File file = mTestFolder.newFile();
AlluxioURI path = new AlluxioURI("/test");
mFileSystemMaster.createFile(path,
CreateFileContext.defaults().setWriteType(WriteType.MUST_CACHE));

mThrown.expect(FileAlreadyExistsException.class);
mFileSystemMaster.createFile(path,
CreateFileContext.defaults().setWriteType(WriteType.MUST_CACHE));
}

@Test
public void createFileUsesOperationTime() throws Exception {
AlluxioURI path = new AlluxioURI("/test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ public void unmountNonMountPointWithException() throws Exception {
mFileSystemMaster.mount(alluxioURI, ufsURI, MountContext.defaults());
AlluxioURI dirURI = alluxioURI.join("dir");
mFileSystemMaster.createDirectory(dirURI, CreateDirectoryContext
.defaults().setWriteType(WriteType.MUST_CACHE));
.defaults().setWriteType(WriteType.CACHE_THROUGH));
mThrown.expect(InvalidPathException.class);
mFileSystemMaster.unmount(dirURI);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class JournalToolTest extends BaseIntegrationTest {
.setProperty(PropertyKey.MASTER_JOURNAL_TYPE, JournalType.UFS)
.setProperty(PropertyKey.MASTER_JOURNAL_CHECKPOINT_PERIOD_ENTRIES, CHECKPOINT_SIZE)
.setProperty(PropertyKey.MASTER_JOURNAL_LOG_SIZE_BYTES_MAX, "100")
.setProperty(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.MUST_CACHE).build();
.setProperty(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.CACHE_THROUGH).build();

private File mDumpDir;
private FileSystem mFs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import alluxio.grpc.LoadMetadataPType;
import alluxio.grpc.OpenFilePOptions;
import alluxio.grpc.ReadPType;
import alluxio.grpc.WritePType;
import alluxio.master.LocalAlluxioCluster;
import alluxio.master.LocalAlluxioJobCluster;
import alluxio.master.job.JobMaster;
Expand Down Expand Up @@ -142,8 +141,7 @@ public static void afterClass() throws Exception {
* @param bytes file size
*/
protected void copyToLocalWithBytes(int bytes) throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH,
bytes);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", bytes);
sFsShell.run("copyToLocal", "/testFile",
sLocalAlluxioCluster.getAlluxioHome() + "/testFile");
assertEquals(getCommandOutput(new String[] {"copyToLocal", "/testFile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void catNotExist() throws Exception {

@Test
public void cat() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
sFsShell.run("cat", "/testFile");
byte[] expect = BufferUtils.getIncreasingByteArray(10);
Assert.assertArrayEquals(expect, mOutput.toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import alluxio.client.cli.fs.AbstractFileSystemShellTest;
import alluxio.client.file.FileSystemTestUtils;
import alluxio.exception.ExceptionMessage;
import alluxio.grpc.WritePType;
import alluxio.util.io.BufferUtils;

import org.apache.commons.codec.digest.DigestUtils;
Expand All @@ -36,7 +35,7 @@ public final class ChecksumCommandIntegrationTest extends AbstractFileSystemShel
*/
@Test
public void checksum() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
sFsShell.run("checksum", "/testFile");
String str = mOutput.toString();
String[] splitString = str.split("\\s+");
Expand All @@ -55,10 +54,8 @@ public void checksum() throws Exception {
*/
@Test
public void checksumWildCard() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFileA",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir2/testFileB",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFileA", 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir2/testFileB", 10);
sFsShell.run("checksum", "/testDir*/testFile*");
String str = mOutput.toString();
String[] splitString = str.split("\\s+");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import alluxio.client.cli.fs.AbstractFileSystemShellTest;
import alluxio.client.file.FileSystemTestUtils;
import alluxio.exception.AlluxioException;
import alluxio.grpc.WritePType;

import org.junit.Assert;
import org.junit.Ignore;
Expand All @@ -33,7 +32,7 @@
public final class ChgrpCommandIntegrationTest extends AbstractFileSystemShellTest {
@Test
public void chgrp() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
sFsShell.run("chgrp", "group1", "/testFile");
String group = sFileSystem.getStatus(new AlluxioURI("/testFile")).getGroup();
Assert.assertEquals("group1", group);
Expand All @@ -47,8 +46,7 @@ public void chgrp() throws IOException, AlluxioException {
*/
@Test
public void chgrpRecursive() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile", 10);
// "chgrp -R group1 /testDir" should apply to both dir and child file
sFsShell.run("chgrp", "-R", "group1", "/testDir");
String group = sFileSystem.getStatus(new AlluxioURI("/testDir")).getGroup();
Expand All @@ -66,12 +64,9 @@ public void chgrpRecursive() throws IOException, AlluxioException {
*/
@Test
public void chgrpWildcard() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/foo/testFile1",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/foo/testFile2",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/bar/testFile3",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/foo/testFile1", 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/foo/testFile2", 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/bar/testFile3", 10);

sFsShell.run("chgrp", "group1", "/testDir/*/testFile*");
String group = sFileSystem.getStatus(new AlluxioURI("/testDir/foo/testFile1")).getGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import alluxio.client.cli.fs.AbstractFileSystemShellTest;
import alluxio.client.file.FileSystemTestUtils;
import alluxio.exception.AlluxioException;
import alluxio.grpc.WritePType;

import org.junit.Assert;
import org.junit.Ignore;
Expand All @@ -33,7 +32,7 @@
public final class ChmodCommandIntegrationTest extends AbstractFileSystemShellTest {
@Test
public void chmod() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
sFsShell.run("chmod", "777", "/testFile");
int permission = sFileSystem.getStatus(new AlluxioURI("/testFile")).getMode();
Assert.assertEquals((short) 0777, permission);
Expand All @@ -47,8 +46,7 @@ public void chmod() throws IOException, AlluxioException {
*/
@Test
public void chmodRecursively() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile", 10);
sFsShell.run("chmod", "-R", "777", "/testDir");
int permission = sFileSystem.getStatus(new AlluxioURI("/testDir")).getMode();
Assert.assertEquals((short) 0777, permission);
Expand All @@ -61,7 +59,7 @@ public void chmodRecursively() throws IOException, AlluxioException {

@Test
public void chmodSymbolic() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
sFsShell.run("chmod", "a=rwx", "/testFile");
int permission = sFileSystem.getStatus(new AlluxioURI("/testFile")).getMode();
Assert.assertEquals((short) 0777, permission);
Expand All @@ -75,10 +73,8 @@ public void chmodSymbolic() throws IOException, AlluxioException {
*/
@Test
public void chmodWildCard() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile1",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir2/testFile2",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile1", 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir2/testFile2", 10);
sFsShell.run("chmod", "a=rwx", "/testDir*/testFile*");
int permission = sFileSystem.getStatus(new AlluxioURI("/testDir/testFile1")).getMode();
Assert.assertEquals((short) 0777, permission);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import alluxio.conf.Configuration;
import alluxio.conf.PropertyKey;
import alluxio.exception.AlluxioException;
import alluxio.grpc.WritePType;

import com.google.common.collect.ImmutableMap;
import org.junit.Assert;
Expand All @@ -44,7 +43,7 @@ public final class ChownCommandIntegrationTest extends AbstractFileSystemShellTe

@Test
public void chown() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
sFsShell.run("chown", TEST_USER_1.getUser(), "/testFile");
String owner = sFileSystem.getStatus(new AlluxioURI("/testFile")).getOwner();
Assert.assertEquals(TEST_USER_1.getUser(), owner);
Expand All @@ -55,7 +54,7 @@ public void chown() throws IOException, AlluxioException {

@Test
public void chownValidOwnerValidGroupSuccess() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
String newOwner = TEST_USER_1.getUser();
String group = "staff";
String expectedCommandOutput =
Expand All @@ -67,7 +66,7 @@ public void chownValidOwnerValidGroupSuccess() throws Exception {

@Test
public void chownValidOwnerValidGroupFail() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
String newOwner = TEST_USER_2.getUser();
String originalOwner = sFileSystem.getStatus(new AlluxioURI("/testFile")).getOwner();
String originalGroup = sFileSystem.getStatus(new AlluxioURI("/testFile")).getGroup();
Expand All @@ -81,7 +80,7 @@ public void chownValidOwnerValidGroupFail() throws Exception {

@Test
public void chownInvalidOwnerValidGroup() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
String nonexistUser = "nonexistuser";
String originalOwner = sFileSystem.getStatus(new AlluxioURI("/testFile")).getOwner();
String originalGroup = sFileSystem.getStatus(new AlluxioURI("/testFile")).getGroup();
Expand All @@ -95,7 +94,7 @@ public void chownInvalidOwnerValidGroup() throws Exception {

@Test
public void chownValidOwnerInvalidGroup() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
String newOwner = TEST_USER_1.getUser();
String nonexistGroup = "nonexistgroup";
String originalOwner = sFileSystem.getStatus(new AlluxioURI("/testFile")).getOwner();
Expand All @@ -110,7 +109,7 @@ public void chownValidOwnerInvalidGroup() throws Exception {

@Test
public void chownInvalidOwnerInvalidGroup() throws Exception {
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testFile", 10);
String nonexistUser = "nonexistuser";
String nonexistGroup = "nonexistgroup";
String originalOwner = sFileSystem.getStatus(new AlluxioURI("/testFile")).getOwner();
Expand All @@ -128,8 +127,7 @@ public void chownInvalidOwnerInvalidGroup() throws Exception {
*/
@Test
public void chownRecursive() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile", 10);
sFsShell.run("chown", "-R", TEST_USER_1.getUser(), "/testDir");
String owner = sFileSystem.getStatus(new AlluxioURI("/testDir/testFile")).getOwner();
Assert.assertEquals(TEST_USER_1.getUser(), owner);
Expand All @@ -145,10 +143,8 @@ public void chownRecursive() throws IOException, AlluxioException {
*/
@Test
public void chownWildcard() throws IOException, AlluxioException {
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile1",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir2/testFile2",
WritePType.CACHE_THROUGH, 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir/testFile1", 10);
FileSystemTestUtils.createByteFile(sFileSystem, "/testDir2/testFile2", 10);

sFsShell.run("chown", "-R", TEST_USER_1.getUser(), "/*/testFile*");
String owner = sFileSystem.getStatus(new AlluxioURI("/testDir/testFile1")).getOwner();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
import static org.hamcrest.CoreMatchers.containsString;

import alluxio.AlluxioURI;
import alluxio.ConfigurationRule;
import alluxio.SystemPropertyRule;
import alluxio.annotation.dora.DoraTestTodoItem;
import alluxio.client.WriteType;
import alluxio.client.cli.fs.AbstractFileSystemShellTest;
import alluxio.client.cli.fs.FileSystemShellUtilsTest;
import alluxio.client.file.FileInStream;
import alluxio.client.file.URIStatus;
import alluxio.conf.Configuration;
import alluxio.conf.PropertyKey;
import alluxio.exception.AlluxioException;
import alluxio.exception.ExceptionMessage;
Expand Down Expand Up @@ -268,23 +265,6 @@ public void copyFromLocal() throws IOException, AlluxioException {
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(10, 20, read));
}

@Test
public void copyFromLocalMustCacheThenCacheThrough() throws Exception {
File file = mTestFolder.newFile();
try (Closeable c = new ConfigurationRule(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT,
WriteType.MUST_CACHE.toString(), Configuration.modifiableGlobal()).toResource()) {
Assert.assertEquals(0, sFsShell.run("copyFromLocal", file.getAbsolutePath(), "/test"));
}
try (Closeable c = new ConfigurationRule(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT,
WriteType.CACHE_THROUGH.toString(), Configuration.modifiableGlobal()).toResource()) {
mOutput.reset();
sFsShell.run("copyFromLocal", file.getAbsolutePath(), "/test");
}
Assert.assertThat(mOutput.toString(),
containsString(
ExceptionMessage.CANNOT_OVERWRITE_FILE_WITHOUT_OVERWRITE.getMessage("/test")));
}

@Test
public void copyFromLocalTestWithFullURI() throws IOException, AlluxioException {
File testFile = generateFileContent("/srcFileURI", BufferUtils.getIncreasingByteArray(10));
Expand Down
Loading

0 comments on commit f579e0d

Please sign in to comment.