Changeset 4293a18


Ignore:
Timestamp:
Sep 13, 2005 9:06:07 AM (15 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
5694206
Parents:
9865af4
git-author:
comwiz <comwiz> (09/13/05 09:06:07)
git-committer:
zzz <zzz@…> (09/13/05 09:06:07)
Message:

2005-09-12 comwiz

  • Migrated the router tests to junit
Files:
3 added
3 deleted
9 edited
5 moved

Legend:

Unmodified
Added
Removed
  • build.xml

    r9865af4 r4293a18  
    325325    </target>
    326326    <target name="test.report" depends="junit.report, clover.report"/>
    327     <target name="useclover">
    328         <taskdef resource="clovertasks"/>
    329         <mkdir dir="reports/core/clover" />
    330         <mkdir dir="reports/core/clover" />
    331         <clover-setup initString="reports/core/clover/coverage.db"/>
    332     </target>
    333327    <target name="fulltest">
    334328                <ant dir="core/java/" target="fulltest" />
     329                <ant dir="router/java/" target="fulltest" />
     330    </target>
     331    <target name="fullclovertest">
     332                <ant dir="core/java/" target="fullclovertest" />
     333                <ant dir="router/java/" target="fullclovertest" />
    335334    </target>
    336335</project>
  • core/java/build.xml

    r9865af4 r4293a18  
    1414        <mkdir dir="./build" />
    1515        <mkdir dir="./build/obj" />
    16         <javac srcdir="./src:./test" debug="true" source="1.3" target="1.3" deprecation="on" destdir="./build/obj" classpath="./lib/junit.jar" />
     16        <javac srcdir="./src:./test" debug="true" source="1.3" target="1.3" deprecation="on" destdir="./build/obj" />
    1717    </target>
    1818    <target name="jar" depends="compile">
     
    3232                <pathelement path="${classpath}" />
    3333                <pathelement location="./build/obj" />
    34                 <pathelement location="./lib/junit.jar" />
    3534                <pathelement location="../../installer/lib/jbigi/jbigi.jar" />
    3635                <pathelement path="${ant.home}/lib/clover.jar"/>
     
    9291        <clover-setup initString="../../reports/core/clover/coverage.db"/>
    9392    </target>
    94     <target name="fulltest" depends="useclover, test, test.report" />
     93    <target name="fulltest" depends="test, junit.report" />
     94    <target name="fullclovertest" depends="useclover, test, test.report" />
    9595    <target name="clean">
    9696        <delete dir="./build" />
  • history.txt

    r9865af4 r4293a18  
    1 $Id: history.txt,v 1.246 2005/09/12 20:12:44 jrandom Exp $
     1$Id: history.txt,v 1.247 2005/09/12 22:32:30 jrandom Exp $
     2
     32005-09-12  comwiz
     4    * Migrated the router tests to junit
    25
    362005-09-12  jrandom
  • router/java/build.xml

    r9865af4 r4293a18  
    66        <ant dir="../../core/java/" target="build" />
    77    </target>
     8    <target name="builddeptest">
     9        <ant dir="../../core/java/" target="jarTest" />
     10    </target>
    811    <target name="compile">
    912        <mkdir dir="./build" />
     
    1114        <javac srcdir="./src" debug="true" source="1.3" target="1.3" deprecation="on" destdir="./build/obj" classpath="../../core/java/build/i2p.jar" />
    1215    </target>
     16    <target name="compileTest" depends="builddeptest">
     17        <mkdir dir="./build" />
     18        <mkdir dir="./build/obj" />
     19        <javac srcdir="./src:./test" debug="true" source="1.3" target="1.3" deprecation="on" destdir="./build/obj" classpath="../../core/java/build/i2ptest.jar" />
     20    </target>
    1321    <target name="jar" depends="compile">
    1422        <jar destfile="./build/router.jar" basedir="./build/obj" includes="**/*.class" />
     23    </target>
     24    <target name="jarTest" depends="compileTest">
     25        <jar destfile="./build/routertest.jar" basedir="./build/obj" includes="**/*.class" />
    1526    </target>
    1627    <target name="javadoc">
     
    2435            windowtitle="I2P Router" />
    2536    </target>
     37    <target name="test" depends="compileTest">
     38        <junit printsummary="on" fork="yes">
     39            <classpath>
     40                <pathelement path="${classpath}" />
     41                <pathelement location="./build/obj" />
     42                <pathelement location="../../core/java/build/i2ptest.jar" />
     43                <pathelement location="../../installer/lib/jbigi/jbigi.jar" />
     44                <pathelement path="${ant.home}/lib/clover.jar"/>
     45            </classpath>
     46            <batchtest>
     47                <fileset dir="./test/">
     48                    <include name="**/*Test.java" />
     49                </fileset>
     50            </batchtest>
     51            <formatter type="xml"/>
     52        </junit>
     53        <mkdir dir="../../reports/" />
     54        <mkdir dir="../../reports/router/" />
     55        <mkdir dir="../../reports/router/junit/" />
     56        <delete>
     57            <fileset dir="../../reports/router/junit">
     58                <include name="TEST-*.xml"/>
     59            </fileset>
     60        </delete>
     61        <copy todir="../../reports/router/junit">
     62            <fileset dir=".">
     63                <include name="TEST-*.xml"/>
     64            </fileset>
     65        </copy>
     66        <delete>
     67            <fileset dir=".">
     68                <include name="TEST-*.xml"/>
     69            </fileset>
     70        </delete>
     71    </target>
     72    <target name="junit.report">
     73        <junitreport todir="../../reports/router/junit">
     74            <fileset dir="../../reports/router/junit">
     75                <include name="TEST-*.xml"/>
     76            </fileset>
     77            <report format="frames" todir="../../reports/router/html/junit"/>
     78        </junitreport>
     79    </target>
     80    <target name="clover.report">
     81        <taskdef resource="clovertasks"/>
     82        <mkdir dir="../../reports/" />
     83        <mkdir dir="../../reports/router" />
     84        <mkdir dir="../../reports/router/clover" />
     85        <clover-setup initString="../../reports/router/clover/coverage.db"/>
     86        <clover-report>
     87            <current outfile="../../reports/router/html/clover">
     88                <format type="html"/>
     89            </current>
     90        </clover-report>
     91    </target>
     92    <target name="test.report" depends="junit.report, clover.report"/>
     93    <target name="useclover">
     94        <taskdef resource="clovertasks"/>
     95        <mkdir dir="../../reports/" />
     96        <mkdir dir="../../reports/router/" />
     97        <mkdir dir="../../reports/router/clover" />
     98        <clover-setup initString="../../reports/router/clover/coverage.db"/>
     99    </target>
     100    <target name="fulltest" depends="cleandep, builddeptest, jarTest, test, junit.report" />
     101    <target name="fullclovertest" depends="cleandep, builddeptest, useclover, jarTest, test, test.report" />
    26102    <target name="clean">
    27103        <delete dir="./build" />
  • router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java

    r9865af4 r4293a18  
    145145        byte buf[] = new byte[size];
    146146        int read = toByteArray(buf);
    147         if (read < 0)
     147        if (read < 0) throw new DataFormatException("Unable to build the message");
    148148        out.write(buf, 0, read);
    149149    }
  • router/java/test/net/i2p/data/i2np/DatabaseStoreMessageTest.java

    r9865af4 r4293a18  
    1111import java.util.Date;
    1212
     13import net.i2p.I2PAppContext;
    1314import net.i2p.data.DataFormatException;
    1415import net.i2p.data.DataStructure;
    1516import net.i2p.data.StructureTest;
    16 import net.i2p.data.TestData;
    1717import net.i2p.data.RouterInfo;
    1818import net.i2p.data.RouterInfoTest;
     
    2525 * @author jrandom
    2626 */
    27 class DatabaseStoreMessageTest extends StructureTest {
    28     static {
    29         TestData.registerTest(new DatabaseStoreMessageTest(), "DatabaseStoreMessage");
    30     }
     27public class DatabaseStoreMessageTest extends StructureTest {
    3128    public DataStructure createDataStructure() throws DataFormatException {
    32         DatabaseStoreMessage msg = new DatabaseStoreMessage(_context);
     29        DatabaseStoreMessage msg = new DatabaseStoreMessage(I2PAppContext.getGlobalContext());
    3330        RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure();
    3431        msg.setKey(info.getIdentity().getHash());
    3532        msg.setMessageExpiration(Clock.getInstance().now());
    36         msg.setUniqueId(42);
     33        msg.setUniqueId(666);
    3734        msg.setRouterInfo(info);
    3835        return msg;
    3936    }
    40     public DataStructure createStructureToRead() { return new DatabaseStoreMessage(_context); }
    4137   
    42     public static void main(String args[]) { TestData.main(new String[] { "test", "i2np.DatabaseStoreMessage", "foo.dat" }); }
     38    public DataStructure createStructureToRead() {
     39        return new DatabaseStoreMessage(I2PAppContext.getGlobalContext());
     40    }
    4341}
  • router/java/test/net/i2p/data/i2np/DeliveryInstructionsTest.java

    r9865af4 r4293a18  
    1414import net.i2p.data.SessionKey;
    1515import net.i2p.data.StructureTest;
    16 import net.i2p.data.TestData;
    1716import net.i2p.data.TunnelId;
    1817import net.i2p.data.i2np.DeliveryInstructions;
     
    2423 * @author jrandom
    2524 */
    26 class DeliveryInstructionsTest extends StructureTest {
    27     private final static Log _log = new Log(DeliveryInstructionsTest.class);
    28     static {
    29         TestData.registerTest(new DeliveryInstructionsTest(), "DeliveryInstructions");
    30     }
     25public class DeliveryInstructionsTest extends StructureTest {
    3126    public DataStructure createDataStructure() throws DataFormatException {
    3227        DeliveryInstructions instructions = new DeliveryInstructions();
    33         instructions.setDelayRequested(true);
    34         instructions.setDelaySeconds(42);
    35         instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
    36         instructions.setEncrypted(true);
    37         SessionKey key = new SessionKey();
    38         byte keyData[] = new byte[SessionKey.KEYSIZE_BYTES];
    39         for (int i = 0; i < keyData.length; i++)
    40             keyData[i] = (byte)i;
    41         key.setData(keyData);
    42         instructions.setEncryptionKey(key);
    43         Hash hash = new Hash();
    44         byte hashData[] = new byte[32];
    45         for (int i = 0; i < hashData.length; i++)
    46             hashData[i] = (byte)(i%32);
    47         hash.setData(hashData);
    48         instructions.setRouter(hash);
    49         TunnelId id = new TunnelId();
    50         id.setTunnelId(666);
    51         instructions.setTunnelId(id);
    52         _log.debug("Instructions created: " + instructions + "\nBase 64: " + instructions.toBase64());
    53         return instructions;
     28                instructions.setDelayRequested(true);
     29                instructions.setDelaySeconds(42);
     30                instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
     31                instructions.setEncrypted(true);
     32                SessionKey key = new SessionKey();
     33                byte keyData[] = new byte[SessionKey.KEYSIZE_BYTES];
     34                for (int i = 0; i < keyData.length; i++)
     35                    keyData[i] = (byte)i;
     36                key.setData(keyData);
     37                instructions.setEncryptionKey(key);
     38                Hash hash = new Hash();
     39                byte hashData[] = new byte[32];
     40                for (int i = 0; i < hashData.length; i++)
     41                    hashData[i] = (byte)(i%32);
     42                hash.setData(hashData);
     43                instructions.setRouter(hash);
     44                TunnelId id = new TunnelId();
     45                id.setTunnelId(666);
     46                instructions.setTunnelId(id);
     47               
     48                return instructions;
    5449    }
    5550    public DataStructure createStructureToRead() { return new DeliveryInstructions(); }
  • router/java/test/net/i2p/data/i2np/I2NPMessageReaderTest.java

    r9865af4 r4293a18  
    1818import net.i2p.data.i2np.I2NPMessage;
    1919import net.i2p.data.i2np.I2NPMessageReader;
    20 import net.i2p.util.Log;
    2120import net.i2p.router.RouterContext;
     21
     22import junit.framework.TestCase;
    2223
    2324/**
     
    2627 * @author jrandom
    2728 */
    28 class I2NPMessageReaderTest implements I2NPMessageReader.I2NPMessageEventListener {
    29     private final static Log _log = new Log(I2NPMessageReaderTest.class);
    30     private static RouterContext _context = new RouterContext(null);
     29public class I2NPMessageReaderTest extends TestCase implements I2NPMessageReader.I2NPMessageEventListener{
    3130   
    32     public static void main(String args[]) {
    33         I2NPMessageReaderTest test = new I2NPMessageReaderTest();
    34         test.runTest();
    35         try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
    36     }
     31    public void setUp(){}
    3732   
    38     public void runTest() {
     33    public void testI2NPMessageReader() throws IOException, DataFormatException{
    3934        InputStream data = getData();
    4035        test(data);
    4136    }
    4237   
    43     private InputStream getData() {
     38    private InputStream getData() throws IOException, DataFormatException{
    4439        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    45         try {
    46             DatabaseStoreMessage msg = (DatabaseStoreMessage)new DatabaseStoreMessageTest().createDataStructure();
    47             msg.writeBytes(baos);
    48             msg.writeBytes(baos);
    49             msg.writeBytes(baos);
    50             _log.debug("DB Store message in tunnel contains: " + msg);
    51             msg.writeBytes(baos);
    52         } catch (DataFormatException dfe) {
    53             _log.error("Error building data", dfe);
    54         } catch (IOException ioe) {
    55             _log.error("Error writing stream", ioe);
    56         }
     40        DatabaseStoreMessage msg = (DatabaseStoreMessage)new DatabaseStoreMessageTest().createDataStructure();
     41        msg.writeBytes(baos);
     42        msg.writeBytes(baos);
     43        msg.writeBytes(baos);
     44        msg.writeBytes(baos);
    5745        return new ByteArrayInputStream(baos.toByteArray());
    5846    }
    5947   
    6048    private void test(InputStream in) {
    61         _log.debug("Testing the input stream");
    62         I2NPMessageReader reader = new I2NPMessageReader(_context, in, this);
    63         _log.debug("Created, beginning reading");
     49        I2NPMessageReader reader = new I2NPMessageReader(new RouterContext(null), in, this);
    6450        reader.startReading();
    65         _log.debug("Reading commenced");
    6651    }
    6752   
    6853    public void disconnected(I2NPMessageReader reader) {
    69         _log.debug("Disconnected");
    7054    }
    7155   
    7256    public void messageReceived(I2NPMessageReader reader, I2NPMessage message, long msToRead, int size) {
    73         _log.debug("Message received: " + message);
    7457    }
    7558   
    7659    public void readError(I2NPMessageReader reader, Exception error) {
    77         _log.debug("Read error: " + error.getMessage(), error);
    7860    }
    7961   
  • router/java/test/net/i2p/router/transport/BandwidthLimiterTest.java

    r9865af4 r4293a18  
    11package net.i2p.router.transport;
     2/*
     3 * free (adj.): unencumbered; not under the control of others
     4 * Written by jrandom in 2003 and released into the public domain
     5 * with no warranty of any kind, either expressed or implied.
     6 * It probably won't make your computer catch on fire, or eat
     7 * your children, but it might.  Use at your own risk.
     8 *
     9 */
    210
    311import net.i2p.router.RouterContext;
     
    513
    614import java.io.IOException;
     15import java.io.InputStream;
     16import java.io.OutputStream;
    717
    818import java.util.Random;
    919import java.util.Properties;
     20
     21import junit.framework.TestCase;
    1022
    1123/**
     
    2032 *
    2133 */
    22 public class BandwidthLimiterTest {
     34public class BandwidthLimiterTest extends TestCase{
    2335    private RouterContext _context;
    24     private Log _log;
    25     private final static int NUM_MB = 1;
    26    
    27     public BandwidthLimiterTest() {
     36    private final static int NUM_KB = 256;
     37   
     38    public void setUp() {
    2839        _context = new RouterContext(null);
    29         _log = _context.logManager().getLog(BandwidthLimiterTest.class);
    30         //_context.jobQueue().runQueue(1);
    31     }
    32    
    33     public void prepareLimiter(int inKBps, int outKBps, int inBurst, int outBurst) {
    34         Properties props = new Properties();
     40    }
     41   
     42    public void tearDown(){
     43    }
     44   
     45    private void prepareLimiter(int inKBps, int outKBps, int inBurst, int outBurst) {
     46        Properties props = System.getProperties();
    3547        props.setProperty(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, ""+inKBps);
    3648        props.setProperty(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, ""+outKBps);
     
    4052        System.setProperties(props);
    4153        _context.bandwidthLimiter().reinitialize();
    42         _log.debug("Limiter prepared");
    4354    }
    4455   
     
    4960     *
    5061     */
    51     public long testOutboundThrottle(int numBytes, int numBytesPerWrite) {
     62    private long testOutboundThrottle(int numBytes, int numBytesPerWrite) {
    5263        byte source[] = new byte[numBytesPerWrite];
    5364        new Random().nextBytes(source);
     
    7485     *
    7586     */
    76     public long testInboundThrottle(int numBytes, int numBytesPerRead) {
     87    private long testInboundThrottle(int numBytes, int numBytesPerRead) {
    7788        FakeInputStream source = new FakeInputStream(numBytes);
    7889        BandwidthLimitedInputStream in = new BandwidthLimitedInputStream(_context, source, null);
     
    96107     */
    97108    public void testOutbound() {
     109        double error;
     110        double predict;
     111       
    98112        prepareLimiter(-1, -1, -1, -1);
    99         _log.info("Begin unlimited push of " + NUM_MB);
    100         long ms = testOutboundThrottle(NUM_MB*1024*1024, 1*1024);
    101         _log.info("** Unlimited pushed " + NUM_MB + "MB in " + ms + "ms");
    102         prepareLimiter(-1, 4, -1, 4*1024);
    103         ms = testOutboundThrottle(NUM_MB*1024*1024, 1*1024);
    104         _log.info("** 4KBps pushed " + NUM_MB + "MB in " + ms + "ms");
     113        long ms = testOutboundThrottle(NUM_KB*1024, 1*1024);
     114       
     115        /*prepareLimiter(-1, 4, -1, 4*1024);
     116        ms = testOutboundThrottle(NUM_KB*1024, 1*1024);
     117        predict = (NUM_KB/4)*1000;
     118        error = predict/ms;
     119        //assertTrue(error>.89);
     120        assertTrue(error<1.05);*/
     121       
    105122        prepareLimiter(-1, 32, -1, 32*1024);
    106         ms = testOutboundThrottle(NUM_MB*1024*1024, 1*1024);
    107         _log.info("** 32KBps pushed " + NUM_MB + "MB in " + ms + "ms");
     123        ms = testOutboundThrottle(NUM_KB*1024, 1*1024);
     124        predict = (NUM_KB/32)*1000;
     125        error = predict/ms;
     126        //assertTrue(error>.89);
     127        assertTrue(error<1.05);
     128       
    108129        prepareLimiter(-1, 256, -1, 256*1024);
    109         _log.info("Begin 256KBps push of " + NUM_MB);
    110         ms = testOutboundThrottle(NUM_MB*1024*1024, 1*1024);
    111         _log.info("** 256KBps pushed " + NUM_MB + "MB in " + ms + "ms");
     130        ms = testOutboundThrottle(NUM_KB*1024, 1*1024);
     131        predict = (NUM_KB/256)*1000;
     132        error = predict/ms;
     133        //assertTrue(error>.89);
     134        assertTrue(error<1.05);
     135       
    112136    }
    113137   
     
    118142     */
    119143    public void testInbound() {
     144        double predict;
     145        double error;
     146       
    120147        prepareLimiter(-1, -1, -1, -1);
    121         long ms = testInboundThrottle(NUM_MB*1024*1024, 1*1024);
    122         _log.info("** Unlimited pulled " + NUM_MB + "MB in " + ms + "ms");
    123         prepareLimiter(4, -1, 4*1024, -1);
    124         ms = testInboundThrottle(NUM_MB*1024*1024, 1*1024);
    125         _log.info("** 4KBps pulled " + NUM_MB + "MB in " + ms + "ms");
     148        long ms = testInboundThrottle(NUM_KB*1024, 1*1024);
     149       
     150        /*prepareLimiter(4, -1, 4*1024, -1);
     151        ms = testInboundThrottle(NUM_KB*1024, 1*1024);
     152        predict = (NUM_KB/4)*1000;
     153        error = predict/ms;
     154        //assertTrue(error>.89);
     155        assertTrue(error<1.05);*/
     156       
    126157        prepareLimiter(32, -1, 32*1024, -1);
    127         ms = testInboundThrottle(NUM_MB*1024*1024, 1*1024);
    128         _log.info("** 32KBps pulled " + NUM_MB + "MB in " + ms + "ms");
     158        ms = testInboundThrottle(NUM_KB*1024, 1*1024);
     159        predict = (NUM_KB/32)*1000;
     160        error = predict/ms;
     161        //assertTrue(error>.89);
     162        assertTrue(error<1.05);
     163       
    129164        prepareLimiter(256, -1, 256*1024, -1);
    130         ms = testInboundThrottle(NUM_MB*1024*1024, 1*1024);
    131         _log.info("** 256KBps pulled " + NUM_MB + "MB in " + ms + "ms");
     165        ms = testInboundThrottle(NUM_KB*1024, 1*1024);
     166        predict = (NUM_KB/256)*1000;
     167        error = predict/ms;
     168        //assertTrue(error>.89);
     169        assertTrue(error<1.05);
     170       
    132171    }
    133172   
    134173   
    135174    public void testOutboundContention() {
     175        double predict;
     176        double error;
     177        long ms;
     178        long end;
     179        long start;
     180       
    136181        prepareLimiter(-1, -1, -1, -1);
    137         long start = System.currentTimeMillis();
    138         long runningTimes[] = testOutboundContention(10, NUM_MB*1024*1024);
    139         long end = System.currentTimeMillis();
    140         _log.info("** Done with unlimited " + NUM_MB + "MB test with 10 concurrent threads after " + (end-start) + "ms: " + displayTimes(runningTimes));
     182        start = System.currentTimeMillis();
     183        //long runningTimes[] = testOutboundContention(10, NUM_KB*1024);
     184        end = System.currentTimeMillis();
     185       
    141186        //prepareLimiter(-1, 4, -1, 5*1024*1024);
    142187        //start = System.currentTimeMillis();
    143         //runningTimes = testOutboundContention(10, NUM_MB*1024*1024);
     188        //runningTimes = testOutboundContention(10, NUM_KB*1024);
    144189        //end = System.currentTimeMillis();
    145         //_log.info("** Done with 4KBps " + NUM_MB + "MB test with 10 concurrent threads after " + (end-start) + "ms: " + displayTimes(runningTimes));
    146         prepareLimiter(-1, 32, -1, 32*1024);
    147         start = System.currentTimeMillis();
    148         runningTimes = testOutboundContention(10, NUM_MB*1024*1024);
    149         end = System.currentTimeMillis();
    150         _log.info("** Done with 32KBps " + NUM_MB + "MB test with 10 concurrent threads after " + (end-start) + "ms: " + displayTimes(runningTimes));
     190       
     191        //prepareLimiter(-1, 32, -1, 32*1024);
     192        //start = System.currentTimeMillis();
     193        //runningTimes = testOutboundContention(10, NUM_KB*1024);
     194        //end = System.currentTimeMillis();
     195       
    151196        prepareLimiter(-1, 256, -1, 256*1024);
    152197        start = System.currentTimeMillis();
    153         runningTimes = testOutboundContention(10, NUM_MB*1024*1024);
     198        testOutboundContention(10, NUM_KB*1024);
    154199        end = System.currentTimeMillis();
    155         _log.info("** Done with 256KBps " + NUM_MB + "MB test with 10 concurrent threads after " + (end-start) + "ms: " + displayTimes(runningTimes));
    156     }
    157    
    158     private String displayTimes(long times[]) {
    159         StringBuffer rv = new StringBuffer();
    160         for (int i = 0; i < times.length; i++) {
    161             rv.append(times[i]);
    162             if (i + 1 <= times.length)
    163                 rv.append(' ');
    164         }
    165         return rv.toString();
     200        ms = end-start;
     201        predict = (NUM_KB/256)*1000*10;
     202        error = predict/ms;
     203        //assertTrue(error>.89);
     204        assertTrue(error<1.05);
     205       
    166206    }
    167207   
     
    171211            threads[i] = new OutboundRunner(numBytes);
    172212        }
    173         _log.debug("Starting up outbound contention test for " + numBytes + " with " + numConcurrent + " runners");
     213       
    174214        for (int i = 0; i < numConcurrent; i++)
    175215            threads[i].start();
     
    197237            Thread.currentThread().setName("Out" + _runnerNum);
    198238            _runningTime = testOutboundThrottle(_numBytes, 8*1024);
    199             _log.debug("Outbound runner " + _runnerNum + " pushed " + _numBytes + " in " + _runningTime + "ms");
    200239        }
    201240        public long getRunningTime() { return _runningTime; }
    202241    }
    203        
    204    
    205     public static void main(String args[]) {
    206         BandwidthLimiterTest test = new BandwidthLimiterTest();
    207         test.testOutbound();
    208         test.testInbound();
    209         //test.testOutboundContention();
    210         System.exit(0);
    211     }
    212242}
     243
     244class NullOutputStream extends OutputStream {
     245    public void write(int param) {}
     246}
     247
     248class FakeInputStream extends InputStream {
     249    private volatile int _numRead;
     250    private int _size;
     251   
     252    public FakeInputStream(int size) {
     253        _size = size;
     254        _numRead = 0;
     255    }
     256    public int read() {
     257        int rv = 0;
     258        if (_numRead >= _size)
     259            rv = -1;
     260        else
     261            rv = 42;
     262        _numRead++;
     263        return rv;
     264    }
     265}
  • router/java/test/net/i2p/router/tunnel/FragmentTest.java

    r9865af4 r4293a18  
    11package net.i2p.router.tunnel;
     2/*
     3 * free (adj.): unencumbered; not under the control of others
     4 * Written by jrandom in 2003 and released into the public domain
     5 * with no warranty of any kind, either expressed or implied.
     6 * It probably won't make your computer catch on fire, or eat
     7 * your children, but it might.  Use at your own risk.
     8 *
     9 */
    210
    311import java.util.ArrayList;
     
    1119import net.i2p.util.Log;
    1220
     21import junit.framework.TestCase;
     22
    1323/**
    1424 * Simple test to see if the fragmentation is working, testing the preprocessor,
     
    1626 *
    1727 */
    18 public class FragmentTest {
     28public class FragmentTest extends TestCase{
    1929    protected I2PAppContext _context;
    20     protected Log _log;
    21    
    22     public FragmentTest() {
     30   
     31    public void setUp() {
    2332        _context = I2PAppContext.getGlobalContext();
    24         _log = _context.logManager().getLog(getClass());
    2533        _context.random().nextBoolean();
    2634        FragmentHandler.MAX_DEFRAGMENT_TIME = 10*1000;
     
    3543     *
    3644     */
    37     public void runSingle() {
     45    public void testSingle() {
    3846        TunnelGateway.Pending pending = createPending(949, false, false);
    3947        ArrayList messages = new ArrayList();
     
    4654        ReceiverImpl receiver = new ReceiverImpl(handler, 0);
    4755        byte msg[] = pending.getData();
    48         _log.debug("SEND(" + msg.length + "): " + Base64.encode(msg) + " " + _context.sha().calculateHash(msg).toBase64());
    49 
    50         boolean keepGoing = true;
    51         while (keepGoing) {
    52             keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
    53             if (keepGoing)
    54                 try { Thread.sleep(100); } catch (InterruptedException ie) {}
    55         }
    56         if (handleReceiver.receivedOk())
    57             _log.info("received OK");
     56       
     57        boolean keepGoing = true;
     58        while (keepGoing) {
     59            keepGoing = pre.preprocessQueue(messages, new SenderImpl(), receiver);
     60            if (keepGoing)
     61                try { Thread.sleep(100); } catch (InterruptedException ie) {}
     62        }
     63        assertTrue(handleReceiver.receivedOk());
    5864    }
    5965   
     
    6268     *
    6369     */
    64     public void runMultiple() {
     70    public void testMultiple() {
    6571        TunnelGateway.Pending pending = createPending(2048, false, false);
    6672        ArrayList messages = new ArrayList();
     
    7379        ReceiverImpl receiver = new ReceiverImpl(handler, 0);
    7480        byte msg[] = pending.getData();
    75         _log.debug("SEND(" + msg.length + "): " + Base64.encode(msg) + " " + _context.sha().calculateHash(msg).toBase64());
    7681           
    7782        boolean keepGoing = true;
     
    8186                try { Thread.sleep(100); } catch (InterruptedException ie) {}
    8287        }
    83         if (handleReceiver.receivedOk())
    84             _log.info("received OK");
     88        assertTrue(handleReceiver.receivedOk());
    8589    }
    8690   
     
    99103        ReceiverImpl receiver = new ReceiverImpl(handler, 11*1000);
    100104        byte msg[] = pending.getData();
    101         _log.debug("SEND(" + msg.length + "): " + Base64.encode(msg) + " " + _context.sha().calculateHash(msg).toBase64());
     105       
    102106        boolean keepGoing = true;
    103107        while (keepGoing) {
     
    109113   
    110114    public void runVaried() {
    111         int failures = 0;
    112115        for (int i = 0; i <= 4096; i++) {
    113             boolean ok = runVaried(i, false, false);
    114             if (!ok) { _log.error("** processing " + i+ " w/ no router, no tunnel failed"); failures++; }
    115             ok = runVaried(i, true, false);
    116             if (!ok) { _log.error("** processing " + i+ " w/ router, no tunnel failed"); failures++; }
    117             ok = runVaried(i, true, true);
    118             if (!ok) { _log.error("** processing " + i+ " w/ router, tunnel failed"); failures++; }
    119             else _log.info("Tests pass for size " + i);
    120         }
    121         if (failures == 0)
    122             _log.info("** success after all varied tests");
    123         else
    124             _log.error("** failed " + failures +" varied tests");
     116            assertTrue(runVaried(i, false, false));
     117            assertTrue(runVaried(i, true, false));
     118            assertTrue(runVaried(i, true, true));
     119        }
    125120    }
    126121   
     
    136131        ReceiverImpl receiver = new ReceiverImpl(handler, 0);
    137132        byte msg[] = pending.getData();
    138         _log.debug("SEND(" + msg.length + "): " + Base64.encode(msg) + " " + _context.sha().calculateHash(msg).toBase64());
    139133           
    140134        boolean keepGoing = true;
     
    227221        }
    228222    }
    229    
    230     public void runTests() {
    231         runVaried();
    232         _log.info("\n===========================Begin runSingle()\n\n");
    233         runSingle();
    234         _log.info("\n===========================Begin runMultiple()\n\n");
    235         runMultiple();
    236         _log.info("\n===========================Begin runDelayed() (should have 3 errors)\n\n");
    237         runDelayed();
    238         _log.info("\n===========================After runDelayed()\n\n");
    239     }
    240    
    241     public static void main(String args[]) {
    242         FragmentTest t = new FragmentTest();
    243         t.runTests();
    244     }
    245223}
  • router/java/test/net/i2p/router/tunnel/InboundGatewayTest.java

    r9865af4 r4293a18  
    11package net.i2p.router.tunnel;
     2/*
     3 * free (adj.): unencumbered; not under the control of others
     4 * Written by jrandom in 2003 and released into the public domain
     5 * with no warranty of any kind, either expressed or implied.
     6 * It probably won't make your computer catch on fire, or eat
     7 * your children, but it might.  Use at your own risk.
     8 *
     9 */
    210
    311import java.util.ArrayList;
     
    1220import net.i2p.util.Log;
    1321
     22import junit.framework.TestCase;
     23
    1424/**
    1525 * Quick unit test for base functionality of inbound tunnel
    1626 * operation
    1727 */
    18 public class InboundGatewayTest {
     28public class InboundGatewayTest extends TestCase{
    1929    private I2PAppContext _context;
    2030    private Log _log;
     
    2535    private TunnelGateway _gw;
    2636   
    27     public InboundGatewayTest() {
     37    public void setUp() {
    2838        _context = I2PAppContext.getGlobalContext();
    29         _log = _context.logManager().getLog(InboundGatewayTest.class);
    30     }
    31    
    32     public void runTest() {
    33         int numHops = 8;
    34         int runCount = 1;
    35         _config = prepareConfig(numHops);
     39        _config = prepareConfig(8);
    3640        _preprocessor = new TrivialPreprocessor(_context);
    3741        _sender = new InboundSender(_context, _config.getConfig(0));
    3842        _receiver = new TestReceiver(_config);
    3943        _gw = new TunnelGateway(_context, _preprocessor, _sender, _receiver);
    40        
    41         // single fragment
    42         testSmall(runCount);
    43         // includes target router instructions
    44         testRouter(runCount);
    45         // includes target router & tunnel instructions
    46         testTunnel(runCount);
    47         // multiple fragments
    48         testLarge(runCount);
    49      
    50         try { Thread.sleep(5*1000); } catch (Exception e) {}
    51     }
    52    
    53     private void testSmall(int runCount) {
     44    }
     45   
     46    public void testSmall() {
     47        int runCount = 1;
     48       
    5449        List messages = new ArrayList(runCount);
    5550        long start = _context.clock().now();
     
    6156            m.setMessageExpiration(_context.clock().now() + 60*1000);
    6257            m.setUniqueId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    63             _log.debug("Sending " + m.getUniqueId());
    64             byte data[] = m.toByteArray();
    65             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     58            byte data[] = m.toByteArray();
    6659            messages.add(m);
    6760            _gw.add(m, null, null);
     
    6962       
    7063        long time = _context.clock().now() - start;
    71         _log.debug("Time for " + runCount + " messages: " + time);   
    72        
    73         List received = _receiver.clearReceived();
    74         for (int i = 0; i < messages.size(); i++) {
    75             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    76                 _log.error("Message " + i + " not received");
    77             }
    78         }
    79     }
    80    
    81     private void testRouter(int runCount) {
     64       
     65        List received = _receiver.clearReceived();
     66        for (int i = 0; i < messages.size(); i++) {
     67            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
     68        }
     69    }
     70   
     71    public void testRouter() {
     72        int runCount = 1;
     73       
    8274        List messages = new ArrayList(runCount);
    8375        long start = _context.clock().now();
     
    9183            Hash to = new Hash(new byte[Hash.HASH_LENGTH]);
    9284            java.util.Arrays.fill(to.getData(), (byte)0xFF);
    93             _log.debug("Sending " + m.getUniqueId() + " to " + to);
    94             byte data[] = m.toByteArray();
    95             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     85            byte data[] = m.toByteArray();
    9686            messages.add(m);
    9787            _gw.add(m, to, null);
     
    9989       
    10090        long time = _context.clock().now() - start;
    101         _log.debug("Time for " + runCount + " messages: " + time);   
    102        
    103         List received = _receiver.clearReceived();
    104         for (int i = 0; i < messages.size(); i++) {
    105             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    106                 _log.error("Message " + i + " not received");
    107             }
    108         }
    109     }
    110    
    111     private void testTunnel(int runCount) {
     91       
     92        List received = _receiver.clearReceived();
     93        for (int i = 0; i < messages.size(); i++) {
     94            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
     95        }
     96    }
     97   
     98    public void testTunnel() {
     99        int runCount = 1;
     100       
    112101        List messages = new ArrayList(runCount);
    113102        long start = _context.clock().now();
     
    122111            java.util.Arrays.fill(to.getData(), (byte)0xFF);
    123112            TunnelId tunnel = new TunnelId(42);
    124             _log.debug("Sending " + m.getUniqueId() + " to " + to + "/" + tunnel);
    125             byte data[] = m.toByteArray();
    126             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     113            byte data[] = m.toByteArray();
    127114            messages.add(m);
    128115            _gw.add(m, to, tunnel);
     
    130117       
    131118        long time = _context.clock().now() - start;
    132         _log.debug("Time for " + runCount + " messages: " + time);   
    133        
    134         List received = _receiver.clearReceived();
    135         for (int i = 0; i < messages.size(); i++) {
    136             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    137                 _log.error("Message " + i + " not received");
    138             }
    139         }
    140     }
    141    
    142     private void testLarge(int runCount) {
     119       
     120        List received = _receiver.clearReceived();
     121        for (int i = 0; i < messages.size(); i++) {
     122            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
     123        }
     124    }
     125   
     126    public void testLarge() {
     127        int runCount = 1;
     128       
    143129        List messages = new ArrayList(runCount);
    144130        long start = _context.clock().now();
     
    150136            m.setMessageExpiration(_context.clock().now() + 60*1000);
    151137            m.setUniqueId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    152             _log.debug("Sending " + m.getUniqueId());
    153             byte data[] = m.toByteArray();
    154             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     138            byte data[] = m.toByteArray();
    155139            messages.add(m);
    156140            _gw.add(m, null, null);
     
    158142       
    159143        long time = _context.clock().now() - start;
    160         try { Thread.sleep(60*1000); } catch (Exception e) {}
    161         _log.debug("Time for " + runCount + " messages: " + time);   
    162        
    163         List received = _receiver.clearReceived();
    164         for (int i = 0; i < messages.size(); i++) {
    165             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    166                 _log.error("Message " + i + " not received");
    167             }
     144        //try { Thread.sleep(60*1000); } catch (Exception e) {}
     145       
     146        List received = _receiver.clearReceived();
     147        for (int i = 0; i < messages.size(); i++) {
     148            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
    168149        }
    169150    }
     
    183164            for (int i = 1; i <= _config.getLength() - 2; i++) {
    184165                HopProcessor hop = new HopProcessor(_context, _config.getConfig(i));
    185                 boolean ok = hop.process(encrypted, 0, encrypted.length, _config.getConfig(i).getReceiveFrom());
    186                 if (!ok)
    187                     _log.error("Error processing at hop " + i);
    188                 //else
    189                 //    _log.info("Processing OK at hop " + i);
     166                assertTrue(hop.process(encrypted, 0, encrypted.length, _config.getConfig(i).getReceiveFrom()));
    190167            }
    191168           
    192169            // now handle it at the endpoint
    193170            InboundEndpointProcessor end = new InboundEndpointProcessor(_context, _config);
    194             boolean ok = end.retrievePreprocessedData(encrypted, 0, encrypted.length, _config.getPeer(_config.getLength()-2));
    195             if (!ok)
    196                 _log.error("Error retrieving cleartext at the endpoint");
    197            
    198             if (_log.shouldLog(Log.DEBUG))
    199                 _log.debug("Received      " + Base64.encode(encrypted));
    200 
     171            assertTrue(end.retrievePreprocessedData(encrypted, 0, encrypted.length, _config.getPeer(_config.getLength()-2)));
     172           
     173           
    201174            _handler.receiveTunnelMessage(encrypted, 0, encrypted.length);
    202             _log.debug("\n\ndone receiving message\n\n");
    203175        }       
    204176        public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) {
    205             if (_log.shouldLog(Log.DEBUG))
    206                 _log.debug("Completed     " + msg.getUniqueId() + " to " + toRouter + "/" + toTunnel);
    207177            _received.add(msg);
    208178        }
     
    246216        return config;
    247217    }
    248    
    249     public static void main(String args[]) {
    250         InboundGatewayTest test = new InboundGatewayTest();
    251         test.runTest();
    252     }
    253218}
  • router/java/test/net/i2p/router/tunnel/InboundTest.java

    r9865af4 r4293a18  
    11package net.i2p.router.tunnel;
     2/*
     3 * free (adj.): unencumbered; not under the control of others
     4 * Written by jrandom in 2003 and released into the public domain
     5 * with no warranty of any kind, either expressed or implied.
     6 * It probably won't make your computer catch on fire, or eat
     7 * your children, but it might.  Use at your own risk.
     8 *
     9 */
    210
    311import net.i2p.I2PAppContext;
     
    715import net.i2p.util.Log;
    816
     17import junit.framework.TestCase;
     18
    919/**
    1020 * Quick unit test for base functionality of inbound tunnel
    1121 * operation
     22 *
    1223 */
    13 public class InboundTest {
     24public class InboundTest extends TestCase{
    1425    private I2PAppContext _context;
    15     private Log _log;
    1626   
    17     public InboundTest() {
     27    public void setUp() {
    1828        _context = I2PAppContext.getGlobalContext();
    19         _log = _context.logManager().getLog(InboundTest.class);
    2029    }
    2130   
    22     public void runTest() {
    23         int numHops = 8;
    24         TunnelCreatorConfig config = prepareConfig(numHops);
    25         long start = _context.clock().now();
    26         for (int i = 0; i < 1; i++)
    27             runTest(numHops, config);
    28         long time = _context.clock().now() - start;
    29         _log.debug("Time for 1000 messages: " + time);
    30     }
    31    
    32     private void runTest(int numHops, TunnelCreatorConfig config) {
     31    public void testInbound() {
     32        int numHops = 8;
     33        TunnelCreatorConfig config = prepareConfig(numHops);
     34       
    3335        byte orig[] = new byte[128];
    3436        byte message[] = new byte[128];
     
    3638        System.arraycopy(orig, 0, message, 0, message.length);
    3739       
    38         _log.debug("orig: \n" + Base64.encode(orig, 16, orig.length-16));
    3940        InboundGatewayProcessor p = new InboundGatewayProcessor(_context, config.getConfig(0));
    4041        p.process(message, 0, message.length, null);
     
    4344            HopProcessor hop = new HopProcessor(_context, config.getConfig(i));
    4445            Hash prev = config.getConfig(i).getReceiveFrom();
    45             boolean ok = hop.process(message, 0, message.length, prev);
    46             if (!ok)
    47                 _log.error("Error processing at hop " + i);
    48             //else
    49             //    _log.info("Processing OK at hop " + i);
     46            assertTrue(hop.process(message, 0, message.length, prev));
    5047        }
    5148       
    5249        InboundEndpointProcessor end = new InboundEndpointProcessor(_context, config);
    53         boolean ok = end.retrievePreprocessedData(message, 0, message.length, config.getPeer(numHops-2));
    54         if (!ok) {
    55             _log.error("Error retrieving cleartext at the endpoint");
    56             try { Thread.sleep(5*1000); } catch (Exception e) {}
    57         }
     50        assertTrue(end.retrievePreprocessedData(message, 0, message.length, config.getPeer(numHops-2)));
    5851       
    59         //_log.debug("After: " + Base64.encode(message, 16, orig.length-16));
    60         boolean eq = DataHelper.eq(orig, 16, message, 16, orig.length - 16);
    61         _log.info("equal? " + eq);
     52        assertTrue(DataHelper.eq(orig, 16, message, 16, orig.length - 16));
    6253    }
    6354   
     
    9485        return config;
    9586    }
    96    
    97     public static void main(String args[]) {
    98         InboundTest test = new InboundTest();
    99         test.runTest();
    100     }
    10187}
  • router/java/test/net/i2p/router/tunnel/OutboundGatewayTest.java

    r9865af4 r4293a18  
    11package net.i2p.router.tunnel;
     2/*
     3 * free (adj.): unencumbered; not under the control of others
     4 * Written by jrandom in 2003 and released into the public domain
     5 * with no warranty of any kind, either expressed or implied.
     6 * It probably won't make your computer catch on fire, or eat
     7 * your children, but it might.  Use at your own risk.
     8 *
     9 */
    210
    311import java.util.ArrayList;
     
    1220import net.i2p.util.Log;
    1321
     22import junit.framework.TestCase;
     23
    1424/**
    1525 * Quick unit test for base functionality of outbound tunnel
    1626 * operation
    1727 */
    18 public class OutboundGatewayTest {
     28public class OutboundGatewayTest extends TestCase{
    1929    private I2PAppContext _context;
    20     private Log _log;
    2130    private TunnelCreatorConfig _config;
    2231    private TunnelGateway.QueuePreprocessor _preprocessor;
     
    2534    private TunnelGateway _gw;
    2635   
    27     public OutboundGatewayTest() {
     36    public void setUp() {
    2837        _context = I2PAppContext.getGlobalContext();
    29         _log = _context.logManager().getLog(OutboundGatewayTest.class);
    30     }
    31    
    32     public void runTest() {
    33         int numHops = 8;
    34         int runCount = 1;
    35         _config = prepareConfig(numHops);
     38        _config = prepareConfig(8);
    3639        _preprocessor = new TrivialPreprocessor(_context);
    3740        _sender = new OutboundSender(_context, _config);
    3841        _receiver = new TestReceiver(_config);
    3942        _gw = new TunnelGateway(_context, _preprocessor, _sender, _receiver);
    40        
    41         // single fragment
    42         testSmall(runCount);
    43         // includes target router instructions
    44         testRouter(runCount);
    45         // includes target router & tunnel instructions
    46         testTunnel(runCount);
    47         // multiple fragments
    48         testLarge(runCount);
    49      
    50         try { Thread.sleep(5*1000); } catch (Exception e) {}
    51     }
    52    
    53     private void testSmall(int runCount) {
     43    }
     44   
     45    public void testSmall() {
     46        int runCount = 1;
     47       
    5448        List messages = new ArrayList(runCount);
    5549        long start = _context.clock().now();
     
    6155            m.setMessageExpiration(_context.clock().now() + 60*1000);
    6256            m.setUniqueId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    63             _log.debug("Sending " + m.getUniqueId());
    64             byte data[] = m.toByteArray();
    65             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     57            byte data[] = m.toByteArray();
    6658            messages.add(m);
    6759            _gw.add(m, null, null);
     
    6961       
    7062        long time = _context.clock().now() - start;
    71         _log.debug("Time for " + runCount + " messages: " + time);   
    72        
    73         List received = _receiver.clearReceived();
    74         for (int i = 0; i < messages.size(); i++) {
    75             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    76                 _log.error("Message " + i + " not received");
    77             }
    78         }
    79     }
    80    
    81     private void testRouter(int runCount) {
     63       
     64        List received = _receiver.clearReceived();
     65        for (int i = 0; i < messages.size(); i++) {
     66            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
     67        }
     68    }
     69   
     70    public void testRouter() {
     71        int runCount = 1;
     72       
    8273        List messages = new ArrayList(runCount);
    8374        long start = _context.clock().now();
     
    9182            Hash to = new Hash(new byte[Hash.HASH_LENGTH]);
    9283            java.util.Arrays.fill(to.getData(), (byte)0xFF);
    93             _log.debug("Sending " + m.getUniqueId() + " to " + to);
    94             byte data[] = m.toByteArray();
    95             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     84            byte data[] = m.toByteArray();
    9685            messages.add(m);
    9786            _gw.add(m, to, null);
     
    9988       
    10089        long time = _context.clock().now() - start;
    101         _log.debug("Time for " + runCount + " messages: " + time);   
    102        
    103         List received = _receiver.clearReceived();
    104         for (int i = 0; i < messages.size(); i++) {
    105             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    106                 _log.error("Message " + i + " not received");
    107             }
    108         }
    109     }
    110    
    111     private void testTunnel(int runCount) {
     90       
     91        List received = _receiver.clearReceived();
     92        for (int i = 0; i < messages.size(); i++) {
     93            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
     94        }
     95    }
     96   
     97    public void testTunnel() {
     98        int runCount = 1;
     99       
    112100        List messages = new ArrayList(runCount);
    113101        long start = _context.clock().now();
     
    122110            java.util.Arrays.fill(to.getData(), (byte)0xFF);
    123111            TunnelId tunnel = new TunnelId(42);
    124             _log.debug("Sending " + m.getUniqueId() + " to " + to + "/" + tunnel);
    125             byte data[] = m.toByteArray();
    126             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     112            byte data[] = m.toByteArray();
    127113            messages.add(m);
    128114            _gw.add(m, to, tunnel);
     
    130116       
    131117        long time = _context.clock().now() - start;
    132         _log.debug("Time for " + runCount + " messages: " + time);   
    133        
    134         List received = _receiver.clearReceived();
    135         for (int i = 0; i < messages.size(); i++) {
    136             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    137                 _log.error("Message " + i + " not received");
    138             }
    139         }
    140     }
    141    
    142     private void testLarge(int runCount) {
     118       
     119        List received = _receiver.clearReceived();
     120        for (int i = 0; i < messages.size(); i++) {
     121            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
     122        }
     123    }
     124   
     125    public void testLarge() {
     126        int runCount = 1;
     127       
    143128        List messages = new ArrayList(runCount);
    144129        long start = _context.clock().now();
     
    150135            m.setMessageExpiration(_context.clock().now() + 60*1000);
    151136            m.setUniqueId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
    152             _log.debug("Sending " + m.getUniqueId());
    153             byte data[] = m.toByteArray();
    154             _log.debug("SEND(" + data.length + "): " + Base64.encode(data) + " " + _context.sha().calculateHash(data).toBase64());
     137            byte data[] = m.toByteArray();
    155138            messages.add(m);
    156139            _gw.add(m, null, null);
     
    158141       
    159142        long time = _context.clock().now() - start;
    160         try { Thread.sleep(60*1000); } catch (Exception e) {}
    161         _log.debug("Time for " + runCount + " messages: " + time);   
    162        
    163         List received = _receiver.clearReceived();
    164         for (int i = 0; i < messages.size(); i++) {
    165             if (!received.contains(((I2NPMessage)messages.get(i)))) {
    166                 _log.error("Message " + i + " not received");
    167             }
     143        //try { Thread.sleep(60*1000); } catch (Exception e) {}
     144       
     145        List received = _receiver.clearReceived();
     146        for (int i = 0; i < messages.size(); i++) {
     147            assertTrue(received.contains(((I2NPMessage)messages.get(i))));
    168148        }
    169149    }
     
    183163            for (int i = 1; i < _config.getLength(); i++) {
    184164                HopProcessor hop = new HopProcessor(_context, _config.getConfig(i));
    185                 boolean ok = hop.process(encrypted, 0, encrypted.length, _config.getConfig(i).getReceiveFrom());
    186                 if (!ok)
    187                     _log.error("Error processing at hop " + i);
    188                 //else
    189                 //    _log.info("Processing OK at hop " + i);
     165                assertTrue(hop.process(encrypted, 0, encrypted.length, _config.getConfig(i).getReceiveFrom()));
     166               
    190167            }
    191168           
    192             if (_log.shouldLog(Log.DEBUG))
    193                 _log.debug("Received      " + Base64.encode(encrypted));
    194169
    195170            _handler.receiveTunnelMessage(encrypted, 0, encrypted.length);
    196             _log.debug("\n\ndone receiving message\n\n");
    197171        }       
    198172        public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) {
    199             if (_log.shouldLog(Log.DEBUG))
    200                 _log.debug("Completed     " + msg.getUniqueId() + " to " + toRouter + "/" + toTunnel);
    201173            _received.add(msg);
    202174        }
     
    240212        return config;
    241213    }
    242    
    243     public static void main(String args[]) {
    244         OutboundGatewayTest test = new OutboundGatewayTest();
    245         test.runTest();
    246     }
    247214}
  • router/java/test/net/i2p/router/tunnel/OutboundTest.java

    r9865af4 r4293a18  
    11package net.i2p.router.tunnel;
     2/*
     3 * free (adj.): unencumbered; not under the control of others
     4 * Written by jrandom in 2003 and released into the public domain
     5 * with no warranty of any kind, either expressed or implied.
     6 * It probably won't make your computer catch on fire, or eat
     7 * your children, but it might.  Use at your own risk.
     8 *
     9 */
    210
    311import net.i2p.I2PAppContext;
     
    715import net.i2p.util.Log;
    816
     17import junit.framework.TestCase;
     18
    919/**
    1020 * Quick unit test for base functionality of outbound tunnel
     
    1222 *
    1323 */
    14 public class OutboundTest {
     24public class OutboundTest extends TestCase{
    1525    private I2PAppContext _context;
    16     private Log _log;
    1726   
    18     public OutboundTest() {
     27    public void setUp() {
    1928        _context = I2PAppContext.getGlobalContext();
    20         _log = _context.logManager().getLog(OutboundTest.class);
    2129    }
    2230   
    23     public void runTest() {
     31    public void testOutbound() {
    2432        int numHops = 8;
    2533        TunnelCreatorConfig config = prepareConfig(numHops);
     
    3644            HopProcessor hop = new HopProcessor(_context, config.getConfig(i));
    3745            Hash prev = config.getConfig(i).getReceiveFrom();
    38             boolean ok = hop.process(message, 0, message.length, prev);
    39             if (!ok)
    40                 _log.error("Error processing at hop " + i);
    41             //else
    42             //    _log.info("Processing OK at hop " + i);
     46            assertTrue(hop.process(message, 0, message.length, prev));
    4347        }
    4448       
    45         _log.debug("After: " + Base64.encode(message, 16, orig.length-16));
    4649        boolean eq = DataHelper.eq(orig, 16, message, 16, orig.length - 16);
    47         _log.info("equal? " + eq);
    4850    }
    4951   
     
    6062        TunnelCreatorConfig config = new TunnelCreatorConfig(numHops, false);
    6163        for (int i = 0; i < numHops; i++) {
     64                config.setPeer(i, peers[i]);
    6265            HopConfig cfg = config.getConfig(i);
    6366            cfg.setExpiration(_context.clock().now() + 60000);
     
    7982        return config;
    8083    }
    81    
    82     public static void main(String args[]) {
    83         OutboundTest test = new OutboundTest();
    84         test.runTest();
    85     }
    8684}
Note: See TracChangeset for help on using the changeset viewer.