use of org.simpleframework.xml.core.Persister in project syncany by syncany.
the class UploadInterruptedTest method testUnreliableUpload_Test4_3_FailsAtTXCommitDuring2ndMultiChunkMoveAndDuringTXRollback.
@Test
public void testUnreliableUpload_Test4_3_FailsAtTXCommitDuring2ndMultiChunkMoveAndDuringTXRollback() throws Exception {
/*
* 1. upload(action-up-987, actions/action-up-987)
* 2. upload(transaction-123, transactions/transaction-123)
* 3. upload(multichunk-1, temp-1)
* 4. upload(multichunk-2, temp-2)
* 5. upload(database-123, temp-3)
* 6. move(temp-1, multichunks/multichunk-1)
* 7. move(temp-2, multichunks/multichunk-2) <<< FAILS HERE (first run)
* 8. move(temp-3, databases/database-123)
*
* 1. upload(action-up-987, actions/action-up-987)
* 2. list(databases/*)
* 3. list(transactions/*)
* 4. upload(transaction-345, transactions/transaction-345) (rollback TX)
* 5. move(multichunks/multichunk-1, temp-80)
* 6. move(temp-1, temp-81) (silently fails, b/c temp-1 does not exist)
* 7. move(multichunks/multichunk-2, temp-82) (silently fails, b/c multichunk-2 does not exist)
* 8. move(temp-2, temp-83)
* 9. move(databases/database-123, temp-84) (silently fails, b/c database-123 does not exist)
* 10. move(temp-3, temp-85)
* 10 move(transactions-345, temp-86)
* 11. delete(temp-80)
* 12. delete(temp-83) <<< FAILS HERE (second run)
*
* Expected: temp-(83,85,86)
*/
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[234].+move.+multichunk", "rel=[567].+delete.+database" }));
TestClient clientA = new TestClient("A", testConnection);
// << larger than one multichunk!
clientA.createNewFile("A-original", 5 * 1024 * 1024);
boolean firstUpFailed = false;
try {
clientA.up();
} catch (StorageException e) {
firstUpFailed = true;
logger.log(Level.INFO, e.getMessage());
}
assertTrue(firstUpFailed);
assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
File[] tempFiles = new File(testConnection.getPath() + "/temporary").listFiles();
assertEquals(2, tempFiles.length);
// The second multichunk should be >500 KB
assertTrue(tempFiles[0].length() > 500 * 1024 || tempFiles[1].length() > 500 * 1024);
// The database file should be <100 KB
assertTrue(tempFiles[0].length() < 100 * 1024 || tempFiles[1].length() < 100 * 1024);
File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);
assertEquals(3, transactionTO.getActions().size());
assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("multichunk-"));
assertTrue(transactionTO.getActions().get(2).getRemoteFile().getName().contains("database-"));
// 2. Double check if list() does not return the multichunk
TransferManager transferManager = TransferManagerFactory.build(clientA.getConfig()).withFeature(TransactionAware.class).asDefault();
Map<String, MultichunkRemoteFile> multiChunkList = transferManager.list(MultichunkRemoteFile.class);
assertEquals(0, multiChunkList.size());
// 3. Second try fails in the beginning, to see if cleanTransactions was successful
boolean secondUpFailed = false;
// Do not resume, since we want to clean transactions.
UpOperationOptions upOptions = new UpOperationOptions();
upOptions.setResume(false);
try {
clientA.up(upOptions);
} catch (StorageException e) {
secondUpFailed = true;
logger.log(Level.INFO, e.getMessage());
}
assertTrue(secondUpFailed);
assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
// left over, 2 failed ops
assertEquals(2, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/temporary/").listFiles().length);
// 4. Third try; this should finally succeed
clientA.up(upOptions);
assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(2, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
// cleaned
assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
// cleaned
assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);
// Tear down
clientA.deleteTestData();
}
use of org.simpleframework.xml.core.Persister in project syncany by syncany.
the class UploadInterruptedTest method testUnreliableUpload_Test2_FailsAtMultichunk.
@Test
public void testUnreliableUpload_Test2_FailsAtMultichunk() throws Exception {
/*
* This test fails when trying to upload the first multichunk.
*/
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { ".+upload.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
clientA.createNewFile("A-original", 10);
boolean upFailed = false;
try {
clientA.up();
} catch (StorageException e) {
upFailed = true;
logger.log(Level.INFO, e.getMessage());
}
assertTrue(upFailed);
assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);
assertEquals(2, transactionTO.getActions().size());
assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("database-"));
// Tear down
clientA.deleteTestData();
}
use of org.simpleframework.xml.core.Persister in project syncany by syncany.
the class TransferSettingsTest method testRestore.
@Test
public void testRestore() throws Exception {
final String fooTest = "foo-test";
final String bazTest = "baz";
final int numberTest = 1234;
final DummyTransferSettings ts = new DummyTransferSettings();
final LocalTransferSettings lts = new LocalTransferSettings();
final InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
final ConfigTO conf = initOperationOptions.getConfigTO();
File repoDir = ((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath();
File localDir = initOperationOptions.getLocalDir();
conf.setTransferSettings(ts);
ts.foo = fooTest;
ts.baz = bazTest;
ts.number = numberTest;
lts.setPath(File.createTempFile("aaa", "bbb"));
ts.subsettings = lts;
assertTrue(ts.isValid());
Serializer serializer = new Persister();
serializer.write(conf, tmpFile);
System.out.println(new String(Files.readAllBytes(Paths.get(tmpFile.toURI()))));
ConfigTO confRestored = ConfigTO.load(tmpFile);
TransferPlugin plugin = Plugins.get(confRestored.getTransferSettings().getType(), TransferPlugin.class);
assertNotNull(plugin);
TransferSettings tsRestored = confRestored.getTransferSettings();
assertNotNull(tsRestored);
DummyTransferManager transferManager = plugin.createTransferManager(tsRestored, config);
assertNotNull(transferManager);
// Tear down
FileUtils.deleteDirectory(localDir);
FileUtils.deleteDirectory(repoDir);
}
use of org.simpleframework.xml.core.Persister in project syncany by syncany.
the class TransferSettingsTest method testDeserializeWrongClass.
@Test(expected = ElementException.class)
public void testDeserializeWrongClass() throws Exception {
LocalTransferSettings lts = new LocalTransferSettings();
lts.setPath(tmpFile);
Serializer serializer = new Persister();
serializer.write(lts, tmpFile);
// This shouldn't blow up!
serializer.read(DummyTransferSettings.class, tmpFile);
}
use of org.simpleframework.xml.core.Persister in project syncany by syncany.
the class TestConfigUtil method createTestLocalConfig.
public static Config createTestLocalConfig(String machineName, TransferSettings connection) throws Exception {
File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, connection));
tempLocalDir.mkdirs();
RepoTO repoTO = createRepoTO();
// Create config TO
ConfigTO configTO = new ConfigTO();
configTO.setMachineName(machineName + CipherUtil.createRandomAlphabeticString(20));
// Get Masterkey
SaltedSecretKey masterKey = getMasterKey();
configTO.setMasterKey(masterKey);
LocalTransferSettings localConnection = (LocalTransferSettings) connection;
// Create connection TO
Map<String, String> localConnectionSettings = new HashMap<String, String>();
localConnectionSettings.put("path", localConnection.getPath().getAbsolutePath());
configTO.setTransferSettings(connection);
// Create
Config config = new Config(tempLocalDir, configTO, repoTO);
config.setConnection(connection);
config.getAppDir().mkdirs();
config.getCacheDir().mkdirs();
config.getDatabaseDir().mkdirs();
config.getLogDir().mkdirs();
config.getStateDir().mkdirs();
// Write to config folder (required for some tests)
new Persister().write(configTO, new File(config.getAppDir() + "/" + Config.FILE_CONFIG));
new Persister().write(repoTO, new File(config.getAppDir() + "/" + Config.FILE_REPO));
return config;
}
Aggregations