github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/hadoopfs/src/test/java/io/lakefs/contract/TestLakeFSFileSystemContract.java (about)

     1  package io.lakefs.contract;
     2  
     3  import org.apache.hadoop.conf.Configuration;
     4  import org.apache.hadoop.fs.FileSystemContractBaseTest;
     5  import org.apache.hadoop.fs.Path;
     6  import org.junit.Assert;
     7  
     8  /**
     9   *  Tests a live S3 system. If your keys and bucket aren't specified, all tests
    10   *  are marked as passed.
    11   *
    12   *  This uses BlockJUnit4ClassRunner because FileSystemContractBaseTest from
    13   *  TestCase which uses the old Junit3 runner that doesn't ignore assumptions
    14   *  properly making it impossible to skip the tests if we don't have a valid
    15   *  bucket.
    16   **/
    17  public abstract class TestLakeFSFileSystemContract extends FileSystemContractBaseTest {
    18    public static final String TEST_FS_LAKEFS_NAME = "test.fs.lakefs.name";
    19  
    20    protected String pathPrefix;
    21  
    22    @Override
    23    protected String getDefaultWorkingDirectory() {
    24        return pathPrefix;
    25    }
    26  
    27    public void init() throws Exception {
    28      Configuration conf = new Configuration();
    29      fs = LakeFSTestUtils.createTestFileSystem(conf);
    30      pathPrefix = conf.get(TEST_FS_LAKEFS_NAME) + "/main/";
    31      fs.setWorkingDirectory(new Path(pathPrefix));
    32    }
    33  
    34    @Override
    35    public void tearDown() throws Exception {
    36      if (fs != null) {
    37        fs.delete(path("/test"), true);
    38      }
    39      super.tearDown();
    40    }
    41  
    42    @Override
    43    public void testMkdirsWithUmask() throws Exception {
    44      // skip("Not supported");
    45    }
    46  
    47    public void testRenameFileAsExistingFile() throws Exception {
    48      Path src = path("/test/hadoop/file");
    49      createFile(src);
    50      Path dst = path("/test/new/newfile");
    51      createFile(dst);
    52  
    53      rename(src, dst, true, false, true);
    54    }
    55  
    56    @Override
    57    public void testRenameDirectoryAsExistingDirectory() throws Exception {
    58      Path src = path("/test/hadoop/dir");
    59      fs.mkdirs(src);
    60      createFile(path("/test/hadoop/dir/file1"));
    61      createFile(path("/test/hadoop/dir/subdir/file2"));
    62  
    63      Path dst = path("/test/new/newdir");
    64      fs.mkdirs(dst);
    65      rename(src, dst, true, false, true);
    66      Assert.assertFalse("Nested file1 exists",
    67          fs.exists(path("/test/hadoop/dir/file1")));
    68      Assert.assertFalse("Nested file2 exists",
    69          fs.exists(path("/test/hadoop/dir/subdir/file2")));
    70      Assert.assertTrue("Renamed nested file1 exists",
    71          fs.exists(path("/test/new/newdir/file1")));
    72      Assert.assertTrue("Renamed nested exists",
    73          fs.exists(path("/test/new/newdir/subdir/file2")));
    74    }
    75  
    76    @Override
    77    public void testWorkingDirectory() throws Exception {
    78      // TODO make this test green and remove override
    79    }
    80   }