protected void testFilesExists(
      HashMap<String, IFileStore> destMap,
      IFileStore sourceRoot,
      IFileStore sourceFile,
      int timeTolerance)
      throws CoreException {
    String relPath = EFSUtils.getRelativePath(sourceRoot, sourceFile, null);
    IFileStore destFile = destMap.get(relPath);
    // System.out.println("Comparing " + relPath);

    assertNotNull(MessageFormat.format("File {0} not found on destination", relPath), destFile);
    IFileInfo f1 = sourceFile.fetchInfo(IExtendedFileStore.DETAILED, null);
    IFileInfo f2 = destFile.fetchInfo(IExtendedFileStore.DETAILED, null);
    if (!f1.isDirectory()) {
      long sourceFileTime = f1.getLastModified();
      long destFileTime = f2.getLastModified();
      long timeDiff = destFileTime - sourceFileTime;

      assertTrue(
          MessageFormat.format(
              "File {0} is {1} seconds newer on destination", relPath, (int) timeDiff / 1000),
          -timeTolerance <= timeDiff && timeDiff <= timeTolerance);
      assertEquals(
          MessageFormat.format("File {0} different sizes", relPath),
          f1.getLength(),
          f2.getLength());
    }
  }
 protected void runGitTag(IFileStore basePath, String tag) {
   IStatus results =
       GitExecutable.instance()
           .runInBackground(new Path(EFSUtils.getAbsolutePath(basePath)), "checkout", "-b", tag);
   if (results == null || !results.isOK()) {
     fail("Git tag failed");
   }
 }
 protected void runGitClone(String url, IFileStore basePath, String directory) {
   IStatus results =
       GitExecutable.instance()
           .runInBackground(new Path(EFSUtils.getAbsolutePath(basePath)), "clone", url, directory);
   if (results == null || !results.isOK()) {
     fail("Git clone failed");
   }
 }
 protected void testFilesEqual(
     IFileStore root1, IFileStore root2, IFileStore file1, IFileStore file2) throws CoreException {
   String file1RelPath = EFSUtils.getRelativePath(root1, file1, null);
   String file2RelPath = EFSUtils.getRelativePath(root2, file2, null);
   assertEquals(
       MessageFormat.format("File {0} and {1} not equal", file1RelPath, file2RelPath),
       file1RelPath,
       file2RelPath);
   IFileInfo f1 = file1.fetchInfo(IExtendedFileStore.DETAILED, null);
   IFileInfo f2 = file2.fetchInfo(IExtendedFileStore.DETAILED, null);
   if (!f1.isDirectory()) {
     assertEquals(
         MessageFormat.format(
             "File {0} and {1} modification times differ", file1RelPath, file2RelPath),
         f1.getLastModified(),
         f2.getLastModified());
     assertEquals(
         MessageFormat.format("File {0} and {1} different sizes", file1RelPath, file2RelPath),
         f1.getLength(),
         f2.getLength());
   }
 }
  protected void testDirectoriesEqual(
      IFileStore root1, IFileStore root2, boolean includeCloakedFiles, int timeTolerance)
      throws CoreException {
    IFileStore[] ctd = EFSUtils.getFiles(root1, true, includeCloakedFiles);
    IFileStore[] ccd = EFSUtils.getFiles(root2, true, includeCloakedFiles);

    // create map of files on destination
    HashMap<String, IFileStore> map = new HashMap<String, IFileStore>();
    for (int i = 0; i < ccd.length; i++) {
      IFileStore fsTest = ccd[i];
      String fileRelPath = EFSUtils.getRelativePath(root2, fsTest, null);
      map.put(fileRelPath, fsTest);
    }

    assertEquals(ctd.length, ccd.length);

    // iterate through source and ensure all files made it to dest
    for (int i = 0; i < ctd.length; i++) {
      IFileStore fsControl = ctd[i];
      testFilesExists(map, root1, fsControl, timeTolerance);
    }
  }
