Search in sources :

Example 6 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class TransferSettingsTest method testDeserializeCorrectClass.

@Test
public void testDeserializeCorrectClass() throws Exception {
    Serializer serializer = new Persister();
    InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
    // Always LocalTransferSettings
    serializer.write(initOperationOptions.getConfigTO(), tmpFile);
    ConfigTO confRestored = ConfigTO.load(tmpFile);
    assertEquals(LocalTransferSettings.class, confRestored.getTransferSettings().getClass());
    // Tear down
    FileUtils.deleteDirectory(initOperationOptions.getLocalDir());
    FileUtils.deleteDirectory(((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath());
}
Also used : InitOperationOptions(org.syncany.operations.init.InitOperationOptions) Persister(org.simpleframework.xml.core.Persister) ConfigTO(org.syncany.config.to.ConfigTO) Serializer(org.simpleframework.xml.Serializer) Test(org.junit.Test)

Example 7 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class UploadInterruptedTest method testUnreliableUpload_Test4_1_FailsAtSecondMultiChunkUpload.

@Test
public void testUnreliableUpload_Test4_1_FailsAtSecondMultiChunkUpload() throws Exception {
    /*
		 * This test fails when trying to upload the second multichunk, but succeeds on retry
		 *
		 * 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) <<< FAILS HERE
		 * 5. upload(database-123, temp-3) 6. move(temp-1, multichunks/multichunk-1)
		 * 7. move(temp-2, multichunks/multichunk-2)
		 * 8. move(temp-3, databases/database-123)
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[456].+upload.+multichunk" }));
    TestClient clientA = new TestClient("A", testConnection);
    // << larger than one multichunk!
    clientA.createNewFile("A-original", 5 * 1024 * 1024);
    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[] tempFiles = new File(testConnection.getPath() + "/temporary/").listFiles();
    assertEquals(1, tempFiles.length);
    // 1 MC with 1 MB, 1 with 4 MB; must be larger than 500 KB
    assertTrue(tempFiles[0].length() > 500 * 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. Second try succeeds and must clean up the transactions
    clientA.up();
    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(2, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
    assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);
    // Tear down
    clientA.deleteTestData();
}
Also used : UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile) TransactionTO(org.syncany.plugins.transfer.to.TransactionTO) Test(org.junit.Test)

Example 8 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class UpdateOperation method executeCheck.

private UpdateOperationResult executeCheck() throws Exception {
    Version localAppVersion = Version.valueOf(Client.getApplicationVersion());
    String appInfoResponseStr = getAppInfoResponseStr();
    AppInfoResponse appInfoResponse = new Persister().read(AppInfoResponse.class, appInfoResponseStr);
    ArrayList<AppInfo> appInfoList = appInfoResponse.getAppInfoList();
    if (appInfoList.size() > 0) {
        AppInfo remoteAppInfo = appInfoList.get(0);
        Version remoteAppVersion = Version.valueOf(remoteAppInfo.getAppVersion());
        boolean newVersionAvailable = remoteAppVersion.greaterThan(localAppVersion);
        result.setResultCode(UpdateResultCode.OK);
        result.setAppInfo(remoteAppInfo);
        result.setNewVersionAvailable(newVersionAvailable);
        return result;
    } else {
        result.setResultCode(UpdateResultCode.NOK);
        return result;
    }
}
Also used : Version(com.github.zafarkhaja.semver.Version) Persister(org.simpleframework.xml.core.Persister)

Example 9 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class ApplicationLink method createTransferSettings.

private TransferSettings createTransferSettings(byte[] plaintextPluginSettingsBytes) throws StorageException, IOException {
    // Find plugin ID and settings XML
    int pluginIdentifierLength = Ints.fromByteArray(Arrays.copyOfRange(plaintextPluginSettingsBytes, 0, INTEGER_BYTES));
    String pluginId = new String(Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES, INTEGER_BYTES + pluginIdentifierLength));
    byte[] gzippedPluginSettingsByteArray = Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES + pluginIdentifierLength, plaintextPluginSettingsBytes.length);
    String pluginSettings = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(gzippedPluginSettingsByteArray)));
    // Create transfer settings object
    try {
        TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
        if (plugin == null) {
            throw new StorageException("Link contains unknown connection type '" + pluginId + "'. Corresponding plugin not found.");
        }
        Class<? extends TransferSettings> pluginTransferSettingsClass = TransferPluginUtil.getTransferSettingsClass(plugin.getClass());
        TransferSettings transferSettings = new Persister().read(pluginTransferSettingsClass, pluginSettings);
        logger.log(Level.INFO, "(Decrypted) link contains: " + pluginId + " -- " + pluginSettings);
        return transferSettings;
    } catch (Exception e) {
        throw new StorageException(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) ByteArrayInputStream(java.io.ByteArrayInputStream) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException)

Example 10 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class TransactionTO method save.

public void save(Transformer transformer, File transactionFile) throws Exception {
    PrintWriter out;
    if (transformer == null) {
        out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(transactionFile), "UTF-8"));
    } else {
        out = new PrintWriter(new OutputStreamWriter(transformer.createOutputStream(new FileOutputStream(transactionFile)), "UTF-8"));
    }
    Serializer serializer = new Persister();
    serializer.write(this, out);
    out.flush();
    out.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Persister(org.simpleframework.xml.core.Persister) PrintWriter(java.io.PrintWriter) Serializer(org.simpleframework.xml.Serializer)

Aggregations

Persister (org.simpleframework.xml.core.Persister)30 File (java.io.File)11 Test (org.junit.Test)11 StorageException (org.syncany.plugins.transfer.StorageException)8 Serializer (org.simpleframework.xml.Serializer)7 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)6 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)5 TransactionTO (org.syncany.plugins.transfer.to.TransactionTO)5 IOException (java.io.IOException)4 ConfigException (org.syncany.config.ConfigException)4 ConfigTO (org.syncany.config.to.ConfigTO)4 TestClient (org.syncany.tests.util.TestClient)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)3 Subscribe (com.google.common.eventbus.Subscribe)2 User (com.lonepulse.robozombie.model.User)2 FileOutputStream (java.io.FileOutputStream)2 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)2 BuildException (org.apache.tools.ant.BuildException)2