refactoring most tests

remove standalone test from junit wildcard
This commit is contained in:
zab2
2013-06-28 22:27:31 +00:00
parent 14944982fb
commit 4f6065b4fa
8 changed files with 175 additions and 260 deletions

View File

@@ -1,19 +1,13 @@
package net.i2p.client.streaming;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
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;
/**
@@ -22,7 +16,7 @@ import net.i2p.util.Log;
* EOF.
*
*/
public class ConnectCloseTest extends TestCase {
public class ConnectCloseTest extends StreamingTestBase {
private Log _log;
private I2PSession _server;
@@ -38,28 +32,28 @@ public class ConnectCloseTest extends TestCase {
runClient(context, createSession());
}
private void runClient(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ClientRunner(ctx, session));
t.setName("client");
t.setDaemon(true);
t.start();
@Override
protected Properties getProperties() {
return System.getProperties();
}
private void runServer(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ServerRunner(ctx, session));
t.setName("server");
t.setDaemon(true);
t.start();
@Override
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
return new ClientRunner(ctx,session);
}
private class ServerRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
@Override
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
return new ServerRunner(ctx,session);
}
private class ServerRunner extends RunnerBase {
public ServerRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ServerRunner.class);
super(ctx,session);
}
public void run() {
@@ -83,14 +77,9 @@ public class ConnectCloseTest extends TestCase {
}
private class ClientRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ClientRunner extends RunnerBase {
public ClientRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ClientRunner.class);
super(ctx,session);
}
public void run() {
@@ -117,18 +106,4 @@ public class ConnectCloseTest extends TestCase {
}
}
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()), System.getProperties());
sess.connect();
return sess;
} catch (Exception e) {
_log.error("error running", e);
throw new RuntimeException("b0rk b0rk b0rk");
}
}
}

View File

@@ -1,24 +1,19 @@
package net.i2p.client.streaming;
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 ConnectInactivityTest extends TestCase{
public class ConnectInactivityTest extends StreamingTestBase {
private Log _log;
private I2PSession _client;
private I2PSession _server;
@@ -37,28 +32,19 @@ public class ConnectInactivityTest extends TestCase{
runClient(context, _client);
}
private void runClient(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ClientRunner(ctx, session));
t.setName("client");
t.setDaemon(false);
t.start();
@Override
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
return new ClientRunner(ctx,session);
}
private void runServer(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ServerRunner(ctx, session));
t.setName("server");
t.setDaemon(false);
t.start();
@Override
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
return new ServerRunner(ctx,session);
}
private class ServerRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ServerRunner extends RunnerBase {
public ServerRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ServerRunner.class);
super(ctx,session);
}
public void run() {
@@ -81,14 +67,9 @@ public class ConnectInactivityTest extends TestCase{
}
private class ClientRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ClientRunner extends RunnerBase {
public ClientRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ClientRunner.class);
super(ctx,session);
}
public void run() {
@@ -98,7 +79,7 @@ public class ConnectInactivityTest extends TestCase{
_log.debug("manager created");
I2PSocket socket = mgr.connect(_server.getMyDestination());
_log.debug("socket created");
try { Thread.sleep(10*60*1000); } catch (InterruptedException ie) {}
Thread.sleep(10*60*1000);
socket.close();
_log.debug("socket closed");
//_session.destroySession();
@@ -109,20 +90,11 @@ public class ConnectInactivityTest extends TestCase{
}
private I2PSession createSession() {
try {
I2PClient client = I2PClientFactory.createClient();
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
Destination dest = client.createDestination(baos);
Properties p = new Properties();
p.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
p.setProperty(I2PClient.PROP_TCP_PORT, "10001");
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
sess.connect();
return sess;
} catch (Exception e) {
_log.error("error running", e);
throw new RuntimeException("b0rk b0rk b0rk");
}
@Override
protected Properties getProperties() {
Properties p = new Properties();
p.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
p.setProperty(I2PClient.PROP_TCP_PORT, "10001");
return p;
}
}

View File

@@ -1,25 +1,19 @@
package net.i2p.client.streaming;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Properties;
import org.junit.Before;
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 ConnectTest extends TestCase {
public class ConnectTest extends StreamingTestBase {
private Log _log;
private I2PSession _server;
@@ -43,28 +37,23 @@ public class ConnectTest extends TestCase {
}
}
private void runClient(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ClientRunner(ctx, session));
t.setName("client");
t.setDaemon(true);
t.start();
@Override
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
return new ClientRunner(ctx,session);
}
private void runServer(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ServerRunner(ctx, session));
t.setName("server");
t.setDaemon(true);
t.start();
@Override
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
return new ServerRunner(ctx,session);
}
private class ServerRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ServerRunner extends RunnerBase {
public ServerRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ServerRunner.class);
super(ctx,session);
}
public void run() {
@@ -87,14 +76,9 @@ public class ConnectTest extends TestCase {
}
private class ClientRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ClientRunner extends RunnerBase {
public ClientRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ClientRunner.class);
super(ctx,session);
}
public void run() {
@@ -117,17 +101,8 @@ public class ConnectTest extends TestCase {
}
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()), System.getProperties());
sess.connect();
return sess;
} catch (Exception e) {
_log.error("error running", e);
throw new RuntimeException("b0rk b0rk b0rk");
}
@Override
protected Properties getProperties() {
return System.getProperties();
}
}

View File

@@ -1,13 +1,10 @@
package net.i2p.client.streaming;
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;
@@ -19,10 +16,9 @@ import net.i2p.util.Log;
* Try to connect to a new nonexistant peer and, of course,
* timeout.
*/
public class ConnectTimeoutTest extends TestCase {
public class ConnectTimeoutTest extends StreamingTestBase {
private Log _log;
private I2PSession _client;
private I2PSession _server;
private Destination _serverDest;
@Test
@@ -37,26 +33,18 @@ public class ConnectTimeoutTest extends TestCase {
runClient(context, _client);
}
private void runClient(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ClientRunner(ctx, session));
t.setName("client");
t.setDaemon(true);
t.start();
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
return new ClientRunner(ctx,session);
}
private class ClientRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ClientRunner extends RunnerBase {
public ClientRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ClientRunner.class);
super(ctx,session);
}
public void run() {
try {
I2PSocketManager mgr = I2PSocketManagerFactory.createManager("localhost", 10001, getProps());
I2PSocketManager mgr = I2PSocketManagerFactory.createManager("localhost", 10001, getProperties());
_log.debug("manager created");
_log.debug("options: " + mgr.getDefaultOptions());
I2PSocket socket = mgr.connect(_serverDest);
@@ -73,18 +61,13 @@ public class ConnectTimeoutTest extends TestCase {
}
private I2PSession createSession() throws Exception {
I2PClient client = I2PClientFactory.createClient();
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
Destination dest = client.createDestination(baos);
Properties p = getProps();
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
sess.connect();
return sess;
@Override
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
return null;
}
private static Properties getProps() {
@Override
protected Properties getProperties() {
Properties p = new Properties();
p.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
p.setProperty("tunnels.depthInbound", "0");

View File

@@ -1,27 +1,21 @@
package net.i2p.client.streaming;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
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.Base64;
import net.i2p.data.Destination;
import net.i2p.util.Log;
/**
*
*/
public class EchoLargeTest extends TestCase {
public class EchoLargeTest extends StreamingTestBase {
private Log _log;
private I2PSession _client;
private I2PSession _server;
@@ -40,28 +34,28 @@ public class EchoLargeTest extends TestCase {
runClient(context, _client);
}
private void runClient(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ClientRunner(ctx, session));
t.setName("client");
t.setDaemon(true);
t.start();
@Override
protected Properties getProperties() {
return new Properties();
}
private void runServer(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ServerRunner(ctx, session));
t.setName("server");
t.setDaemon(true);
t.start();
@Override
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
return new ClientRunner(ctx,session);
}
private class ServerRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
@Override
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
return new ServerRunner(ctx,session);
}
private class ServerRunner extends RunnerBase {
public ServerRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ServerRunner.class);
super(ctx,session);
}
public void run() {
@@ -105,14 +99,9 @@ public class EchoLargeTest extends TestCase {
}
private class ClientRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ClientRunner extends RunnerBase {
public ClientRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ClientRunner.class);
super(ctx,session);
}
public void run() {
@@ -178,18 +167,4 @@ public class EchoLargeTest extends TestCase {
}
}
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) {
_log.error("error running", e);
throw new RuntimeException("b0rk b0rk b0rk");
}
}
}

View File

@@ -1,26 +1,20 @@
package net.i2p.client.streaming;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
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 EchoTest extends TestCase {
public class EchoTest extends StreamingTestBase {
private Log _log;
private I2PSession _client;
private I2PSession _server;
@@ -39,28 +33,28 @@ public class EchoTest extends TestCase {
runClient(context, _client);
}
private void runClient(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ClientRunner(ctx, session));
t.setName("client");
t.setDaemon(true);
t.start();
@Override
protected Properties getProperties() {
return new Properties();
}
private void runServer(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(new ServerRunner(ctx, session));
t.setName("server");
t.setDaemon(true);
t.start();
@Override
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
return new ClientRunner(ctx,session);
}
private class ServerRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
@Override
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
return new ServerRunner(ctx,session);
}
private class ServerRunner extends RunnerBase {
public ServerRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ServerRunner.class);
super(ctx,session);
}
public void run() {
@@ -104,14 +98,9 @@ public class EchoTest extends TestCase {
}
private class ClientRunner implements Runnable {
private I2PAppContext _context;
private I2PSession _session;
private Log _log;
private class ClientRunner extends RunnerBase {
public ClientRunner(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(ClientRunner.class);
super(ctx,session);
}
public void run() {
@@ -157,18 +146,4 @@ public class EchoTest extends TestCase {
}
}
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) {
_log.error("error running", e);
throw new RuntimeException("b0rk b0rk b0rk");
}
}
}

View File

@@ -0,0 +1,60 @@
package net.i2p.client.streaming;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.client.I2PClient;
import net.i2p.client.I2PClientFactory;
import net.i2p.client.I2PSession;
import net.i2p.util.Log;
import junit.framework.TestCase;
abstract class StreamingTestBase extends TestCase {
protected abstract Properties getProperties();
protected I2PSession createSession() throws Exception {
I2PClient client = I2PClientFactory.createClient();
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
client.createDestination(baos);
Properties p = getProperties();
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
sess.connect();
return sess;
}
protected abstract Runnable getClient(I2PAppContext ctx, I2PSession session);
protected final void runClient(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(getClient(ctx,session));
t.setName("client");
t.setDaemon(true);
t.start();
}
protected abstract class RunnerBase implements Runnable {
protected final I2PAppContext _context;
protected final I2PSession _session;
protected final Log _log;
protected RunnerBase(I2PAppContext ctx, I2PSession session) {
_context = ctx;
_session = session;
_log = ctx.logManager().getLog(this.getClass());
}
}
protected abstract Runnable getServer(I2PAppContext ctx, I2PSession session);
protected final void runServer(I2PAppContext ctx, I2PSession session) {
Thread t = new Thread(getServer(ctx,session));
t.setName("servert");
t.setDaemon(false);
t.start();
}
}