diff --git a/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageOutputStreamTest.java b/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageOutputStreamTest.java index 8a1bcf5beae891637f5bf3ef5c968fc9ec111f8f..2961495bb9e8b96b51fc4f377a469b371b901deb 100644 --- a/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageOutputStreamTest.java +++ b/apps/streaming/java/test/junit/net/i2p/client/streaming/MessageOutputStreamTest.java @@ -1,33 +1,34 @@ package net.i2p.client.streaming; import java.io.ByteArrayOutputStream; -import java.io.IOException; + +import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Test; import net.i2p.I2PAppContext; import net.i2p.data.Base64; -import net.i2p.util.Log; +import net.i2p.util.SimpleTimer2; -/** - * - */ -public class MessageOutputStreamTest { +public class MessageOutputStreamTest extends TestCase { private I2PAppContext _context; - private Log _log; + private SimpleTimer2 _st2; - public MessageOutputStreamTest() { + @Before + public void setUp() { _context = I2PAppContext.getGlobalContext(); - _log = _context.logManager().getLog(MessageOutputStreamTest.class); + _st2 = _context.simpleTimer2(); } - public void test() { + @Test + public void test() throws Exception { Receiver receiver = new Receiver(); - MessageOutputStream out = new MessageOutputStream(_context, receiver); + MessageOutputStream out = new MessageOutputStream(_context, _st2, receiver, 100); byte buf[] = new byte[128*1024]; _context.random().nextBytes(buf); - try { - out.write(buf); - out.flush(); - } catch (IOException ioe) { ioe.printStackTrace(); } + out.write(buf); + out.flush(); byte read[] = receiver.getData(); int firstOff = -1; for (int k = 0; k < buf.length; k++) { @@ -36,14 +37,12 @@ public class MessageOutputStreamTest { break; } } - if (firstOff < 0) { - System.out.println("** Read match"); - } else { - System.out.println("** Read does not match: first off = " + firstOff); - _log.error("read does not match (first off = " + firstOff + "): \n" - + Base64.encode(buf) + "\n" - + Base64.encode(read)); - } + assertTrue( + "read does not match (first off = " + firstOff + "): \n" + + Base64.encode(buf) + "\n" + + Base64.encode(read) + , + firstOff < 0); } private class Receiver implements MessageOutputStream.DataReceiver { @@ -66,9 +65,4 @@ public class MessageOutputStreamTest { public boolean writeFailed() { return false; } public boolean writeSuccessful() { return true; } } - - public static void main(String args[]) { - MessageOutputStreamTest t = new MessageOutputStreamTest(); - t.test(); - } } diff --git a/apps/streaming/java/test/junit/net/i2p/client/streaming/PingTest.java b/apps/streaming/java/test/junit/net/i2p/client/streaming/PingTest.java index 7ad5ba442076e5b10a745cc6e4c4121f361feb19..99a13d8a973635771ed858d092b1e34d52ccd6d2 100644 --- a/apps/streaming/java/test/junit/net/i2p/client/streaming/PingTest.java +++ b/apps/streaming/java/test/junit/net/i2p/client/streaming/PingTest.java @@ -4,53 +4,34 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.Properties; +import org.junit.Test; + +import junit.framework.TestCase; + import net.i2p.I2PAppContext; import net.i2p.client.I2PClient; import net.i2p.client.I2PClientFactory; import net.i2p.client.I2PSession; -import net.i2p.data.Destination; -import net.i2p.util.Log; -/** - * - */ -public class PingTest { - public void test() { - try { - I2PAppContext context = I2PAppContext.getGlobalContext(); - I2PSession session = createSession(); - ConnectionManager mgr = new ConnectionManager(context, session, -1, null); - Log log = context.logManager().getLog(PingTest.class); - for (int i = 0; i < 10; i++) { - log.debug("ping " + i); - long before = context.clock().now(); - boolean ponged = mgr.ping(session.getMyDestination(), 2*1000); - long after = context.clock().now(); - log.debug("ponged? " + ponged + " after " + (after-before) + "ms"); - } - } catch (Exception e) { - e.printStackTrace(); - } - try { Thread.sleep(30*1000); } catch (Exception e) {} - - } - - private I2PSession createSession() { - try { - I2PClient client = I2PClientFactory.createClient(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(512); - Destination dest = client.createDestination(baos); - I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties()); - sess.connect(); - return sess; - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("b0rk b0rk b0rk"); +public class PingTest extends TestCase { + + @Test + public void test() throws Exception { + I2PAppContext context = I2PAppContext.getGlobalContext(); + I2PSession session = createSession(); + ConnectionManager mgr = new ConnectionManager(context, session, new ConnectionOptions()); + for (int i = 0; i < 10; i++) { + boolean ponged = mgr.ping(session.getMyDestination(), 2*1000); + assertTrue(ponged); } } - public static void main(String args[]) { - PingTest pt = new PingTest(); - pt.test(); + private I2PSession createSession() throws Exception { + I2PClient client = I2PClientFactory.createClient(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(512); + client.createDestination(baos); + I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties()); + sess.connect(); + return sess; } }