Plugins may dispose of resources differently depending on whether a

connection was recognised.
This commit is contained in:
akwizgran
2011-12-08 18:56:53 +00:00
parent 0fdc69ff00
commit 844ae8f0a7
18 changed files with 97 additions and 74 deletions

View File

@@ -38,10 +38,10 @@ abstract class StreamTest {
} else {
System.out.println("No response");
}
s.dispose(true);
s.dispose(false, true);
} catch(IOException e) {
e.printStackTrace();
s.dispose(false);
s.dispose(true, true);
}
}
@@ -62,10 +62,10 @@ abstract class StreamTest {
} else {
System.out.println("No challenge");
}
s.dispose(true);
s.dispose(false, true);
} catch(IOException e) {
e.printStackTrace();
s.dispose(false);
s.dispose(true, true);
}
}
}

View File

@@ -283,11 +283,9 @@ public class RemovableDrivePluginTest extends TestCase {
out.write(new byte[123]);
out.flush();
out.close();
assertEquals(123L, files[0].length());
// Successfully disposing of the writer should not delete the file
writer.dispose(true);
files = drive1.listFiles();
assertEquals(1, files.length);
// Disposing of the writer should not delete the file
writer.dispose(false);
assertTrue(files[0].exists());
assertEquals(123L, files[0].length());
context.assertIsSatisfied();

View File

@@ -95,7 +95,7 @@ public class SimpleSocketPluginTest extends TestCase {
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertFalse(error.get());
// Clean up
conn.dispose(true);
conn.dispose(false, true);
ss.close();
plugin.stop();
}

View File

@@ -118,7 +118,8 @@ public class BatchConnectionReadWriteTest extends TestCase {
transport);
// Write whatever needs to be written
batchOut.write();
assertTrue(transport.getSuccess());
assertTrue(transport.getDisposed());
assertFalse(transport.getException());
// Close Alice's database
db.close();
// Return the contents of the batch connection
@@ -172,7 +173,9 @@ public class BatchConnectionReadWriteTest extends TestCase {
assertFalse(listener.messagesAdded);
// Read whatever needs to be read
batchIn.read();
assertTrue(transport.getSuccess());
assertTrue(transport.getDisposed());
assertFalse(transport.getException());
assertTrue(transport.getRecognised());
// The private message from Alice should have been added
assertTrue(listener.messagesAdded);
// Close Bob's database

View File

@@ -87,8 +87,9 @@ public class OutgoingBatchConnectionTest extends TestCase {
connection.write();
// Nothing should have been written
assertEquals(0, out.size());
// The transport should have been disposed with success == false
assertFalse(transport.getSuccess());
// The transport should have been disposed with exception == true
assertTrue(transport.getDisposed());
assertTrue(transport.getException());
context.assertIsSatisfied();
}
@@ -122,8 +123,9 @@ public class OutgoingBatchConnectionTest extends TestCase {
connection.write();
// Nothing should have been written
assertEquals(0, out.size());
// The transport should have been disposed with success == true
assertTrue(transport.getSuccess());
// The transport should have been disposed with exception == false
assertTrue(transport.getDisposed());
assertFalse(transport.getException());
context.assertIsSatisfied();
}
@@ -171,8 +173,9 @@ public class OutgoingBatchConnectionTest extends TestCase {
connection.write();
// Something should have been written
assertTrue(out.size() > UniqueId.LENGTH + message.length);
// The transport should have been disposed with success == true
assertTrue(transport.getSuccess());
// The transport should have been disposed with exception == false
assertTrue(transport.getDisposed());
assertFalse(transport.getException());
context.assertIsSatisfied();
}
}

View File

@@ -4,12 +4,11 @@ import java.io.InputStream;
import net.sf.briar.api.transport.BatchTransportReader;
class TestBatchTransportReader
implements BatchTransportReader {
class TestBatchTransportReader implements BatchTransportReader {
private final InputStream in;
private boolean success = false;
private boolean disposed = false, exception = false, recognised = false;
TestBatchTransportReader(InputStream in) {
this.in = in;
@@ -19,11 +18,22 @@ implements BatchTransportReader {
return in;
}
public void dispose(boolean success) {
this.success = success;
public void dispose(boolean exception, boolean recognised) {
assert !disposed;
disposed = true;
this.exception = exception;
this.recognised = recognised;
}
boolean getSuccess() {
return success;
boolean getDisposed() {
return disposed;
}
boolean getException() {
return exception;
}
boolean getRecognised() {
return recognised;
}
}

View File

@@ -5,16 +5,14 @@ import java.io.OutputStream;
import net.sf.briar.api.transport.BatchTransportWriter;
class TestBatchTransportWriter
implements BatchTransportWriter {
class TestBatchTransportWriter implements BatchTransportWriter {
private final ByteArrayOutputStream out;
private final long capacity;
private boolean success = false;
private boolean disposed = false, exception = false;
TestBatchTransportWriter(ByteArrayOutputStream out,
long capacity) {
TestBatchTransportWriter(ByteArrayOutputStream out, long capacity) {
this.out = out;
this.capacity = capacity;
}
@@ -27,11 +25,17 @@ implements BatchTransportWriter {
return out;
}
public void dispose(boolean success) {
this.success = success;
public void dispose(boolean exception) {
assert !disposed;
disposed = true;
this.exception = exception;
}
boolean getSuccess() {
return success;
boolean getDisposed() {
return disposed;
}
boolean getException() {
return exception;
}
}