RDBConnector { public void close() { connection.close(); } RDBConnector(String hostname, Integer port); void open(); void close(); boolean databaseExists(String database); boolean squirrelDatabaseExists(); boolean tableExists(String database, String table); public Connection connection; }
@Test public void testHasKnownURI() throws UnknownHostException { CrawleableUri uri = factory.create(URI.create("http: UriType.UNKNOWN); long timestamp = System.currentTimeMillis(); r.db("squirrel").table("knownurifilter").insert(convertURITimestampToRDB(uri, timestamp)).run(rdbConnector.connection); Cursor cursor = r.db("squirrel").table("knownurifilter").getAll(uri.getUri().toString()).optArg("index", "uri").run(rdbConnector.connection); assert(cursor.hasNext()); cursor.close(); }
@Test public void testHasOutdatedKnownURI() throws UnknownHostException { CrawleableUri uri = factory.create(URI.create("http: UriType.UNKNOWN); long timestamp = 100000; long invalidationTime = 100000; r.db("squirrel").table("knownurifilter").insert(convertURITimestampToRDB(uri, timestamp)).run(rdbConnector.connection); Cursor cursor = r.db("squirrel") .table("knownurifilter") .getAll(uri.getUri().toString()) .optArg("index", "uri") .run(rdbConnector.connection); assert(cursor.hasNext()); HashMap crawleableUri = (HashMap) cursor.next(); long retrievedTimestamp = (long) crawleableUri.get("timestamp"); assert((System.currentTimeMillis() - retrievedTimestamp) > invalidationTime); cursor.close(); }