Package org.syncany.tests.util

Examples of org.syncany.tests.util.TestClient


  @Test
  public void testFirstVersionDirty() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
   
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
   
    UpOperationOptions forceUpOperationOptions = new UpOperationOptions();
    forceUpOperationOptions.setForceUploadEnabled(true);
   
    // Run
    clientA.createNewFile("A-file1.jpg", 1*1024*1024);
    clientA.up(forceUpOperationOptions)
   
    Thread.sleep(200); // B's timestamp must be later
   
    TestFileUtil.copyFile(clientA.getLocalFile("A-file1.jpg"), clientB.getLocalFile("A-file1.jpg"));
    clientB.up(forceUpOperationOptions)

    // Client B loses   
    clientB.down()// <<<<<<< This used to throw all sorts of PRIMARY KEY CONSTRAINT errors
   
    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile());
    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile());
   
    TestAssertUtil.assertSqlDatabaseTablesEqual(clientA.getDatabaseFile(), clientB.getDatabaseFile(), new String[] {
      "chunk", "multichunk", "filecontent", "filecontent_chunk"
    });
   
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionB));   
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status='DIRTY'", databaseConnectionB));
   
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from filehistory", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from filehistory", databaseConnectionB));   
   
    assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("2", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));   

    // The table "multichunk_chunk" has 4 entries in B, but only 2 in A (!)
    // This is because the same file (= same chunks) are uploaded twice.
   
    // TODO [medium] The cleanup operation does not clean multichunks with redundant chunks, or does it?!
       
    assertEquals(
        2*Integer.parseInt(TestSqlUtil.runSqlSelect("select count(*) from multichunk_chunk", databaseConnectionA)),
        Integer.parseInt(TestSqlUtil.runSqlSelect("select count(*) from multichunk_chunk", databaseConnectionB)));   
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here


  @Test
  public void testEvilC() 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);
   
    // Run
    clientA.createNewFile("A1");
    clientA.upWithForceChecksum();
    clientA.moveFile("A1", "A2");
    clientA.upWithForceChecksum()
    clientA.changeFile("A2");
    clientA.createNewFile("A3");
    clientA.upWithForceChecksum();
    clientA.deleteFile("A3");
    clientA.upWithForceChecksum();
   
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    clientB.createNewFile("A4,B1");
    clientB.up();
   
    clientC.createNewFile("C1"); // Evil. "up" without "down"
    clientC.changeFile("C1");
    clientC.up();
    clientC.changeFile("C1");
    clientC.up();
    clientC.changeFile("C1");
    clientC.up();
   
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    Map<String, File> beforeSyncDownBFileList = clientB.getLocalFilesExcludeLockedAndNoRead();
    clientB.down();
    assertFileListEquals("No change in file lists expected. Nothing changed for 'B'.", beforeSyncDownBFileList, clientB.getLocalFilesExcludeLockedAndNoRead());
       
    clientC.down();
    assertEquals("Client C is expected to have one more local file (C1)", clientA.getLocalFilesExcludeLockedAndNoRead().size()+1, clientC.getLocalFilesExcludeLockedAndNoRead().size());
   
    clientA.up();
    clientB.up();
    clientC.up();
   
    clientA.down();
    clientB.down();
    clientC.down();   
   
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());   
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
  }
