Example #1
0
  protected String getURI(String path) {
    String ret =
        String.format(
            "%s://%s:%d%s", cli.hasSsl() ? "https" : "http", cli.getHost(), cli.getPort(), path);

    logger.info(String.format("URI: %s", ret));

    return ret;
  }
Example #2
0
  private void run(String[] args) {
    try {
      cli = new CommandLineUtils(getClass());
      cli.useAllow().useBaseDir().useClient().useSync().useTimeZone();

      if (cli.parseArgs(args)) {
        if (cli.isHelp()) {
          cli.displayHelp();
        } else {
          blockSize = FileUtils.MIN_BLOCK_SIZE;

          RemoteClient remoteClient =
              RemoteClient.builder()
                  .ssl(cli.hasSsl())
                  .host(cli.getHost())
                  .port(cli.getPort())
                  .build();
          try {
            BlockReader localReader = new BlockReaderLocalImpl();
            BlockWriter localWriter = new BlockWriterLocalImpl();
            BlockReader remoteReader = new BlockReaderRemoteImpl(remoteClient);
            BlockWriter remoteWriter = new BlockWriterRemoteImpl(remoteClient);
            HashRequester remoteHasher = new HashRequesterRemoteImpl(remoteClient);
            DirectoryLister remoteLister = new DirectoryListerRemoteImpl(remoteClient);

            testMakeDirectory(remoteLister, REMOTE_PATH);

            for (int xx = 0; xx < 5; xx++) {
              File readFile = createTestFile(blockSize + rand.nextInt(blockSize * 5), 0);

              testCopyFile(
                  localReader,
                  readFile.getName(),
                  remoteWriter,
                  fileName,
                  readFile.getParentFile());

              testHash(remoteHasher, REMOTE_PATH);

              File writeFile = createTestFile();

              testCopyFile(
                  remoteReader,
                  fileName,
                  localWriter,
                  writeFile.getName(),
                  writeFile.getParentFile());

              assertTrue(
                  "Files different after copy local", FileUtils.compareFiles(writeFile, readFile));

              testListDirectory(remoteLister, REMOTE_PATH);

              testDeleteFile(remoteWriter, fileName, writeFile.getParentFile());

              readFile.delete();
              writeFile.delete();
            }

            testDeleteDirectory(remoteLister, REMOTE_PATH);
          } finally {
            remoteClient.finished();
          }
        }
      }
    } catch (Throwable ee) {
      logger.error(String.format("Error running test: %s", ee.getMessage()), ee);
    }
  }