diff --git a/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java b/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java index 6df39002d1cf7b0e4fbc95dcfc50a1545d771458..70234f81f02570e13cef0e342a35035a0d4a8f71 100644 --- a/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java +++ b/core/java/test/junit/net/i2p/client/naming/BlockfileNamingServiceTest.java @@ -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{