mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Fix ReturnShardIntegrationTest
This commit is contained in:
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.test.TestDatabaseConfigModule;
|
||||
import org.briarproject.briar.api.socialbackup.BackupPayload;
|
||||
import org.briarproject.briar.api.socialbackup.MessageEncoder;
|
||||
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
||||
import org.briarproject.briar.api.socialbackup.Shard;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
|
||||
@@ -15,9 +16,9 @@ import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
||||
@@ -32,6 +33,8 @@ public class ReturnShardIntegrationTest extends BrambleTestCase {
|
||||
|
||||
private ReturnShardIntegrationTestComponent owner, custodian;
|
||||
|
||||
private ReturnShardPayload remotePayload;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
assertTrue(testDir.mkdirs());
|
||||
@@ -50,16 +53,20 @@ public class ReturnShardIntegrationTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnShard() {
|
||||
public void testReturnShard() throws Exception {
|
||||
SecretOwnerTask secretOwnerTask = owner.getSecretOwnerTask();
|
||||
CustodianTask custodianTask = custodian.getCustodianTask();
|
||||
byte[] payload = "its nice to be important but its more important to be nice".getBytes();
|
||||
MessageEncoder messageEncoder = owner.getMessageEncoder();
|
||||
|
||||
Shard shard = new Shard("secretid".getBytes(), "shard".getBytes());
|
||||
CountDownLatch secretOwnerFinished = new CountDownLatch(1);
|
||||
CountDownLatch custodianFinished = new CountDownLatch(1);
|
||||
|
||||
Shard shard = new Shard("secret id".getBytes(), "shard".getBytes());
|
||||
BackupPayload backupPayload = new BackupPayload("backup payload".getBytes());
|
||||
ReturnShardPayload returnShardPayload = new ReturnShardPayload(shard, backupPayload);
|
||||
|
||||
// payloadBytes = clientHelper
|
||||
byte[] payloadBytes = messageEncoder.encodeReturnShardPayload(returnShardPayload);
|
||||
|
||||
|
||||
SecretOwnerTask.Observer ownerObserver =
|
||||
state -> {
|
||||
@@ -67,30 +74,21 @@ public class ReturnShardIntegrationTest extends BrambleTestCase {
|
||||
SecretOwnerTask.State.Listening listening =
|
||||
(SecretOwnerTask.State.Listening) state;
|
||||
byte[] qrPayload = listening.getLocalPayload();
|
||||
System.out.println(qrPayload.length);
|
||||
transferQrCode(custodianTask, qrPayload);
|
||||
} else if (state instanceof SecretOwnerTask.State.Success) {
|
||||
ReturnShardPayload remotePayload = ((SecretOwnerTask.State.Success) state).getRemotePayload();
|
||||
assertTrue(remotePayload.equals(payload));
|
||||
System.out.println("Success");
|
||||
remotePayload = ((SecretOwnerTask.State.Success) state).getRemotePayload();
|
||||
secretOwnerFinished.countDown();
|
||||
} else if (state instanceof SecretOwnerTask.State.Failure) {
|
||||
System.out.println("Owner state: failure");
|
||||
fail();
|
||||
} else {
|
||||
System.out.println(
|
||||
"owner: " + state.getClass().getSimpleName());
|
||||
}
|
||||
};
|
||||
|
||||
CustodianTask.Observer custodianObserver =
|
||||
state -> {
|
||||
if (state instanceof CustodianTask.State.Success) {
|
||||
assertEquals(1, 1);
|
||||
custodianFinished.countDown();
|
||||
} else if (state instanceof CustodianTask.State.Failure) {
|
||||
fail();
|
||||
} else {
|
||||
System.out.println(
|
||||
"custodian: " + state.getClass().getSimpleName());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -105,19 +103,14 @@ public class ReturnShardIntegrationTest extends BrambleTestCase {
|
||||
|
||||
custodian.getIoExecutor().execute(() -> {
|
||||
try {
|
||||
custodianTask.start(custodianObserver, payload);
|
||||
custodianTask.start(custodianObserver, payloadBytes);
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO how to get the test to wait for the io to finish
|
||||
try {
|
||||
// Thread.sleep(1000);
|
||||
tearDown();
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
assertTrue(secretOwnerFinished.await(15000, MILLISECONDS));
|
||||
assertTrue(custodianFinished.await(15000, MILLISECONDS));
|
||||
assertTrue(remotePayload.equals(returnShardPayload));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.socialbackup.recovery;
|
||||
|
||||
import org.briarproject.bramble.BrambleCoreIntegrationTestEagerSingletons;
|
||||
import org.briarproject.bramble.BrambleCoreModule;
|
||||
import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.connection.ConnectionManager;
|
||||
import org.briarproject.bramble.api.contact.ContactExchangeManager;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
@@ -10,6 +11,7 @@ import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule;
|
||||
import org.briarproject.briar.api.socialbackup.MessageEncoder;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
|
||||
import org.briarproject.briar.socialbackup.SocialBackupModule;
|
||||
@@ -44,6 +46,8 @@ interface ReturnShardIntegrationTestComponent
|
||||
|
||||
LifecycleManager getLifecycleManager();
|
||||
|
||||
MessageEncoder getMessageEncoder();
|
||||
|
||||
SecretOwnerTask getSecretOwnerTask();
|
||||
|
||||
CustodianTask getCustodianTask();
|
||||
|
||||
Reference in New Issue
Block a user