|
@@ -17,10 +17,6 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.fs;
|
|
|
|
|
|
-import static org.hamcrest.CoreMatchers.is;
|
|
|
-import static org.hamcrest.CoreMatchers.not;
|
|
|
-import static org.junit.Assert.assertThat;
|
|
|
-
|
|
|
import java.text.ParseException;
|
|
|
import java.util.Date;
|
|
|
|
|
@@ -34,6 +30,8 @@ import org.junit.Test;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import static org.assertj.core.api.Assertions.assertThat;
|
|
|
+
|
|
|
public class TestFsShellTouch {
|
|
|
static final Logger LOG = LoggerFactory.getLogger(TestFsShellTouch.class);
|
|
|
|
|
@@ -71,23 +69,25 @@ public class TestFsShellTouch {
|
|
|
final String newFileName = "newFile";
|
|
|
final Path newFile = new Path(newFileName);
|
|
|
lfs.delete(newFile, true);
|
|
|
- assertThat(lfs.exists(newFile), is(false));
|
|
|
+ assertThat(lfs.exists(newFile)).isFalse();
|
|
|
|
|
|
- assertThat("Expected successful touchz on a new file",
|
|
|
- shellRun("-touchz", newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touchz", newFileName))
|
|
|
+ .as("Expected successful touchz on a new file").isEqualTo(0);
|
|
|
shellRun("-ls", newFileName);
|
|
|
|
|
|
- assertThat("Expected successful touchz on an existing zero-length file",
|
|
|
- shellRun("-touchz", newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touchz", newFileName))
|
|
|
+ .as("Expected successful touchz on an existing zero-length file")
|
|
|
+ .isEqualTo(0);
|
|
|
|
|
|
// Ensure noDir does not exist
|
|
|
final String noDirName = "noDir";
|
|
|
final Path noDir = new Path(noDirName);
|
|
|
lfs.delete(noDir, true);
|
|
|
- assertThat(lfs.exists(noDir), is(false));
|
|
|
+ assertThat(lfs.exists(noDir)).isFalse();
|
|
|
|
|
|
- assertThat("Expected failed touchz in a non-existent directory",
|
|
|
- shellRun("-touchz", noDirName + "/foo"), is(not(0)));
|
|
|
+ assertThat(shellRun("-touchz", noDirName + "/foo"))
|
|
|
+ .as("Expected failed touchz in a non-existent directory")
|
|
|
+ .isNotEqualTo(0);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -96,25 +96,28 @@ public class TestFsShellTouch {
|
|
|
final String newFileName = "newFile2";
|
|
|
final Path newFile = new Path(newFileName);
|
|
|
lfs.delete(newFile, true);
|
|
|
- assertThat(lfs.exists(newFile), is(false));
|
|
|
+ assertThat(lfs.exists(newFile)).isFalse();
|
|
|
|
|
|
{
|
|
|
- assertThat(
|
|
|
- "Expected successful touch on a non-existent file with -c option",
|
|
|
- shellRun("-touch", "-c", newFileName), is(0));
|
|
|
- assertThat(lfs.exists(newFile), is(false));
|
|
|
+ assertThat(shellRun("-touch", "-c", newFileName))
|
|
|
+ .as("Expected successful touch on a non-existent file" +
|
|
|
+ " with -c option")
|
|
|
+ .isEqualTo(0);
|
|
|
+ assertThat(lfs.exists(newFile)).isFalse();
|
|
|
}
|
|
|
|
|
|
{
|
|
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
|
|
Date dateObj = parseTimestamp(strTime);
|
|
|
|
|
|
- assertThat(
|
|
|
- "Expected successful touch on a new file with a specified timestamp",
|
|
|
- shellRun("-touch", "-t", strTime, newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touch", "-t", strTime, newFileName))
|
|
|
+ .as("Expected successful touch on a new file" +
|
|
|
+ " with a specified timestamp")
|
|
|
+ .isEqualTo(0);
|
|
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
|
|
- assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
|
|
- assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
|
|
+ assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
|
|
+ assertThat(new_status.getModificationTime())
|
|
|
+ .isEqualTo(dateObj.getTime());
|
|
|
}
|
|
|
|
|
|
FileStatus fstatus = lfs.getFileStatus(newFile);
|
|
@@ -123,14 +126,15 @@ public class TestFsShellTouch {
|
|
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
|
|
Date dateObj = parseTimestamp(strTime);
|
|
|
|
|
|
- assertThat("Expected successful touch with a specified access time",
|
|
|
- shellRun("-touch", "-a", "-t", strTime, newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touch", "-a", "-t", strTime, newFileName))
|
|
|
+ .as("Expected successful touch with a specified access time")
|
|
|
+ .isEqualTo(0);
|
|
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
|
|
// Verify if access time is recorded correctly (and modification time
|
|
|
// remains unchanged).
|
|
|
- assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
|
|
- assertThat(new_status.getModificationTime(),
|
|
|
- is(fstatus.getModificationTime()));
|
|
|
+ assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
|
|
+ assertThat(new_status.getModificationTime())
|
|
|
+ .isEqualTo(fstatus.getModificationTime());
|
|
|
}
|
|
|
|
|
|
fstatus = lfs.getFileStatus(newFile);
|
|
@@ -139,56 +143,63 @@ public class TestFsShellTouch {
|
|
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
|
|
Date dateObj = parseTimestamp(strTime);
|
|
|
|
|
|
- assertThat(
|
|
|
- "Expected successful touch with a specified modification time",
|
|
|
- shellRun("-touch", "-m", "-t", strTime, newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touch", "-m", "-t", strTime, newFileName))
|
|
|
+ .as("Expected successful touch with a specified modification time")
|
|
|
+ .isEqualTo(0);
|
|
|
// Verify if modification time is recorded correctly (and access time
|
|
|
// remains unchanged).
|
|
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
|
|
- assertThat(new_status.getAccessTime(), is(fstatus.getAccessTime()));
|
|
|
- assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
|
|
+ assertThat(new_status.getAccessTime())
|
|
|
+ .isEqualTo(fstatus.getAccessTime());
|
|
|
+ assertThat(new_status.getModificationTime())
|
|
|
+ .isEqualTo(dateObj.getTime());
|
|
|
}
|
|
|
|
|
|
{
|
|
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
|
|
Date dateObj = parseTimestamp(strTime);
|
|
|
|
|
|
- assertThat("Expected successful touch with a specified timestamp",
|
|
|
- shellRun("-touch", "-t", strTime, newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touch", "-t", strTime, newFileName))
|
|
|
+ .as("Expected successful touch with a specified timestamp")
|
|
|
+ .isEqualTo(0);
|
|
|
|
|
|
// Verify if both modification and access times are recorded correctly
|
|
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
|
|
- assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
|
|
- assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
|
|
+ assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
|
|
+ assertThat(new_status.getModificationTime())
|
|
|
+ .isEqualTo(dateObj.getTime());
|
|
|
}
|
|
|
|
|
|
{
|
|
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
|
|
Date dateObj = parseTimestamp(strTime);
|
|
|
|
|
|
- assertThat("Expected successful touch with a specified timestamp",
|
|
|
- shellRun("-touch", "-a", "-m", "-t", strTime, newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touch", "-a", "-m", "-t", strTime, newFileName))
|
|
|
+ .as("Expected successful touch with a specified timestamp")
|
|
|
+ .isEqualTo(0);
|
|
|
|
|
|
// Verify if both modification and access times are recorded correctly
|
|
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
|
|
- assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
|
|
- assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
|
|
+ assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
|
|
+ assertThat(new_status.getModificationTime())
|
|
|
+ .isEqualTo(dateObj.getTime());
|
|
|
}
|
|
|
|
|
|
{
|
|
|
- assertThat("Expected failed touch with a missing timestamp",
|
|
|
- shellRun("-touch", "-t", newFileName), is(not(0)));
|
|
|
+ assertThat(shellRun("-touch", "-t", newFileName))
|
|
|
+ .as("Expected failed touch with a missing timestamp")
|
|
|
+ .isNotEqualTo(0);
|
|
|
}
|
|
|
|
|
|
// Verify -c option when file exists.
|
|
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
|
|
Date dateObj = parseTimestamp(strTime);
|
|
|
- assertThat(
|
|
|
- "Expected successful touch on a non-existent file with -c option",
|
|
|
- shellRun("-touch", "-c", "-t", strTime, newFileName), is(0));
|
|
|
+ assertThat(shellRun("-touch", "-c", "-t", strTime, newFileName))
|
|
|
+ .as("Expected successful touch on a non-existent file with -c option")
|
|
|
+ .isEqualTo(0);
|
|
|
FileStatus fileStatus = lfs.getFileStatus(newFile);
|
|
|
- assertThat(fileStatus.getAccessTime(), is(dateObj.getTime()));
|
|
|
- assertThat(fileStatus.getModificationTime(), is(dateObj.getTime()));
|
|
|
+ assertThat(fileStatus.getAccessTime()).isEqualTo(dateObj.getTime());
|
|
|
+ assertThat(fileStatus.getModificationTime()).isEqualTo(dateObj.getTime());
|
|
|
}
|
|
|
|
|
|
private String formatTimestamp(long timeInMillis) {
|