use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class CleanupOperationTest method testEasyCleanup.
@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.setRemoveOldVersions(true);
options.setMinKeepSeconds(0);
// Run
// A: Create some file versions
// These two files' chunks will be in one multichunk
clientA.createNewFile("someotherfile.jpg");
// Only one of the chunks will be needed after cleanup!
clientA.createNewFile("file.jpg");
// 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(), false);
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(), false);
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(11, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(7, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(4, cleanupOperationResult.getRemovedOldVersionsCount());
// 1 version for "file.jpg", 1 versions for "otherfile.txt" and 1 version for "someotherfile.jpg"
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from fileversion", databaseConnectionA));
// 4
assertEquals("4", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='file.jpg'", databaseConnectionA));
// 3
assertEquals("3", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='otherfile.txt'", databaseConnectionA));
assertEquals("1", TestSqlUtil.runSqlSelect("select sum(version) from fileversion where path='someotherfile.jpg'", databaseConnectionA));
// 3 chunks remain; one was obsolete so we removed it!
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
// 3 chunks in 3 multichunks
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from multichunk", databaseConnectionA));
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from filecontent", databaseConnectionA));
assertEquals("3", TestSqlUtil.runSqlSelect("select count(distinct id) from filehistory", databaseConnectionA));
// Test the repo
assertEquals(3, new File(testConnection.getPath() + "/multichunks/").list().length);
assertEquals(1, new File(testConnection.getPath() + "/databases/").list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("database-");
}
}).length);
// B: Sync down cleanup
clientB.down();
TestAssertUtil.assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class AllFilePossibilitiesScenarioTest method testAllPossibilities.
@Test
public void testAllPossibilities() throws Exception {
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
ClientActions.run(clientA, new Executable() {
@Override
public void execute() throws Exception {
// Nothing.
}
}, new AbstractClientAction[] { new CreateFileTree(), new ChangeContentWithoutFileSize(), new ChangeFileSize(), new ChangeLastModifiedDate(), new ChangePermissionsOfFile(), new ChangePermissionsOfFolder(), new ChangeSymlinkTarget(), new ChangeTypeFileToFolder(), new ChangeTypeFileToSymlinkWithNonExistingTarget(), new ChangeTypeFileToSymlinkWithTargetFile(), new ChangeTypeFileToSymlinkWithTargetFolder(), new ChangeTypeSymlinkWithNonExistingTargetToFile(), new ChangeTypeSymlinkWithTargetFileToFile(), new ChangeTypeSymlinkWithTargetFolderToFile(), new ChangeTypeSymlinkWithNonExistingTargetToFolder(), new ChangeTypeSymlinkWithTargetFileToFolder(), new ChangeTypeSymlinkWithTargetFolderToFolder(), new ChangeTypeFolderToFile(), new ChangeTypeFolderToSymlinkWithNonExistingTarget(), new ChangeTypeFolderToSymlinkWithTargetFile(), new ChangeTypeFolderToSymlinkWithTargetFolder(), new CreateFile(), new CreateFolder(), new CreateSymlinkToFile(), new CreateSymlinkToFolder(), new CreateSymlinkToNonExisting(), new DeleteFile(), new DeleteFolder(), new MoveFileToOtherFolder(), new MoveFileWithinFolder(), new MoveFolderToOtherFolder(), new MoveFolderWithinFolder() // new LockFile() and new UnlockFile() are not compatible with these tests
}, new Executable() {
@Override
public void execute() throws Exception {
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
}
});
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class AllFilePossibilitiesScenarioTest method testChangeTypeSymlinkWithTargetFileToFolder.
@Test
public void testChangeTypeSymlinkWithTargetFileToFolder() throws Exception {
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
ClientActions.run(clientA, null, new CreateFileTree(), null);
ClientActions.run(clientA, null, new ChangeTypeFileToSymlinkWithTargetFolder(), null);
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class ChangedAttributesScenarioTest method testNewFileWithDifferingAttributes.
@Test
public void testNewFileWithDifferingAttributes() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Create new file with differing attributes
clientA.createNewFile("file1.jpg");
FileUtils.copyFile(clientA.getLocalFile("file1.jpg"), clientB.getLocalFile("file1.jpg"));
// Client B's attributes differ!
File aFile = clientA.getLocalFile("file1.jpg");
Path aFilePath = Paths.get(aFile.getAbsolutePath());
Object aReadOnlyAttribute = null;
Set<PosixFilePermission> aPosixFilePermissions = null;
// Client B's attributes differ!
File bFile = clientB.getLocalFile("file1.jpg");
Path bFilePath = Paths.get(bFile.getAbsolutePath());
if (EnvironmentUtil.isWindows()) {
aReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
Files.setAttribute(bFilePath, "dos:readonly", true);
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
aPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
Files.setPosixFilePermissions(bFilePath, PosixFilePermissions.fromString("rwxrwxrwx"));
}
clientA.upWithForceChecksum();
// This is the key operation
DownOperationResult downResult = clientB.down();
// Test 1: Check result sets for inconsistencies
assertTrue("File should be downloaded.", downResult.getChangeSet().hasChanges());
// Test 2: file1.jpg permissions (again!
if (EnvironmentUtil.isWindows()) {
Object bReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
assertEquals("Read-only should be true.", aReadOnlyAttribute, bReadOnlyAttribute);
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
Set<PosixFilePermission> bPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
assertEquals("Should be rwxrwxrwx.", PosixFilePermissions.toString(aPosixFilePermissions), PosixFilePermissions.toString(bPosixFilePermissions));
}
// Test 3: The rest
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class ChangedAttributesScenarioTest method testChangeAttributes.
@Test
public void testChangeAttributes() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
clientA.createNewFile("file1.jpg");
clientA.upWithForceChecksum();
clientB.down();
File bFile = clientB.getLocalFile("file1.jpg");
Path bFilePath = Paths.get(bFile.getAbsolutePath());
if (EnvironmentUtil.isWindows()) {
Files.setAttribute(bFilePath, "dos:readonly", true);
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
Files.setPosixFilePermissions(bFilePath, PosixFilePermissions.fromString("rwxrwxrwx"));
}
StatusOperationResult statusResult = clientB.status();
assertNotNull(statusResult);
ChangeSet changes = statusResult.getChangeSet();
assertTrue("Status-Operation should return changes.", changes.hasChanges());
UpOperationResult upResult = clientB.up();
StatusOperationResult statusResultFromUp = upResult.getStatusResult();
// Test 1: Check result sets for inconsistencies
assertTrue("Status should return changes.", statusResultFromUp.getChangeSet().hasChanges());
assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());
// Test 2: Check database for inconsistencies
SqlDatabase database = clientB.loadLocalDatabase();
assertEquals("File should be uploaded.", 1, database.getFileList("file1.jpg", null, false, false, false, null).size());
assertEquals("There should be a new database version, because file should not have been added.", 2, database.getLocalDatabaseBranch().size());
// B down
clientA.down();
// Test 1: file1.jpg permissions
File aFile = clientA.getLocalFile("file1.jpg");
Path aFilePath = Paths.get(aFile.getAbsolutePath());
if (EnvironmentUtil.isWindows()) {
Object readOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
assertTrue("Read-only should be true.", (Boolean) readOnlyAttribute);
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(aFilePath);
assertEquals("Should be rwxrwxrwx.", "rwxrwxrwx", PosixFilePermissions.toString(posixFilePermissions));
}
// Test 2: The rest
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations