forked from I2P_Developers/i2p.i2p
Fix test and make it actually test something
This commit is contained in:
@@ -2,9 +2,12 @@ package net.i2p.client.naming;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -18,28 +21,41 @@ import net.i2p.data.Destination;
|
|||||||
public class BlockfileNamingServiceTest extends TestCase {
|
public class BlockfileNamingServiceTest extends TestCase {
|
||||||
BlockfileNamingService _bns;
|
BlockfileNamingService _bns;
|
||||||
List<String> _names;
|
List<String> _names;
|
||||||
|
File hostsTxt, routerDir;
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
I2PAppContext ctx = new I2PAppContext();
|
I2PAppContext ctx = new I2PAppContext();
|
||||||
_bns = new BlockfileNamingService(ctx);
|
routerDir = ctx.getRouterDir();
|
||||||
_names = null;
|
|
||||||
|
// first load the list of hosts that will be queried
|
||||||
|
InputStream is = getClass().getResourceAsStream("/hosts.txt");
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
try {
|
assertNotNull("test classpath not set correctly",is);
|
||||||
InputStream is = getClass().getResourceAsStream("/hosts.txt");
|
DataHelper.loadProps(props, is, true);
|
||||||
assertNotNull("test classpath not set correctly",is);
|
_names = new ArrayList(props.keySet());
|
||||||
DataHelper.loadProps(props, is, true);
|
Collections.shuffle(_names);
|
||||||
_names = new ArrayList(props.keySet());
|
is.close();
|
||||||
Collections.shuffle(_names);
|
|
||||||
} catch (IOException ioe) {
|
// then copy the hosts.txt file so that the naming service can load them
|
||||||
_bns.shutdown();
|
hostsTxt = new File(routerDir, "hosts.txt");
|
||||||
return;
|
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() {
|
public void tearDown() {
|
||||||
_bns.shutdown();
|
_bns.shutdown();
|
||||||
File f = new File("hostsdb.blockfile");
|
if (routerDir != null) {
|
||||||
f.delete();
|
File f = new File(routerDir,"hostsdb.blockfile");
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
if (hostsTxt != null)
|
||||||
|
hostsTxt.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRepeatedLookup() throws Exception{
|
public void testRepeatedLookup() throws Exception{
|
||||||
|
|||||||
Reference in New Issue
Block a user