From 44386401f62f4490017ba840f59630567cd49492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Thu, 15 Sep 2011 15:29:35 +0000 Subject: [PATCH] SOLR-2540: Fixing commitWithin tests which timed out git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1171138 13f79535-47bb-0310-9956-ffa450edef68 --- .../ExtractingRequestHandlerTest.java | 32 +++++---- .../handler/BufferingRequestProcessor.java | 66 +++++++++++++++++++ .../solr/handler/CSVRequestHandlerTest.java | 54 +++++++++++++++ .../apache/solr/handler/JsonLoaderTest.java | 48 +------------- .../apache/solr/handler/TestCSVLoader.java | 9 --- 5 files changed, 139 insertions(+), 70 deletions(-) create mode 100644 solr/core/src/test/org/apache/solr/handler/BufferingRequestProcessor.java create mode 100644 solr/core/src/test/org/apache/solr/handler/CSVRequestHandlerTest.java diff --git a/solr/contrib/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java b/solr/contrib/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java index 3acc9ba8b42..b2dd1bb501c 100644 --- a/solr/contrib/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java +++ b/solr/contrib/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java @@ -28,7 +28,10 @@ import org.apache.solr.handler.extraction.ExtractingDocumentLoader; import org.apache.solr.handler.extraction.ExtractingParams; import org.apache.solr.handler.extraction.ExtractingRequestHandler; import org.apache.solr.request.LocalSolrQueryRequest; +import org.apache.solr.handler.BufferingRequestProcessor; +import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.update.AddUpdateCommand; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -39,6 +42,7 @@ import org.junit.Test; * **/ public class ExtractingRequestHandlerTest extends SolrTestCaseJ4 { + @BeforeClass public static void beforeClass() throws Exception { initCore("solrconfig.xml", "schema.xml", getFile("extraction/solr").getAbsolutePath()); @@ -289,21 +293,21 @@ public class ExtractingRequestHandlerTest extends SolrTestCaseJ4 { public void testCommitWithin() throws Exception { ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract"); assertTrue("handler is null and it shouldn't be", handler != null); + + SolrQueryRequest req = req("literal.id", "one", + ExtractingParams.RESOURCE_NAME, "extraction/version_control.txt", + "commitWithin", "200" + ); + SolrQueryResponse rsp = new SolrQueryResponse(); + BufferingRequestProcessor p = new BufferingRequestProcessor(null); - // Load plain text specifying filename - loadLocal("extraction/version_control.txt", "fmap.created", "extractedDate", "fmap.producer", "extractedProducer", - "fmap.creator", "extractedCreator", "fmap.Keywords", "extractedKeywords", - "fmap.Author", "extractedAuthor", - "literal.id", "one", - "fmap.language", "extractedLanguage", - "fmap.content", "extractedContent", - ExtractingParams.RESOURCE_NAME, "extraction/version_control.txt", - "commitWithin", "200" - ); - assertQ(req("id:one"), "//*[@numFound='0']"); - // TODO: Find better way of testing commitWithin without sleeping? - Thread.sleep(1000); - assertQ(req("id:one"), "//*[@numFound='1']"); + ExtractingDocumentLoader loader = (ExtractingDocumentLoader) handler.newLoader(req, p); + loader.load(req, rsp, new ContentStreamBase.FileStream(getFile("extraction/version_control.txt"))); + + AddUpdateCommand add = p.addCommands.get(0); + assertEquals(200, add.commitWithin); + + req.close(); } // Note: If you load a plain text file specifying neither MIME type nor filename, extraction will silently fail. This is because Tika's diff --git a/solr/core/src/test/org/apache/solr/handler/BufferingRequestProcessor.java b/solr/core/src/test/org/apache/solr/handler/BufferingRequestProcessor.java new file mode 100644 index 00000000000..e8d708301ed --- /dev/null +++ b/solr/core/src/test/org/apache/solr/handler/BufferingRequestProcessor.java @@ -0,0 +1,66 @@ +/** + * 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. + */ + +package org.apache.solr.handler; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.solr.update.AddUpdateCommand; +import org.apache.solr.update.CommitUpdateCommand; +import org.apache.solr.update.DeleteUpdateCommand; +import org.apache.solr.update.RollbackUpdateCommand; +import org.apache.solr.update.processor.UpdateRequestProcessor; + +public class BufferingRequestProcessor extends UpdateRequestProcessor +{ + public List addCommands = new ArrayList(); + public List deleteCommands = new ArrayList(); + public List commitCommands = new ArrayList(); + public List rollbackCommands = new ArrayList(); + + public BufferingRequestProcessor(UpdateRequestProcessor next) { + super(next); + } + + @Override + public void processAdd(AddUpdateCommand cmd) throws IOException { + addCommands.add( cmd ); + } + + @Override + public void processDelete(DeleteUpdateCommand cmd) throws IOException { + deleteCommands.add( cmd ); + } + + @Override + public void processCommit(CommitUpdateCommand cmd) throws IOException { + commitCommands.add( cmd ); + } + + @Override + public void processRollback(RollbackUpdateCommand cmd) throws IOException + { + rollbackCommands.add( cmd ); + } + + @Override + public void finish() throws IOException { + // nothing? + } +} diff --git a/solr/core/src/test/org/apache/solr/handler/CSVRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/CSVRequestHandlerTest.java new file mode 100644 index 00000000000..9ac4fc2ce82 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/handler/CSVRequestHandlerTest.java @@ -0,0 +1,54 @@ +/** + * 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. + */ + +package org.apache.solr.handler; + +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.common.util.ContentStreamBase; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.update.AddUpdateCommand; +import org.junit.BeforeClass; +import org.junit.Test; + + +public class CSVRequestHandlerTest extends SolrTestCaseJ4 { + + @BeforeClass + public static void beforeClass() throws Exception { + initCore("solrconfig.xml", "schema.xml"); + } + + @Test + public void testCommitWithin() throws Exception { + CSVRequestHandler handler = new CSVRequestHandler(); + + String csvString = "id;name\n123;hello"; + SolrQueryRequest req = req("separator", ";", + "commitWithin", "200"); + SolrQueryResponse rsp = new SolrQueryResponse(); + BufferingRequestProcessor p = new BufferingRequestProcessor(null); + + CSVLoader loader = (CSVLoader) handler.newLoader(req, p); + loader.load(req, rsp, new ContentStreamBase.StringStream.StringStream(csvString)); + + AddUpdateCommand add = p.addCommands.get(0); + assertEquals(200, add.commitWithin); + + req.close(); + } +} diff --git a/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java b/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java index 54bb57f89fd..67bec011a50 100644 --- a/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java +++ b/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java @@ -17,11 +17,6 @@ package org.apache.solr.handler; -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -import org.apache.noggit.JSONParser; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.SolrInputField; @@ -31,8 +26,6 @@ import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.update.AddUpdateCommand; import org.apache.solr.update.CommitUpdateCommand; import org.apache.solr.update.DeleteUpdateCommand; -import org.apache.solr.update.RollbackUpdateCommand; -import org.apache.solr.update.processor.UpdateRequestProcessor; import org.junit.BeforeClass; import org.junit.Test; @@ -199,43 +192,4 @@ public class JsonLoaderTest extends SolrTestCaseJ4 { ); } -} - - -class BufferingRequestProcessor extends UpdateRequestProcessor -{ - List addCommands = new ArrayList(); - List deleteCommands = new ArrayList(); - List commitCommands = new ArrayList(); - List rollbackCommands = new ArrayList(); - - public BufferingRequestProcessor(UpdateRequestProcessor next) { - super(next); - } - - @Override - public void processAdd(AddUpdateCommand cmd) throws IOException { - addCommands.add( cmd ); - } - - @Override - public void processDelete(DeleteUpdateCommand cmd) throws IOException { - deleteCommands.add( cmd ); - } - - @Override - public void processCommit(CommitUpdateCommand cmd) throws IOException { - commitCommands.add( cmd ); - } - - @Override - public void processRollback(RollbackUpdateCommand cmd) throws IOException - { - rollbackCommands.add( cmd ); - } - - @Override - public void finish() throws IOException { - // nothing? - } -} +} \ No newline at end of file diff --git a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java index 52359649aae..aebbd1e3726 100755 --- a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java +++ b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java @@ -113,15 +113,6 @@ public class TestCSVLoader extends SolrTestCaseJ4 { assertQ(req("id:[100 TO 110]"),"//*[@numFound='3']"); } - @Test - public void testCommitWithin() throws Exception { - makeFile("id\n100\n101\n102"); - loadLocal("stream.file",filename,"commitWithin","200"); - assertQ(req("id:[100 TO 110]"),"//*[@numFound='0']"); - Thread.sleep(1000); - assertQ(req("id:[100 TO 110]"),"//*[@numFound='3']"); - } - @Test public void testCommitTrue() throws Exception { makeFile("id\n100\n101\n102");