|
79 | 79 | import org.apache.gravitino.exceptions.NoSuchSchemaException;
|
80 | 80 | import org.apache.gravitino.exceptions.NonEmptySchemaException;
|
81 | 81 | import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
|
| 82 | +import org.apache.gravitino.file.FileInfo; |
82 | 83 | import org.apache.gravitino.file.Fileset;
|
83 | 84 | import org.apache.gravitino.file.FilesetChange;
|
84 | 85 | import org.apache.gravitino.storage.IdGenerator;
|
@@ -241,7 +242,7 @@ public static void setUp() {
|
241 | 242 | .getSchemaIdByMetalakeNameAndCatalogNameAndSchemaName(
|
242 | 243 | Mockito.anyString(), Mockito.anyString(), Mockito.eq("schema11"));
|
243 | 244 |
|
244 |
| - for (int i = 10; i < 30; i++) { |
| 245 | + for (int i = 10; i < 33; i++) { |
245 | 246 | doReturn(new SchemaIds(1L, 1L, (long) i))
|
246 | 247 | .when(spySchemaMetaService)
|
247 | 248 | .getSchemaIdByMetalakeNameAndCatalogNameAndSchemaName(
|
@@ -899,6 +900,110 @@ public void testListFilesets() throws IOException {
|
899 | 900 | }
|
900 | 901 | }
|
901 | 902 |
|
| 903 | + @Test |
| 904 | + public void testListFilesetFiles() throws IOException { |
| 905 | + String schemaName = "schema30"; |
| 906 | + String comment = "comment30"; |
| 907 | + String filesetName = "fileset30"; |
| 908 | + String schemaPath = TEST_ROOT_PATH + "/" + schemaName; |
| 909 | + |
| 910 | + createSchema(schemaName, comment, null, schemaPath); |
| 911 | + createFileset(filesetName, schemaName, comment, Fileset.Type.MANAGED, null, null); |
| 912 | + |
| 913 | + try (SecureHadoopCatalogOperations ops = new SecureHadoopCatalogOperations(store)) { |
| 914 | + ops.initialize(Maps.newHashMap(), randomCatalogInfo(), HADOOP_PROPERTIES_METADATA); |
| 915 | + NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, filesetName); |
| 916 | + |
| 917 | + Path testDir = new Path(schemaPath + "/" + filesetName); |
| 918 | + FileSystem fs = testDir.getFileSystem(new Configuration()); |
| 919 | + fs.mkdirs(testDir); |
| 920 | + fs.create(new Path(testDir, "test_file1.txt")).close(); |
| 921 | + fs.create(new Path(testDir, "test_file2.txt")).close(); |
| 922 | + fs.mkdirs(new Path(testDir, "test_subdir")); |
| 923 | + |
| 924 | + FileInfo[] files = ops.listFiles(filesetIdent, null, "/"); |
| 925 | + |
| 926 | + Assertions.assertNotNull(files); |
| 927 | + Assertions.assertTrue(files.length >= 3); |
| 928 | + |
| 929 | + Set<String> fileNames = Arrays.stream(files).map(FileInfo::name).collect(Collectors.toSet()); |
| 930 | + |
| 931 | + Assertions.assertTrue(fileNames.contains("test_file1.txt")); |
| 932 | + Assertions.assertTrue(fileNames.contains("test_file2.txt")); |
| 933 | + Assertions.assertTrue(fileNames.contains("test_subdir")); |
| 934 | + |
| 935 | + for (FileInfo file : files) { |
| 936 | + // verify file type related properties |
| 937 | + if (file.name().equals("test_file1.txt") || file.name().equals("test_file2.txt")) { |
| 938 | + Assertions.assertFalse(file.isDir(), "File should not be directory: " + file.name()); |
| 939 | + Assertions.assertTrue(file.size() >= 0, "File size should be non-negative"); |
| 940 | + } else if (file.name().equals("test_subdir")) { |
| 941 | + Assertions.assertTrue(file.isDir(), "Directory should be marked as directory"); |
| 942 | + Assertions.assertEquals(0, file.size(), "Directory size should be 0"); |
| 943 | + } |
| 944 | + // verify other properties |
| 945 | + Assertions.assertNotNull(file.name(), "File name should not be null"); |
| 946 | + Assertions.assertNotNull(file.path(), "File path should not be null"); |
| 947 | + Assertions.assertTrue(file.lastModified() > 0, "Last modified time should be positive"); |
| 948 | + } |
| 949 | + } |
| 950 | + } |
| 951 | + |
| 952 | + @Test |
| 953 | + public void testListFilesetFilesWithFSOpsDisabled() throws Exception { |
| 954 | + String schemaName = "schema31"; |
| 955 | + String comment = "comment31"; |
| 956 | + String filesetName = "fileset31"; |
| 957 | + String schemaPath = TEST_ROOT_PATH + "/" + schemaName; |
| 958 | + |
| 959 | + createSchema(schemaName, comment, null, schemaPath); |
| 960 | + createFileset(filesetName, schemaName, comment, Fileset.Type.MANAGED, null, null); |
| 961 | + |
| 962 | + Map<String, String> catalogProps = Maps.newHashMap(); |
| 963 | + catalogProps.put(DISABLE_FILESYSTEM_OPS, "true"); |
| 964 | + |
| 965 | + try (SecureHadoopCatalogOperations ops = new SecureHadoopCatalogOperations(store)) { |
| 966 | + ops.initialize(catalogProps, randomCatalogInfo(), HADOOP_PROPERTIES_METADATA); |
| 967 | + NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, filesetName); |
| 968 | + |
| 969 | + UnsupportedOperationException ex = |
| 970 | + Assertions.assertThrows( |
| 971 | + UnsupportedOperationException.class, |
| 972 | + () -> ops.listFiles(filesetIdent, null, "/"), |
| 973 | + "Expected listFiles to throw UnsupportedOperationException when disableFSOps is true"); |
| 974 | + Assertions.assertTrue( |
| 975 | + ex.getMessage().contains("Filesystem operations are disabled on this server"), |
| 976 | + "Exception message should mention 'Filesystem operations are disabled on this server'"); |
| 977 | + } |
| 978 | + } |
| 979 | + |
| 980 | + @Test |
| 981 | + public void testListFilesetFilesWithNonExistentPath() throws IOException { |
| 982 | + String schemaName = "schema32"; |
| 983 | + String comment = "comment32"; |
| 984 | + String filesetName = "fileset32"; |
| 985 | + String schemaPath = TEST_ROOT_PATH + "/" + schemaName; |
| 986 | + |
| 987 | + createSchema(schemaName, comment, null, schemaPath); |
| 988 | + createFileset(filesetName, schemaName, comment, Fileset.Type.MANAGED, null, null); |
| 989 | + |
| 990 | + try (SecureHadoopCatalogOperations ops = new SecureHadoopCatalogOperations(store)) { |
| 991 | + ops.initialize(Maps.newHashMap(), randomCatalogInfo(), HADOOP_PROPERTIES_METADATA); |
| 992 | + NameIdentifier filesetIdent = NameIdentifier.of("m1", "c1", schemaName, filesetName); |
| 993 | + |
| 994 | + String nonExistentSubPath = "/non_existent_file.txt"; |
| 995 | + IllegalArgumentException ex = |
| 996 | + Assertions.assertThrows( |
| 997 | + IllegalArgumentException.class, |
| 998 | + () -> ops.listFiles(filesetIdent, null, nonExistentSubPath), |
| 999 | + "Listing a non-existent fileset directory should throw IllegalArgumentException"); |
| 1000 | + |
| 1001 | + Assertions.assertTrue( |
| 1002 | + ex.getMessage().contains("does not exist"), |
| 1003 | + "Exception message should mention that the path does not exist"); |
| 1004 | + } |
| 1005 | + } |
| 1006 | + |
902 | 1007 | @ParameterizedTest
|
903 | 1008 | @MethodSource("testRenameArguments")
|
904 | 1009 | public void testRenameFileset(
|
|
0 commit comments