Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82E9A9B95 for ; Mon, 7 May 2012 17:25:13 +0000 (UTC) Received: (qmail 79357 invoked by uid 500); 7 May 2012 17:25:13 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 79350 invoked by uid 99); 7 May 2012 17:25:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 May 2012 17:25:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 May 2012 17:25:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 1AC9E2388860; Mon, 7 May 2012 17:24:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1335140 - in /lucene/dev/trunk/solr: ./ contrib/dataimporthandler/ contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ contrib/dataimporthandler/src/test-files/dih/solr/conf/ contrib/dataimporthandler/src/test/org/apache... Date: Mon, 07 May 2012 17:24:43 -0000 To: commits@lucene.apache.org From: jdyer@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120507172444.1AC9E2388860@eris.apache.org> Author: jdyer Date: Mon May 7 17:24:42 2012 New Revision: 1335140 URL: http://svn.apache.org/viewvc?rev=1335140&view=rev Log: SOLR-3430: DIH expanded test coverage & subsequent bug fixes (cache support). Added: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/data-config-end-to-end.xml (with props) lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-solrconfig-end-to-end.xml (with props) lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHJdbcTestCase.java (with props) lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDIHEndToEnd.java (with props) Modified: lucene/dev/trunk/solr/common-build.xml lucene/dev/trunk/solr/contrib/dataimporthandler/CHANGES.txt lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SortedMapBackedCache.java lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java Modified: lucene/dev/trunk/solr/common-build.xml URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/common-build.xml?rev=1335140&r1=1335139&r2=1335140&view=diff ============================================================================== --- lucene/dev/trunk/solr/common-build.xml (original) +++ lucene/dev/trunk/solr/common-build.xml Mon May 7 17:24:42 2012 @@ -64,6 +64,7 @@ + Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/CHANGES.txt?rev=1335140&r1=1335139&r2=1335140&view=diff ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/CHANGES.txt (original) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/CHANGES.txt Mon May 7 17:24:42 2012 @@ -9,6 +9,10 @@ HTTP data sources quick and easy. $Id$ ================== 4.0.0-dev ============== +Bug Fixes +---------------------- +* SOLR-3430: Added a new test against a real SQL database. Fixed problems revealed by this new test + related to the expanded cache support added to 3.6/SOLR-2382 (James Dyer) Other Changes ---------------------- Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java?rev=1335140&r1=1335139&r2=1335140&view=diff ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java (original) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java Mon May 7 17:24:42 2012 @@ -57,8 +57,6 @@ public class EntityProcessorBase extends firstInit(context); } if(cacheSupport!=null) { - rowIterator = null; - query = null; cacheSupport.initNewParent(context); } Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SortedMapBackedCache.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SortedMapBackedCache.java?rev=1335140&r1=1335139&r2=1335140&view=diff ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SortedMapBackedCache.java (original) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SortedMapBackedCache.java Mon May 7 17:24:42 2012 @@ -120,6 +120,20 @@ public class SortedMapBackedCache implem @Override public Iterator> iterator(Object key) { checkOpen(true); + if(key instanceof Iterable) { + List> vals = new ArrayList>(); + Iterator iter = ((Iterable) key).iterator(); + while(iter.hasNext()) { + List> val = theMap.get(iter.next()); + if(val!=null) { + vals.addAll(val); + } + } + if(vals.size()==0) { + return null; + } + return vals.iterator(); + } List> val = theMap.get(key); if (val == null) { return null; Added: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/data-config-end-to-end.xml URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/data-config-end-to-end.xml?rev=1335140&view=auto ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/data-config-end-to-end.xml (added) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/data-config-end-to-end.xml Mon May 7 17:24:42 2012 @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml?rev=1335140&r1=1335139&r2=1335140&view=diff ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml (original) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-schema.xml Mon May 7 17:24:42 2012 @@ -1,308 +1,58 @@ - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - id - - - desc - - - - - + + + + + + + + + + + + + + + + + + + + + + + id + desc + + \ No newline at end of file Added: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-solrconfig-end-to-end.xml URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-solrconfig-end-to-end.xml?rev=1335140&view=auto ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-solrconfig-end-to-end.xml (added) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/test-files/dih/solr/conf/dataimport-solrconfig-end-to-end.xml Mon May 7 17:24:42 2012 @@ -0,0 +1,45 @@ + + + + + ${tests.luceneMatchVersion:LUCENE_CURRENT} + + + 100000 + + + + + + + + explicit + + + + + data-config-end-to-end.xml + + + + + explicit + + + + Added: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHJdbcTestCase.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHJdbcTestCase.java?rev=1335140&view=auto ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHJdbcTestCase.java (added) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDIHJdbcTestCase.java Mon May 7 17:24:42 2012 @@ -0,0 +1,170 @@ +package org.apache.solr.handler.dataimport; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; + +import junit.framework.Assert; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +/** + * This sets up an in-memory Derby Sql database with a little sample data. + * The schema here is poorly-designed to illustrate DIH's ability to + * overcome these kinds of challenges. + */ +public abstract class AbstractDIHJdbcTestCase extends AbstractDataImportHandlerTestCase { + @BeforeClass + public static void beforeClassDihJdbcTest() throws Exception { + try { + Class.forName("org.hsqldb.jdbcDriver").newInstance(); + } catch (Exception e) { + throw e; + } + + Connection conn = null; + Statement s = null; + PreparedStatement ps = null; + try { + conn = DriverManager.getConnection("jdbc:hsqldb:mem:."); + s = conn.createStatement(); + s.executeUpdate("create table countries(code char(2) not null primary key, country_name varchar(50))"); + s.executeUpdate("create table people(id int not null primary key, name varchar(50), country_codes varchar(100))"); + s.executeUpdate("create table people_sports(id int not null primary key, person_id int, sport_name varchar(50))"); + + ps = conn.prepareStatement("insert into countries values (?,?)"); + for(String[] country : countries) { + ps.setString(1, country[0]); + ps.setString(2, country[1]); + Assert.assertEquals(1, ps.executeUpdate()); + } + ps.close(); + + ps = conn.prepareStatement("insert into people values (?,?,?)"); + for(Object[] person : people) { + ps.setInt(1, (Integer) person[0]); + ps.setString(2, (String) person[1]); + ps.setString(3, (String) person[2]); + Assert.assertEquals(1, ps.executeUpdate()); + } + ps.close(); + + ps = conn.prepareStatement("insert into people_sports values (?,?,?)"); + for(Object[] sport : people_sports) { + ps.setInt(1, (Integer) sport[0]); + ps.setInt(2, (Integer) sport[1]); + ps.setString(3, (String) sport[2]); + Assert.assertEquals(1, ps.executeUpdate()); + } + ps.close(); + conn.close(); + } catch(Exception e) { + throw e; + } finally { + if(s!=null) { s.close(); } + if(ps!=null) { ps.close(); } + if(conn!=null) { conn.close(); } + } + } + + @AfterClass + public static void afterClassDihJdbcTest() throws Exception { + Connection conn = null; + Statement s = null; + try { + conn = DriverManager.getConnection("jdbc:hsqldb:mem:."); + s = conn.createStatement(); + s.executeUpdate("shutdown"); + } catch (SQLException e) { + throw e; + } finally { + if(s!=null) { s.close(); } + if(conn!=null) { conn.close(); } + } + } + + public static final String[][] countries = { + {"NA", "Namibia"}, + {"NC", "New Caledonia"}, + {"NE", "Niger"}, + {"NF", "Norfolk Island"}, + {"NG", "Nigeria"}, + {"NI", "Nicaragua"}, + {"NL", "Netherlands"}, + {"NO", "Norway"}, + {"NP", "Nepal"}, + {"NR", "Nauru"}, + {"NU", "Niue"}, + {"NZ", "New Zealand"} + }; + + public static final Object[][] people = { + {1,"Jacob","NZ"}, + {2,"Ethan","NU,NA,NE"}, + {3,"Michael","NR"}, + {4,"Jayden","NP"}, + {5,"William","NO"}, + {6,"Alexander","NL"}, + {7,"Noah","NI"}, + {8,"Daniel","NG"}, + {9,"Aiden","NF"}, + {10,"Anthony","NE"}, + {11,"Emma","NL"}, + {12,"Grace","NI"}, + {13,"Hailey","NG"}, + {14,"Isabella","NF"}, + {15,"Lily","NE"}, + {16,"Madison","NC"}, + {17,"Mia","NA"}, + {18,"Natalie","NP,NR,NU,NZ"}, + {19,"Olivia","NU"}, + {20,"Samantha","NR"} + }; + + public static final Object[][] people_sports = { + {100, 1, "Swimming"}, + {200, 2, "Triathlon"}, + {300, 3, "Water polo"}, + {310, 3, "Underwater rugby"}, + {320, 3, "Kayaking"}, + {400, 4, "Snorkeling"}, + {500, 5, "Synchronized diving"}, + {600, 6, "Underwater rugby"}, + {700, 7, "Boating"}, + {800, 8, "Bodyboarding"}, + {900, 9, "Canoeing"}, + {1000, 10, "Fishing"}, + {1100, 11, "Jet Ski"}, + {1110, 11, "Rowing"}, + {1120, 11, "Sailing"}, + {1200, 12, "Kayaking"}, + {1210, 12, "Canoeing"}, + {1300, 13, "Kite surfing"}, + {1400, 14, "Parasailing"}, + {1500, 15, "Rafting"}, + {1600, 16, "Rowing"}, + {1700, 17, "Sailing"}, + {1800, 18, "White Water Rafting"}, + {1900, 19, "Water skiing"}, + {2000, 20, "Windsurfing"} + }; + +} Added: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDIHEndToEnd.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDIHEndToEnd.java?rev=1335140&view=auto ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDIHEndToEnd.java (added) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestDIHEndToEnd.java Mon May 7 17:24:42 2012 @@ -0,0 +1,58 @@ +package org.apache.solr.handler.dataimport; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.solr.request.LocalSolrQueryRequest; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestDIHEndToEnd extends AbstractDIHJdbcTestCase { + @BeforeClass + public static void beforeClass() throws Exception { + initCore("dataimport-solrconfig-end-to-end.xml", "dataimport-schema.xml"); + } + @Test + public void testEndToEnd() throws Exception { + LocalSolrQueryRequest request = lrf.makeRequest("command", "full-import", + "clean", "true", "commit", "true", "synchronous", "true", "indent", "true"); + h.query("/dataimport-end-to-end", request); + assertQ(req("*:*"), "//*[@numFound='20']"); + assertQ(req("COUNTRY_NAME:zealand"), "//*[@numFound='2']"); + assertQ(req("COUNTRY_NAME:niue"), "//*[@numFound='3']"); + + //It would be nice if there was a way to get it to run transformers before putting + //data in the cache, then id=2 (person=Ethan, country=NU,NA,NE) could join...) + //assertQ(req("COUNTRY_NAME:Netherlands"), "//*[@numFound='3']"); + + assertQ(req("NAME:michael"), "//*[@numFound='1']"); + assertQ(req("SPORT_NAME:kayaking"), "//*[@numFound='2']"); + assertQ(req("SPORT_NAME:fishing"), "//*[@numFound='1']"); + + request = lrf.makeRequest("indent", "true"); + String response = h.query("/dataimport-end-to-end", request); + Matcher m = Pattern.compile(".str name..Total Requests made to DataSource..(\\d+)..str.").matcher(response); + Assert.assertTrue(m.find() && m.groupCount()==1); + int numRequests = Integer.parseInt(m.group(1)); + Assert.assertTrue( + "The database should have been hit once each " + + "for 'Person' & 'Country' and ~20 times for 'Sport'", numRequests<30); + } +} Modified: lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java?rev=1335140&r1=1335139&r2=1335140&view=diff ============================================================================== --- lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java (original) +++ lucene/dev/trunk/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java Mon May 7 17:24:42 2012 @@ -43,11 +43,11 @@ import org.junit.Test; * @since solr 1.3 */ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase { - Driver driver; - DataSource dataSource; - Connection connection; - IMocksControl mockControl; - JdbcDataSource jdbcDataSource = new JdbcDataSource(); + private Driver driver; + private DataSource dataSource; + private Connection connection; + private IMocksControl mockControl; + private JdbcDataSource jdbcDataSource = new JdbcDataSource(); List> fields = new ArrayList>(); Context context = AbstractDataImportHandlerTestCase.getContext(null, null, @@ -129,7 +129,7 @@ public class TestJdbcDataSource extends @Test public void testRetrieveFromDriverManager() throws Exception { DriverManager.registerDriver(driver); - + try { EasyMock.expect( driver.connect((String) EasyMock.notNull(), (Properties) EasyMock .notNull())).andReturn(connection); @@ -147,6 +147,11 @@ public class TestJdbcDataSource extends mockControl.verify(); assertSame("connection", conn, connection); + } catch(Exception e) { + throw e; + } finally { + DriverManager.deregisterDriver(driver); + } } @Test