I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3cfd28de authored by jrandom's avatar jrandom Committed by zzz
Browse files

add a new unit test for repeated fast reconnections

parent 4888207e
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import java.io.OutputStream; ...@@ -7,6 +7,7 @@ import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import net.i2p.util.Log; import net.i2p.util.Log;
import net.i2p.util.Clock;
public class TestCreateSessionRaw { public class TestCreateSessionRaw {
private static Log _log = new Log(TestCreateSessionRaw.class); private static Log _log = new Log(TestCreateSessionRaw.class);
...@@ -15,6 +16,7 @@ public class TestCreateSessionRaw { ...@@ -15,6 +16,7 @@ public class TestCreateSessionRaw {
testTransient(samHost, samPort, conOptions); testTransient(samHost, samPort, conOptions);
testNewDest(samHost, samPort, conOptions); testNewDest(samHost, samPort, conOptions);
testOldDest(samHost, samPort, conOptions); testOldDest(samHost, samPort, conOptions);
testFast(samHost, samPort, conOptions);
} }
private static void testTransient(String host, int port, String conOptions) { private static void testTransient(String host, int port, String conOptions) {
...@@ -36,21 +38,34 @@ public class TestCreateSessionRaw { ...@@ -36,21 +38,34 @@ public class TestCreateSessionRaw {
_log.debug("\n\nTest of subsequent contact complete\n\n"); _log.debug("\n\nTest of subsequent contact complete\n\n");
} }
private static void testFast(String host, int port, String conOptions) {
String destName = "Alice" + Math.random();
long totalTime = 0;
for (int i = 0; i < 10; i++) {
long before = Clock.getInstance().now();
testDest(host, port, conOptions, destName);
long after = Clock.getInstance().now();
long difference = after-before;
_log.debug("Time to test destination: " + difference + " \n\n");
totalTime += difference;
}
_log.debug("\n\nTime to test fast reconnection: " + totalTime + " over 10 runs");
}
private static void testDest(String host, int port, String conOptions, String destName) { private static void testDest(String host, int port, String conOptions, String destName) {
_log.info("\n\nTesting creating a new destination (should come back with 'SESSION STATUS RESULT=OK DESTINATION=someName)\n\n\n"); //_log.info("\n\nTesting creating a new destination (should come back with 'SESSION STATUS RESULT=OK DESTINATION=someName)\n\n\n");
try { try {
Socket s = new Socket(host, port); Socket s = new Socket(host, port);
OutputStream out = s.getOutputStream(); OutputStream out = s.getOutputStream();
out.write("HELLO VERSION MIN=1.0 MAX=1.0\n".getBytes()); out.write("HELLO VERSION MIN=1.0 MAX=1.0\n".getBytes());
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line = reader.readLine(); String line = reader.readLine();
_log.debug("line read for valid version: " + line); //_log.debug("line read for valid version: " + line);
String req = "SESSION CREATE STYLE=RAW DESTINATION=" + destName + " " + conOptions + "\n"; String req = "SESSION CREATE STYLE=RAW DESTINATION=" + destName + " " + conOptions + "\n";
out.write(req.getBytes()); out.write(req.getBytes());
line = reader.readLine(); line = reader.readLine();
_log.info("Response to creating the session with destination " + destName + ": " + line); _log.info("Response to creating the session with destination " + destName + ": " + line);
_log.debug("The above should contain SESSION STATUS RESULT=OK\n\n\n"); _log.debug("The above should contain SESSION STATUS RESULT=OK");
try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
s.close(); s.close();
} catch (Exception e) { } catch (Exception e) {
_log.error("Error testing for valid version", e); _log.error("Error testing for valid version", e);
...@@ -60,7 +75,7 @@ public class TestCreateSessionRaw { ...@@ -60,7 +75,7 @@ public class TestCreateSessionRaw {
public static void main(String args[]) { public static void main(String args[]) {
// "i2cp.tcp.host=www.i2p.net i2cp.tcp.port=7765"; // "i2cp.tcp.host=www.i2p.net i2cp.tcp.port=7765";
// "i2cp.tcp.host=localhost i2cp.tcp.port=7654 tunnels.inboundDepth=0"; // "i2cp.tcp.host=localhost i2cp.tcp.port=7654 tunnels.inboundDepth=0";
String conOptions = "i2cp.tcp.host=dev.i2p.net i2cp.tcp.port=7002 tunnels.inboundDepth=0"; String conOptions = "i2cp.tcp.host=dev.i2p.net i2cp.tcp.port=7002 tunnels.depthInbound=0 tunnels.depthOutbound=0";
if (args.length > 0) { if (args.length > 0) {
conOptions = ""; conOptions = "";
for (int i = 0; i < args.length; i++) for (int i = 0; i < args.length; i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment