Package org.syncany.tests.util

Examples of org.syncany.tests.util.TestClient


            // Make fourth upload fail
            "rel=(8|9|10) .+upload" // << 3 retries!!
        }
            ));

    TestClient clientA = new TestClient("A", testConnection);

    int i = 0;
    while (i++ < 5) {
      clientA.createNewFile("A-original-" + i, 50 * 1024);

      try {
        Thread.sleep(100);
        clientA.up();
        clientA.down();
      }
      catch (StorageException e) {
        logger.log(Level.INFO, e.getMessage());
      }
    }

    assertTrue(new File(testConnection.getPath() + "/databases/database-A-0000000001").exists());
    assertTrue(new File(testConnection.getPath() + "/databases/database-A-0000000002").exists());
    assertTrue(new File(testConnection.getPath() + "/databases/database-A-0000000003").exists());
    assertFalse(new File(testConnection.getPath() + "/databases/database-A-0000000004").exists());
    assertFalse(new File(testConnection.getPath() + "/databases/database-A-0000000005").exists());

    // Tear down
    clientA.deleteTestData();
  }
View Full Code Here


 
  @Test
  public void testFolderNonEmptyMove1NoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);

    // Create files and upload
    clientA.createNewFolder("folder");   
    clientA.createNewFile("folder/file");
    clientA.up();
   
    clientB.down();
    clientB.moveFile("folder", "moved");
    clientB.up();
     
    clientA.down();
    assertFalse("Deleted folder should not exist.", clientA.getLocalFile("folder").exists());
    assertFalse("Deleted file should not exist.", clientA.getLocalFile("folder/file").exists());
    assertFileEquals(clientA.getLocalFile("moved"), clientB.getLocalFile("moved"));
    assertFileEquals(clientA.getLocalFile("moved/file"), clientB.getLocalFile("moved/file"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
  }   
View Full Code Here

            ".+upload.+multichunk",
        }
            ));

    TestClient clientA = new TestClient("A", testConnection);

    clientA.createNewFile("A-original", 10);

    boolean upFailed = false;

    try {
      clientA.up();
    }
    catch (StorageException e) {
      upFailed = true;
      logger.log(Level.INFO, e.getMessage());
    }

    assertTrue(upFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);

    assertEquals(2, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("database-"));

    // Tear down
    clientA.deleteTestData();
  }
View Full Code Here

 
  @Test
  public void testFolderNonEmptyMove2NoConflicts() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);

    // Create files and upload
    clientA.createNewFolder("folder");   
    clientA.createNewFile("folder/file");
    clientA.createNewFolder("folder/folder2");
    clientA.createNewFile("folder/folder2/file2");
    clientA.up();
   
    clientB.down();
    clientB.moveFile("folder", "moved");
    clientB.up();
     
    clientA.down();
    assertFalse("Deleted folder should not exist.", clientA.getLocalFile("folder").exists());
    assertFalse("Deleted file should not exist.", clientA.getLocalFile("folder/file").exists());
    assertFileEquals(clientA.getLocalFile("moved"), clientB.getLocalFile("moved"));
    assertFileEquals(clientA.getLocalFile("moved/file"), clientB.getLocalFile("moved/file"));
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    // Cleanup
    clientA.deleteTestData();
    clientB.deleteTestData();
  }     
View Full Code Here

            "rel=[456].+upload.+database",
        }
            ));

    TestClient clientA = new TestClient("A", testConnection);

    // 1. First upload fails
    clientA.createNewFile("A-original", 10);

    boolean upFailed = false;

    try {
      clientA.up();
    }
    catch (StorageException e) {
      upFailed = true;
      logger.log(Level.INFO, e.getMessage());
    }

    assertTrue(upFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    assertEquals(1, new File(testConnection.getPath() + "/temporary/").listFiles().length);

    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);

    assertEquals(2, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("database-"));

    // 2. Second try succeeds and must clean up the transactions
    clientA.up();

    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);

    // Tear down
    clientA.deleteTestData();
  }
View Full Code Here

            "rel=[456].+upload.+multichunk",
        }
            ));

    TestClient clientA = new TestClient("A", testConnection);

    clientA.createNewFile("A-original", 5 * 1024 * 1024); // << larger than one multichunk!

    boolean upFailed = false;

    try {
      clientA.up();
    }
    catch (StorageException e) {
      upFailed = true;
      logger.log(Level.INFO, e.getMessage());
    }

    assertTrue(upFailed);
    assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    File[] tempFiles = new File(testConnection.getPath() + "/temporary/").listFiles();

    assertEquals(1, tempFiles.length);
    assertTrue(tempFiles[0].length() > 500 * 1024); // 1 MC with 1 MB, 1 with 4 MB; must be larger than 500 KB

    File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
    TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);

    assertEquals(3, transactionTO.getActions().size());
    assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("multichunk-"));
    assertTrue(transactionTO.getActions().get(2).getRemoteFile().getName().contains("database-"));

    // 2. Second try succeeds and must clean up the transactions
    clientA.up();

    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(2, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);

    assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);

    // Tear down
    clientA.deleteTestData();
  }
View Full Code Here

  @Test
  public void testDirtyDatabase() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    // Run
    UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
    upOptionsForceEnabled.setForceUploadEnabled(true);
   
    clientA.createNewFile("A-file1.jpg", 50*1024);
    clientA.up(upOptionsForceEnabled);
       
    clientB.createNewFile("A-file1.jpg", 51*1024);
    clientB.up(upOptionsForceEnabled);
   
    clientB.down(); // This creates a dirty database       
   
    // Test (for dirty database existence)
    Config configB = clientB.getConfig();
    java.sql.Connection databaseConnectionB = configB.createDatabaseConnection();

    ChunkSqlDao chunkDao = new ChunkSqlDao(databaseConnectionB);
    MultiChunkSqlDao multiChunkDao = new MultiChunkSqlDao(databaseConnectionB);
    FileVersionSqlDao fileVersionDao = new FileVersionSqlDao(databaseConnectionB);
    FileHistorySqlDao fileHistoryDao = new FileHistorySqlDao(databaseConnectionB, fileVersionDao);
    FileContentSqlDao fileContentDao = new FileContentSqlDao(databaseConnectionB);
    DatabaseVersionSqlDao databaseVersionDao = new DatabaseVersionSqlDao(databaseConnectionB, chunkDao, fileContentDao, fileVersionDao, fileHistoryDao, multiChunkDao);
   
    Iterator<DatabaseVersion> databaseVersionsDirtyB = databaseVersionDao.getDirtyDatabaseVersions();
    List<DatabaseVersion> databaseVersionsDirtyListB = TestCollectionUtil.toList(databaseVersionsDirtyB);
   
    assertEquals(1, databaseVersionsDirtyListB.size());
   
    DatabaseVersion dirtyDatabaseVersionB = databaseVersionsDirtyListB.get(0);
    assertNotNull(dirtyDatabaseVersionB);
    assertEquals(1, dirtyDatabaseVersionB.getFileHistories().size());
   
    PartialFileHistory fileHistoryFile1B = dirtyDatabaseVersionB.getFileHistories().iterator().next();   
    assertNotNull(fileHistoryFile1B);
    assertEquals(1, fileHistoryFile1B.getFileVersions().size());
    assertEquals("A-file1.jpg", fileHistoryFile1B.getLastVersion().getPath());
       
    assertFileEquals(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
    assertConflictingFileExists("A-file1.jpg", clientB.getLocalFilesExcludeLockedAndNoRead());   
   
    // Run (part 2)
    clientB.up(); // This deletes the dirty database file
   
    Iterator<DatabaseVersion> databaseVersionsDirtyB2 = databaseVersionDao.getDirtyDatabaseVersions();
    List<DatabaseVersion> databaseVersionsDirtyListB2 = TestCollectionUtil.toList(databaseVersionsDirtyB2);
   
    assertEquals(0, databaseVersionsDirtyListB2.size());

    // Run (part 3)
    clientA.down(); // This pulls down the conflicting file
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    assertConflictingFileExists("A-file1.jpg", clientA.getLocalFilesExcludeLockedAndNoRead());
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

  @Test
  public void testDirtyCleanupDirty() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    TestClient clientD = new TestClient("D", testConnection);
 
    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);
   
    UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
    upOptionsForceEnabled.setStatusOptions(statusOptions);
    upOptionsForceEnabled.setForceUploadEnabled(true);
   
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);

    // Run
   
    //// 1. CREATE FIRST DIRTY VERSION
   
    clientA.createNewFile("A-file1.jpg", 50*1024);
    clientA.up(upOptionsForceEnabled); // (A1)
   
    clientB.down();
    clientB.changeFile("A-file1.jpg");;
    clientB.up(upOptionsForceEnabled); // (A1,B1)
       
    clientA.down();
   
    clientA.changeFile("A-file1.jpg")// conflict (winner)
    clientA.up(upOptionsForceEnabled); // (A2,B1)
   
    clientB.changeFile("A-file1.jpg"); // conflict (loser)
    clientB.up(upOptionsForceEnabled);
   
    clientA.createNewFolder("new folder at A"); // don't care about the conflict, just continue
    clientA.up(upOptionsForceEnabled); // (A3,B1)
   
    clientB.createNewFolder("new folder at B"); // don't care about the conflict, just continue
    clientB.up(upOptionsForceEnabled);
   
    clientA.down(); // resolve conflict (wins, no DIRTY)
   
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile());
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
   
    clientB.down(); // resolve conflict (loses, creates DIRTY version)
   
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile());
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
    assertEquals("(A1,B2)\n(A1,B3)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status='DIRTY' order by id", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionB));
   
    StatusOperationResult statusResultBAfterDirty = clientB.status();
    assertNotNull(statusResultBAfterDirty);
   
    ChangeSet changeSetBAfterDirty = statusResultBAfterDirty.getChangeSet();   
    assertEquals(2, changeSetBAfterDirty.getNewFiles().size());
    TestAssertUtil.assertConflictingFileExists("A-file1.jpg", clientB.getLocalFiles());
   
    clientB.up(upOptionsForceEnabled); // (A3,B2)
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
   
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA)); // (A1), (A1,B1), (A2,B1), (A3,B1)
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionA));
   
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));

   
    //// 2. NOW THAT CLIENT B RESOLVED IT, A GETS DIRTY
   
    clientA.changeFile("A-file1.jpg"); // No 'down'! This version will become DIRTY
    clientA.createNewFile("dirty1");
    clientA.up(upOptionsForceEnabled);
   
    clientA.changeFile("A-file1.jpg"); // No 'down'! This version will become DIRTY
    clientA.createNewFile("dirty2");
    clientA.up(upOptionsForceEnabled);
   
    clientA.changeFile("A-file1.jpg"); // No 'down'! This version will become DIRTY
    clientA.createNewFile("dirty3");
    clientA.up(upOptionsForceEnabled);
   
    clientA.changeFile("A-file1.jpg"); // No 'down'! This version will become DIRTY
    clientA.createNewFile("dirty4");
    clientA.up(upOptionsForceEnabled);
   
    clientA.changeFile("A-file1.jpg"); // No 'down'! This version will become DIRTY
    clientA.createNewFile("dirty5");
    clientA.up(upOptionsForceEnabled);
   
    clientA.changeFile("A-file1.jpg"); // No 'down'! This version will become DIRTY
    clientA.createNewFile("dirty6");
    clientA.up(upOptionsForceEnabled);
   
    clientA.changeFile("A-file1.jpg"); // No 'down'! This version will become DIRTY
    clientA.createNewFile("dirty7");
    clientA.up(upOptionsForceEnabled);
   
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

    clientA.down();
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("7", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion where status<>'DIRTY' order by id", databaseConnectionA));
   
    clientB.down(); // Does nothing; A versions lose against (A3,B2) // same as above!
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));
    assertEquals("(A1)\n(A1,B1)\n(A2,B1)\n(A3,B1)\n(A3,B4)", TestSqlUtil.runSqlSelect("select vectorclock_serialized from databaseversion order by id", databaseConnectionB));
   

    //// 3. NEW CLIENT JOINS
   
    clientC.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientB.getDatabaseFile(), clientC.getDatabaseFile());
   

    //// 4. FORCE MERGE DATABASES ON CLIENT A
   
    clientA.deleteFile("dirty1");
    clientA.deleteFile("dirty2");
   
    clientA.up(upOptionsForceEnabled); // upload DIRTY version
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("0", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionA));
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
   
    clientA.createNewFile("A-file2.jpg");

    int numberOfDatabaseVersions = 6;
    int cleanupEveryXUps = 7; // For every X up's call 'cleanup' ("X" is larger than the max. length of file versions in a history)
   
    for (int i=1; i<=21; i++) {
      clientA.changeFile("A-file2.jpg");
     
      clientA.up(upOptionsForceEnabled);
      numberOfDatabaseVersions++;
         
      if (i % cleanupEveryXUps == 0) {
        clientA.cleanup(cleanupOptions);
        numberOfDatabaseVersions++;

        assertEquals(""+numberOfDatabaseVersions, TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
      }
      else {
        assertEquals(""+numberOfDatabaseVersions, TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
      }
    }
   
    clientA.cleanup(cleanupOptions);
   
    clientB.down();
    clientC.down();
    clientD.down();
   
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientD.getDatabaseFile());   
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
    clientD.deleteTestData();
  }