View Full Code Here

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

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMergeRemoteFiles(false);
    options.setRemoveOldVersions(true);
    options.setKeepVersionsCount(2);

    // Run

    // A: Create some file versions
    clientA.createNewFile("someotherfile.jpg"); // These two files' chunks will be in one multichunk
    clientA.createNewFile("file.jpg"); // Only one of the chunks will be needed after cleanup!
                      // The multichunk will be 50% useless
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    clientA.createNewFile("otherfile.txt");
    for (int i = 1; i <= 3; i++) {
      clientA.changeFile("otherfile.txt");
      clientA.upWithForceChecksum();
    }

    clientA.createNewFile("deletedfile.txt");
    for (int i = 1; i <= 3; i++) {
      clientA.changeFile("deletedfile.txt");
      clientA.upWithForceChecksum();
    }
    clientA.deleteFile("deletedfile.txt");
    clientA.upWithForceChecksum();

    java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile());
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
    assertEquals("10", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionA));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionA));

    // B: Sync down by other client
    clientB.down();

    java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile());
    assertEquals("12", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionB));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionB));
    assertEquals("10", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionB));
    assertEquals("11", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionB));
    assertEquals("4", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionB));

    // A: Cleanup this mess (except for two) <<<< This is the interesting part!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(5, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(3, cleanupOperationResult.getRemovedOldVersionsCount());

    // 2 versions for "file.jpg", 2 versions for "otherfile.txt" and one version for "someotherfile.jpg"
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
    assertEquals("7", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='file.jpg'", databaseConnectionA)); // 3+4
    assertEquals("5", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='otherfile.txt'", databaseConnectionA)); // 2+3
    assertEquals("1", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='someotherfile.jpg'", databaseConnectionA));

    // 5 chunks remain; one was obsolete so we removed it!
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));

    // 6 chunks in 5 multichunks
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
    assertEquals("5", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionA));
    assertEquals("3", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionA));

    // Test the repo
    assertEquals(5, new File(testConnection.getPath() + "/multichunks/").list().length);
    assertEquals(12, new File(testConnection.getPath() + "/databases/").list().length);

    // B: Sync down cleanup
    clientB.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());

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

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

    StatusOperationOptions statusOptions = new StatusOperationOptions();
    statusOptions.setForceChecksum(true);

    CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
    cleanupOptions.setStatusOptions(statusOptions);
    cleanupOptions.setMergeRemoteFiles(false);
    cleanupOptions.setRemoveOldVersions(true);
    cleanupOptions.setKeepVersionsCount(2);

    // Run

    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    // B: Sync down, add something
    clientB.down();

    clientB.changeFile("file.jpg");

    CleanupOperationResult cleanupOperationResult = clientB.cleanup(cleanupOptions);
    assertEquals(CleanupResultCode.NOK_LOCAL_CHANGES, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());

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

 
  @Test
  public void testCallUpWhileDeletingFiles() throws Exception {
    // Setup
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("A", testConnection);
    final TestClient clientB = new TestClient("B", testConnection);
    final int numFiles = 100;
    final int numFilesVanished = 50;
    final int numFilesRemaining = numFiles - numFilesVanished;
    final int sizeFiles = 500*1024;
   
    // Prepare by creating test files
    logger.log(Level.INFO, "Creating test files ...");
   
    for (int i=0; i<=numFiles; i++) {
      clientA.createNewFile("A-original"+i, sizeFiles);
    }
   
    // Prepare threads (delete & run up)
    Thread deleteFilesThread = new Thread(new Runnable() {
      @Override
      public void run() {
        for (int i=numFiles; i>=numFilesVanished; i--) {
          boolean deleteSuccess = clientA.deleteFile("A-original"+i);
         
          if (deleteSuccess) {
            logger.log(Level.SEVERE, "Deleted "+clientA.getLocalFile("A-original"+i));
          }
          else {
            logger.log(Level.SEVERE, "FAILED TO DELETE FILE "+clientA.getLocalFile("A-original"+i));
          }
         
          try { Thread.sleep(50); }
          catch (Exception e) { }
        }
      }     
    }, "A-delete");
   
    Thread runUpThread = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          Thread.sleep(40);
          clientA.up();
        }
        catch (Exception e) {
          e.printStackTrace();
          fail(e.getMessage());
        }       
      }     
    }, "A-up");
   
    // Before we start: init database (this takes a while)
    clientA.status();
    clientB.status();
   
    // Delete files and run up simultaneously
    // --> This will hopefully lead to a couple of 'vanished' files
    logger.log(Level.INFO, "Starting 'up' thread ...");   
    runUpThread.start();

    logger.log(Level.INFO, "Starting 'delete' thread ...");
    deleteFilesThread.start();   
   
    runUpThread.join();
    deleteFilesThread.join();
   
    // Test 1: There should be between 50 and 100 file histories in the database
    SqlDatabase databaseClientA = clientA.loadLocalDatabase();
   
    assertTrue("There should be less file histories than originally added files.", databaseClientA.getFileHistoriesWithFileVersions().size() < numFiles);
    assertTrue("There should be more (or equal size) file histories than files there are.", databaseClientA.getFileHistoriesWithFileVersions().size() >= numFilesRemaining);
   
    // Test 2: Now up the rest, there should be exactly 50 files in the database
    clientA.up();
    clientA.cleanup();
   
    databaseClientA = clientA.loadLocalDatabase();
    assertEquals("There should be EXACTLY "+numFilesRemaining+" file histories in the database.", numFilesRemaining, databaseClientA.getFileHistoriesWithFileVersions().size());
   
    // Test 3: After that, the sync between the clients should of course still work
    clientB.down();
    assertFileListEquals("Files of both clients should be identical.", clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());       
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
  }
