Converted ReliabilityLayer into an interface for better testability.

This commit is contained in:
akwizgran
2012-12-14 21:57:50 +00:00
parent e5d15d42d6
commit 47749c3c0d
11 changed files with 175 additions and 214 deletions

View File

@@ -1,42 +0,0 @@
package net.sf.briar.plugins.modem;
import static java.util.logging.Level.INFO;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
public class HangupClientTest {
public static void main(String[] args) throws Exception {
if(args.length != 2) {
System.err.println("Please specify the server's phone number "
+ " and the serial port");
System.exit(1);
}
String number = args[0];
String portName = args[1];
Logger.getLogger("net.sf.briar").setLevel(INFO);
ExecutorService executor = Executors.newCachedThreadPool();
Modem.Callback callback = new Modem.Callback() {
public void incomingCallConnected() {
System.err.println("Unexpected incoming call");
System.exit(1);
}
};
try {
Modem modem = new ModemImpl(executor, callback, portName);
modem.start();
System.out.println("Dialling");
if(modem.dial(number)) {
System.out.println("Connected, waiting for server to hang up");
Thread.sleep(60 * 1000);
} else {
System.out.println("Did not connect");
}
modem.stop();
} finally {
executor.shutdown();
}
}
}

View File

@@ -1,43 +0,0 @@
package net.sf.briar.plugins.modem;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.logging.Level.INFO;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
public class HangupServerTest {
public static void main(String[] args) throws Exception {
if(args.length != 1) {
System.err.println("Please specify the serial port");
System.exit(1);
}
String portName = args[0];
Logger.getLogger("net.sf.briar").setLevel(INFO);
ExecutorService executor = Executors.newCachedThreadPool();
final CountDownLatch latch = new CountDownLatch(1);
Modem.Callback callback = new Modem.Callback() {
public void incomingCallConnected() {
System.out.println("Connected");
latch.countDown();
}
};
try {
final Modem modem = new ModemImpl(executor, callback, portName);
modem.start();
System.out.println("Waiting for incoming call");
if(latch.await(60, SECONDS)) {
System.out.println("Hanging up");
modem.hangUp();
} else {
System.out.println("Did not connect");
}
modem.stop();
} finally {
executor.shutdown();
}
}
}

View File

@@ -27,8 +27,8 @@ public class ModemClientTest extends DuplexClientTest {
// Create the plugin
callback = new ClientCallback(new TransportConfig(),
new TransportProperties(), remote);
plugin = new ModemPlugin(executor, new ModemFactoryImpl(executor),
callback, 0L);
plugin = new ModemPlugin(executor, new ModemFactoryImpl(executor,
new ReliabilityLayerFactoryImpl(executor)), callback, 0L);
}
public static void main(String[] args) throws Exception {

View File

@@ -21,8 +21,8 @@ public class ModemServerTest extends DuplexServerTest {
callback = new ServerCallback(new TransportConfig(),
new TransportProperties(), Collections.singletonMap(contactId,
new TransportProperties()));
plugin = new ModemPlugin(executor, new ModemFactoryImpl(executor),
callback, 0L);
plugin = new ModemPlugin(executor, new ModemFactoryImpl(executor,
new ReliabilityLayerFactoryImpl(executor)), callback, 0L);
}
public static void main(String[] args) throws Exception {