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;
@ -66,11 +67,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)) {
d = LookupDest.lookupBase32Hash(_context, hostname.substring(0, BASE32_HASH_LENGTH));
if (d != null) {
putCache(hostname, d);
return d;
_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);
}
}

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,27 +56,30 @@ 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;
I2PClient client = new I2PSimpleClient();
Properties opts = new Properties();
String s = ctx.getProperty(I2PClient.PROP_TCP_HOST);
if (s != null)
opts.put(I2PClient.PROP_TCP_HOST, s);
s = ctx.getProperty(I2PClient.PROP_TCP_PORT);
if (s != null)
opts.put(I2PClient.PROP_TCP_PORT, s);
I2PSession session = null;
try {
I2PClient client = new I2PSimpleClient();
Properties opts = new Properties();
String s = ctx.getProperty(I2PClient.PROP_TCP_HOST);
if (s != null)
opts.put(I2PClient.PROP_TCP_HOST, s);
s = ctx.getProperty(I2PClient.PROP_TCP_PORT);
if (s != null)
opts.put(I2PClient.PROP_TCP_PORT, s);
I2PSession session = client.createSession(null, opts);
session = client.createSession(null, opts);
session.connect();
rv = session.lookupDest(key, DEFAULT_TIMEOUT);
session.destroySession();
} catch (I2PSessionException ise) {}
} finally {
if (session != null)
session.destroySession();
}
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,18 +1,38 @@
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{
// The good b64 and b32 are the destination of www.i2p2.i2p =)
String goodB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA";