1818 */
1919package org .apache .iceberg .hadoop ;
2020
21+ import static org .apache .hadoop .fs .CommonConfigurationKeysPublic .FS_TRASH_INTERVAL_KEY ;
2122import static org .assertj .core .api .Assertions .assertThat ;
2223import static org .assertj .core .api .Assertions .assertThatThrownBy ;
2324
3031import java .util .UUID ;
3132import java .util .Vector ;
3233import java .util .stream .Collectors ;
34+ import java .util .stream .StreamSupport ;
3335import org .apache .hadoop .conf .Configuration ;
3436import org .apache .hadoop .fs .FileSystem ;
3537import org .apache .hadoop .fs .Path ;
@@ -126,6 +128,48 @@ public void testDeletePrefix() {
126128 .hasMessageContaining ("java.io.FileNotFoundException" );
127129 }
128130
131+ @ Test
132+ public void testDeletePrefixWithTrashEnabled () throws IOException {
133+ Configuration conf = new Configuration ();
134+ conf .set (FS_TRASH_INTERVAL_KEY , "60" );
135+ fs = FileSystem .getLocal (conf );
136+
137+ hadoopFileIO = new HadoopFileIO (conf );
138+ Path parent = new Path (tempDir .toURI ());
139+
140+ List <Integer > scaleSizes = Lists .newArrayList (1 , 1000 , 2500 );
141+
142+ scaleSizes .parallelStream ()
143+ .forEach (
144+ scale -> {
145+ Path scalePath = new Path (parent , Integer .toString (scale ));
146+
147+ createRandomFiles (scalePath , scale );
148+ hadoopFileIO .deletePrefix (scalePath .toUri ().toString ());
149+
150+ // Hadoop filesystem will throw if the path does not exist
151+ assertThatThrownBy (
152+ () -> hadoopFileIO .listPrefix (scalePath .toUri ().toString ()).iterator ())
153+ .isInstanceOf (UncheckedIOException .class )
154+ .hasMessageContaining ("java.io.FileNotFoundException" );
155+ assertThat (
156+ StreamSupport .stream (
157+ hadoopFileIO
158+ .listPrefix (
159+ fs .getTrashRoot (scalePath ).toString () + "/Current" + tempDir )
160+ .spliterator (),
161+ false )
162+ .count ())
163+ .isEqualTo ((Long ) (long ) (int ) scale );
164+ });
165+
166+ hadoopFileIO .deletePrefix (parent .toUri ().toString ());
167+ // Hadoop filesystem will throw if the path does not exist
168+ assertThatThrownBy (() -> hadoopFileIO .listPrefix (parent .toUri ().toString ()).iterator ())
169+ .isInstanceOf (UncheckedIOException .class )
170+ .hasMessageContaining ("java.io.FileNotFoundException" );
171+ }
172+
129173 @ Test
130174 public void testDeleteFiles () {
131175 Path parent = new Path (tempDir .toURI ());
@@ -136,6 +180,29 @@ public void testDeleteFiles() {
136180 file -> assertThat (hadoopFileIO .newInputFile (file .toString ()).exists ()).isFalse ());
137181 }
138182
183+ @ Test
184+ public void testDeleteFilesWithTrashEnabled () throws IOException {
185+ Configuration conf = new Configuration ();
186+ conf .set (FS_TRASH_INTERVAL_KEY , "60" );
187+ fs = FileSystem .getLocal (conf );
188+
189+ hadoopFileIO = new HadoopFileIO (conf );
190+ Path parent = new Path (tempDir .toURI ());
191+ List <Path > filesCreated = createRandomFiles (parent , 10 );
192+ hadoopFileIO .deleteFiles (
193+ filesCreated .stream ().map (Path ::toString ).collect (Collectors .toList ()));
194+ filesCreated .forEach (
195+ file -> assertThat (hadoopFileIO .newInputFile (file .toString ()).exists ()).isFalse ());
196+ assertThat (
197+ StreamSupport .stream (
198+ hadoopFileIO
199+ .listPrefix (fs .getTrashRoot (parent ).toString () + "/Current" + tempDir )
200+ .spliterator (),
201+ false )
202+ .count ())
203+ .isEqualTo (10L );
204+ }
205+
139206 @ Test
140207 public void testDeleteFilesErrorHandling () {
141208 List <String > filesCreated =
0 commit comments