private byte[] compressDecompressZlib(
      byte[] rawData, ZlibCompressor zlibCompressor, ZlibDecompressor zlibDecompressor)
      throws IOException {
    int cSize = 0;
    byte[] compressedByte = new byte[rawData.length];
    byte[] decompressedRawData = new byte[rawData.length];
    zlibCompressor.setInput(rawData, 0, rawData.length);
    zlibCompressor.finish();
    while (!zlibCompressor.finished()) {
      cSize = zlibCompressor.compress(compressedByte, 0, compressedByte.length);
    }
    zlibCompressor.reset();

    assertTrue(zlibDecompressor.getBytesWritten() == 0);
    assertTrue(zlibDecompressor.getBytesRead() == 0);
    assertTrue(zlibDecompressor.needsInput());
    zlibDecompressor.setInput(compressedByte, 0, cSize);
    assertFalse(zlibDecompressor.needsInput());
    while (!zlibDecompressor.finished()) {
      zlibDecompressor.decompress(decompressedRawData, 0, decompressedRawData.length);
    }
    assertTrue(zlibDecompressor.getBytesWritten() == rawData.length);
    assertTrue(zlibDecompressor.getBytesRead() == cSize);
    zlibDecompressor.reset();
    assertTrue(zlibDecompressor.getRemaining() == 0);
    assertArrayEquals(
        "testZlibCompressorDecompressorWithConfiguration array equals error",
        rawData,
        decompressedRawData);

    return decompressedRawData;
  }
  @Test
  public void testZlibCompressDecompress() {
    byte[] rawData = null;
    int rawDataSize = 0;
    rawDataSize = 1024 * 64;
    rawData = generate(rawDataSize);
    try {
      ZlibCompressor compressor = new ZlibCompressor();
      ZlibDecompressor decompressor = new ZlibDecompressor();
      assertFalse("testZlibCompressDecompress finished error", compressor.finished());
      compressor.setInput(rawData, 0, rawData.length);
      assertTrue(
          "testZlibCompressDecompress getBytesRead before error", compressor.getBytesRead() == 0);
      compressor.finish();

      byte[] compressedResult = new byte[rawDataSize];
      int cSize = compressor.compress(compressedResult, 0, rawDataSize);
      assertTrue(
          "testZlibCompressDecompress getBytesRead ather error",
          compressor.getBytesRead() == rawDataSize);
      assertTrue(
          "testZlibCompressDecompress compressed size no less then original size",
          cSize < rawDataSize);
      decompressor.setInput(compressedResult, 0, cSize);
      byte[] decompressedBytes = new byte[rawDataSize];
      decompressor.decompress(decompressedBytes, 0, decompressedBytes.length);
      assertArrayEquals(
          "testZlibCompressDecompress arrays not equals ", rawData, decompressedBytes);
      compressor.reset();
      decompressor.reset();
    } catch (IOException ex) {
      fail("testZlibCompressDecompress ex !!!" + ex);
    }
  }
  @Test(timeout = 10000)
  public void testRenameDirectory() throws IOException {
    Path srcPath = path("/tests3a/a");

    assertTrue(fs.mkdirs(srcPath));
    writeFile(new Path(srcPath, "b/testfile"), 1024);

    Path nonEmptyPath = path("/tests3a/nonempty");
    writeFile(new Path(nonEmptyPath, "b/testfile"), 1024);

    assertFalse(fs.rename(srcPath, nonEmptyPath));

    Path dstPath = path("/tests3a/b");
    assertTrue(fs.rename(srcPath, dstPath));
    assertFalse(fs.exists(srcPath));
    assertTrue(fs.exists(new Path(dstPath, "b/testfile")));
  }
  @Test(timeout = 1200000)
  public void testRenameFile() throws IOException {
    Path srcPath = path("/tests3a/a/srcfile");

    final OutputStream outputStream = fs.create(srcPath, false);
    generateTestData(outputStream, 11 * 1024 * 1024);
    outputStream.close();

    assertTrue(fs.exists(srcPath));

    Path dstPath = path("/tests3a/b/dstfile");

    assertFalse(fs.rename(srcPath, dstPath));
    assertTrue(fs.mkdirs(dstPath.getParent()));
    assertTrue(fs.rename(srcPath, dstPath));
    assertTrue(fs.exists(dstPath));
    assertFalse(fs.exists(srcPath));
    assertTrue(fs.exists(srcPath.getParent()));
  }
  @Test(timeout = 20000)
  public void testDelete() throws IOException {
    // Test deleting an empty directory
    assertTrue(fs.mkdirs(path("/tests3a/d")));
    assertTrue(fs.delete(path("/tests3a/d"), true));
    assertFalse(fs.exists(path("/tests3a/d")));

    // Test deleting a deep empty directory
    assertTrue(fs.mkdirs(path("/tests3a/e/f/g/h")));
    assertTrue(fs.delete(path("/tests3a/e/f/g"), true));
    assertFalse(fs.exists(path("/tests3a/e/f/g/h")));
    assertFalse(fs.exists(path("/tests3a/e/f/g")));
    assertTrue(fs.exists(path("/tests3a/e/f")));

    // Test delete of just a file
    writeFile(path("/tests3a/f/f/file"), 1000);
    assertTrue(fs.exists(path("/tests3a/f/f/file")));
    assertTrue(fs.delete(path("/tests3a/f/f/file"), false));
    assertFalse(fs.exists(path("/tests3a/f/f/file")));

    // Test delete of a path with files in various directories
    writeFile(path("/tests3a/g/h/i/file"), 1000);
    assertTrue(fs.exists(path("/tests3a/g/h/i/file")));
    writeFile(path("/tests3a/g/h/j/file"), 1000);
    assertTrue(fs.exists(path("/tests3a/g/h/j/file")));
    try {
      assertFalse(fs.delete(path("/tests3a/g/h"), false));
      fail("Expected delete to fail with recursion turned off");
    } catch (IOException e) {
    }
    assertTrue(fs.exists(path("/tests3a/g/h/j/file")));
    assertTrue(fs.delete(path("/tests3a/g/h"), true));
    assertFalse(fs.exists(path("/tests3a/g/h/j")));
  }