use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.
the class CallUpWhileStillWritingFileScenarioTest method testUpWhileWritingFile.
@Test
public void testUpWhileWritingFile() throws Exception {
// Setup
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
final File testFile = clientA.getLocalFile("large-test-file");
final long testFileLength = 100 * 1024 * 1024;
Thread writeFileThread = new Thread(new Runnable() {
@Override
public void run() {
try {
logger.log(Level.INFO, "Started thread to write file to " + testFile + " ...");
FileOutputStream fos = new FileOutputStream(testFile);
Random randomEngine = new Random();
byte[] buf = new byte[4096];
int writtenLen = 0;
while (writtenLen < testFileLength) {
randomEngine.nextBytes(buf);
fos.write(buf, 0, buf.length);
writtenLen += buf.length;
}
fos.close();
logger.log(Level.INFO, "Ended thread to write file to " + testFile + " ...");
} catch (IOException e) {
logger.log(Level.FINE, "Thread failed to write to file", e);
}
}
}, "writerThread");
// Before start: setup up databases (takes a while)
clientA.status();
clientB.status();
// Run!
writeFileThread.start();
Thread.sleep(50);
logger.log(Level.INFO, "Started clientA.up()");
UpOperationResult upResult = clientA.up();
StatusOperationResult statusResult = upResult.getStatusResult();
logger.log(Level.INFO, "Ended clientA.up()");
writeFileThread.join();
// Test 1: Check result sets for inconsistencies
assertTrue("Status command expected to return changes.", statusResult.getChangeSet().hasChanges());
assertFalse("File should NOT be uploaded while still writing (no half-file upload).", upResult.getChangeSet().hasChanges());
// Test 2: Check database for inconsistencies
SqlDatabase database = clientA.loadLocalDatabase();
assertEquals("File should NOT be uploaded while still writing (no half-file upload).", 0, database.getFileList("large-test-file", null, false, false, false, null).size());
assertNull("There should NOT be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());
// Test 3: Check file system for inconsistencies
File repoPath = new File(((LocalTransferSettings) testConnection).getPath() + "/databases");
String[] repoFileList = repoPath.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("database-");
}
});
assertEquals("Repository should NOT contain any files.", 0, repoFileList.length);
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_5.
@Test
public void testIssue58_5() throws Exception {
// Test for https://github.com/syncany/syncany/issues/58#issuecomment-43472118
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
TestClient clientC = new TestClient("C", testConnection);
TestClient clientD = new TestClient("D", testConnection);
TestClient clientE = new TestClient("E", testConnection);
CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
cleanupOptionsKeep1.setRemoveOldVersions(true);
StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
statusOptionsForceChecksum.setForceChecksum(true);
UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);
UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);
// First round
clientB.createNewFile("fileA");
clientB.up(upNoCleanupForceChecksum);
clientA.down();
TestFileUtil.copyFile(clientA.getLocalFile("fileA"), clientA.getLocalFile("fileAcopy"));
clientA.up(upNoCleanupForceChecksum);
clientA.down();
for (int i = 0; i < 30; i++) {
clientA.down();
clientA.changeFile("fileA");
clientA.up(upNoCleanupForceChecksum);
}
// First cleanup
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_1_before_cleanup"));
FileUtils.copyDirectory(clientA.getConfig().getDatabaseDir(), new File(clientA.getConfig().getAppDir(), "1_before_cleanup"));
CleanupOperationOptions cleanupMergeAndRemoveOldFiles = new CleanupOperationOptions();
cleanupMergeAndRemoveOldFiles.setRemoveOldVersions(true);
clientA.cleanup(cleanupMergeAndRemoveOldFiles);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_2_after_cleanup"));
FileUtils.copyDirectory(clientA.getConfig().getDatabaseDir(), new File(clientA.getConfig().getAppDir(), "2_after_cleanup"));
// If this doesn't crash that's a win!
clientC.down();
for (int i = 0; i < 30; i++) {
clientB.down();
clientB.changeFile("fileA");
clientB.up(upNoCleanupForceChecksum);
}
// Second cleanup
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_3_before_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "3_before_cleanup"));
clientB.cleanup(cleanupMergeAndRemoveOldFiles);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_4_after_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "4_after_cleanup"));
// If this doesn't crash that's a win!
clientD.down();
for (int i = 0; i < 30; i++) {
clientB.down();
clientB.changeFile("fileA");
clientB.up(upNoCleanupForceChecksum);
}
// < Remove original checksum from first DBV
clientB.deleteFile("fileAcopy");
clientB.up(upNoCleanupForceChecksum);
// Third cleanup
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_5_before_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "5_before_cleanup"));
clientB.cleanup(cleanupMergeAndRemoveOldFiles);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath() + "_6_after_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getDatabaseDir(), new File(clientB.getConfig().getAppDir(), "6_after_cleanup"));
// If this doesn't crash that's a win!
clientE.down();
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
clientD.deleteTestData();
clientE.deleteTestData();
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_1_before_cleanup"));
FileUtils.deleteDirectory(new File(clientA.getConfig().getAppDir(), "1_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_2_after_cleanup"));
FileUtils.deleteDirectory(new File(clientA.getConfig().getAppDir(), "2_after_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_3_before_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "3_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_4_after_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "4_after_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_5_before_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "5_before_cleanup"));
FileUtils.deleteDirectory(new File(testConnection.getPath() + "_6_after_cleanup"));
FileUtils.deleteDirectory(new File(clientB.getConfig().getAppDir(), "6_after_cleanup"));
}
use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testIssue58_3.
@Test
public void testIssue58_3() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
TestClient clientC = new TestClient("C", testConnection);
CleanupOperationOptions cleanupOptionsKeep1 = new CleanupOperationOptions();
cleanupOptionsKeep1.setRemoveOldVersions(true);
StatusOperationOptions statusOptionsForceChecksum = new StatusOperationOptions();
statusOptionsForceChecksum.setForceChecksum(true);
UpOperationOptions upNoCleanupForceChecksum = new UpOperationOptions();
upNoCleanupForceChecksum.setStatusOptions(statusOptionsForceChecksum);
UpOperationOptions upWithCleanupKeep1ForceChecksum = new UpOperationOptions();
upWithCleanupKeep1ForceChecksum.setStatusOptions(statusOptionsForceChecksum);
clientA.createNewFile("fileA");
clientB.createNewFile("fileB");
clientA.up(upNoCleanupForceChecksum);
clientB.down();
TestFileUtil.copyFile(clientA.getLocalFile("fileA"), clientB.getLocalFile("fileB"));
String problemChecksum = StringUtil.toHex(FileUtil.createChecksum(clientA.getLocalFile("fileA"), "SHA1"));
clientB.up(upNoCleanupForceChecksum);
for (int i = 0; i < 20; i++) {
clientA.down();
clientA.changeFile("fileA");
clientA.up(upNoCleanupForceChecksum);
clientB.down();
clientB.changeFile("fileB");
clientB.up(upNoCleanupForceChecksum);
}
System.out.println("Problem checksum: " + problemChecksum);
clientB.cleanup();
clientA.down();
clientA.cleanup();
clientA.down();
clientC.down();
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
}
use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.
the class CleanupMergeDatabaseFilesScenarioTest method testCleanupMergeDatabaseFilesScenario1.
@Test
public void testCleanupMergeDatabaseFilesScenario1() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
TestClient clientC = new TestClient("C", testConnection);
CleanupOperationOptions cleanupOptionsOnlyMergeDatabases = new CleanupOperationOptions();
cleanupOptionsOnlyMergeDatabases.setRemoveOldVersions(false);
UpOperationOptions upOperationOptionsNoCleanup = new UpOperationOptions();
upOperationOptionsNoCleanup.setForceUploadEnabled(true);
// Run preparations
int[] clientUpSequence = new int[] { // 16x "1", merge happens after 15!
1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
for (int i = 0; i < clientUpSequence.length; i++) {
if (clientUpSequence[i] == 1) {
clientA.down();
clientA.createNewFile("A-file" + i + ".jpg", i);
clientA.up(upOperationOptionsNoCleanup);
} else {
clientB.down();
clientB.createNewFile("B-file" + i + ".jpg", i);
clientB.up(upOperationOptionsNoCleanup);
}
}
clientA.cleanup();
clientA.down();
clientB.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Make sure the "merge" process actually happened
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000001").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000005").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000010").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000030").exists());
assertFalse(new File(testConnection.getPath(), "databases/database-A-0000000031").exists());
assertTrue(new File(testConnection.getPath(), "databases/database-A-0000000032").exists());
// Run
// <<< Here is/was the issue: Client C failed when downloading
clientC.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientC.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
clientC.deleteTestData();
}
use of org.syncany.plugins.local.LocalTransferSettings in project syncany by syncany.
the class CleanupOperationTest method testCleanupNoChangeBecauseDirty.
@Test
public void testCleanupNoChangeBecauseDirty() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
CleanupOperationOptions removeOldCleanupOperationOptions = new CleanupOperationOptions();
removeOldCleanupOperationOptions.setRemoveOldVersions(true);
StatusOperationOptions forceChecksumStatusOperationOptions = new StatusOperationOptions();
forceChecksumStatusOperationOptions.setForceChecksum(true);
UpOperationOptions noCleanupAndForceUpOperationOptions = new UpOperationOptions();
noCleanupAndForceUpOperationOptions.setForceUploadEnabled(true);
noCleanupAndForceUpOperationOptions.setStatusOptions(forceChecksumStatusOperationOptions);
// 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: Change file.jpg (first step in creating a conflict)
clientA.changeFile("file.jpg");
clientA.up(noCleanupAndForceUpOperationOptions);
// B: Change file.jpg (second step in creating a conflict)
clientB.changeFile("file.jpg");
// << creates conflict
clientB.up(noCleanupAndForceUpOperationOptions);
// B: Sync down (creates a local conflict file and marks local changes as DRITY)
// << creates DIRTY database entries
clientB.down();
// B: Cleanup
CleanupOperationResult cleanupOperationResult = clientB.cleanup(removeOldCleanupOperationOptions);
assertEquals(CleanupResultCode.NOK_DIRTY_LOCAL, cleanupOperationResult.getResultCode());
assertEquals(0, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations