Java 类org.apache.hadoop.fs.swift.util.SwiftTestUtils 实例源码

项目:hadoop    文件:TestSwiftFileSystemDirectories.java   
/**
 * test that a dir off root has a listStatus() call that
 * works as expected. and that when a child is added. it changes
 *
 * @throws Exception on failures
 */
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testDirectoriesOffRootHaveMatchingFileStatus() throws Exception {
  Path test = path("/test");
  fs.delete(test, true);
  mkdirs(test);
  assertExists("created test directory", test);
  FileStatus[] statuses = fs.listStatus(test);
  String statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 0,
               statuses.length);

  Path src = path("/test/file");

  //create a zero byte file
  SwiftTestUtils.touch(fs, src);
  //stat it
  statuses = fs.listStatus(test);
  statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 1,
               statuses.length);
  SwiftFileStatus stat = (SwiftFileStatus) statuses[0];
  assertTrue("isDir(): Not a directory: " + stat, stat.isDir());
  extraStatusAssertions(stat);
}
项目:hadoop    文件:TestSwiftFileSystemRename.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamedConsistence() throws IOException {
  assumeRenameSupported();
  describe("verify that overwriting a file with new data doesn't impact" +
          " the existing content");

  final Path filePath = new Path("/test/home/user/documents/file.txt");
  final Path newFilePath = new Path("/test/home/user/files/file.txt");
  mkdirs(newFilePath.getParent());
  int len = 1024;
  byte[] dataset = dataset(len, 'A', 26);
  byte[] dataset2 = dataset(len, 'a', 26);
  writeDataset(fs, filePath, dataset, len, len, false);
  rename(filePath, newFilePath, true, false, true);
  SwiftTestUtils.writeAndRead(fs, filePath, dataset2, len, len, false, true);
  byte[] dest = readDataset(fs, newFilePath, len);
  compareByteArrays(dataset, dest, len);
  String reread = readBytesToString(fs, newFilePath, 20);
}
项目:hadoop    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeleteSmallPartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeleteSmallPartitionedFile");

  final int len1 = 1024;
  final byte[] src1 = SwiftTestUtils.dataset(len1, 'A', 'Z');
  SwiftTestUtils.writeDataset(fs, path, src1, len1, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 found under " + ls, part_0002);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
}
项目:hadoop    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeletePartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeletePartitionedFile");

  SwiftTestUtils.writeDataset(fs, path, data, data.length, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 file still under " + ls, part_0002);
}
项目:hadoop    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testSeekBigFile() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  assertEquals(0, instream.getPos());
  //expect that seek to 0 works
  instream.seek(0);
  int result = instream.read();
  assertEquals(0, result);
  assertEquals(1, instream.read());
  assertEquals(2, instream.read());

  //do seek 32KB ahead
  instream.seek(32768);
  assertEquals("@32768", block[32768], (byte) instream.read());
  instream.seek(40000);
  assertEquals("@40000", block[40000], (byte) instream.read());
  instream.seek(8191);
  assertEquals("@8191", block[8191], (byte) instream.read());
  instream.seek(0);
  assertEquals("@0", 0, (byte) instream.read());
}
项目:hadoop    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPositionedBulkReadDoesntChangePosition() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  instream.seek(39999);
  assertTrue(-1 != instream.read());
  assertEquals (40000, instream.getPos());

  byte[] readBuffer = new byte[256];
  instream.read(128, readBuffer, 0, readBuffer.length);
  //have gone back
  assertEquals(40000, instream.getPos());
  //content is the same too
  assertEquals("@40000", block[40000], (byte) instream.read());
  //now verify the picked up data
  for (int i = 0; i < 256; i++) {
    assertEquals("@" + i, block[i + 128], readBuffer[i]);
  }
}
项目:aliyun-oss-hadoop-fs    文件:TestSwiftFileSystemDirectories.java   
/**
 * test that a dir off root has a listStatus() call that
 * works as expected. and that when a child is added. it changes
 *
 * @throws Exception on failures
 */
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testDirectoriesOffRootHaveMatchingFileStatus() throws Exception {
  Path test = path("/test");
  fs.delete(test, true);
  mkdirs(test);
  assertExists("created test directory", test);
  FileStatus[] statuses = fs.listStatus(test);
  String statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 0,
               statuses.length);

  Path src = path("/test/file");

  //create a zero byte file
  SwiftTestUtils.touch(fs, src);
  //stat it
  statuses = fs.listStatus(test);
  statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 1,
               statuses.length);
  SwiftFileStatus stat = (SwiftFileStatus) statuses[0];
  assertTrue("isDir(): Not a directory: " + stat, stat.isDir());
  extraStatusAssertions(stat);
}
项目:aliyun-oss-hadoop-fs    文件:TestSwiftFileSystemRename.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamedConsistence() throws IOException {
  assumeRenameSupported();
  describe("verify that overwriting a file with new data doesn't impact" +
          " the existing content");

  final Path filePath = new Path("/test/home/user/documents/file.txt");
  final Path newFilePath = new Path("/test/home/user/files/file.txt");
  mkdirs(newFilePath.getParent());
  int len = 1024;
  byte[] dataset = dataset(len, 'A', 26);
  byte[] dataset2 = dataset(len, 'a', 26);
  writeDataset(fs, filePath, dataset, len, len, false);
  rename(filePath, newFilePath, true, false, true);
  SwiftTestUtils.writeAndRead(fs, filePath, dataset2, len, len, false, true);
  byte[] dest = readDataset(fs, newFilePath, len);
  compareByteArrays(dataset, dest, len);
  String reread = readBytesToString(fs, newFilePath, 20);
}
项目:aliyun-oss-hadoop-fs    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeleteSmallPartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeleteSmallPartitionedFile");

  final int len1 = 1024;
  final byte[] src1 = SwiftTestUtils.dataset(len1, 'A', 'Z');
  SwiftTestUtils.writeDataset(fs, path, src1, len1, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 found under " + ls, part_0002);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
}
项目:aliyun-oss-hadoop-fs    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeletePartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeletePartitionedFile");

  SwiftTestUtils.writeDataset(fs, path, data, data.length, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 file still under " + ls, part_0002);
}
项目:aliyun-oss-hadoop-fs    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testSeekBigFile() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  assertEquals(0, instream.getPos());
  //expect that seek to 0 works
  instream.seek(0);
  int result = instream.read();
  assertEquals(0, result);
  assertEquals(1, instream.read());
  assertEquals(2, instream.read());

  //do seek 32KB ahead
  instream.seek(32768);
  assertEquals("@32768", block[32768], (byte) instream.read());
  instream.seek(40000);
  assertEquals("@40000", block[40000], (byte) instream.read());
  instream.seek(8191);
  assertEquals("@8191", block[8191], (byte) instream.read());
  instream.seek(0);
  assertEquals("@0", 0, (byte) instream.read());
}
项目:aliyun-oss-hadoop-fs    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPositionedBulkReadDoesntChangePosition() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  instream.seek(39999);
  assertTrue(-1 != instream.read());
  assertEquals (40000, instream.getPos());

  byte[] readBuffer = new byte[256];
  instream.read(128, readBuffer, 0, readBuffer.length);
  //have gone back
  assertEquals(40000, instream.getPos());
  //content is the same too
  assertEquals("@40000", block[40000], (byte) instream.read());
  //now verify the picked up data
  for (int i = 0; i < 256; i++) {
    assertEquals("@" + i, block[i + 128], readBuffer[i]);
  }
}
项目:big-c    文件:TestSwiftFileSystemDirectories.java   
/**
 * test that a dir off root has a listStatus() call that
 * works as expected. and that when a child is added. it changes
 *
 * @throws Exception on failures
 */
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testDirectoriesOffRootHaveMatchingFileStatus() throws Exception {
  Path test = path("/test");
  fs.delete(test, true);
  mkdirs(test);
  assertExists("created test directory", test);
  FileStatus[] statuses = fs.listStatus(test);
  String statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 0,
               statuses.length);

  Path src = path("/test/file");

  //create a zero byte file
  SwiftTestUtils.touch(fs, src);
  //stat it
  statuses = fs.listStatus(test);
  statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 1,
               statuses.length);
  SwiftFileStatus stat = (SwiftFileStatus) statuses[0];
  assertTrue("isDir(): Not a directory: " + stat, stat.isDir());
  extraStatusAssertions(stat);
}
项目:big-c    文件:TestSwiftFileSystemRename.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamedConsistence() throws IOException {
  assumeRenameSupported();
  describe("verify that overwriting a file with new data doesn't impact" +
          " the existing content");

  final Path filePath = new Path("/test/home/user/documents/file.txt");
  final Path newFilePath = new Path("/test/home/user/files/file.txt");
  mkdirs(newFilePath.getParent());
  int len = 1024;
  byte[] dataset = dataset(len, 'A', 26);
  byte[] dataset2 = dataset(len, 'a', 26);
  writeDataset(fs, filePath, dataset, len, len, false);
  rename(filePath, newFilePath, true, false, true);
  SwiftTestUtils.writeAndRead(fs, filePath, dataset2, len, len, false, true);
  byte[] dest = readDataset(fs, newFilePath, len);
  compareByteArrays(dataset, dest, len);
  String reread = readBytesToString(fs, newFilePath, 20);
}
项目:big-c    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeleteSmallPartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeleteSmallPartitionedFile");

  final int len1 = 1024;
  final byte[] src1 = SwiftTestUtils.dataset(len1, 'A', 'Z');
  SwiftTestUtils.writeDataset(fs, path, src1, len1, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 found under " + ls, part_0002);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
}
项目:big-c    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeletePartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeletePartitionedFile");

  SwiftTestUtils.writeDataset(fs, path, data, data.length, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 file still under " + ls, part_0002);
}
项目:big-c    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testSeekBigFile() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  assertEquals(0, instream.getPos());
  //expect that seek to 0 works
  instream.seek(0);
  int result = instream.read();
  assertEquals(0, result);
  assertEquals(1, instream.read());
  assertEquals(2, instream.read());

  //do seek 32KB ahead
  instream.seek(32768);
  assertEquals("@32768", block[32768], (byte) instream.read());
  instream.seek(40000);
  assertEquals("@40000", block[40000], (byte) instream.read());
  instream.seek(8191);
  assertEquals("@8191", block[8191], (byte) instream.read());
  instream.seek(0);
  assertEquals("@0", 0, (byte) instream.read());
}
项目:big-c    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPositionedBulkReadDoesntChangePosition() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  instream.seek(39999);
  assertTrue(-1 != instream.read());
  assertEquals (40000, instream.getPos());

  byte[] readBuffer = new byte[256];
  instream.read(128, readBuffer, 0, readBuffer.length);
  //have gone back
  assertEquals(40000, instream.getPos());
  //content is the same too
  assertEquals("@40000", block[40000], (byte) instream.read());
  //now verify the picked up data
  for (int i = 0; i < 256; i++) {
    assertEquals("@" + i, block[i + 128], readBuffer[i]);
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestSwiftFileSystemDirectories.java   
/**
 * test that a dir off root has a listStatus() call that
 * works as expected. and that when a child is added. it changes
 *
 * @throws Exception on failures
 */
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testDirectoriesOffRootHaveMatchingFileStatus() throws Exception {
  Path test = path("/test");
  fs.delete(test, true);
  mkdirs(test);
  assertExists("created test directory", test);
  FileStatus[] statuses = fs.listStatus(test);
  String statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 0,
               statuses.length);

  Path src = path("/test/file");

  //create a zero byte file
  SwiftTestUtils.touch(fs, src);
  //stat it
  statuses = fs.listStatus(test);
  statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 1,
               statuses.length);
  SwiftFileStatus stat = (SwiftFileStatus) statuses[0];
  assertTrue("isDir(): Not a directory: " + stat, stat.isDir());
  extraStatusAssertions(stat);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestSwiftFileSystemRename.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamedConsistence() throws IOException {
  assumeRenameSupported();
  describe("verify that overwriting a file with new data doesn't impact" +
          " the existing content");

  final Path filePath = new Path("/test/home/user/documents/file.txt");
  final Path newFilePath = new Path("/test/home/user/files/file.txt");
  mkdirs(newFilePath.getParent());
  int len = 1024;
  byte[] dataset = dataset(len, 'A', 26);
  byte[] dataset2 = dataset(len, 'a', 26);
  writeDataset(fs, filePath, dataset, len, len, false);
  rename(filePath, newFilePath, true, false, true);
  SwiftTestUtils.writeAndRead(fs, filePath, dataset2, len, len, false, true);
  byte[] dest = readDataset(fs, newFilePath, len);
  compareByteArrays(dataset, dest, len);
  String reread = readBytesToString(fs, newFilePath, 20);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeleteSmallPartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeleteSmallPartitionedFile");

  final int len1 = 1024;
  final byte[] src1 = SwiftTestUtils.dataset(len1, 'A', 'Z');
  SwiftTestUtils.writeDataset(fs, path, src1, len1, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 found under " + ls, part_0002);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeletePartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeletePartitionedFile");

  SwiftTestUtils.writeDataset(fs, path, data, data.length, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 file still under " + ls, part_0002);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testSeekBigFile() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  assertEquals(0, instream.getPos());
  //expect that seek to 0 works
  instream.seek(0);
  int result = instream.read();
  assertEquals(0, result);
  assertEquals(1, instream.read());
  assertEquals(2, instream.read());

  //do seek 32KB ahead
  instream.seek(32768);
  assertEquals("@32768", block[32768], (byte) instream.read());
  instream.seek(40000);
  assertEquals("@40000", block[40000], (byte) instream.read());
  instream.seek(8191);
  assertEquals("@8191", block[8191], (byte) instream.read());
  instream.seek(0);
  assertEquals("@0", 0, (byte) instream.read());
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPositionedBulkReadDoesntChangePosition() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  instream.seek(39999);
  assertTrue(-1 != instream.read());
  assertEquals (40000, instream.getPos());

  byte[] readBuffer = new byte[256];
  instream.read(128, readBuffer, 0, readBuffer.length);
  //have gone back
  assertEquals(40000, instream.getPos());
  //content is the same too
  assertEquals("@40000", block[40000], (byte) instream.read());
  //now verify the picked up data
  for (int i = 0; i < 256; i++) {
    assertEquals("@" + i, block[i + 128], readBuffer[i]);
  }
}
项目:hops    文件:TestSwiftFileSystemDirectories.java   
/**
 * test that a dir off root has a listStatus() call that
 * works as expected. and that when a child is added. it changes
 *
 * @throws Exception on failures
 */
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testDirectoriesOffRootHaveMatchingFileStatus() throws Exception {
  Path test = path("/test");
  fs.delete(test, true);
  mkdirs(test);
  assertExists("created test directory", test);
  FileStatus[] statuses = fs.listStatus(test);
  String statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 0,
               statuses.length);

  Path src = path("/test/file");

  //create a zero byte file
  SwiftTestUtils.touch(fs, src);
  //stat it
  statuses = fs.listStatus(test);
  statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 1,
               statuses.length);
  SwiftFileStatus stat = (SwiftFileStatus) statuses[0];
  assertTrue("isDir(): Not a directory: " + stat, stat.isDir());
  extraStatusAssertions(stat);
}
项目:hops    文件:TestSwiftFileSystemRename.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamedConsistence() throws IOException {
  assumeRenameSupported();
  describe("verify that overwriting a file with new data doesn't impact" +
          " the existing content");

  final Path filePath = new Path("/test/home/user/documents/file.txt");
  final Path newFilePath = new Path("/test/home/user/files/file.txt");
  mkdirs(newFilePath.getParent());
  int len = 1024;
  byte[] dataset = dataset(len, 'A', 26);
  byte[] dataset2 = dataset(len, 'a', 26);
  writeDataset(fs, filePath, dataset, len, len, false);
  rename(filePath, newFilePath, true, false, true);
  SwiftTestUtils.writeAndRead(fs, filePath, dataset2, len, len, false, true);
  byte[] dest = readDataset(fs, newFilePath, len);
  compareByteArrays(dataset, dest, len);
  String reread = readBytesToString(fs, newFilePath, 20);
}
项目:hops    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeleteSmallPartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeleteSmallPartitionedFile");

  final int len1 = 1024;
  final byte[] src1 = SwiftTestUtils.dataset(len1, 'A', 'Z');
  SwiftTestUtils.writeDataset(fs, path, src1, len1, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 found under " + ls, part_0002);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
}
项目:hops    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeletePartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeletePartitionedFile");

  SwiftTestUtils.writeDataset(fs, path, data, data.length, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 file still under " + ls, part_0002);
}
项目:hops    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testSeekBigFile() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  assertEquals(0, instream.getPos());
  //expect that seek to 0 works
  instream.seek(0);
  int result = instream.read();
  assertEquals(0, result);
  assertEquals(1, instream.read());
  assertEquals(2, instream.read());

  //do seek 32KB ahead
  instream.seek(32768);
  assertEquals("@32768", block[32768], (byte) instream.read());
  instream.seek(40000);
  assertEquals("@40000", block[40000], (byte) instream.read());
  instream.seek(8191);
  assertEquals("@8191", block[8191], (byte) instream.read());
  instream.seek(0);
  assertEquals("@0", 0, (byte) instream.read());
}
项目:hops    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPositionedBulkReadDoesntChangePosition() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  instream.seek(39999);
  assertTrue(-1 != instream.read());
  assertEquals (40000, instream.getPos());

  byte[] readBuffer = new byte[256];
  instream.read(128, readBuffer, 0, readBuffer.length);
  //have gone back
  assertEquals(40000, instream.getPos());
  //content is the same too
  assertEquals("@40000", block[40000], (byte) instream.read());
  //now verify the picked up data
  for (int i = 0; i < 256; i++) {
    assertEquals("@" + i, block[i + 128], readBuffer[i]);
  }
}
项目:hadoop-on-lustre2    文件:TestSwiftFileSystemDirectories.java   
/**
 * test that a dir off root has a listStatus() call that
 * works as expected. and that when a child is added. it changes
 *
 * @throws Exception on failures
 */
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testDirectoriesOffRootHaveMatchingFileStatus() throws Exception {
  Path test = path("/test");
  fs.delete(test, true);
  mkdirs(test);
  assertExists("created test directory", test);
  FileStatus[] statuses = fs.listStatus(test);
  String statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 0,
               statuses.length);

  Path src = path("/test/file");

  //create a zero byte file
  SwiftTestUtils.touch(fs, src);
  //stat it
  statuses = fs.listStatus(test);
  statusString = statusToString(test.toString(), statuses);
  assertEquals("Wrong number of elements in file status " + statusString, 1,
               statuses.length);
  SwiftFileStatus stat = (SwiftFileStatus) statuses[0];
  assertTrue("isDir(): Not a directory: " + stat, stat.isDir());
  extraStatusAssertions(stat);
}
项目:hadoop-on-lustre2    文件:TestSwiftFileSystemRename.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamedConsistence() throws IOException {
  assumeRenameSupported();
  describe("verify that overwriting a file with new data doesn't impact" +
          " the existing content");

  final Path filePath = new Path("/test/home/user/documents/file.txt");
  final Path newFilePath = new Path("/test/home/user/files/file.txt");
  mkdirs(newFilePath.getParent());
  int len = 1024;
  byte[] dataset = dataset(len, 'A', 26);
  byte[] dataset2 = dataset(len, 'a', 26);
  writeDataset(fs, filePath, dataset, len, len, false);
  rename(filePath, newFilePath, true, false, true);
  SwiftTestUtils.writeAndRead(fs, filePath, dataset2, len, len, false, true);
  byte[] dest = readDataset(fs, newFilePath, len);
  compareByteArrays(dataset, dest, len);
  String reread = readBytesToString(fs, newFilePath, 20);
}
项目:hadoop-on-lustre2    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeleteSmallPartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeleteSmallPartitionedFile");

  final int len1 = 1024;
  final byte[] src1 = SwiftTestUtils.dataset(len1, 'A', 'Z');
  SwiftTestUtils.writeDataset(fs, path, src1, len1, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 found under " + ls, part_0002);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
}
项目:hadoop-on-lustre2    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeletePartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeletePartitionedFile");

  SwiftTestUtils.writeDataset(fs, path, data, data.length, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 file still under " + ls, part_0002);
}
项目:hadoop-on-lustre2    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testSeekBigFile() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  assertEquals(0, instream.getPos());
  //expect that seek to 0 works
  instream.seek(0);
  int result = instream.read();
  assertEquals(0, result);
  assertEquals(1, instream.read());
  assertEquals(2, instream.read());

  //do seek 32KB ahead
  instream.seek(32768);
  assertEquals("@32768", block[32768], (byte) instream.read());
  instream.seek(40000);
  assertEquals("@40000", block[40000], (byte) instream.read());
  instream.seek(8191);
  assertEquals("@8191", block[8191], (byte) instream.read());
  instream.seek(0);
  assertEquals("@0", 0, (byte) instream.read());
}
项目:hadoop-on-lustre2    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPositionedBulkReadDoesntChangePosition() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  instream.seek(39999);
  assertTrue(-1 != instream.read());
  assertEquals (40000, instream.getPos());

  byte[] readBuffer = new byte[256];
  instream.read(128, readBuffer, 0, readBuffer.length);
  //have gone back
  assertEquals(40000, instream.getPos());
  //content is the same too
  assertEquals("@40000", block[40000], (byte) instream.read());
  //now verify the picked up data
  for (int i = 0; i < 256; i++) {
    assertEquals("@" + i, block[i + 128], readBuffer[i]);
  }
}
项目:sahara-extra    文件:TestSwiftFileSystemRename.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamedConsistence() throws IOException {
  assumeRenameSupported();
  describe("verify that overwriting a file with new data doesn't impact" +
          " the existing content");

  final Path filePath = new Path("/test/home/user/documents/file.txt");
  final Path newFilePath = new Path("/test/home/user/files/file.txt");
  mkdirs(newFilePath.getParent());
  int len = 1024;
  byte[] dataset = dataset(len, 'A', 26);
  byte[] dataset2 = dataset(len, 'a', 26);
  writeDataset(fs, filePath, dataset, len, len, false);
  rename(filePath, newFilePath, true, false, true);
  SwiftTestUtils.writeAndRead(fs, filePath, dataset2, len, len, false, true);
  byte[] dest = readDataset(fs, newFilePath, len);
  compareByteArrays(dataset, dest, len);
  String reread = readBytesToString(fs, newFilePath, 20);
}
项目:sahara-extra    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeleteSmallPartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeleteSmallPartitionedFile");

  final int len1 = 1024;
  final byte[] src1 = SwiftTestUtils.dataset(len1, 'A', 'Z');
  SwiftTestUtils.writeDataset(fs, path, src1, len1, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 found under " + ls, part_0002);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
}
项目:sahara-extra    文件:TestSwiftFileSystemPartitionedUploads.java   
@Test(timeout = SWIFT_BULK_IO_TEST_TIMEOUT)
public void testDeletePartitionedFile() throws Throwable {
  final Path path = new Path("/test/testDeletePartitionedFile");

  SwiftTestUtils.writeDataset(fs, path, data, data.length, 1024, false);
  assertExists("Exists", path);

  Path part_0001 = new Path(path, SwiftUtils.partitionFilenameFromNumber(1));
  Path part_0002 = new Path(path, SwiftUtils.partitionFilenameFromNumber(2));
  String ls = SwiftTestUtils.ls(fs, path);
  assertExists("Partition 0001 Exists in " + ls, part_0001);
  assertExists("Partition 0002 Exists in " + ls, part_0001);
  fs.delete(path, false);
  assertPathDoesNotExist("deleted file still there", path);
  ls = SwiftTestUtils.ls(fs, path);
  assertPathDoesNotExist("partition 0001 file still under " + ls, part_0001);
  assertPathDoesNotExist("partition 0002 file still under " + ls, part_0002);
}
项目:sahara-extra    文件:TestSeek.java   
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testSeekBigFile() throws Throwable {
  Path testSeekFile = new Path(testPath, "bigseekfile.txt");
  byte[] block = SwiftTestUtils.dataset(65536, 0, 255);
  createFile(testSeekFile, block);
  instream = fs.open(testSeekFile);
  assertEquals(0, instream.getPos());
  //expect that seek to 0 works
  instream.seek(0);
  int result = instream.read();
  assertEquals(0, result);
  assertEquals(1, instream.read());
  assertEquals(2, instream.read());

  //do seek 32KB ahead
  instream.seek(32768);
  assertEquals("@32768", block[32768], (byte) instream.read());
  instream.seek(40000);
  assertEquals("@40000", block[40000], (byte) instream.read());
  instream.seek(8191);
  assertEquals("@8191", block[8191], (byte) instream.read());
  instream.seek(0);
  assertEquals("@0", 0, (byte) instream.read());
}