use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class SingleFileNoConflictsScenarioTest method testSingleFileMoveNoConflicts.
@Test
public void testSingleFileMoveNoConflicts() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Create files and upload
clientA.createNewFile("file");
clientA.up();
clientB.down();
assertFileEquals(clientA.getLocalFile("file"), clientB.getLocalFile("file"));
clientB.moveFile("file", "moved");
clientB.up();
clientA.down();
assertFalse("Originally moved file should not exist.", clientA.getLocalFile("file").exists());
assertFileEquals(clientA.getLocalFile("moved"), clientB.getLocalFile("moved"));
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
// Cleanup
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class CleanupOperationTest method testCleanupNoChanges.
@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.setRemoveOldVersions(true);
options.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
// 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.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class CleanupOperationTest method testQuickDoubleCleanup.
@Test
public void testQuickDoubleCleanup() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
CleanupOperationOptions options = new CleanupOperationOptions();
options.setRemoveOldVersions(false);
options.setRemoveVersionsByInterval(false);
options.setMinSecondsBetweenCleanups(40000000);
// Run
// A: Create some file versions
clientA.createNewFile("file.jpg");
for (int i = 1; i <= 16; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
// B: Cleanup
CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(16, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
for (int i = 1; i <= 15; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
// Because of minimum timeout, this cleanup should not do anything
cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.NOK_RECENTLY_CLEANED, cleanupOperationResult.getResultCode());
// When force is on, the cleanup should go through
options.setForce(true);
cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(16, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
// Tear down
clientA.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class CleanupOperationTest method testCleanupFailsMidCommit.
@Test
public void testCleanupFailsMidCommit() throws Exception {
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
"rel=(13|14|15).+move" }));
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();
StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
forceChecksumStatusOperationOptions.setForceChecksum(true);
CleanupOperationOptions options = new CleanupOperationOptions();
options.setStatusOptions(forceChecksumStatusOperationOptions);
options.setRemoveOldVersions(true);
options.setMinKeepSeconds(0);
options.setMinSecondsBetweenCleanups(40000000);
options.setForce(true);
File repoDir = testConnection.getPath();
File repoMultiChunkDir = new File(testConnection.getPath() + "/multichunks");
File repoActionsDir = new File(testConnection.getPath() + "/actions");
File repoDatabasesDir = new File(testConnection.getPath() + "/databases");
File repoTransactionsDir = new File(testConnection.getPath() + "/transactions");
File repoTemporaryDir = new File(testConnection.getPath() + "/temporary");
// Run
clientA.createNewFile("A-file1", 5 * 1024);
clientA.up();
for (int i = 0; i < 5; i++) {
clientA.changeFile("A-file1");
clientA.upWithForceChecksum();
}
assertEquals(6, repoDatabasesDir.listFiles().length);
assertEquals(6, repoMultiChunkDir.listFiles().length);
assertEquals(0, repoActionsDir.listFiles().length);
assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
// Run cleanup, fails mid-move!
boolean operationFailed = false;
try {
clientA.cleanup(options);
} catch (Exception e) {
// That is supposed to happen!
operationFailed = true;
e.printStackTrace();
}
assertTrue(operationFailed);
assertEquals(1, repoTransactionsDir.listFiles().length);
assertEquals(0, repoTemporaryDir.listFiles().length);
assertEquals(6, repoDatabasesDir.listFiles().length);
assertEquals(6, repoMultiChunkDir.listFiles().length);
assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
// Retry
clientA.cleanup(options);
assertEquals(1, repoDatabasesDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("database-");
}
}).length);
assertEquals(1, repoMultiChunkDir.listFiles().length);
assertEquals(0, repoActionsDir.listFiles().length);
assertEquals(0, repoDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("transaction-");
}
}).length);
assertEquals(0, repoDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("temp-");
}
}).length);
assertEquals("1", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
// Tear down
clientA.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class CleanupOperationTest method testCleanupMaxDatabaseFiles.
@Test
public void testCleanupMaxDatabaseFiles() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
CleanupOperationOptions options = new CleanupOperationOptions();
options.setMinSecondsBetweenCleanups(0);
options.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
options.setRemoveOldVersions(true);
options.setMaxDatabaseFiles(3);
// Run
// A: Create some file versions
clientA.createNewFile("file.jpg");
for (int i = 1; i <= 4; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
// B: Cleanup
CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(4, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
TestClient clientB = new TestClient("B", testConnection);
clientB.down();
// B: Create some file versions
clientB.createNewFile("file-B.jpg");
for (int i = 1; i <= 6; i++) {
clientB.changeFile("file-B.jpg");
clientB.upWithForceChecksum();
}
// B: Cleanup (2 clients, so 7 databases is too much)
cleanupOperationResult = clientB.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(7, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations