1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.crawler.datamodel;
24
25 import junit.framework.TestCase;
26
27 import org.apache.commons.httpclient.URIException;
28 import org.archive.crawler.settings.SettingsHandler;
29 import org.archive.net.UURI;
30 import org.archive.net.UURIFactory;
31
32 /***
33 * Test the BigMapServerCache
34 *
35 * @author gojomo
36 */
37 public class ServerCacheTest extends TestCase {
38 public void testHolds() throws Exception {
39 ServerCache servers = new ServerCache((SettingsHandler)null);
40 String serverKey = "www.example.com:9090";
41 String hostKey = "www.example.com";
42 servers.getServerFor(serverKey);
43 servers.getHostFor(hostKey);
44 assertTrue("cache lost server", servers.containsServer(serverKey));
45 assertTrue("cache lost host", servers.containsHost(hostKey));
46 }
47
48 public void testCrawlURIKeys()
49 throws Exception {
50 ServerCache servers = new ServerCache((SettingsHandler)null);
51 testHostServer(servers, "http://www.example.com");
52 testHostServer(servers, "http://www.example.com:9090");
53 testHostServer(servers, "dns://www.example.com:9090");
54 }
55
56 private void testHostServer(ServerCache servers, String uri)
57 throws URIException {
58 UURI uuri = UURIFactory.getInstance(uri);
59 CrawlURI curi = new CrawlURI(uuri);
60 servers.getServerFor(curi);
61 servers.getHostFor(curi);
62 assertTrue("cache lost server",
63 servers.containsServer(CrawlServer.getServerKey(curi)));
64 assertTrue("cache lost host",
65 servers.containsHost(curi.getUURI().getHost()));
66 }
67 }