forked from I2P_Developers/i2p.i2p
refactoring most tests
remove standalone test from junit wildcard
This commit is contained in:
@@ -1,19 +1,13 @@
|
|||||||
package net.i2p.client.streaming;
|
package net.i2p.client.streaming;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.I2PClient;
|
|
||||||
import net.i2p.client.I2PClientFactory;
|
|
||||||
import net.i2p.client.I2PSession;
|
import net.i2p.client.I2PSession;
|
||||||
import net.i2p.data.Destination;
|
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,7 +16,7 @@ import net.i2p.util.Log;
|
|||||||
* EOF.
|
* EOF.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ConnectCloseTest extends TestCase {
|
public class ConnectCloseTest extends StreamingTestBase {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private I2PSession _server;
|
private I2PSession _server;
|
||||||
|
|
||||||
@@ -38,28 +32,28 @@ public class ConnectCloseTest extends TestCase {
|
|||||||
runClient(context, createSession());
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
|
||||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
|
||||||
t.setName("server");
|
|
||||||
t.setDaemon(true);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ServerRunner implements Runnable {
|
@Override
|
||||||
private I2PAppContext _context;
|
protected Properties getProperties() {
|
||||||
private I2PSession _session;
|
return System.getProperties();
|
||||||
private Log _log;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
|
||||||
|
return new ClientRunner(ctx,session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
|
||||||
|
return new ServerRunner(ctx,session);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private class ServerRunner extends RunnerBase {
|
||||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -83,14 +77,9 @@ public class ConnectCloseTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClientRunner implements Runnable {
|
private class ClientRunner extends RunnerBase {
|
||||||
private I2PAppContext _context;
|
|
||||||
private I2PSession _session;
|
|
||||||
private Log _log;
|
|
||||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,24 +1,19 @@
|
|||||||
package net.i2p.client.streaming;
|
package net.i2p.client.streaming;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.I2PClient;
|
import net.i2p.client.I2PClient;
|
||||||
import net.i2p.client.I2PClientFactory;
|
|
||||||
import net.i2p.client.I2PSession;
|
import net.i2p.client.I2PSession;
|
||||||
import net.i2p.data.Destination;
|
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ConnectInactivityTest extends TestCase{
|
public class ConnectInactivityTest extends StreamingTestBase {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private I2PSession _client;
|
private I2PSession _client;
|
||||||
private I2PSession _server;
|
private I2PSession _server;
|
||||||
@@ -37,28 +32,19 @@ public class ConnectInactivityTest extends TestCase{
|
|||||||
runClient(context, _client);
|
runClient(context, _client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
@Override
|
||||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
|
||||||
t.setName("client");
|
return new ClientRunner(ctx,session);
|
||||||
t.setDaemon(false);
|
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
@Override
|
||||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
|
||||||
t.setName("server");
|
return new ServerRunner(ctx,session);
|
||||||
t.setDaemon(false);
|
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ServerRunner implements Runnable {
|
private class ServerRunner extends RunnerBase {
|
||||||
private I2PAppContext _context;
|
|
||||||
private I2PSession _session;
|
|
||||||
private Log _log;
|
|
||||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -81,14 +67,9 @@ public class ConnectInactivityTest extends TestCase{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClientRunner implements Runnable {
|
private class ClientRunner extends RunnerBase {
|
||||||
private I2PAppContext _context;
|
|
||||||
private I2PSession _session;
|
|
||||||
private Log _log;
|
|
||||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -98,7 +79,7 @@ public class ConnectInactivityTest extends TestCase{
|
|||||||
_log.debug("manager created");
|
_log.debug("manager created");
|
||||||
I2PSocket socket = mgr.connect(_server.getMyDestination());
|
I2PSocket socket = mgr.connect(_server.getMyDestination());
|
||||||
_log.debug("socket created");
|
_log.debug("socket created");
|
||||||
try { Thread.sleep(10*60*1000); } catch (InterruptedException ie) {}
|
Thread.sleep(10*60*1000);
|
||||||
socket.close();
|
socket.close();
|
||||||
_log.debug("socket closed");
|
_log.debug("socket closed");
|
||||||
//_session.destroySession();
|
//_session.destroySession();
|
||||||
@@ -109,20 +90,11 @@ public class ConnectInactivityTest extends TestCase{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private I2PSession createSession() {
|
@Override
|
||||||
try {
|
protected Properties getProperties() {
|
||||||
I2PClient client = I2PClientFactory.createClient();
|
Properties p = new Properties();
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
p.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
|
||||||
Destination dest = client.createDestination(baos);
|
p.setProperty(I2PClient.PROP_TCP_PORT, "10001");
|
||||||
Properties p = new Properties();
|
return p;
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,25 +1,19 @@
|
|||||||
package net.i2p.client.streaming;
|
package net.i2p.client.streaming;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.I2PClient;
|
import net.i2p.client.I2PClient;
|
||||||
import net.i2p.client.I2PClientFactory;
|
|
||||||
import net.i2p.client.I2PSession;
|
import net.i2p.client.I2PSession;
|
||||||
import net.i2p.data.Destination;
|
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ConnectTest extends TestCase {
|
public class ConnectTest extends StreamingTestBase {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private I2PSession _server;
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
|
||||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
|
||||||
t.setName("server");
|
|
||||||
t.setDaemon(true);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ServerRunner implements Runnable {
|
@Override
|
||||||
private I2PAppContext _context;
|
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
|
||||||
private I2PSession _session;
|
return new ClientRunner(ctx,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) {
|
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -87,14 +76,9 @@ public class ConnectTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClientRunner implements Runnable {
|
private class ClientRunner extends RunnerBase {
|
||||||
private I2PAppContext _context;
|
|
||||||
private I2PSession _session;
|
|
||||||
private Log _log;
|
|
||||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -117,17 +101,8 @@ public class ConnectTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private I2PSession createSession() {
|
@Override
|
||||||
try {
|
protected Properties getProperties() {
|
||||||
I2PClient client = I2PClientFactory.createClient();
|
return System.getProperties();
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
package net.i2p.client.streaming;
|
package net.i2p.client.streaming;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.I2PClient;
|
import net.i2p.client.I2PClient;
|
||||||
import net.i2p.client.I2PClientFactory;
|
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,
|
* Try to connect to a new nonexistant peer and, of course,
|
||||||
* timeout.
|
* timeout.
|
||||||
*/
|
*/
|
||||||
public class ConnectTimeoutTest extends TestCase {
|
public class ConnectTimeoutTest extends StreamingTestBase {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private I2PSession _client;
|
private I2PSession _client;
|
||||||
private I2PSession _server;
|
|
||||||
private Destination _serverDest;
|
private Destination _serverDest;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -37,26 +33,18 @@ public class ConnectTimeoutTest extends TestCase {
|
|||||||
runClient(context, _client);
|
runClient(context, _client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runClient(I2PAppContext ctx, I2PSession session) {
|
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
|
||||||
Thread t = new Thread(new ClientRunner(ctx, session));
|
return new ClientRunner(ctx,session);
|
||||||
t.setName("client");
|
|
||||||
t.setDaemon(true);
|
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClientRunner implements Runnable {
|
private class ClientRunner extends RunnerBase {
|
||||||
private I2PAppContext _context;
|
|
||||||
private I2PSession _session;
|
|
||||||
private Log _log;
|
|
||||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
I2PSocketManager mgr = I2PSocketManagerFactory.createManager("localhost", 10001, getProps());
|
I2PSocketManager mgr = I2PSocketManagerFactory.createManager("localhost", 10001, getProperties());
|
||||||
_log.debug("manager created");
|
_log.debug("manager created");
|
||||||
_log.debug("options: " + mgr.getDefaultOptions());
|
_log.debug("options: " + mgr.getDefaultOptions());
|
||||||
I2PSocket socket = mgr.connect(_serverDest);
|
I2PSocket socket = mgr.connect(_serverDest);
|
||||||
@@ -73,18 +61,13 @@ public class ConnectTimeoutTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private I2PSession createSession() throws Exception {
|
@Override
|
||||||
I2PClient client = I2PClientFactory.createClient();
|
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
|
return null;
|
||||||
Destination dest = client.createDestination(baos);
|
|
||||||
Properties p = getProps();
|
|
||||||
|
|
||||||
I2PSession sess = client.createSession(new ByteArrayInputStream(baos.toByteArray()), p);
|
|
||||||
sess.connect();
|
|
||||||
return sess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Properties getProps() {
|
@Override
|
||||||
|
protected Properties getProperties() {
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
p.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
|
p.setProperty(I2PSocketManagerFactory.PROP_MANAGER, I2PSocketManagerFull.class.getName());
|
||||||
p.setProperty("tunnels.depthInbound", "0");
|
p.setProperty("tunnels.depthInbound", "0");
|
||||||
|
@@ -1,27 +1,21 @@
|
|||||||
package net.i2p.client.streaming;
|
package net.i2p.client.streaming;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.I2PClient;
|
|
||||||
import net.i2p.client.I2PClientFactory;
|
|
||||||
import net.i2p.client.I2PSession;
|
import net.i2p.client.I2PSession;
|
||||||
import net.i2p.data.Base64;
|
import net.i2p.data.Base64;
|
||||||
import net.i2p.data.Destination;
|
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EchoLargeTest extends TestCase {
|
public class EchoLargeTest extends StreamingTestBase {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private I2PSession _client;
|
private I2PSession _client;
|
||||||
private I2PSession _server;
|
private I2PSession _server;
|
||||||
@@ -40,28 +34,28 @@ public class EchoLargeTest extends TestCase {
|
|||||||
runClient(context, _client);
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
|
||||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
|
||||||
t.setName("server");
|
|
||||||
t.setDaemon(true);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ServerRunner implements Runnable {
|
@Override
|
||||||
private I2PAppContext _context;
|
protected Properties getProperties() {
|
||||||
private I2PSession _session;
|
return new Properties();
|
||||||
private Log _log;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
|
||||||
|
return new ClientRunner(ctx,session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
|
||||||
|
return new ServerRunner(ctx,session);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private class ServerRunner extends RunnerBase {
|
||||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -105,14 +99,9 @@ public class EchoLargeTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClientRunner implements Runnable {
|
private class ClientRunner extends RunnerBase {
|
||||||
private I2PAppContext _context;
|
|
||||||
private I2PSession _session;
|
|
||||||
private Log _log;
|
|
||||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,26 +1,20 @@
|
|||||||
package net.i2p.client.streaming;
|
package net.i2p.client.streaming;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.client.I2PClient;
|
|
||||||
import net.i2p.client.I2PClientFactory;
|
|
||||||
import net.i2p.client.I2PSession;
|
import net.i2p.client.I2PSession;
|
||||||
import net.i2p.data.Destination;
|
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EchoTest extends TestCase {
|
public class EchoTest extends StreamingTestBase {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private I2PSession _client;
|
private I2PSession _client;
|
||||||
private I2PSession _server;
|
private I2PSession _server;
|
||||||
@@ -39,28 +33,28 @@ public class EchoTest extends TestCase {
|
|||||||
runClient(context, _client);
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runServer(I2PAppContext ctx, I2PSession session) {
|
|
||||||
Thread t = new Thread(new ServerRunner(ctx, session));
|
|
||||||
t.setName("server");
|
|
||||||
t.setDaemon(true);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ServerRunner implements Runnable {
|
@Override
|
||||||
private I2PAppContext _context;
|
protected Properties getProperties() {
|
||||||
private I2PSession _session;
|
return new Properties();
|
||||||
private Log _log;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Runnable getClient(I2PAppContext ctx, I2PSession session) {
|
||||||
|
return new ClientRunner(ctx,session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Runnable getServer(I2PAppContext ctx, I2PSession session) {
|
||||||
|
return new ServerRunner(ctx,session);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private class ServerRunner extends RunnerBase {
|
||||||
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
public ServerRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ServerRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -104,14 +98,9 @@ public class EchoTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClientRunner implements Runnable {
|
private class ClientRunner extends RunnerBase {
|
||||||
private I2PAppContext _context;
|
|
||||||
private I2PSession _session;
|
|
||||||
private Log _log;
|
|
||||||
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
public ClientRunner(I2PAppContext ctx, I2PSession session) {
|
||||||
_context = ctx;
|
super(ctx,session);
|
||||||
_session = session;
|
|
||||||
_log = ctx.logManager().getLog(ClientRunner.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user