Source Code Cross Referenced for AutoCommitTest.java in  » Search-Engine » apache-solr-1.2.0 » org » apache » solr » update » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » apache solr 1.2.0 » org.apache.solr.update 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */package org.apache.solr.update;
017:
018:        import java.util.ArrayList;
019:        import java.util.Collection;
020:        import java.util.HashMap;
021:
022:        import org.apache.solr.core.SolrCore;
023:        import org.apache.solr.handler.XmlUpdateRequestHandler;
024:        import org.apache.solr.util.ContentStream;
025:        import org.apache.solr.request.MapSolrParams;
026:        import org.apache.solr.request.SolrQueryRequestBase;
027:        import org.apache.solr.request.SolrQueryResponse;
028:        import org.apache.solr.util.AbstractSolrTestCase;
029:        import org.apache.solr.util.ContentStreamBase;
030:
031:        /**
032:         * 
033:         * @author ryan
034:         *
035:         */
036:        public class AutoCommitTest extends AbstractSolrTestCase {
037:
038:            public String getSchemaFile() {
039:                return "schema.xml";
040:            }
041:
042:            public String getSolrConfigFile() {
043:                return "solrconfig.xml";
044:            }
045:
046:            /**
047:             * Take a string and make it an iterable ContentStream
048:             * 
049:             * This should be moved to a helper class. (it is useful for the client too!)
050:             */
051:            public static Collection<ContentStream> toContentStreams(
052:                    final String str, final String contentType) {
053:                ArrayList<ContentStream> streams = new ArrayList<ContentStream>();
054:                ContentStreamBase stream = new ContentStreamBase.StringStream(
055:                        str);
056:                stream.setContentType(contentType);
057:                streams.add(stream);
058:                return streams;
059:            }
060:
061:            public void testMaxDocs() throws Exception {
062:
063:                DirectUpdateHandler2 updater = (DirectUpdateHandler2) SolrCore
064:                        .getSolrCore().getUpdateHandler();
065:                DirectUpdateHandler2.CommitTracker tracker = updater.tracker;
066:                tracker.timeUpperBound = -1;
067:                tracker.docsUpperBound = 14;
068:
069:                XmlUpdateRequestHandler handler = new XmlUpdateRequestHandler();
070:                handler.init(null);
071:
072:                SolrCore core = SolrCore.getSolrCore();
073:                MapSolrParams params = new MapSolrParams(
074:                        new HashMap<String, String>());
075:
076:                // Add a single document
077:                SolrQueryResponse rsp = new SolrQueryResponse();
078:                SolrQueryRequestBase req = new SolrQueryRequestBase(core,
079:                        params) {
080:                };
081:                for (int i = 0; i < 14; i++) {
082:                    req.setContentStreams(toContentStreams(adoc("id", "A" + i,
083:                            "subject", "info"), null));
084:                    handler.handleRequest(req, rsp);
085:                }
086:                // It should not be there right away
087:                assertQ("shouldn't find any", req("id:A1"),
088:                        "//result[@numFound=0]");
089:                assertEquals(0, tracker.autoCommitCount);
090:
091:                req.setContentStreams(toContentStreams(adoc("id", "A14",
092:                        "subject", "info"), null));
093:                handler.handleRequest(req, rsp);
094:                // Wait longer then the autocommit time
095:                Thread.sleep(500);
096:                // blocks until commit is complete
097:                req.setContentStreams(toContentStreams(adoc("id", "A15",
098:                        "subject", "info"), null));
099:                handler.handleRequest(req, rsp);
100:
101:                // Now make sure we can find it
102:                assertQ("should find one", req("id:A14"),
103:                        "//result[@numFound=1]");
104:                assertEquals(1, tracker.autoCommitCount);
105:                // But not the one added afterward
106:                assertQ("should find one", req("id:A15"),
107:                        "//result[@numFound=0]");
108:                assertEquals(1, tracker.autoCommitCount);
109:
110:                // Now add some more
111:                for (int i = 0; i < 14; i++) {
112:                    req.setContentStreams(toContentStreams(adoc("id", "B" + i,
113:                            "subject", "info"), null));
114:                    handler.handleRequest(req, rsp);
115:                }
116:                // It should not be there right away
117:                assertQ("shouldn't find any", req("id:B1"),
118:                        "//result[@numFound=0]");
119:                assertEquals(1, tracker.autoCommitCount);
120:
121:                req.setContentStreams(toContentStreams(adoc("id", "B14",
122:                        "subject", "info"), null));
123:                handler.handleRequest(req, rsp);
124:                Thread.sleep(500);
125:
126:                // add request will block if commit has already started or completed
127:                req.setContentStreams(toContentStreams(adoc("id", "B15",
128:                        "subject", "info"), null));
129:                handler.handleRequest(req, rsp);
130:
131:                assertQ("should find one", req("id:B14"),
132:                        "//result[@numFound=1]");
133:                assertEquals(2, tracker.autoCommitCount);
134:                assertQ("should find none", req("id:B15"),
135:                        "//result[@numFound=0]");
136:                assertEquals(2, tracker.autoCommitCount);
137:            }
138:
139:            public void testMaxTime() throws Exception {
140:
141:                DirectUpdateHandler2 updater = (DirectUpdateHandler2) SolrCore
142:                        .getSolrCore().getUpdateHandler();
143:                DirectUpdateHandler2.CommitTracker tracker = updater.tracker;
144:                tracker.timeUpperBound = 500;
145:                tracker.docsUpperBound = -1;
146:
147:                XmlUpdateRequestHandler handler = new XmlUpdateRequestHandler();
148:                handler.init(null);
149:
150:                SolrCore core = SolrCore.getSolrCore();
151:                MapSolrParams params = new MapSolrParams(
152:                        new HashMap<String, String>());
153:
154:                // Add a single document
155:                SolrQueryResponse rsp = new SolrQueryResponse();
156:                SolrQueryRequestBase req = new SolrQueryRequestBase(core,
157:                        params) {
158:                };
159:                req.setContentStreams(toContentStreams(adoc("id", "529",
160:                        "field_t", "what's inside?", "subject", "info"), null));
161:                handler.handleRequest(req, rsp);
162:
163:                // Check it it is in the index
164:                assertQ("shouldn't find any", req("id:529"),
165:                        "//result[@numFound=0]");
166:
167:                // Wait longer then the autocommit time
168:                Thread.sleep(1000);
169:                req.setContentStreams(toContentStreams(adoc("id", "530",
170:                        "field_t", "what's inside?", "subject", "info"), null));
171:                handler.handleRequest(req, rsp);
172:
173:                // Now make sure we can find it
174:                assertQ("should find one", req("id:529"),
175:                        "//result[@numFound=1]");
176:                // But not this one
177:                assertQ("should find none", req("id:530"),
178:                        "//result[@numFound=0]");
179:
180:                // now make the call 10 times really fast and make sure it 
181:                // only commits once
182:                req
183:                        .setContentStreams(toContentStreams(adoc("id", "500"),
184:                                null));
185:                for (int i = 0; i < 10; i++) {
186:                    handler.handleRequest(req, rsp);
187:                }
188:                assertQ("should not be there yet", req("id:500"),
189:                        "//result[@numFound=0]");
190:                assertEquals(1, tracker.autoCommitCount);
191:
192:                // Wait longer then the autocommit time
193:                Thread.sleep(1000);
194:                req.setContentStreams(toContentStreams(adoc("id", "531",
195:                        "field_t", "what's inside?", "subject", "info"), null));
196:
197:                assertQ("now it should", req("id:500"), "//result[@numFound=1]");
198:                assertQ("but not this", req("id:531"), "//result[@numFound=0]");
199:                assertEquals(2, tracker.autoCommitCount);
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.