use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class IgnoredFileScenarioTest method testIgnoredFileBasicRecursive.
@Test
public void testIgnoredFileBasicRecursive() throws Exception {
// Scenario: A ignores a file, creates it then ups, B should not have the file
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
//Create ignore file and reload it
File syncanyIgnore = clientA.getLocalFile(Config.FILE_IGNORE);
TestFileUtil.createFileWithContent(syncanyIgnore, "ignoredfile.txt");
clientA.getConfig().getIgnoredFiles().loadPatterns();
// A new/up
clientA.createNewFile("ignoredfile.txt");
clientA.createNewFile("nonignoredfile.txt");
clientA.createNewFolder("sub");
clientA.createNewFileInFolder("ignoredfile.txt", "sub");
clientA.up();
clientB.down();
// The ignored file should not exist at B
assertTrue(clientA.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientA.getLocalFile("nonignoredfile.txt").exists());
assertTrue(clientA.getLocalFile("sub").exists());
assertTrue(clientA.getLocalFileInFolder("ignoredfile.txt", "sub").exists());
assertFalse(clientB.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientB.getLocalFile("nonignoredfile.txt").exists());
assertTrue(clientB.getLocalFile("sub").exists());
assertFalse(clientB.getLocalFileInFolder("ignoredfile.txt", "sub").exists());
//Delete ignore file and reload patterns
TestFileUtil.deleteFile(syncanyIgnore);
clientA.getConfig().getIgnoredFiles().loadPatterns();
clientA.up();
clientB.down();
// All files should be synced
assertTrue(clientA.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientA.getLocalFile("nonignoredfile.txt").exists());
assertTrue(clientA.getLocalFile("sub").exists());
assertTrue(clientA.getLocalFileInFolder("ignoredfile.txt", "sub").exists());
assertTrue(clientB.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientB.getLocalFile("nonignoredfile.txt").exists());
assertTrue(clientB.getLocalFile("sub").exists());
assertTrue(clientB.getLocalFileInFolder("ignoredfile.txt", "sub").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class IgnoredFileScenarioTest method testIgnoredFileRegex.
@Test
public void testIgnoredFileRegex() throws Exception {
// Scenario: A ignores files with a regular expression, creates it then ups, B should not have the file
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
//Create ignore file and reload it
File syncanyIgnore = clientA.getLocalFile(Config.FILE_IGNORE);
TestFileUtil.createFileWithContent(syncanyIgnore, "regex:.*.bak");
clientA.getConfig().getIgnoredFiles().loadPatterns();
// A new/up
clientA.createNewFile("ignoredfile.bak");
clientA.up();
clientB.down();
// The ignored file should not exist at B
assertTrue(clientA.getLocalFile("ignoredfile.bak").exists());
assertFalse(clientB.getLocalFile("ignoredfile.bak").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class IgnoredFileScenarioTest method testIgnoredFileBasic.
@Test
public void testIgnoredFileBasic() throws Exception {
// Scenario: A ignores a file, creates it then ups, B should not have the file
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
//Create ignore file and reload it
File syncanyIgnore = clientA.getLocalFile(Config.FILE_IGNORE);
TestFileUtil.createFileWithContent(syncanyIgnore, "ignoredfile.txt");
clientA.getConfig().getIgnoredFiles().loadPatterns();
// A new/up
clientA.createNewFile("ignoredfile.txt");
clientA.createNewFile("nonignoredfile.txt");
clientA.up();
clientB.down();
// The ignored file should not exist at B
assertTrue(clientA.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientA.getLocalFile("nonignoredfile.txt").exists());
assertFalse(clientB.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientB.getLocalFile("nonignoredfile.txt").exists());
//Delete ignore file and reload patterns
TestFileUtil.deleteFile(syncanyIgnore);
clientA.getConfig().getIgnoredFiles().loadPatterns();
clientA.up();
clientB.down();
// All files should be synced
assertTrue(clientA.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientA.getLocalFile("nonignoredfile.txt").exists());
assertTrue(clientB.getLocalFile("ignoredfile.txt").exists());
assertTrue(clientB.getLocalFile("nonignoredfile.txt").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class Issue200ScenarioTest method testIssue200.
@Test
public void testIssue200() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
clientA.createNewFolder("folder");
clientA.createNewFile("folder/file");
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientA.changeFile("folder/file");
clientA.upWithForceChecksum();
clientB.deleteFile("folder/file");
clientB.down();
assertTrue(clientB.getLocalFile("folder/file").exists());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.tests.util.TestClient in project syncany by syncany.
the class Issue288ScenarioTest method testIssue288.
@Test
public void testIssue288() throws Exception {
/*
* This tests issue #288, an issue in which a file with duplicate chunks are created
* incorrectly, because the cleanup throws away too many entries in the filecontent_chunks
* database table.
*
* The test first creates a file with duplicate chunks, then syncs this file, and then
* moves this file on both clients -- that forces the other client to recreate the file
* from scratch.
*/
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
cleanupOptionsKeepOne.setForce(true);
// Create file content with two duplicate chunks
// The file has 4 chunks (4 * 512 bytes), the middle chunks are identical
// 1 MB
byte[] fileContentA = new byte[2 * 1024 * 1024];
for (int i = 0; i < 512 * 1024; i++) {
// First chunk
fileContentA[i] = (byte) i;
}
for (int i = 512 * 1024; i < 1536 * 1024; i++) {
// Two identical middle chunks
fileContentA[i] = 99;
}
for (int i = 1536 * 1024; i < 2 * 1024 * 1024; i++) {
// Last chunk
fileContentA[i] = (byte) (i + i);
}
FileUtils.writeByteArrayToFile(clientA.getLocalFile("fileA"), fileContentA);
clientA.upWithForceChecksum();
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from filecontent_chunk", databaseConnectionA));
// Sync file to client B
clientB.down();
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionB));
assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from filecontent_chunk", databaseConnectionB));
// Move file, sync again and perform cleanup (wipe everything but one file version)
clientA.moveFile("fileA", "fileA-moved");
clientA.upWithForceChecksum();
clientA.cleanup(cleanupOptionsKeepOne);
// Delete file locally and sync down
clientB.deleteFile("fileA");
// <<<< This throws an exception!
clientB.down();
// Tear down
clientB.deleteTestData();
clientA.deleteTestData();
}
Aggregations