Changeset 4f6065b


Ignore:
Timestamp:
Jun 28, 2013 10:27:31 PM (7 years ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
1c68852
Parents:
14944982
Message:

refactoring most tests

remove standalone test from junit wildcard

Location:
apps/streaming/java/test/junit/net/i2p/client/streaming
Files:
1 added
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectCloseTest.java

    r14944982 r4f6065b  
    11package net.i2p.client.streaming;
    22
    3 import java.io.ByteArrayInputStream;
    4 import java.io.ByteArrayOutputStream;
    53import java.io.InputStream;
    64import java.util.Properties;
     
    86import org.junit.Test;
    97
    10 import junit.framework.TestCase;
    118
    129import net.i2p.I2PAppContext;
    13 import net.i2p.client.I2PClient;
    14 import net.i2p.client.I2PClientFactory;
    1510import net.i2p.client.I2PSession;
    16 import net.i2p.data.Destination;
    1711import net.i2p.util.Log;
    1812
     
    2317 *
    2418 */
    25 public class ConnectCloseTest extends TestCase {
     19public class ConnectCloseTest extends StreamingTestBase {
    2620    private Log _log;
    2721    private I2PSession _server;
     
    3933    }
    4034   
    41     private void runClient(I2PAppContext ctx, I2PSession session) {
    42         Thread t = new Thread(new ClientRunner(ctx, session));
    43         t.setName("client");
    44         t.setDaemon(true);
    45         t.start();
     35   
     36   
     37    @Override
     38    protected Properties getProperties() {
     39        return System.getProperties();
    4640    }
    47    
    48     private void runServer(I2PAppContext ctx, I2PSession session) {
    49         Thread t = new Thread(new ServerRunner(ctx, session));
    50         t.setName("server");
    51         t.setDaemon(true);
    52         t.start();
     41
     42    @Override
     43    protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
     44        return new ClientRunner(ctx,session);
    5345    }
    54    
    55     private class ServerRunner implements Runnable {
    56         private I2PAppContext _context;
    57         private I2PSession _session;
    58         private Log _log;
     46
     47    @Override
     48    protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
     49        return new ServerRunner(ctx,session);
     50    }
     51
     52
     53
     54    private class ServerRunner extends RunnerBase {
    5955        public ServerRunner(I2PAppContext ctx, I2PSession session) {
    60             _context = ctx;
    61             _session = session;
    62             _log = ctx.logManager().getLog(ServerRunner.class);
     56            super(ctx,session);
    6357        }
    6458       
     
    8478    }
    8579   
    86     private class ClientRunner implements Runnable {
    87         private I2PAppContext _context;
    88         private I2PSession _session;
    89         private Log _log;
     80    private class ClientRunner extends RunnerBase {
    9081        public ClientRunner(I2PAppContext ctx, I2PSession session) {
    91             _context = ctx;
    92             _session = session;
    93             _log = ctx.logManager().getLog(ClientRunner.class);
     82            super(ctx,session);
    9483        }
    9584       
     
    118107       
    119108    }
    120    
    121     private I2PSession createSession() {
    122         try {
    123             I2PClient client = I2PClientFactory.createClient();
    124             ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    125             Destination dest = client.createDestination(baos);
    126             I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), System.getProperties());
    127             sess.connect();
    128             return sess;
    129         } catch (Exception e) {
    130             _log.error("error running", e);
    131             throw new RuntimeException("b0rk b0rk b0rk");
    132         }
    133     }
    134109}
  • apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectInactivityTest.java

    r14944982 r4f6065b  
    11package net.i2p.client.streaming;
    22
    3 import java.io.ByteArrayInputStream;
    4 import java.io.ByteArrayOutputStream;
    53import java.util.Properties;
    64
    75import org.junit.Test;
    86
    9 import junit.framework.TestCase;
    107
    118import net.i2p.I2PAppContext;
    129import net.i2p.client.I2PClient;
    13 import net.i2p.client.I2PClientFactory;
    1410import net.i2p.client.I2PSession;
    15 import net.i2p.data.Destination;
    1611import net.i2p.util.Log;
    1712
     
    1914 *
    2015 */
    21 public class ConnectInactivityTest extends TestCase{
     16public class ConnectInactivityTest extends StreamingTestBase {
    2217    private Log _log;
    2318    private I2PSession _client;
     
    3833    }
    3934   
    40     private void runClient(I2PAppContext ctx, I2PSession session) {
    41         Thread t = new Thread(new ClientRunner(ctx, session));
    42         t.setName("client");
    43         t.setDaemon(false);
    44         t.start();
     35    @Override
     36    protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
     37        return new ClientRunner(ctx,session);
    4538    }
    4639   
    47     private void runServer(I2PAppContext ctx, I2PSession session) {
    48         Thread t = new Thread(new ServerRunner(ctx, session));
    49         t.setName("server");
    50         t.setDaemon(false);
    51         t.start();
     40    @Override
     41    protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
     42        return new ServerRunner(ctx,session);
    5243    }
    5344   
    54     private class ServerRunner implements Runnable {
    55         private I2PAppContext _context;
    56         private I2PSession _session;
    57         private Log _log;
     45    private class ServerRunner extends RunnerBase {
    5846        public ServerRunner(I2PAppContext ctx, I2PSession session) {
    59             _context = ctx;
    60             _session = session;
    61             _log = ctx.logManager().getLog(ServerRunner.class);
     47            super(ctx,session);
    6248        }
    6349       
     
    8268    }
    8369   
    84     private class ClientRunner implements Runnable {
    85         private I2PAppContext _context;
    86         private I2PSession _session;
    87         private Log _log;
     70    private class ClientRunner extends RunnerBase {
    8871        public ClientRunner(I2PAppContext ctx, I2PSession session) {
    89             _context = ctx;
    90             _session = session;
    91             _log = ctx.logManager().getLog(ClientRunner.class);
     72            super(ctx,session);
    9273        }
    9374       
     
    9980                I2PSocket socket = mgr.connect(_server.getMyDestination());
    10081                _log.debug("socket created");
    101                 try { Thread.sleep(10*60*1000); } catch (InterruptedException ie) {}
     82                Thread.sleep(10*60*1000);
    10283                socket.close();
    10384                _log.debug("socket closed");
     
    11091    }
    11192   
    112     private I2PSession createSession() {
    113         try {
    114             I2PClient client = I2PClientFactory.createClient();
    115             ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    116             Destination dest = client.createDestination(baos);
    117             Properties p = new Properties();
    118             p.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
    119             p.setProperty(I2PClient.PROP_TCP_PORT, "10001");
    120             I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
    121             sess.connect();
    122             return sess;
    123         } catch (Exception e) {
    124             _log.error("error running", e);
    125             throw new RuntimeException("b0rk b0rk b0rk");
    126         }
     93    @Override
     94    protected Properties getProperties() {
     95        Properties p = new Properties();
     96        p.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
     97        p.setProperty(I2PClient.PROP_TCP_PORT, "10001");
     98        return p;
    12799    }
    128100}
  • apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTest.java

    r14944982 r4f6065b  
    11package net.i2p.client.streaming;
    22
    3 import java.io.ByteArrayInputStream;
    4 import java.io.ByteArrayOutputStream;
    53import java.util.Properties;
    64
     
    86import org.junit.Test;
    97
    10 import junit.framework.TestCase;
    11 
    128import net.i2p.I2PAppContext;
    139import net.i2p.client.I2PClient;
    14 import net.i2p.client.I2PClientFactory;
    1510import net.i2p.client.I2PSession;
    16 import net.i2p.data.Destination;
    1711import net.i2p.util.Log;
    1812
     
    2014 *
    2115 */
    22 public class ConnectTest  extends TestCase {
     16public class ConnectTest extends StreamingTestBase {
    2317    private Log _log;
    2418    private I2PSession _server;
     
    4438    }
    4539   
    46     private void runClient(I2PAppContext ctx, I2PSession session) {
    47         Thread t = new Thread(new ClientRunner(ctx, session));
    48         t.setName("client");
    49         t.setDaemon(true);
    50         t.start();
     40   
     41   
     42    @Override
     43    protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
     44        return new ClientRunner(ctx,session);
    5145    }
    52    
    53     private void runServer(I2PAppContext ctx, I2PSession session) {
    54         Thread t = new Thread(new ServerRunner(ctx, session));
    55         t.setName("server");
    56         t.setDaemon(true);
    57         t.start();
     46
     47    @Override
     48    protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
     49        return new ServerRunner(ctx,session);
    5850    }
    59    
    60     private class ServerRunner implements Runnable {
    61         private I2PAppContext _context;
    62         private I2PSession _session;
    63         private Log _log;
     51
     52
     53
     54    private class ServerRunner extends RunnerBase {
    6455        public ServerRunner(I2PAppContext ctx, I2PSession session) {
    65             _context = ctx;
    66             _session = session;
    67             _log = ctx.logManager().getLog(ServerRunner.class);
     56            super(ctx,session);
    6857        }
    6958       
     
    8877    }
    8978   
    90     private class ClientRunner implements Runnable {
    91         private I2PAppContext _context;
    92         private I2PSession _session;
    93         private Log _log;
     79    private class ClientRunner extends RunnerBase {
    9480        public ClientRunner(I2PAppContext ctx, I2PSession session) {
    95             _context = ctx;
    96             _session = session;
    97             _log = ctx.logManager().getLog(ClientRunner.class);
     81            super(ctx,session);
    9882        }
    9983       
     
    118102    }
    119103   
    120     private I2PSession createSession() {
    121         try {
    122             I2PClient client = I2PClientFactory.createClient();
    123             ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    124             Destination dest = client.createDestination(baos);
    125             I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), System.getProperties());
    126             sess.connect();
    127             return sess;
    128         } catch (Exception e) {
    129             _log.error("error running", e);
    130             throw new RuntimeException("b0rk b0rk b0rk");
    131         }
     104    @Override
     105    protected Properties getProperties() {
     106        return System.getProperties();
    132107    }
    133108}
  • apps/streaming/java/test/junit/net/i2p/client/streaming/ConnectTimeoutTest.java

    r14944982 r4f6065b  
    11package net.i2p.client.streaming;
    22
    3 import java.io.ByteArrayInputStream;
    43import java.io.ByteArrayOutputStream;
    54import java.util.Properties;
    65
    76import org.junit.Test;
    8 
    9 import junit.framework.TestCase;
    107
    118import net.i2p.I2PAppContext;
     
    2017 * timeout.
    2118 */
    22 public class ConnectTimeoutTest  extends TestCase {
     19public class ConnectTimeoutTest  extends StreamingTestBase {
    2320    private Log _log;
    2421    private I2PSession _client;
    25     private I2PSession _server;
    2622    private Destination _serverDest;
    2723   
     
    3834    }
    3935   
    40     private void runClient(I2PAppContext ctx, I2PSession session) {
    41         Thread t = new Thread(new ClientRunner(ctx, session));
    42         t.setName("client");
    43         t.setDaemon(true);
    44         t.start();
     36    protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
     37        return new ClientRunner(ctx,session);
    4538    }
    4639   
    47     private class ClientRunner implements Runnable {
    48         private I2PAppContext _context;
    49         private I2PSession _session;
    50         private Log _log;
     40    private class ClientRunner extends RunnerBase {
    5141        public ClientRunner(I2PAppContext ctx, I2PSession session) {
    52             _context = ctx;
    53             _session = session;
    54             _log = ctx.logManager().getLog(ClientRunner.class);
     42            super(ctx,session);
    5543        }
    5644       
    5745        public void run() {
    5846            try {
    59                 I2PSocketManager mgr = I2PSocketManagerFactory.createManager("localhost", 10001, getProps());
     47                I2PSocketManager mgr = I2PSocketManagerFactory.createManager("localhost", 10001, getProperties());
    6048                _log.debug("manager created");
    6149                _log.debug("options: " + mgr.getDefaultOptions());
     
    7462    }
    7563   
    76     private I2PSession createSession() throws Exception {
    77         I2PClient client = I2PClientFactory.createClient();
    78         ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    79         Destination dest = client.createDestination(baos);
    80         Properties p = getProps();
    81 
    82         I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
    83         sess.connect();
    84         return sess;
     64    @Override
     65    protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
     66        return null;
    8567    }
    8668   
    87     private static Properties getProps() {
     69    @Override
     70    protected Properties getProperties() {
    8871        Properties p = new Properties();
    8972        p.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
  • apps/streaming/java/test/junit/net/i2p/client/streaming/EchoLargeTest.java

    r14944982 r4f6065b  
    11package net.i2p.client.streaming;
    22
    3 import java.io.ByteArrayInputStream;
    4 import java.io.ByteArrayOutputStream;
    53import java.io.InputStream;
    64import java.io.OutputStream;
     
    97import org.junit.Test;
    108
    11 import junit.framework.TestCase;
    129
    1310import net.i2p.I2PAppContext;
    14 import net.i2p.client.I2PClient;
    15 import net.i2p.client.I2PClientFactory;
    1611import net.i2p.client.I2PSession;
    1712import net.i2p.data.Base64;
    18 import net.i2p.data.Destination;
    1913import net.i2p.util.Log;
    2014
     
    2216 *
    2317 */
    24 public class EchoLargeTest extends TestCase {
     18public class EchoLargeTest extends StreamingTestBase {
    2519    private Log _log;
    2620    private I2PSession _client;
     
    4135    }
    4236   
    43     private void runClient(I2PAppContext ctx, I2PSession session) {
    44         Thread t = new Thread(new ClientRunner(ctx, session));
    45         t.setName("client");
    46         t.setDaemon(true);
    47         t.start();
     37   
     38   
     39    @Override
     40    protected Properties getProperties() {
     41        return new Properties();
    4842    }
    49    
    50     private void runServer(I2PAppContext ctx, I2PSession session) {
    51         Thread t = new Thread(new ServerRunner(ctx, session));
    52         t.setName("server");
    53         t.setDaemon(true);
    54         t.start();
     43
     44    @Override
     45    protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
     46        return new ClientRunner(ctx,session);
    5547    }
    56    
    57     private class ServerRunner implements Runnable {
    58         private I2PAppContext _context;
    59         private I2PSession _session;
    60         private Log _log;
     48
     49    @Override
     50    protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
     51        return new ServerRunner(ctx,session);
     52    }
     53
     54
     55
     56    private class ServerRunner extends RunnerBase {
    6157        public ServerRunner(I2PAppContext ctx, I2PSession session) {
    62             _context = ctx;
    63             _session = session;
    64             _log = ctx.logManager().getLog(ServerRunner.class);
     58            super(ctx,session);
    6559        }
    6660       
     
    106100    }
    107101   
    108     private class ClientRunner implements Runnable {
    109         private I2PAppContext _context;
    110         private I2PSession _session;
    111         private Log _log;
     102    private class ClientRunner extends RunnerBase {
    112103        public ClientRunner(I2PAppContext ctx, I2PSession session) {
    113             _context = ctx;
    114             _session = session;
    115             _log = ctx.logManager().getLog(ClientRunner.class);
     104            super(ctx,session);
    116105        }
    117106       
     
    179168       
    180169    }
    181    
    182     private I2PSession createSession() {
    183         try {
    184             I2PClient client = I2PClientFactory.createClient();
    185             ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    186             Destination dest = client.createDestination(baos);
    187             I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties());
    188             sess.connect();
    189             return sess;
    190         } catch (Exception e) {
    191             _log.error("error running", e);
    192             throw new RuntimeException("b0rk b0rk b0rk");
    193         }
    194     }
    195170}
  • apps/streaming/java/test/junit/net/i2p/client/streaming/EchoTest.java

    r14944982 r4f6065b  
    11package net.i2p.client.streaming;
    22
    3 import java.io.ByteArrayInputStream;
    4 import java.io.ByteArrayOutputStream;
    53import java.io.InputStream;
    64import java.io.OutputStream;
     
    97import org.junit.Test;
    108
    11 import junit.framework.TestCase;
    129
    1310import net.i2p.I2PAppContext;
    14 import net.i2p.client.I2PClient;
    15 import net.i2p.client.I2PClientFactory;
    1611import net.i2p.client.I2PSession;
    17 import net.i2p.data.Destination;
    1812import net.i2p.util.Log;
    1913
     
    2115 *
    2216 */
    23 public class EchoTest extends TestCase {
     17public class EchoTest extends StreamingTestBase {
    2418    private Log _log;
    2519    private I2PSession _client;
     
    4034    }
    4135   
    42     private void runClient(I2PAppContext ctx, I2PSession session) {
    43         Thread t = new Thread(new ClientRunner(ctx, session));
    44         t.setName("client");
    45         t.setDaemon(true);
    46         t.start();
     36   
     37   
     38    @Override
     39    protected Properties getProperties() {
     40        return new Properties();
    4741    }
    48    
    49     private void runServer(I2PAppContext ctx, I2PSession session) {
    50         Thread t = new Thread(new ServerRunner(ctx, session));
    51         t.setName("server");
    52         t.setDaemon(true);
    53         t.start();
     42
     43    @Override
     44    protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
     45        return new ClientRunner(ctx,session);
    5446    }
    55    
    56     private class ServerRunner implements Runnable {
    57         private I2PAppContext _context;
    58         private I2PSession _session;
    59         private Log _log;
     47
     48    @Override
     49    protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
     50        return new ServerRunner(ctx,session);
     51    }
     52
     53
     54
     55    private class ServerRunner extends RunnerBase {
    6056        public ServerRunner(I2PAppContext ctx, I2PSession session) {
    61             _context = ctx;
    62             _session = session;
    63             _log = ctx.logManager().getLog(ServerRunner.class);
     57            super(ctx,session);
    6458        }
    6559       
     
    10599    }
    106100   
    107     private class ClientRunner implements Runnable {
    108         private I2PAppContext _context;
    109         private I2PSession _session;
    110         private Log _log;
     101    private class ClientRunner extends RunnerBase {
    111102        public ClientRunner(I2PAppContext ctx, I2PSession session) {
    112             _context = ctx;
    113             _session = session;
    114             _log = ctx.logManager().getLog(ClientRunner.class);
     103            super(ctx,session);
    115104        }
    116105       
     
    158147       
    159148    }
    160    
    161     private I2PSession createSession() {
    162         try {
    163             I2PClient client = I2PClientFactory.createClient();
    164             ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
    165             Destination dest = client.createDestination(baos);
    166             I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), new Properties());
    167             sess.connect();
    168             return sess;
    169         } catch (Exception e) {
    170             _log.error("error running", e);
    171             throw new RuntimeException("b0rk b0rk b0rk");
    172         }
    173     }
    174149}
Note: See TracChangeset for help on using the changeset viewer.