01: /* ServerCacheTest
02: *
03: * Created on August 4, 2004
04: *
05: * Copyright (C) 2004 Internet Archive.
06: *
07: * This file is part of the Heritrix web crawler (crawler.archive.org).
08: *
09: * Heritrix is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU Lesser Public License as published by
11: * the Free Software Foundation; either version 2.1 of the License, or
12: * any later version.
13: *
14: * Heritrix is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * GNU Lesser Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser Public License
20: * along with Heritrix; if not, write to the Free Software
21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
45: .containsServer(serverKey));
46: assertTrue("cache lost host", servers.containsHost(hostKey));
47: }
48:
49: public void testCrawlURIKeys() 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", servers
63: .containsServer(CrawlServer.getServerKey(curi)));
64: assertTrue("cache lost host", servers.containsHost(curi
65: .getUURI().getHost()));
66: }
67: }
|