work on failing JUnit test

This commit is contained in:
zab2
2013-11-07 20:38:52 +00:00
parent ae76a6ee1a
commit 919ec3af01
3 changed files with 48 additions and 20 deletions

View File

@ -12,6 +12,7 @@ import java.util.Map;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.client.I2PSessionException;
import net.i2p.data.Destination;
import net.i2p.util.LHMCache;
@ -67,11 +68,15 @@ class DummyNamingService extends NamingService {
// Try Base32 decoding
if (hostname.length() == BASE32_HASH_LENGTH + 8 && hostname.toLowerCase(Locale.US).endsWith(".b32.i2p") &&
_context.getBooleanPropertyDefaultTrue(PROP_B32)) {
try {
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
if (d != null) {
putCache(hostname, d);
return d;
}
} catch (I2PSessionException i2pse) {
_log.warn("couldn't lookup b32",i2pse);
}
}
return null;

View File

@ -38,7 +38,7 @@ class LookupDest {
protected LookupDest(I2PAppContext context) {}
/** @param key 52 chars (do not include the .b32.i2p suffix) */
static Destination lookupBase32Hash(I2PAppContext ctx, String key) {
static Destination lookupBase32Hash(I2PAppContext ctx, String key) throws I2PSessionException {
byte[] h = Base32.decode(key);
if (h == null)
return null;
@ -56,10 +56,9 @@ class LookupDest {
****/
/** @param h 32 byte hash */
static Destination lookupHash(I2PAppContext ctx, byte[] h) {
static Destination lookupHash(I2PAppContext ctx, byte[] h) throws I2PSessionException {
Hash key = Hash.create(h);
Destination rv = null;
try {
I2PClient client = new I2PSimpleClient();
Properties opts = new Properties();
String s = ctx.getProperty(I2PClient.PROP_TCP_HOST);
@ -68,15 +67,19 @@ class LookupDest {
s = ctx.getProperty(I2PClient.PROP_TCP_PORT);
if (s != null)
opts.put(I2PClient.PROP_TCP_PORT, s);
I2PSession session = client.createSession(null, opts);
I2PSession session = null;
try {
session = client.createSession(null, opts);
session.connect();
rv = session.lookupDest(key, DEFAULT_TIMEOUT);
} finally {
if (session != null)
session.destroySession();
} catch (I2PSessionException ise) {}
}
return rv;
}
public static void main(String args[]) {
public static void main(String args[]) throws I2PSessionException {
Destination dest = lookupBase32Hash(I2PAppContext.getGlobalContext(), args[0]);
if (dest == null)
System.out.println("Destination not found!");

View File

@ -1,16 +1,36 @@
package net.i2p.client.naming;
import java.util.Properties;
import junit.framework.TestCase;
import net.i2p.I2PAppContext;
import net.i2p.client.I2PClient;
import net.i2p.client.I2PSession;
import net.i2p.client.I2PSimpleClient;
import net.i2p.data.Destination;
public class DummyNamingServiceTest extends TestCase {
private I2PAppContext _context;
public void setUp() {
public void setUp() throws Exception {
_context = new I2PAppContext();
verifySession();
}
/** makes sure we can create a session */
private void verifySession() throws Exception {
I2PClient client = new I2PSimpleClient();
Properties opts = new Properties();
I2PSession session = null;
try {
session = client.createSession(null, opts);
session.connect();
} finally {
if (session != null)
session.destroySession();
}
}
public void testLookup() throws Exception{