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

Skip to content
Snippets Groups Projects
Commit 1939aaca authored by zab's avatar zab
Browse files

Fix test and make it actually test something

parent d0cb714f
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,12 @@ package net.i2p.client.naming;
import junit.framework.TestCase;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -18,28 +21,41 @@ import net.i2p.data.Destination;
public class BlockfileNamingServiceTest extends TestCase {
BlockfileNamingService _bns;
List<String> _names;
File hostsTxt, routerDir;
public void setUp() {
public void setUp() throws Exception {
I2PAppContext ctx = new I2PAppContext();
_bns = new BlockfileNamingService(ctx);
_names = null;
routerDir = ctx.getRouterDir();
// first load the list of hosts that will be queried
InputStream is = getClass().getResourceAsStream("/hosts.txt");
Properties props = new Properties();
try {
InputStream is = getClass().getResourceAsStream("/hosts.txt");
assertNotNull("test classpath not set correctly",is);
DataHelper.loadProps(props, is, true);
_names = new ArrayList(props.keySet());
Collections.shuffle(_names);
} catch (IOException ioe) {
_bns.shutdown();
return;
}
assertNotNull("test classpath not set correctly",is);
DataHelper.loadProps(props, is, true);
_names = new ArrayList(props.keySet());
Collections.shuffle(_names);
is.close();
// then copy the hosts.txt file so that the naming service can load them
hostsTxt = new File(routerDir, "hosts.txt");
OutputStream os = new BufferedOutputStream(new FileOutputStream(hostsTxt));
is = getClass().getResourceAsStream("/hosts.txt");
byte [] b = new byte[8196];
int read = 0;
while ((read = is.read(b)) > 0 )
os.write(b,0,read);
os.flush(); os.close();
_bns = new BlockfileNamingService(ctx);
}
public void tearDown() {
_bns.shutdown();
File f = new File("hostsdb.blockfile");
f.delete();
if (routerDir != null) {
File f = new File(routerDir,"hostsdb.blockfile");
f.delete();
}
if (hostsTxt != null)
hostsTxt.delete();
}
public void testRepeatedLookup() throws Exception{
......
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