Exemple #6
0
  public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    boolean result = false;

    if (receiver instanceof IResource) {
      IResource resource = (IResource) receiver;

      if (IS_FILTERED.equals(property)) {
        IFileStore fileStore = EFSUtils.getFileStore(resource);
        boolean expectedResult = toBoolean(expectedValue);

        result = (IndexFilterManager.getInstance().isFilteredItem(fileStore) == expectedResult);
      }
    }

    return result;
  }
  // @formatter:on
  public void syncTest(boolean includeCloakedFiles, long sysTime)
      throws IOException, CoreException {
    String CLIENT_TEST = "client_test";
    String CLIENT_CONTROL = "client_control";
    String SERVER_LOCAL = "server_local";
    String SERVER_TEST = "server_test";
    int timeTolerance = 60000;

    IFileStore clientTestDirectory =
        clientDirectory.getFileStore(new Path("/" + CLIENT_TEST + sysTime));
    IFileStore clientControlDirectory =
        clientDirectory.getFileStore(new Path("/" + CLIENT_CONTROL + sysTime));
    IFileStore serverLocalDirectory =
        clientDirectory.getFileStore(new Path("/" + SERVER_LOCAL + sysTime));
    IFileStore serverTestDirectory =
        serverDirectory.getFileStore(new Path("/" + SERVER_TEST + sysTime));
    serverTestDirectory.mkdir(EFS.NONE, null);

    // clone version x of github-services to local directory (newer)
    System.out.println(
        "1) Writing github repo to " + EFSUtils.getAbsolutePath(clientTestDirectory));
    runGitClone(
        "git://github.com/DmitryBaranovskiy/raphael.git",
        clientDirectory,
        clientTestDirectory.getName());

    System.out.println(
        "2) Writing github repo to " + EFSUtils.getAbsolutePath(serverLocalDirectory));
    runGitClone(
        "git://github.com/DmitryBaranovskiy/raphael.git",
        clientDirectory,
        serverLocalDirectory.getName());

    // checkout specific tags
    System.out.println("Checking out tag v1.4.0 on client_test");
    runGitTag(clientTestDirectory, "v1.4.0");

    System.out.println("Checking out tag v1.3.0 on server_local");
    runGitTag(serverLocalDirectory, "v1.3.0");

    System.out.println(
        "3) Copying github repo to " + EFSUtils.getAbsolutePath(clientControlDirectory));
    clientTestDirectory.copy(clientControlDirectory, EFS.OVERWRITE, null);

    Synchronizer syncManager = new Synchronizer(true, timeTolerance, includeCloakedFiles);
    syncManager.setLogger(
        new ILogger() {

          public void logWarning(String message, Throwable th) {
            System.out.println(message);
          }

          public void logInfo(String message, Throwable th) {
            System.out.println(message);
          }

          public void logError(String message, Throwable th) {
            System.out.println(message);
          }
        });

    System.out.println("4) upload from server_local to server_test");
    VirtualFileSyncPair[] items =
        syncManager.getSyncItems(
            clientManager, serverManager, serverLocalDirectory, serverTestDirectory, null);
    syncManager.upload(items, null);

    System.out.println("5) ensure local version matches remote version");
    testDirectoriesEqual(
        serverLocalDirectory, serverTestDirectory, includeCloakedFiles, timeTolerance);

    System.out.println(
        "6) test to make sure client_test and client_control are identical, as nothing should have changed locally");
    testDirectoriesEqual(
        clientTestDirectory, clientControlDirectory, includeCloakedFiles, timeTolerance);

    // Now get sync items between local and remote directories
    System.out.println("7) sync between client_test and server_test, deleting on remote");
    VirtualFileSyncPair[] items2 =
        syncManager.getSyncItems(
            clientManager, serverManager, clientTestDirectory, serverTestDirectory, null);
    syncManager.uploadAndDelete(items2, null);

    System.out.println(
        "8) test to make sure client_test and client_control are identical, as nothing should have changed locally");
    testDirectoriesEqual(
        clientTestDirectory, clientControlDirectory, includeCloakedFiles, timeTolerance);

    System.out.println("9) test to make sure client_test and server_test are identical after sync");
    testDirectoriesEqual(
        clientTestDirectory, serverTestDirectory, includeCloakedFiles, timeTolerance);
  }