Moved callback initialisation from start() to constructor so it can be

accessed outside the lock.
This commit is contained in:
akwizgran
2011-10-08 12:46:35 +01:00
parent 7eaefd97cb
commit 5f40015ec2
13 changed files with 88 additions and 101 deletions

View File

@@ -36,10 +36,10 @@ public class BluetoothClientTest {
remoteProperties.put(contactId, properties);
// Create the plugin
BluetoothPlugin plugin =
new BluetoothPlugin(new ImmediateExecutor(), 0L);
new BluetoothPlugin(new ImmediateExecutor(), callback, 0L);
// Start the plugin
System.out.println("Starting plugin");
plugin.start(localProperties, remoteProperties, config, callback);
plugin.start(localProperties, remoteProperties, config);
// Try to connect to the server
System.out.println("Creating connection");
StreamTransportConnection conn = plugin.createConnection(contactId);

View File

@@ -29,10 +29,10 @@ public class BluetoothServerTest {
config.put("uuid", UUID);
// Create the plugin
BluetoothPlugin plugin =
new BluetoothPlugin(new ImmediateExecutor(), 0L);
new BluetoothPlugin(new ImmediateExecutor(), callback, 0L);
// Start the plugin
System.out.println("Starting plugin");
plugin.start(localProperties, remoteProperties, config, callback);
plugin.start(localProperties, remoteProperties, config);
// Wait for a connection
System.out.println("Waiting for connection");
synchronized(callback) {

View File

@@ -48,13 +48,15 @@ public class RemovableDrivePluginTest extends TestCase {
public void testGetId() {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
callback, finder, monitor);
assertEquals(RemovableDrivePlugin.TRANSPORT_ID,
plugin.getId().getInt());
@@ -68,12 +70,12 @@ public class RemovableDrivePluginTest extends TestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
@@ -82,8 +84,8 @@ public class RemovableDrivePluginTest extends TestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
assertNull(plugin.createWriter(contactId));
@@ -100,12 +102,12 @@ public class RemovableDrivePluginTest extends TestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
@@ -117,8 +119,8 @@ public class RemovableDrivePluginTest extends TestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
assertNull(plugin.createWriter(contactId));
File[] files = drive1.listFiles();
@@ -137,12 +139,12 @@ public class RemovableDrivePluginTest extends TestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
@@ -154,8 +156,8 @@ public class RemovableDrivePluginTest extends TestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
assertNull(plugin.createWriter(contactId));
File[] files = drive1.listFiles();
@@ -176,12 +178,12 @@ public class RemovableDrivePluginTest extends TestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
@@ -193,8 +195,8 @@ public class RemovableDrivePluginTest extends TestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
assertNull(plugin.createWriter(contactId));
File[] files = drive1.listFiles();
@@ -215,12 +217,12 @@ public class RemovableDrivePluginTest extends TestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
@@ -232,8 +234,8 @@ public class RemovableDrivePluginTest extends TestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
assertNotNull(plugin.createWriter(contactId));
// The output file should exist and should be empty
@@ -257,12 +259,12 @@ public class RemovableDrivePluginTest extends TestCase {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
@@ -275,8 +277,8 @@ public class RemovableDrivePluginTest extends TestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
BatchTransportWriter writer = plugin.createWriter(contactId);
assertNotNull(writer);
@@ -303,20 +305,20 @@ public class RemovableDrivePluginTest extends TestCase {
public void testEmptyDriveIsIgnored() throws Exception {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
plugin.driveInserted(testDir);
@@ -327,13 +329,15 @@ public class RemovableDrivePluginTest extends TestCase {
public void testFilenames() {
Mockery context = new Mockery();
final Executor executor = context.mock(Executor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
finder, monitor);
callback, finder, monitor);
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
@@ -348,20 +352,20 @@ public class RemovableDrivePluginTest extends TestCase {
@Test
public void testSmallFileIsIgnored() throws Exception {
Mockery context = new Mockery();
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
new ImmediateExecutor(), finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
new ImmediateExecutor(), callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
File f = new File(testDir, "abcdefgh.dat");
OutputStream out = new FileOutputStream(f);
@@ -377,12 +381,12 @@ public class RemovableDrivePluginTest extends TestCase {
@Test
public void testReaderIsCreated() throws Exception {
Mockery context = new Mockery();
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
final RemovableDriveFinder finder =
context.mock(RemovableDriveFinder.class);
final RemovableDriveMonitor monitor =
context.mock(RemovableDriveMonitor.class);
final BatchTransportCallback callback =
context.mock(BatchTransportCallback.class);
context.checking(new Expectations() {{
oneOf(monitor).start(with(any(Callback.class)));
@@ -390,8 +394,8 @@ public class RemovableDrivePluginTest extends TestCase {
}});
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
new ImmediateExecutor(), finder, monitor);
plugin.start(localProperties, remoteProperties, config, callback);
new ImmediateExecutor(), callback, finder, monitor);
plugin.start(localProperties, remoteProperties, config);
File f = new File(testDir, "abcdefgh.dat");
OutputStream out = new FileOutputStream(f);

View File

@@ -42,8 +42,8 @@ public class SimpleSocketPluginTest extends TestCase {
localProperties.put("host", "127.0.0.1");
localProperties.put("port", "0");
SimpleSocketPlugin plugin =
new SimpleSocketPlugin(new ImmediateExecutor(), 10);
plugin.start(localProperties, remoteProperties, config, callback);
new SimpleSocketPlugin(new ImmediateExecutor(), callback, 0L);
plugin.start(localProperties, remoteProperties, config);
// The plugin should have bound a socket and stored the port number
assertNotNull(callback.localProperties);
String host = callback.localProperties.get("host");
@@ -76,8 +76,8 @@ public class SimpleSocketPluginTest extends TestCase {
public void testOutgoingConnection() throws Exception {
StubStreamCallback callback = new StubStreamCallback();
SimpleSocketPlugin plugin =
new SimpleSocketPlugin(new ImmediateExecutor(), 10);
plugin.start(localProperties, remoteProperties, config, callback);
new SimpleSocketPlugin(new ImmediateExecutor(), callback, 0L);
plugin.start(localProperties, remoteProperties, config);
// Listen on a local port
final ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress("127.0.0.1", 0), 10);
@@ -118,8 +118,8 @@ public class SimpleSocketPluginTest extends TestCase {
localProperties.put("host", "127.0.0.1");
localProperties.put("port", "0");
SimpleSocketPlugin plugin =
new SimpleSocketPlugin(new ImmediateExecutor(), 10);
plugin.start(localProperties, remoteProperties, config, callback);
new SimpleSocketPlugin(new ImmediateExecutor(), callback, 0L);
plugin.start(localProperties, remoteProperties, config);
// The plugin should have bound a socket and stored the port number
assertNotNull(callback.localProperties);
String host = callback.localProperties.get("host");