use of org.syncany.operations.AbstractTransferOperation in project syncany by syncany.
the class SplitSyncUpOperationTest method testUploadLocalDatabase.
private void testUploadLocalDatabase(int fileSize, int fileAmount, int expectedTransactions, UpOperationOptions options) throws Exception {
List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
// Run!
AbstractTransferOperation op = new UpOperation(testConfig, options);
UpOperationResult opResult = (UpOperationResult) op.execute();
// Ensure that the expected number of transactions has been completed to upload the files
assertNotNull(opResult);
assertTrue(opResult.getTransactionsCompleted() == expectedTransactions);
// Get databases (for comparison)
LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
File localDatabaseDir = testConfig.getDatabaseDir();
assertNotNull(localDatabaseDir.listFiles());
assertTrue(localDatabaseDir.listFiles().length > 0);
List<File> remoteDatabaseFiles = new ArrayList<>();
for (int transaction = 1; transaction <= expectedTransactions; transaction++) {
String databaseVersion = String.format("%010d", transaction);
File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-" + databaseVersion);
assertTrue(remoteDatabaseFile.exists());
remoteDatabaseFiles.add(remoteDatabaseFile);
}
// Import remote databases into memory database
DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
MemoryDatabase remoteDatabase = new MemoryDatabase();
for (File remoteDatabaseFile : remoteDatabaseFiles) {
dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseXmlSerializer.DatabaseReadType.FULL);
}
// Open local SQL Database
SqlDatabase localDatabase = new SqlDatabase(testConfig);
// Compare!
assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabase.getLastDatabaseVersion().getHeader());
Map<PartialFileHistory.FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
Collection<PartialFileHistory> remoteFileHistories = remoteDatabase.getFileHistories();
assertEquals(localDatabase.getCurrentFileTree().size(), fileAmount);
assertEquals(localFileHistories.size(), remoteDatabase.getFileHistories().size());
List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
List<FileVersion> localFileVersions = new ArrayList<FileVersion>();
for (PartialFileHistory partialFileHistory : remoteFileHistories) {
remoteFileVersions.add(partialFileHistory.getLastVersion());
assertNotNull(localFileHistories.get(partialFileHistory.getFileHistoryId()));
}
for (PartialFileHistory partialFileHistory : localFileHistories.values()) {
localFileVersions.add(partialFileHistory.getLastVersion());
}
assertTrue(CollectionUtil.containsExactly(localFileVersions, remoteFileVersions));
compareFileVersionsAgainstOriginalFiles(originalFiles, localFileVersions);
compareFileVersionsAgainstOriginalFiles(originalFiles, remoteFileVersions);
}
use of org.syncany.operations.AbstractTransferOperation in project syncany by syncany.
the class UpOperationTest method testUploadLocalDatabase.
@Test
public void testUploadLocalDatabase() throws Exception {
int fileSize = 1230 * 1024;
int fileAmount = 3;
List<File> originalFiles = TestFileUtil.createRandomFilesInDirectory(testConfig.getLocalDir(), fileSize, fileAmount);
// Run!
AbstractTransferOperation op = new UpOperation(testConfig);
op.execute();
// Get databases (for comparison)
LocalTransferSettings localConnection = (LocalTransferSettings) testConfig.getConnection();
File localDatabaseDir = testConfig.getDatabaseDir();
File remoteDatabaseFile = new File(localConnection.getPath() + "/databases/database-" + testConfig.getMachineName() + "-0000000001");
assertNotNull(localDatabaseDir.listFiles());
assertTrue(localDatabaseDir.listFiles().length > 0);
assertTrue(remoteDatabaseFile.exists());
// - Memory database
DatabaseXmlSerializer dDAO = new DatabaseXmlSerializer(testConfig.getTransformer());
MemoryDatabase remoteDatabase = new MemoryDatabase();
dDAO.load(remoteDatabase, remoteDatabaseFile, null, null, DatabaseReadType.FULL);
DatabaseVersion remoteDatabaseVersion = remoteDatabase.getLastDatabaseVersion();
// - Sql Database
SqlDatabase localDatabase = new SqlDatabase(testConfig);
Map<FileHistoryId, PartialFileHistory> localFileHistories = localDatabase.getFileHistoriesWithFileVersions();
// Compare!
assertEquals(localDatabase.getLastDatabaseVersionHeader(), remoteDatabaseVersion.getHeader());
assertEquals(localFileHistories.size(), fileAmount);
assertEquals(localDatabase.getFileHistoriesWithFileVersions().size(), remoteDatabaseVersion.getFileHistories().size());
Collection<PartialFileHistory> remoteFileHistories = remoteDatabaseVersion.getFileHistories();
List<FileVersion> remoteFileVersions = new ArrayList<FileVersion>();
List<FileVersion> localFileVersions = new ArrayList<FileVersion>();
for (PartialFileHistory partialFileHistory : remoteFileHistories) {
remoteFileVersions.add(partialFileHistory.getLastVersion());
assertNotNull(localFileHistories.get(partialFileHistory.getFileHistoryId()));
}
for (PartialFileHistory partialFileHistory : localFileHistories.values()) {
localFileVersions.add(partialFileHistory.getLastVersion());
}
assertTrue(CollectionUtil.containsExactly(localFileVersions, remoteFileVersions));
compareFileVersionsAgainstOriginalFiles(originalFiles, localFileVersions);
compareFileVersionsAgainstOriginalFiles(originalFiles, remoteFileVersions);
}
Aggregations