* This test tries to provoke issue #132, i.e. the deletion of
* multichunks of DIRTY database versions of other clients.
*/
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
UpOperationOptions upOptionsWithForce = new UpOperationOptions();
upOptionsWithForce.setForceUploadEnabled(true);
// Run
clientA.createNewFile("file1.jpg");
clientA.up();
clientB.down();
clientB.createNewFile("file2.jpg");
clientB.up();
clientA.createNewFile("file3.jpg");
clientA.up(upOptionsWithForce); // No 'down' (creates dirty version)
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath()+"_1_before_down"));
FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir()+"_1_before_down"));
assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "0");
clientB.down(); // Download A's version, realize it's muddy (= dirty by other client)
assertSqlResultEquals(clientB.getDatabaseFile(), "select count(*) from multichunk_muddy", "1");
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath()+"_2_after_down_before_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir()+"_2_after_down_before_cleanup"));
assertEquals(3, new File(testConnection.getPath(), "multichunks").listFiles().length);
clientB.cleanup(); // <<< This should NOT delete any lost multichunks of DIRTY database versions!
assertEquals(3, new File(testConnection.getPath(), "multichunks").listFiles().length);
FileUtils.copyDirectory(testConnection.getPath(), new File(testConnection.getPath()+"_3_after_cleanup"));
FileUtils.copyDirectory(clientB.getConfig().getLocalDir(), new File(clientB.getConfig().getLocalDir()+"_3_after_cleanup"));
clientA.down(); // Adds dirty database
assertSqlResultEquals(clientA.getDatabaseFile(), "select count(*) from databaseversion where status='DIRTY'", "1");