View Full Code Here

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

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMergeRemoteFiles(false);
    options.setRemoveOldVersions(true);
    options.setKeepVersionsCount(2);

    // Run

    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    // B: Sync down, add something
    clientB.down();

    // A: Add something
    clientA.changeFile("file.jpg");
    clientA.upWithForceChecksum();

    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(options);
    assertEquals(CleanupResultCode.NOK_REMOTE_CHANGES, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());

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

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

    // A
    clientA.createNewFolder("folder1");   
    clientA.up();

    // B
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    // A
    clientA.createNewFile("folder1/file1")
    clientA.up();
   
    // B
    clientB.deleteFile("folder1");
    assertFalse(clientB.getLocalFile("folder1").exists());
   
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
   
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
 
View Full Code Here

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

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMergeRemoteFiles(false);
    options.setRemoveOldVersions(true);
    options.setKeepVersionsCount(10); // <<<<<< Different!

    // Run

    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    // B: Sync down, add something
    clientB.down();

    // B: Cleanup
    CleanupOperationResult cleanupOperationResult = clientB.cleanup(options);
    assertEquals(CleanupResultCode.OK_NOTHING_DONE, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(0, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());

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

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

    CleanupOperationOptions options = new CleanupOperationOptions();
    options.setMergeRemoteFiles(false);
    options.setRemoveOldVersions(true);
    options.setKeepVersionsCount(2);

    // Run

    // A: Create some file versions
    clientA.createNewFile("file.jpg");
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    // B: Sync down
    clientB.down();

    // A: Cleanup
    CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
    assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
    assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
    assertEquals(2, cleanupOperationResult.getRemovedMultiChunks().size());
    assertEquals(1, cleanupOperationResult.getRemovedOldVersionsCount());

    // A: Continue to upload stuff ! <<<<<<<<<<<<<<<<<<<<<
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file.jpg");
      clientA.upWithForceChecksum();
    }

    clientA.createNewFile("file2.jpg");
    for (int i = 1; i <= 4; i++) {
      clientA.changeFile("file2.jpg");
      clientA.upWithForceChecksum();
    }

    // B: Sync down
    clientB.down();
    TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());

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

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

    // Run
   
    // Prepare, create file at A, sync it to B
    clientA.createNewFile("A-file1");
    clientA.sync();   
    clientB.sync();
       
    // Now move file, and sync
    clientA.moveFile("A-file1", "A-file-moved1");
    clientA.up();
   
    DownOperationResult downOperationResult = clientB.down();   
    assertEquals("No multichunks should have been downloaded.", 0, downOperationResult.getDownloadedMultiChunks().size());
    assertTrue("Moved files should exist.", clientB.getLocalFile("A-file-moved1").exists());   
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
   
    // 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.