Fixed Bluetooth shutdown issues.

This commit is contained in:
akwizgran
2011-12-09 23:01:32 +00:00
parent 5ba5887565
commit e47d4990c3
8 changed files with 58 additions and 37 deletions

View File

@@ -11,6 +11,8 @@ import net.sf.briar.api.transport.StreamTransportConnection;
public abstract class StreamClientTest extends StreamTest {
protected ClientCallback callback = null;
protected void run() throws IOException {
assert plugin != null;
// Start the plugin

View File

@@ -1,6 +1,7 @@
package net.sf.briar.plugins;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
@@ -10,6 +11,8 @@ import net.sf.briar.api.transport.StreamTransportConnection;
public abstract class StreamServerTest extends StreamTest {
protected ServerCallback callback = null;
protected void run() throws Exception {
assert callback != null;
assert plugin != null;
@@ -18,9 +21,7 @@ public abstract class StreamServerTest extends StreamTest {
plugin.start();
// Wait for a connection
System.out.println("Waiting for connection");
synchronized(callback) {
callback.wait();
}
callback.latch.await();
// Try to accept an invitation
System.out.println("Accepting invitation");
StreamTransportConnection s = plugin.acceptInvitation(123,
@@ -47,6 +48,8 @@ public abstract class StreamServerTest extends StreamTest {
protected class ServerCallback implements StreamPluginCallback {
private final CountDownLatch latch = new CountDownLatch(1);
private TransportConfig config;
private TransportProperties local;
private Map<ContactId, TransportProperties> remote;
@@ -91,9 +94,7 @@ public abstract class StreamServerTest extends StreamTest {
public void incomingConnectionCreated(StreamTransportConnection s) {
System.out.println("Connection received");
sendChallengeReceiveResponse(s);
synchronized(this) {
notifyAll();
}
latch.countDown();
}
public void outgoingConnectionCreated(ContactId contactId,

View File

@@ -6,7 +6,6 @@ import java.util.Scanner;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.plugins.StreamPlugin;
import net.sf.briar.api.plugins.StreamPluginCallback;
import net.sf.briar.api.transport.StreamTransportConnection;
abstract class StreamTest {
@@ -17,7 +16,6 @@ abstract class StreamTest {
protected final ContactId contactId = new ContactId(0);
protected StreamPluginCallback callback = null;
protected StreamPlugin plugin = null;
protected void sendChallengeReceiveResponse(StreamTransportConnection s) {

View File

@@ -2,8 +2,9 @@ package net.sf.briar.plugins.bluetooth;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
@@ -14,7 +15,7 @@ import net.sf.briar.plugins.StreamClientTest;
// is running on another machine
public class BluetoothClientTest extends StreamClientTest {
private BluetoothClientTest(String serverAddress) {
private BluetoothClientTest(Executor executor, String serverAddress) {
// Store the server's Bluetooth address and UUID
TransportProperties p = new TransportProperties();
p.put("address", serverAddress);
@@ -24,7 +25,6 @@ public class BluetoothClientTest extends StreamClientTest {
// Create the plugin
callback = new ClientCallback(new TransportConfig(),
new TransportProperties(), remote);
Executor executor = Executors.newCachedThreadPool();
plugin = new BluetoothPlugin(executor, callback, 0L);
}
@@ -33,6 +33,11 @@ public class BluetoothClientTest extends StreamClientTest {
System.err.println("Please specify the server's Bluetooth address");
System.exit(1);
}
new BluetoothClientTest(args[0]).run();
ExecutorService executor = Executors.newCachedThreadPool();
try {
new BluetoothClientTest(executor, args[0]).run();
} finally {
executor.shutdown();
}
}
}

View File

@@ -1,8 +1,9 @@
package net.sf.briar.plugins.bluetooth;
import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import net.sf.briar.api.TransportConfig;
import net.sf.briar.api.TransportProperties;
@@ -12,18 +13,22 @@ import net.sf.briar.plugins.StreamServerTest;
// is running on another machine
public class BluetoothServerTest extends StreamServerTest {
private BluetoothServerTest() {
private BluetoothServerTest(Executor executor) {
// Store the UUID
TransportProperties local = new TransportProperties();
local.put("uuid", BluetoothTest.UUID);
// Create the plugin
callback = new ServerCallback(new TransportConfig(), local,
Collections.singletonMap(contactId, new TransportProperties()));
Executor executor = Executors.newCachedThreadPool();
plugin = new BluetoothPlugin(executor, callback, 0L);
}
public static void main(String[] args) throws Exception {
new BluetoothServerTest().run();
ExecutorService executor = Executors.newCachedThreadPool();
try {
new BluetoothServerTest(executor).run();
} finally {
executor.shutdown();
}
}
}

View File

@@ -2,6 +2,7 @@ package net.sf.briar.plugins.socket;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
@@ -14,7 +15,8 @@ import net.sf.briar.plugins.StreamClientTest;
// is running on another machine
public class LanSocketClientTest extends StreamClientTest {
private LanSocketClientTest(String serverAddress, String serverPort) {
private LanSocketClientTest(Executor executor, String serverAddress,
String serverPort) {
// Store the server's internal address and port
TransportProperties p = new TransportProperties();
p.put("internal", serverAddress);
@@ -24,7 +26,6 @@ public class LanSocketClientTest extends StreamClientTest {
// Create the plugin
callback = new ClientCallback(new TransportConfig(),
new TransportProperties(), remote);
Executor executor = Executors.newCachedThreadPool();
plugin = new LanSocketPlugin(executor, callback, 0L);
}
@@ -33,6 +34,11 @@ public class LanSocketClientTest extends StreamClientTest {
System.err.println("Please specify the server's address and port");
System.exit(1);
}
new LanSocketClientTest(args[0], args[1]).run();
ExecutorService executor = Executors.newCachedThreadPool();
try {
new LanSocketClientTest(executor, args[0], args[1]).run();
} finally {
executor.shutdown();
}
}
}

View File

@@ -1,8 +1,9 @@
package net.sf.briar.plugins.socket;
import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import net.sf.briar.api.TransportConfig;
import net.sf.briar.api.TransportProperties;
@@ -12,15 +13,19 @@ import net.sf.briar.plugins.StreamServerTest;
// is running on another machine
public class LanSocketServerTest extends StreamServerTest {
private LanSocketServerTest() {
private LanSocketServerTest(Executor executor) {
callback = new ServerCallback(new TransportConfig(),
new TransportProperties(),
Collections.singletonMap(contactId, new TransportProperties()));
Executor executor = Executors.newCachedThreadPool();
plugin = new LanSocketPlugin(executor, callback, 0L);
}
public static void main(String[] args) throws Exception {
new LanSocketServerTest().run();
ExecutorService executor = Executors.newCachedThreadPool();
try {
new LanSocketServerTest(executor).run();
} finally {
executor.shutdown();
}
}
}