public void testCliSyncUpWithCleanup() throws Exception {
Map<String, String> connectionSettings = TestConfigUtil.createTestLocalConnectionSettings();
Map<String, String> clientA = TestCliUtil.createLocalTestEnvAndInit("A", connectionSettings);
Map<String, String> clientB = TestCliUtil.createLocalTestEnvAndConnect("B", connectionSettings);
new CommandLineClient(new String[] {
"--localdir", clientA.get("localdir"),
"up"
}).start();
for (int i=1; i<=20; i++) {
new File(clientA.get("localdir")+"/somefolder"+i).mkdir();
new CommandLineClient(new String[] {
"--localdir", clientA.get("localdir"),
"up"
}).start();
}
// Delete something so that cleanup actually does something
new File(clientA.get("localdir")+"/somefolder1").delete();
new CommandLineClient(new String[] {
"--localdir", clientA.get("localdir"),
"up"
}).start();
// Apply all changes at B
new CommandLineClient(new String[] {
"--localdir", clientB.get("localdir"),
"down"
}).start();
// Now cleanup
String[] cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] {
"--localdir", clientA.get("localdir"),
"cleanup"
}));
assertEquals(7, cliOut.length);
assertTrue(cliOut[4].contains("22 database files merged"));
assertTrue(cliOut[5].contains("1 file histories shortened"));
assertTrue(cliOut[6].contains("Cleanup successful"));
for (int i=1; i<=21; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File databaseFileInRepo = new File(connectionSettings.get("path")+"/databases/"+expectedDatabaseRemoteFile.getName());
assertFalse("Database file SHOULD NOT exist: "+databaseFileInRepo, databaseFileInRepo.exists());
}
for (int i=22; i<=22; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File databaseFileInRepo = new File(connectionSettings.get("path")+"/databases/"+expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: "+databaseFileInRepo, databaseFileInRepo.exists());
}
cliOut = TestCliUtil.runAndCaptureOutput(new CommandLineClient(new String[] {
"--localdir", clientB.get("localdir"),
"down"
}));
assertEquals(6, cliOut.length);