Skip to content
Snippets Groups Projects
Commit ef8841e7 authored by akwizgran's avatar akwizgran
Browse files

Non-JUnit tests for detecting when the other end hangs up.

parent a6777f1f
No related branches found
No related tags found
No related merge requests found
......@@ -13,5 +13,6 @@
<classpathentry kind="lib" path="/briar-core/libs/commons-io-2.0.1.jar"/>
<classpathentry kind="lib" path="/briar-core/libs/jnotify-0.93.jar"/>
<classpathentry kind="lib" path="/briar-core/libs/scprov-jdk15on-1.47.0.3-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="/briar-core/libs/jssc-0.9-briar.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
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");
Thread.sleep(10 * 1000);
} else {
System.out.println("Did not connect");
}
modem.stop();
} finally {
executor.shutdown();
}
}
}
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();
}
}
}
......@@ -44,5 +44,4 @@ public class ModemClientTest extends DuplexClientTest {
executor.shutdown();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment