Search in sources :

Example 31 with Persister

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

the class UploadInterruptedTest method testUnreliableUpload_Test3_FailsAtDatabaseFile.

@Test
public void testUnreliableUpload_Test3_FailsAtDatabaseFile() throws Exception {
    /*
		 * This test fails when trying to upload the first database file, 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)
		 * 5. upload(database-123, temp-2) <<< FAILS HERE
		 * 6. move(temp-1, multichunks/multichunk-1)
		 * 8. move(temp-2, databases/database-123)
		 */
    // Setup
    UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[456].+upload.+database" }));
    TestClient clientA = new TestClient("A", testConnection);
    // 1. First upload fails
    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);
    assertEquals(1, new File(testConnection.getPath() + "/temporary/").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-"));
    // 2. Second try succeeds and must clean up the transactions
    clientA.up();
    assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
    assertEquals(1, 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)

Aggregations

Persister (org.simpleframework.xml.core.Persister)31 File (java.io.File)12 Test (org.junit.Test)11 Serializer (org.simpleframework.xml.Serializer)8 StorageException (org.syncany.plugins.transfer.StorageException)8 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)6 ConfigTO (org.syncany.config.to.ConfigTO)5 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 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