use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedFile.
@Test
public void testRestoreDeletedFile() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFile("A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
File deletedFile = new File(tempDir, "A-original-DELETED");
FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
clientA.upWithForceChecksum();
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("A-original (restored version 1)").exists());
assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-original (restored version 1)"))));
assertEquals(deletedFile.lastModified(), clientA.getLocalFile("A-original (restored version 1)").lastModified());
assertEquals(deletedFile.length(), clientA.getLocalFile("A-original (restored version 1)").length());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedWithSubfolders.
@Test
public void testRestoreDeletedWithSubfolders() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFolder("folder/subfolder");
clientA.createNewFile("folder/subfolder/A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion where path='folder/subfolder/A-original'", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
FileUtils.deleteDirectory(clientA.getLocalFile("folder"));
clientA.upWithForceChecksum();
assertFalse(clientA.getLocalFile("folder").exists());
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("folder/subfolder").exists());
assertTrue(clientA.getLocalFile("folder/subfolder/A-original (restored version 1)").exists());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class Issue316ScenarioTest method testIssue316CleanupThenDeleteFileButLocalFileChanged.
@Test
public void testIssue316CleanupThenDeleteFileButLocalFileChanged() throws Exception {
/*
* Same test as above, but local file has changed at client B.
*/
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
"rel=(5|6|7) .+download.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
cleanupOptionsKeepOne.setMaxDatabaseFiles(1);
cleanupOptionsKeepOne.setForce(true);
clientA.createNewFile("Kazam_screencast_00010.mp4");
clientA.upWithForceChecksum();
clientB.down();
assertTrue(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
// <<<<<<<<< Different from above test
clientB.changeFile("Kazam_screencast_00010.mp4");
clientA.createNewFile("SomeFileTOIncreaseTheDatabaseFileCount");
clientA.upWithForceChecksum();
CleanupOperationResult cleanupResult = clientA.cleanup(cleanupOptionsKeepOne);
assertEquals(CleanupResultCode.OK, cleanupResult.getResultCode());
clientA.deleteFile("Kazam_screencast_00010.mp4");
clientA.upWithForceChecksum();
// First 'down' of client B after the cleanup.
// This fails AFTER the local database was wiped.
boolean downFailedAtB = false;
try {
clientB.down();
} catch (Exception e) {
downFailedAtB = true;
}
assertTrue("Down operation should have failed.", downFailedAtB);
// Second 'down' of client B; This should delete the file 'Kazam_screencast_00010.mp4',
// because it matches the checksum of the 'DELETED' entry
clientB.down();
// <<<<<<<<< Different from above test
assertConflictingFileExists("Kazam_screencast_00010.mp4", clientB.getLocalFiles());
assertFalse(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
// Tear down
clientB.deleteTestData();
clientA.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class Issue374Pre1965DateScenarioTest method testIssue316CleanupThenDeleteFile.
@Test
public void testIssue316CleanupThenDeleteFile() throws Exception {
/*
* This test simulates files with a timestamp before 1965 (unix time < 0).
*/
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
clientA.createNewFile("pre1965.txt");
Date dateBefore1965 = new SimpleDateFormat("dd-MM-yyyy").parse("31-12-1964");
Files.setLastModifiedTime(clientA.getLocalFile("pre1965.txt").toPath(), FileTime.fromMillis(dateBefore1965.getTime()));
clientA.upWithForceChecksum();
// This was throwing an exception in FileSystemAction.setLastModified()
clientB.down();
// Tear down
clientB.deleteTestData();
clientA.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class Issue429ScenarioTest method testSameFileDifferentNameFuzzy.
@Ignore
public void testSameFileDifferentNameFuzzy() throws Exception {
for (int seed = 0; seed < 1000; seed++) {
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
Random randomA = new Random(2 * seed);
Random randomB = new Random(2 * seed + 1);
Queue<String> queue = new ConcurrentLinkedQueue<>();
activeThread A = new activeThread(randomA, clientA, queue);
activeThread B = new activeThread(randomB, clientB, queue);
Thread AThread = new Thread(A, "A");
Thread BThread = new Thread(B, "B");
try {
AThread.start();
BThread.start();
for (int i = 0; i < 50; i++) {
TestClient clientC = new TestClient("C", testConnection);
clientC.down();
if (!AThread.isAlive() || !BThread.isAlive()) {
throw new RuntimeException("One of the threads died");
}
FileUtils.deleteDirectory(clientC.getLocalFile(""));
Thread.sleep(2000);
}
AThread.interrupt();
BThread.interrupt();
} catch (Exception e) {
logger.log(Level.INFO, "Queue:" + queue.toString());
logger.log(Level.INFO, "Something went wrong at seed: " + seed);
throw e;
}
clientA.deleteTestData();
clientB.deleteTestData();
}
}
Aggregations