public class SwiftTestUtils
extends org.junit.Assert
Modifier and Type | Field and Description |
---|---|
static String |
IO_FILE_BUFFER_SIZE |
static String |
TEST_FS_SWIFT |
Constructor and Description |
---|
SwiftTestUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
assertDeleted(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path file,
boolean recursive) |
static void |
assertFileHasLength(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
int expected)
Make an assertion about the length of a file
|
static void |
assertIsDirectory(org.apache.hadoop.fs.FileStatus fileStatus)
Assert that a path refers to a directory
|
static void |
assertIsDirectory(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Assert that a path refers to a directory
|
static void |
assertIsFile(org.apache.hadoop.fs.FileSystem fileSystem,
org.apache.hadoop.fs.Path filename)
/**
Assert that a file exists and whose
FileStatus entry
declares that this is a file and not a symlink or directory. |
static void |
assertListStatusFinds(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path dir,
org.apache.hadoop.fs.Path subdir)
Assert that a FileSystem.listStatus on a dir finds the subdir/child entry
|
static void |
assertPathDoesNotExist(org.apache.hadoop.fs.FileSystem fileSystem,
String message,
org.apache.hadoop.fs.Path path)
Assert that a path does not exist
|
static void |
assertPathExists(org.apache.hadoop.fs.FileSystem fileSystem,
String message,
org.apache.hadoop.fs.Path path)
Assert that a path exists -but make no assertions as to the
type of that entry
|
static void |
assertPropertyEquals(Properties props,
String key,
String expected)
Assert that a property in the property set matches the expected value
|
static void |
cleanup(String action,
org.apache.hadoop.fs.FileSystem fileSystem,
String cleanupPath) |
static void |
cleanupInTeardown(org.apache.hadoop.fs.FileSystem fileSystem,
String cleanupPath) |
static void |
compareByteArrays(byte[] src,
byte[] dest,
int len)
Assert that tthe array src[0..len] and dest[] are equal
|
static byte[] |
dataset(int len,
int base,
int modulo)
Create a dataset for use in the tests; all data is in the range
base to (base+modulo-1) inclusive
|
static void |
downgrade(String message,
Throwable failure)
downgrade a failure to a message and a warning, then an
exception for the Junit test runner to mark as failed
|
static String |
dumpStats(String pathname,
org.apache.hadoop.fs.FileStatus[] stats) |
static String |
getDefaultWorkingDirectory() |
static URI |
getServiceURI(org.apache.hadoop.conf.Configuration conf)
Get the test URI
|
static boolean |
hasServiceURI(org.apache.hadoop.conf.Configuration conf) |
static String |
ls(org.apache.hadoop.fs.FileSystem fileSystem,
org.apache.hadoop.fs.Path path) |
static void |
noteAction(String action) |
static String |
readBytesToString(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
int length)
Read in "length" bytes, convert to an ascii string
|
static byte[] |
readDataset(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
int len)
Read the file and convert to a byte dataaset
|
static void |
skip(String message)
report a test has been skipped for some reason
|
static byte[] |
toAsciiByteArray(String s) |
static String |
toChar(byte b)
Convert a byte to a character for printing.
|
static String |
toChar(byte[] buffer) |
static void |
touch(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Touch a file: fails if it is already there
|
static void |
unsupported(String message)
report an overridden test as unsupported
|
static void |
writeAndRead(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
byte[] src,
int len,
int blocksize,
boolean overwrite,
boolean delete)
Write a file and read it in, validating the result.
|
static void |
writeDataset(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
byte[] src,
int len,
int blocksize,
boolean overwrite)
Write a file.
|
static byte[] |
writeTextFile(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
String text,
boolean overwrite)
Write the text to a file, returning the converted byte array
for use in validating the round trip
|
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
public static final String TEST_FS_SWIFT
public static final String IO_FILE_BUFFER_SIZE
public static URI getServiceURI(org.apache.hadoop.conf.Configuration conf) throws SwiftConfigurationException
conf
- configurationSwiftConfigurationException
- missing parameter or bad URIpublic static boolean hasServiceURI(org.apache.hadoop.conf.Configuration conf)
public static void assertPropertyEquals(Properties props, String key, String expected)
props
- property setkey
- property nameexpected
- expected value. If null, the property must not be in the setpublic static void writeAndRead(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, byte[] src, int len, int blocksize, boolean overwrite, boolean delete) throws IOException
fs
- filesystempath
- path to write tolen
- length of dataoverwrite
- should the create option allow overwrites?delete
- should the file be deleted afterwards? -with a verification
that it worked. Deletion is not attempted if an assertion has failed
earlier -it is not in a finally{}
block.IOException
- IO problemspublic static void writeDataset(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, byte[] src, int len, int blocksize, boolean overwrite) throws IOException
fs
- filesystempath
- path to write tolen
- length of dataoverwrite
- should the create option allow overwrites?IOException
- IO problemspublic static byte[] readDataset(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, int len) throws IOException
fs
- filesystempath
- path to read fromlen
- length of data to readIOException
- IO problemspublic static void compareByteArrays(byte[] src, byte[] dest, int len)
src
- source datadest
- actuallen
- length of bytes to comparepublic static String toChar(byte b)
b
- bytepublic static String toChar(byte[] buffer)
public static byte[] toAsciiByteArray(String s)
public static void cleanupInTeardown(org.apache.hadoop.fs.FileSystem fileSystem, String cleanupPath)
public static void cleanup(String action, org.apache.hadoop.fs.FileSystem fileSystem, String cleanupPath)
public static void noteAction(String action)
public static void downgrade(String message, Throwable failure)
message
- text messagefailure
- what failedorg.junit.internal.AssumptionViolatedException
- alwayspublic static void unsupported(String message)
message
- message to use in the textorg.junit.internal.AssumptionViolatedException
- alwayspublic static void skip(String message)
message
- message to use in the textorg.junit.internal.AssumptionViolatedException
- alwayspublic static void assertFileHasLength(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, int expected) throws IOException
fs
- filesystempath
- path of the fileexpected
- expected lengthIOException
- on File IO problemspublic static void assertIsDirectory(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException
fs
- filesystempath
- path of the directoryIOException
- on File IO problemspublic static void assertIsDirectory(org.apache.hadoop.fs.FileStatus fileStatus)
fileStatus
- stats to checkpublic static byte[] writeTextFile(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, String text, boolean overwrite) throws IOException
fs
- filesystempath
- path of filetext
- text to writeoverwrite
- should the operation overwrite any existing file?IOException
- on IO problemspublic static void touch(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException
fs
- filesystempath
- pathIOException
- IO problemspublic static void assertDeleted(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path file, boolean recursive) throws IOException
IOException
public static String readBytesToString(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, int length) throws IOException
fs
- filesystempath
- path to readlength
- #of bytes to read.IOException
public static String getDefaultWorkingDirectory()
public static String ls(org.apache.hadoop.fs.FileSystem fileSystem, org.apache.hadoop.fs.Path path) throws IOException
IOException
public static void assertIsFile(org.apache.hadoop.fs.FileSystem fileSystem, org.apache.hadoop.fs.Path filename) throws IOException
FileStatus
entry
declares that this is a file and not a symlink or directory.fileSystem
- filesystem to resolve path againstfilename
- name of the fileIOException
- IO problems during file operationspublic static byte[] dataset(int len, int base, int modulo)
len
- length of database
- base of the datamodulo
- the modulopublic static void assertPathExists(org.apache.hadoop.fs.FileSystem fileSystem, String message, org.apache.hadoop.fs.Path path) throws IOException
fileSystem
- filesystem to examinemessage
- message to include in the assertion failure messagepath
- path in the filesystemIOException
- IO problemspublic static void assertPathDoesNotExist(org.apache.hadoop.fs.FileSystem fileSystem, String message, org.apache.hadoop.fs.Path path) throws IOException
fileSystem
- filesystem to examinemessage
- message to include in the assertion failure messagepath
- path in the filesystemIOException
- IO problemspublic static void assertListStatusFinds(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, org.apache.hadoop.fs.Path subdir) throws IOException
fs
- filesystemdir
- directory to scansubdir
- full path to look forIOException
- IO problesCopyright © 2015 Apache Software Foundation. All Rights Reserved.