- Fix junit path typo

- Fix several router unit test compile errors.
  They all compile now.
- Move SubmitMessageHistoryJob to i2p.scripts, it is not a unit test
This commit is contained in:
zzz
2013-01-03 16:10:49 +00:00
parent 17ac0e4b5f
commit 8f4f7a677f
10 changed files with 20 additions and 129 deletions

View File

@ -133,8 +133,8 @@
<pathelement location="${hamcrest.home}/hamcrest-core.jar" />
<pathelement location="${hamcrest.home}/hamcrest-library.jar" />
<pathelement location="${hamcrest.home}/hamcrest-integration.jar" />
<pathelement location="$junit.home}/junit.jar" />
<pathelement location="$junit.home}/junit4.jar" />
<pathelement location="${junit.home}/junit.jar" />
<pathelement location="${junit.home}/junit4.jar" />
<pathelement location="../../core/java/build/i2ptest.jar" />
</classpath>
<compilerarg line="${javac.compilerargs}" />
@ -223,6 +223,11 @@
<sysproperty key="net.sourceforge.cobertura.datafile" file="./cobertura.ser" />
<classpath>
<pathelement path="${classpath}" />
<pathelement location="${hamcrest.home}/hamcrest-core.jar" />
<pathelement location="${hamcrest.home}/hamcrest-library.jar" />
<pathelement location="${hamcrest.home}/hamcrest-integration.jar" />
<pathelement location="${junit.home}/junit.jar" />
<pathelement location="${junit.home}/junit4.jar" />
<pathelement location="./build/obj_cobertura" />
<pathelement location="./build/obj" />
<pathelement location="../../core/java/build/i2ptest.jar" />

View File

@ -25,10 +25,9 @@ public class DatabaseStoreMessageTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
DatabaseStoreMessage msg = new DatabaseStoreMessage(I2PAppContext.getGlobalContext());
RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure();
msg.setKey(info.getIdentity().getHash());
msg.setMessageExpiration(Clock.getInstance().now());
msg.setUniqueId(666);
msg.setRouterInfo(info);
msg.setEntry(info);
return msg;
}

View File

@ -271,7 +271,7 @@ public class SSUDemo {
// is registered as
DatabaseStoreMessage m = (DatabaseStoreMessage)_msg;
try {
_us.netDb().store(m.getKey(), m.getRouterInfo());
_us.netDb().store(m.getKey(), (RouterInfo) m.getEntry());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
}

View File

@ -1,118 +0,0 @@
package net.i2p.router;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import net.i2p.router.transport.BandwidthLimitedInputStream;
import net.i2p.util.HTTPSendData;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
/**
* Job that, if its allowed to, will submit the data gathered by the MessageHistory
* component to some URL so that the network can be debugged more easily. By default
* it does not submit any data or touch the message history file, but if the router
* has the line "router.submitHistory=true", it will send the file that the
* MessageHistory component is configured to write to once an hour, post it to
* http://i2p.net/cgi-bin/submitMessageHistory, and then delete that file
* locally. This should only be used if the MessageHistory component is configured to
* gather data (via "router.keepHistory=true").
*
*/
public class SubmitMessageHistoryJob extends JobImpl {
private Log _log;
/** default submitting data every hour */
private final static long DEFAULT_REQUEUE_DELAY = 60*60*1000;
/**
* router config param for whether we want to autosubmit (and delete) the
* history data managed by MessageHistory
*/
public final static String PARAM_SUBMIT_DATA = "router.submitHistory";
/** default value for whether we autosubmit the data */
public final static boolean DEFAULT_SUBMIT_DATA = true;
/** where the data should be submitted to (via HTTP POST) */
public final static String PARAM_SUBMIT_URL = "router.submitHistoryURL";
/** default location */
public final static String DEFAULT_SUBMIT_URL = "http://i2p.net/cgi-bin/submitMessageHistory";
public SubmitMessageHistoryJob(RouterContext context) {
super(context);
_log = context.logManager().getLog(SubmitMessageHistoryJob.class);
}
public void runJob() {
if (shouldSubmit()) {
submit();
} else {
_log.debug("Not submitting data");
// if we didn't submit we can just requeue
requeue(getRequeueDelay());
}
}
/**
* We don't want this to be run within the jobqueue itself, so fire off a new thread
* to do the actual submission, enqueueing a new submit job when its done
*/
private void submit() {
I2PThread t = new I2PThread(new Runnable() {
public void run() {
_log.debug("Submitting data");
getContext().messageHistory().setPauseFlushes(true);
String filename = getContext().messageHistory().getFilename();
send(filename);
getContext().messageHistory().setPauseFlushes(false);
Job job = new SubmitMessageHistoryJob(getContext());
job.getTiming().setStartAfter(getContext().clock().now() + getRequeueDelay());
getContext().jobQueue().addJob(job);
}
});
t.setName("SubmitData");
t.setPriority(I2PThread.MIN_PRIORITY);
t.setDaemon(true);
t.start();
}
private void send(String filename) {
String url = getURL();
try {
File dataFile = new File(filename);
if (!dataFile.exists() || !dataFile.canRead()) {
_log.warn("Unable to read the message data file [" + dataFile.getAbsolutePath() + "]");
return;
}
long size = dataFile.length();
FileInputStream fin = new FileInputStream(dataFile);
BandwidthLimitedInputStream in = new BandwidthLimitedInputStream(getContext(), fin, null, true);
boolean sent = HTTPSendData.postData(url, size, in);
fin.close();
boolean deleted = dataFile.delete();
_log.debug("Submitted " + size + " bytes? " + sent + " and deleted? " + deleted);
} catch (IOException ioe) {
_log.error("Error sending the data", ioe);
}
}
private String getURL() {
String str = getContext().router().getConfigSetting(PARAM_SUBMIT_URL);
if ( (str == null) || (str.trim().length() <= 0) )
return DEFAULT_SUBMIT_URL;
else
return str.trim();
}
private boolean shouldSubmit() {
String str = getContext().router().getConfigSetting(PARAM_SUBMIT_DATA);
if (str == null) {
_log.debug("History submit config not specified [" + PARAM_SUBMIT_DATA + "], default = " + DEFAULT_SUBMIT_DATA);
return DEFAULT_SUBMIT_DATA;
} else {
_log.debug("History submit config specified [" + str + "]");
}
return Boolean.TRUE.toString().equals(str);
}
private long getRequeueDelay() { return DEFAULT_REQUEUE_DELAY; }
public String getName() { return "Submit Message History"; }
}

View File

@ -78,7 +78,8 @@ public class SendGarlicJob extends JobImpl {
public void runJob() {
long before = getContext().clock().now();
_message = GarlicMessageBuilder.buildMessage(getContext(), _config, _wrappedKey, _wrappedTags);
_message = GarlicMessageBuilder.buildMessage(getContext(), _config, _wrappedKey, _wrappedTags,
getContext().sessionKeyManager());
long after = getContext().clock().now();
if ( (after - before) > 1000) {
if (_log.shouldLog(Log.WARN))

View File

@ -43,7 +43,7 @@ public class KBucketImplTest extends TestCase{
int low = 1;
int high = 2000;
Hash local = Hash.FAKE_HASH;
LocalHash local = new LocalHash(Hash.FAKE_HASH);
local.prepareCache();
KBucketImpl bucket = new KBucketImpl(I2PAppContext.getGlobalContext(), local);
bucket.setRange(low, high);
@ -62,7 +62,7 @@ public class KBucketImplTest extends TestCase{
byte hash[] = new byte[Hash.HASH_LENGTH];
RandomSource.getInstance().nextBytes(hash);
Hash local = new Hash(hash);
LocalHash local = new LocalHash(hash);
local.prepareCache();
KBucketImpl bucket = new KBucketImpl(I2PAppContext.getGlobalContext(), local);
bucket.setRange(low, high);
@ -74,4 +74,4 @@ public class KBucketImplTest extends TestCase{
assertTrue(bucket.shouldContain(rnd));
}
}
}
}

View File

@ -104,7 +104,8 @@ public class UDPEndpointTest {
//try {
if (true) throw new RuntimeException("fixme");
//packet.initialize(priority, expiration, InetAddress.getLocalHost(), _endpoints[curPeer].getListenPort());
packet.writeData(data, 0, 1024);
// Following method is commented out in UDPPacket
//packet.writeData(data, 0, 1024);
packet.getPacket().setLength(1024);
int outstanding = _sentNotReceived.size() + 1;
_sentNotReceived.add(new ByteArray(data, 0, 1024));

View File

@ -161,7 +161,7 @@ public class FragmentTest extends TestCase{
protected class SenderImpl implements TunnelGateway.Sender {
public long sendPreprocessed(byte[] preprocessed, TunnelGateway.Receiver receiver) {
receiver.receiveEncrypted(preprocessed);
return receiver.receiveEncrypted(preprocessed);
}
}
protected class ReceiverImpl implements TunnelGateway.Receiver {
@ -174,6 +174,7 @@ public class FragmentTest extends TestCase{
public long receiveEncrypted(byte[] encrypted) {
_handler.receiveTunnelMessage(encrypted, 0, encrypted.length);
try { Thread.sleep(_delay); } catch (Exception e) {}
return -1; // or do we need to return the real message ID?
}
@Override
public Hash getSendTo() {

View File

@ -171,6 +171,7 @@ public class InboundGatewayTest extends TestCase{
_handler.receiveTunnelMessage(encrypted, 0, encrypted.length);
return -1; // or do we need to return the real message ID?
}
public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) {
_received.add(msg);

View File

@ -166,6 +166,7 @@ public class OutboundGatewayTest extends TestCase{
_handler.receiveTunnelMessage(encrypted, 0, encrypted.length);
return -1; // or do we need to return the real message ID?
}
public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) {
_received.add(msg);