View Full Code Here

   * This is one single test to prevent issues with parallelism. (Occupied ports, EventBus mixups etc.)
   */
  @Test
  public void testWatchServer() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();   
    final TestClient clientA = new TestClient("ClientA", testConnection);
    final TestClient clientB = new TestClient("ClientB", testConnection);
    int port = 58443;
   
    // Load config template
    DaemonConfigTO daemonConfig = TestDaemonUtil.loadDaemonConfig("daemonTwoFoldersNoWebServer.xml");
   
    // Set port to prevent conflicts with default daemons
    daemonConfig.getWebServer().setBindPort(port);
   
    // Dynamically insert paths
    daemonConfig.getFolders().get(0).setPath(clientA.getConfig().getLocalDir().getAbsolutePath());
    daemonConfig.getFolders().get(1).setPath(clientB.getConfig().getLocalDir().getAbsolutePath());
   
    // Create access token (not needed in this test, but prevents errors in daemon)
    daemonConfig.setPortTO(TestDaemonUtil.createPortTO(port));
     
    // Create watchServer
    WatchServer watchServer = new WatchServer();
   
    clientA.createNewFile("file-1");
    watchServer.start(daemonConfig);
   
    for (int i = 0; i < 20; i++) {
      if (clientB.getLocalFile("file-1").exists()) {
        break;
      }
     
      Thread.sleep(1000);
    }
   
    assertTrue("File has not synced to clientB", clientB.getLocalFile("file-1").exists());
    assertEquals(clientA.getLocalFile("file-1").length(), clientB.getLocalFile("file-1").length());
     
    registerWithBus();
   
    // Create watchServer
    clientA.createNewFolder("folder");
    clientA.createNewFile("folder/file-2");
   
    // Allow server to settle
    Thread.sleep(100);
   
    // Repeat request until 3 files are found.
    FileVersion[] files = null;
   
    for (int i = 0; i < 20; i++) {
      LsFolderRequest request = new LsFolderRequest();
      LsOperationOptions lsOperationOption = new LsOperationOptions();
     
      request.setId(i);
      request.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
      request.setOptions(lsOperationOption);
      eventBus.post(request);
     
      Response response = waitForResponse(i);
     
      assertTrue(response instanceof LsFolderResponse);
      LsFolderResponse treeResponse = (LsFolderResponse) response;
     
      files = treeResponse.getResult().getFileTree().values().toArray(new FileVersion[]{});
     
      if (files.length == 2) {
        break;
      }
     
      if (i == 19) {
        assertEquals(2, files.length);
      }
      else {
        Thread.sleep(1000);
      }
    }
   
    if (files[0].getName().equals("folder")) {
      files = new FileVersion[]{files[1], files[0]};
    }

    assertEquals(clientA.getLocalFile("file-1").getName(), files[0].getName());
    assertEquals(clientA.getLocalFile("file-1").length(), (long) files[0].getSize());

    assertEquals(clientA.getLocalFile("folder").getName(), files[1].getName());
    assertTrue(clientA.getLocalFile("folder").isDirectory());
    assertEquals(files[1].getType(), FileVersion.FileType.FOLDER);

    // Create GetFileHistoryRequest for the first returned file
    GetFileHistoryFolderRequest request = new GetFileHistoryFolderRequest();
    request.setId(21);
    request.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    request.setFileHistoryId(files[0].getFileHistoryId().toString());
   
    eventBus.post(request);
   
    Response response = waitForResponse(21);
    assertTrue(response instanceof GetFileHistoryFolderResponse);
    GetFileHistoryFolderResponse fileHistoryResponse = (GetFileHistoryFolderResponse) response;
    assertEquals(1, fileHistoryResponse.getFiles().size());
    assertEquals(files[0], fileHistoryResponse.getFiles().get(0));
   
    // Create GetFileRequest for the first returned file
    GetFileFolderRequest getFileRequest = new GetFileFolderRequest();
    getFileRequest.setId(22);
    getFileRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    getFileRequest.setFileHistoryId(files[0].getFileHistoryId().toString());
    getFileRequest.setVersion(1);   
       
    eventBus.post(getFileRequest);
   
    int i = 0;
    while (internalResponse == null && i < 40) {
      Thread.sleep(100);
      i++;
    }
   
    assertEquals((long)files[0].getSize(), internalResponse.getTempFile().length());
   
    // Cli Requests
    clientA.copyFile("file-1", "file-1.bak");
   
    // CLI request while running.
    StatusFolderRequest statusRequest = new StatusFolderRequest();
    StatusOperationOptions statusOperationOption = new StatusOperationOptions();
    statusOperationOption.setForceChecksum(true);
   
    statusRequest.setId(30);
    statusRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    statusRequest.setOptions(statusOperationOption);
   
    // Create big file to trigger sync
    clientA.createNewFile("bigfileforlongsync", 5000);

    // ^^ Now sync should start and we send 'status' requests
    boolean syncRunningMessageReceived = false;
   
    for (i = 30; i < 50; i++) {
      statusRequest.setId(i);
      eventBus.post(statusRequest);
     
      response = waitForResponse(i);
     
      if (response instanceof AlreadySyncingResponse) {
        syncRunningMessageReceived = true;
        break;
      }     
     
      Thread.sleep(200);
    }
   
    assertTrue(syncRunningMessageReceived);
   
    // Allow daemon to sync
   
    Thread.sleep(10000);
    for (i = 50; i < 60; i++) {
      statusRequest.setId(i);
      eventBus.post(statusRequest);
     
      response = waitForResponse(i);
     
      if (response instanceof StatusFolderResponse) {
        break;
      }
     
      Thread.sleep(1000);
    }   
   
    assertNotNull(response);
    //assertEquals("No local changes.\n", cliResponse.getOutput());
   
    // Restore file test
   
    RestoreFolderRequest restoreRequest = new RestoreFolderRequest();
    RestoreOperationOptions restoreOperationOption = new RestoreOperationOptions();
    restoreOperationOption.setFileHistoryId(files[0].getFileHistoryId());
    restoreOperationOption.setFileVersion(1);
   
    restoreRequest.setId(70);
    restoreRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    restoreRequest.setOptions(restoreOperationOption);
   
    eventBus.post(restoreRequest);
   
    response = waitForResponse(70);
   
    assertTrue(response instanceof RestoreFolderResponse);
    RestoreFolderResponse restoreResponse = (RestoreFolderResponse) response;
   
    byte[] copyChecksum = FileUtil.createChecksum(clientA.getLocalFile("file-1.bak"), "SHA1");
    byte[] restoreChecksum = FileUtil.createChecksum(restoreResponse.getResult().getTargetFile(), "SHA1");
   
    assertArrayEquals(copyChecksum, restoreChecksum);
    watchServer.stop();
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

  @Test
  public void testChangeAttributes() throws Exception {   
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();   
   
    TestClient clientA = new TestClient("A", testConnection);
    java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
   
    TestClient clientB = new TestClient("B", testConnection);
   
    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setMinSecondsBetweenCleanups(0);

    // Scenario, see
    // https://github.com/syncany/syncany/issues/143#issuecomment-50964685
   
    // Run
    clientA.createNewFile("file1.jpg");
    clientA.upWithForceChecksum();
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

    TestFileUtil.copyFile(clientA.getLocalFile("file1.jpg"), clientA.getLocalFile("file1 (copy).jpg"));
    clientA.upWithForceChecksum();
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

    clientA.deleteFile("file1 (copy).jpg");
    clientA.upWithForceChecksum();
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
   
    clientA.cleanup(cleanupOptions); // Creates PURGE database version with deleted file
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

    TestFileUtil.copyFile(clientA.getLocalFile("file1.jpg"), clientA.getLocalFile("file1 (copy).jpg"));
    clientA.upWithForceChecksum();
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
   
    clientA.deleteFile("file1.jpg");
    clientA.upWithForceChecksum();
    assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
   
    clientA.cleanup(cleanupOptions); // Creates PURGE database version with deleted file
    assertEquals("7", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
       
    clientB.down(); // <<<< This creates the exception in #143
                    // integrity constraint violation: foreign key no parent; SYS_FK_10173 table: FILEVERSION
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
 
View Full Code Here

TOP

Related Classes of org.syncany.tests.util.TestClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.