From: <bra...@us...> - 2008-06-05 22:49:08
|
Revision: 2288 http://archive-access.svn.sourceforge.net/archive-access/?rev=2288&view=rev Author: bradtofel Date: 2008-06-05 15:49:14 -0700 (Thu, 05 Jun 2008) Log Message: ----------- MOVED: Tests to conform with new packages, class names, and method names. Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/ trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDBTest.java trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/ResoruceFileLocationDBLogTest.java Removed Paths: ------------- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBLogTest.java trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBTest.java Deleted: trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBLogTest.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBLogTest.java 2008-06-05 21:58:07 UTC (rev 2287) +++ trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBLogTest.java 2008-06-05 22:49:14 UTC (rev 2288) @@ -1,95 +0,0 @@ -/* FileLocationDBLogTest - * - * $Id$ - * - * Created on 4:54:04 PM Aug 21, 2006. - * - * Copyright (C) 2006 Internet Archive. - * - * This file is part of Wayback. - * - * Wayback is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Wayback is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Wayback; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package org.archive.wayback.resourcestore.http; - -import java.io.File; -import java.util.Iterator; -import junit.framework.TestCase; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class FileLocationDBLogTest extends TestCase { - FileLocationDBLog log; - protected void setUp() throws Exception { - super.setUp(); - File tmp = File.createTempFile("fldb","log"); - - log = new FileLocationDBLog(tmp.getAbsolutePath()); - } - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - if(!log.delete()) { - fail("FAILED to delete tmp file"); - } - } - - /** - * @throws Exception - */ - public void testEmptyFile() throws Exception { - String newArc1 = "foo.arc.gz"; - String newArc2 = "bar.arc.gz"; - long mark1 = log.getCurrentMark(); - assertEquals(mark1,0); - Iterator<String> itr = log.getArcsBetweenMarks(0,0); - assertFalse(itr.hasNext()); - log.addArc(newArc1); - long mark2 = log.getCurrentMark(); - assertEquals(newArc1.length() + 1,mark2); - itr = log.getArcsBetweenMarks(mark1,mark2); - assertTrue(itr.hasNext()); - String gotArc = (String) itr.next(); - assertFalse(itr.hasNext()); - assertTrue(newArc1.equals(gotArc)); - log.addArc(newArc2); - long mark3 = log.getCurrentMark(); - assertEquals(newArc1.length() + newArc2.length() + 2, mark3); - - itr = log.getArcsBetweenMarks(mark2,mark3); - assertTrue(itr.hasNext()); - gotArc = (String) itr.next(); - assertFalse(itr.hasNext()); - assertTrue(newArc2.equals(gotArc)); - - itr = log.getArcsBetweenMarks(mark1,mark3); - assertTrue(itr.hasNext()); - gotArc = (String) itr.next(); - assertTrue(newArc1.equals(gotArc)); - - assertTrue(itr.hasNext()); - gotArc = (String) itr.next(); - assertTrue(newArc2.equals(gotArc)); - - assertFalse(itr.hasNext()); - } -} Deleted: trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBTest.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBTest.java 2008-06-05 21:58:07 UTC (rev 2287) +++ trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/http/FileLocationDBTest.java 2008-06-05 22:49:14 UTC (rev 2288) @@ -1,199 +0,0 @@ -/* FileLocationDBTest - * - * $Id$ - * - * Created on 5:17:23 PM Aug 21, 2006. - * - * Copyright (C) 2006 Internet Archive. - * - * This file is part of Wayback. - * - * Wayback is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Wayback is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Wayback; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package org.archive.wayback.resourcestore.http; - -import java.io.File; -import java.io.IOException; -import java.util.Iterator; - -import org.archive.wayback.resourcestore.http.FileLocationDB; - -import junit.framework.TestCase; - -/** - * - * - * @author brad - * @version $Date$, $Revision$ - */ -public class FileLocationDBTest extends TestCase { - private FileLocationDB db = null; - private String dbPath = null; - private String dbName = null; - private File tmpFile = null; - private File tmpLogFile = null; - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - - tmpFile = File.createTempFile("test-FileLocationDB",".tmp"); - tmpLogFile = File.createTempFile("test-FileLocationDB",".log"); - assertTrue(tmpFile.delete()); - assertTrue(tmpFile.mkdirs()); - dbPath = tmpFile.getAbsolutePath(); - dbName = "test-FileLocationDB"; - db = new FileLocationDB(); - - db.setBdbName(dbName); - db.setBdbPath(dbPath); - db.setLogPath(tmpLogFile.getAbsolutePath()); - db.init(); - - super.setUp(); - } - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - db.shutdownDB(); - if(tmpFile.isDirectory()) { - File files[] = tmpFile.listFiles(); - for(int i = 0; i < files.length; i++) { - assertTrue(files[i].isFile()); - assertTrue(files[i].delete()); - } - assertTrue(tmpFile.delete()); - } - assertTrue(tmpLogFile.delete()); - } - - private void testMarkLength(long start, long end, int count) throws IOException { - Iterator<String> itr = db.getArcsBetweenMarks(start,end); - int found = 0; - while(itr.hasNext()) { - itr.next(); - found++; - } - assertEquals(count,found); - } - - /** - * Test method for 'org.archive.wayback.http11resourcestore.FileLocationDB - */ - public void testDB() { - assertNotNull(db); - String urls[] = null; - try { - // empty results OK: - urls = db.arcToUrls("arc1"); - assertNull(urls); - //assertEquals(urls.length,0); - testMarkLength(0,0,0); - - // add an URL, and get it back: - db.addArcUrl("arc1","url1"); - urls = db.arcToUrls("arc1"); - assertNotNull(urls); - assertEquals(1,urls.length); - assertEquals("url1",urls[0]); - testMarkLength(0,5,1); - - // add the same URL again, verify only comes back once: - db.addArcUrl("arc1","url1"); - urls = db.arcToUrls("arc1"); - assertNotNull(urls); - assertEquals(1,urls.length); - assertEquals("url1",urls[0]); - testMarkLength(0,5,1); - - // check for empty results for a diff arc: - urls = db.arcToUrls("arc2"); - assertNull(urls); - //assertEquals(urls.length,0); - - // add a diff URL for first arc, verify both come back: - db.addArcUrl("arc1","url2"); - urls = db.arcToUrls("arc1"); - assertNotNull(urls); - assertEquals(2,urls.length); - assertEquals("url1",urls[0]); - assertEquals("url2",urls[1]); - testMarkLength(0,5,1); - - // still nothing for arc2: - urls = db.arcToUrls("arc2"); - assertNull(urls); - //assertEquals(urls.length,0); - - // add an URL for arc2, and get it back: - db.addArcUrl("arc2","url2-1"); - urls = db.arcToUrls("arc2"); - assertNotNull(urls); - assertEquals(1,urls.length); - assertEquals("url2-1",urls[0]); - testMarkLength(0,10,2); - testMarkLength(5,10,1); - - // remove unknown URL for arc2 - db.removeArcUrl("arc2","url2-2"); - urls = db.arcToUrls("arc2"); - assertNotNull(urls); - assertEquals(1,urls.length); - assertEquals("url2-1",urls[0]); - - // remove the right URL for arc2 - db.removeArcUrl("arc2","url2-1"); - urls = db.arcToUrls("arc2"); - assertNull(urls); - //assertEquals(urls.length,0); - - // remove non-existant URL for first arc, verify two still come back - db.removeArcUrl("arc1","url-non"); - urls = db.arcToUrls("arc1"); - assertNotNull(urls); - assertEquals(2,urls.length); - assertEquals("url1",urls[0]); - assertEquals("url2",urls[1]); - - // remove a right URL for arc1 - db.removeArcUrl("arc1","url1"); - urls = db.arcToUrls("arc1"); - assertNotNull(urls); - assertEquals(1,urls.length); - assertEquals("url2",urls[0]); - - // remove a now wrong URL for arc1 - db.removeArcUrl("arc1","url1"); - urls = db.arcToUrls("arc1"); - assertNotNull(urls); - assertEquals(1,urls.length); - assertEquals("url2",urls[0]); - - // remove a last URL for arc1 - db.removeArcUrl("arc1","url2"); - urls = db.arcToUrls("arc1"); - assertNull(urls); - //assertEquals(urls.length,0); - - } catch (Exception e) { - fail("arcToUrls threw " + e.getMessage()); - } - - } -} Added: trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDBTest.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDBTest.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/BDBResourceFileLocationDBTest.java 2008-06-05 22:49:14 UTC (rev 2288) @@ -0,0 +1,199 @@ +/* FileLocationDBTest + * + * $Id: FileLocationDBTest.java 1856 2007-07-25 00:17:15Z bradtofel $ + * + * Created on 5:17:23 PM Aug 21, 2006. + * + * Copyright (C) 2006 Internet Archive. + * + * This file is part of Wayback. + * + * Wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * Wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with Wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.resourcestore.locationdb; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; + +import org.archive.wayback.resourcestore.locationdb.BDBResourceFileLocationDB; + +import junit.framework.TestCase; + +/** + * + * + * @author brad + * @version $Date: 2007-07-24 17:17:15 -0700 (Tue, 24 Jul 2007) $, $Revision: 1856 $ + */ +public class BDBResourceFileLocationDBTest extends TestCase { + private BDBResourceFileLocationDB db = null; + private String dbPath = null; + private String dbName = null; + private File tmpFile = null; + private File tmpLogFile = null; + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + + tmpFile = File.createTempFile("test-FileLocationDB",".tmp"); + tmpLogFile = File.createTempFile("test-FileLocationDB",".log"); + assertTrue(tmpFile.delete()); + assertTrue(tmpFile.mkdirs()); + dbPath = tmpFile.getAbsolutePath(); + dbName = "test-FileLocationDB"; + db = new BDBResourceFileLocationDB(); + + db.setBdbName(dbName); + db.setBdbPath(dbPath); + db.setLogPath(tmpLogFile.getAbsolutePath()); + db.init(); + + super.setUp(); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + db.shutdown(); + if(tmpFile.isDirectory()) { + File files[] = tmpFile.listFiles(); + for(int i = 0; i < files.length; i++) { + assertTrue(files[i].isFile()); + assertTrue(files[i].delete()); + } + assertTrue(tmpFile.delete()); + } + assertTrue(tmpLogFile.delete()); + } + + private void testMarkLength(long start, long end, int count) throws IOException { + Iterator<String> itr = db.getNamesBetweenMarks(start,end); + int found = 0; + while(itr.hasNext()) { + itr.next(); + found++; + } + assertEquals(count,found); + } + + /** + * Test method for 'org.archive.wayback.http11resourcestore.FileLocationDB + */ + public void testDB() { + assertNotNull(db); + String urls[] = null; + try { + // empty results OK: + urls = db.nameToUrls("arc1"); + assertNull(urls); + //assertEquals(urls.length,0); + testMarkLength(0,0,0); + + // add an URL, and get it back: + db.addNameUrl("arc1","url1"); + urls = db.nameToUrls("arc1"); + assertNotNull(urls); + assertEquals(1,urls.length); + assertEquals("url1",urls[0]); + testMarkLength(0,5,1); + + // add the same URL again, verify only comes back once: + db.addNameUrl("arc1","url1"); + urls = db.nameToUrls("arc1"); + assertNotNull(urls); + assertEquals(1,urls.length); + assertEquals("url1",urls[0]); + testMarkLength(0,5,1); + + // check for empty results for a diff arc: + urls = db.nameToUrls("arc2"); + assertNull(urls); + //assertEquals(urls.length,0); + + // add a diff URL for first arc, verify both come back: + db.addNameUrl("arc1","url2"); + urls = db.nameToUrls("arc1"); + assertNotNull(urls); + assertEquals(2,urls.length); + assertEquals("url1",urls[0]); + assertEquals("url2",urls[1]); + testMarkLength(0,5,1); + + // still nothing for arc2: + urls = db.nameToUrls("arc2"); + assertNull(urls); + //assertEquals(urls.length,0); + + // add an URL for arc2, and get it back: + db.addNameUrl("arc2","url2-1"); + urls = db.nameToUrls("arc2"); + assertNotNull(urls); + assertEquals(1,urls.length); + assertEquals("url2-1",urls[0]); + testMarkLength(0,10,2); + testMarkLength(5,10,1); + + // remove unknown URL for arc2 + db.removeNameUrl("arc2","url2-2"); + urls = db.nameToUrls("arc2"); + assertNotNull(urls); + assertEquals(1,urls.length); + assertEquals("url2-1",urls[0]); + + // remove the right URL for arc2 + db.removeNameUrl("arc2","url2-1"); + urls = db.nameToUrls("arc2"); + assertNull(urls); + //assertEquals(urls.length,0); + + // remove non-existant URL for first arc, verify two still come back + db.removeNameUrl("arc1","url-non"); + urls = db.nameToUrls("arc1"); + assertNotNull(urls); + assertEquals(2,urls.length); + assertEquals("url1",urls[0]); + assertEquals("url2",urls[1]); + + // remove a right URL for arc1 + db.removeNameUrl("arc1","url1"); + urls = db.nameToUrls("arc1"); + assertNotNull(urls); + assertEquals(1,urls.length); + assertEquals("url2",urls[0]); + + // remove a now wrong URL for arc1 + db.removeNameUrl("arc1","url1"); + urls = db.nameToUrls("arc1"); + assertNotNull(urls); + assertEquals(1,urls.length); + assertEquals("url2",urls[0]); + + // remove a last URL for arc1 + db.removeNameUrl("arc1","url2"); + urls = db.nameToUrls("arc1"); + assertNull(urls); + //assertEquals(urls.length,0); + + } catch (Exception e) { + fail("arcToUrls threw " + e.getMessage()); + } + + } +} Added: trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/ResoruceFileLocationDBLogTest.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/ResoruceFileLocationDBLogTest.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/test/java/org/archive/wayback/resourcestore/locationdb/ResoruceFileLocationDBLogTest.java 2008-06-05 22:49:14 UTC (rev 2288) @@ -0,0 +1,98 @@ +/* FileLocationDBLogTest + * + * $Id: FileLocationDBLogTest.java 1856 2007-07-25 00:17:15Z bradtofel $ + * + * Created on 4:54:04 PM Aug 21, 2006. + * + * Copyright (C) 2006 Internet Archive. + * + * This file is part of Wayback. + * + * Wayback is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * Wayback is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with Wayback; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.resourcestore.locationdb; + +import java.io.File; +import java.util.Iterator; + +import org.archive.wayback.resourcestore.locationdb.ResourceFileLocationDBLog; + +import junit.framework.TestCase; + +/** + * + * + * @author brad + * @version $Date: 2007-07-24 17:17:15 -0700 (Tue, 24 Jul 2007) $, $Revision: 1856 $ + */ +public class ResoruceFileLocationDBLogTest extends TestCase { + ResourceFileLocationDBLog log; + protected void setUp() throws Exception { + super.setUp(); + File tmp = File.createTempFile("fldb","log"); + + log = new ResourceFileLocationDBLog(tmp.getAbsolutePath()); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + if(!log.delete()) { + fail("FAILED to delete tmp file"); + } + } + + /** + * @throws Exception + */ + public void testEmptyFile() throws Exception { + String newArc1 = "foo.arc.gz"; + String newArc2 = "bar.arc.gz"; + long mark1 = log.getCurrentMark(); + assertEquals(mark1,0); + Iterator<String> itr = log.getNamesBetweenMarks(0,0); + assertFalse(itr.hasNext()); + log.addName(newArc1); + long mark2 = log.getCurrentMark(); + assertEquals(newArc1.length() + 1,mark2); + itr = log.getNamesBetweenMarks(mark1,mark2); + assertTrue(itr.hasNext()); + String gotArc = (String) itr.next(); + assertFalse(itr.hasNext()); + assertTrue(newArc1.equals(gotArc)); + log.addName(newArc2); + long mark3 = log.getCurrentMark(); + assertEquals(newArc1.length() + newArc2.length() + 2, mark3); + + itr = log.getNamesBetweenMarks(mark2,mark3); + assertTrue(itr.hasNext()); + gotArc = (String) itr.next(); + assertFalse(itr.hasNext()); + assertTrue(newArc2.equals(gotArc)); + + itr = log.getNamesBetweenMarks(mark1,mark3); + assertTrue(itr.hasNext()); + gotArc = (String) itr.next(); + assertTrue(newArc1.equals(gotArc)); + + assertTrue(itr.hasNext()); + gotArc = (String) itr.next(); + assertTrue(newArc2.equals(gotArc)); + + assertFalse(itr.hasNext()); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |