org.cdlib.xtf.crossQuery.test
Class TestableCrossQuery

Object
  extended by GenericServlet
      extended by HttpServlet
          extended by TextServlet
              extended by CrossQuery
                  extended by TestableCrossQuery
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class TestableCrossQuery
extends CrossQuery

Derived version of the crossQuery servlet, used to abuse crossQuery during load tests. The main difference is that it throws exceptions upward instead of formatting an error page. This ensures that exceptions don't get hidden in the noise. Also, for each thread we track the number of hits returned by the last request.

Author:
Martin Haye
See Also:
Serialized Form

Field Summary
private  String baseDir
           
private  String indexDirOverride
           
private  IndexWarmer indexWarmer
           
private  ThreadLocal<Integer> nHits
           
 
Fields inherited from class CrossQuery
config, decimalFormat, profListener
 
Fields inherited from class TextServlet
stylesheetCache
 
Constructor Summary
TestableCrossQuery(String baseDir)
          Simplified initialization for use outside a real servlet container.
 
Method Summary
 QueryProcessor createQueryProcessor()
          For test mode, allow override of index warmer.
protected  void formatHits(String mainTagName, HttpServletRequest req, HttpServletResponse res, AttribList attribs, QueryRequest queryRequest, QueryResult queryResult, long startTime)
          Formats a list of hits using the resultFormatter stylesheet.
protected  void genErrorPage(HttpServletRequest req, HttpServletResponse res, Exception exc)
          Generate an error page based on the given exception.
 int nHits()
          Return the number of hits in the last request processed by this thread
 void overrideIndexDir(String dir)
          Allows overriding the directory specified in future query requests.
protected  QueryRequest runQueryParser(HttpServletRequest req, HttpServletResponse res, QueryRoute route, AttribList attribs)
          Allow overriding the index directory
 void service(String url)
          Simplified method to test-get the given URL.
 void setIndexWarmer(IndexWarmer warmer)
          Allows overriding default index warmer.
protected  void setupTrace(TextConfig config)
          For test mode, do nothing to the current trace flags.
 
Methods inherited from class CrossQuery
apply, doGet, getConfig, getConfigName, getServletInfo, readConfig, runQueryRouter, shuntQueryReq, stepSetup
 
Methods inherited from class TextServlet
addParam, addToken, addTokens, buildParamBlock, calcMimeType, convertUTF8inURL, cqlTokenize, createFilteredReceiver, decodeURL, defaultTokenize, destroy, doPost, getCurRequest, getCurResponse, getCurServlet, getRealPath, getRequestURL, getRequestURL, getText, isEmpty, isSessionTrackingEnabled, makeAttribList, makeHtmlString, makeHtmlString, rawTokenize, readBranding, requireOrElse, restoreWildcards, saveWildcards, service, setErrorGenSheet, stuffAttribs, stuffAttribs, stuffSpecialAttribs
 
Methods inherited from class HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service
 
Methods inherited from class GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseDir

private String baseDir

indexDirOverride

private String indexDirOverride

indexWarmer

private IndexWarmer indexWarmer

nHits

private ThreadLocal<Integer> nHits
Constructor Detail

TestableCrossQuery

public TestableCrossQuery(String baseDir)
                   throws ServletException
Simplified initialization for use outside a real servlet container.

Parameters:
baseDir - the XTF home directory.
Throws:
ServletException - if anything goes wrong.
Method Detail

overrideIndexDir

public void overrideIndexDir(String dir)
Allows overriding the directory specified in future query requests.


setIndexWarmer

public void setIndexWarmer(IndexWarmer warmer)
Allows overriding default index warmer.


nHits

public int nHits()
Return the number of hits in the last request processed by this thread


setupTrace

protected void setupTrace(TextConfig config)
For test mode, do nothing to the current trace flags.

Overrides:
setupTrace in class TextServlet

runQueryParser

protected QueryRequest runQueryParser(HttpServletRequest req,
                                      HttpServletResponse res,
                                      QueryRoute route,
                                      AttribList attribs)
                               throws Exception
Allow overriding the index directory

Overrides:
runQueryParser in class CrossQuery
Parameters:
req - The original HTTP request
res - The HTTP response (used for step mode only)
route - Route to the query parser
attribs - Attributes to pass to the stylesheet.
Returns:
A parsed query request, or null if before that step
Throws:
Exception

createQueryProcessor

public QueryProcessor createQueryProcessor()
For test mode, allow override of index warmer. Default to foreground warming.

Overrides:
createQueryProcessor in class TextServlet

service

public void service(String url)
             throws ServletException,
                    IOException
Simplified method to test-get the given URL. Throws away the output but retains the number of hits.

Parameters:
url - the URL to test-get
Throws:
ServletException
IOException

formatHits

protected void formatHits(String mainTagName,
                          HttpServletRequest req,
                          HttpServletResponse res,
                          AttribList attribs,
                          QueryRequest queryRequest,
                          QueryResult queryResult,
                          long startTime)
                   throws Exception
Description copied from class: CrossQuery
Formats a list of hits using the resultFormatter stylesheet.

Overrides:
formatHits in class CrossQuery
Parameters:
mainTagName - Name of the top-level tag to generate (e.g. "crossQueryResult", etc.)
req - The original HTTP request
res - Where to send the HTML response
attribs - Parameters to pass to the stylesheet
queryRequest - Query request that produced the hits
queryResult - Hits resulting from the query request
startTime - Time (in milliseconds) request began
Throws:
Exception

genErrorPage

protected void genErrorPage(HttpServletRequest req,
                            HttpServletResponse res,
                            Exception exc)
Description copied from class: TextServlet
Generate an error page based on the given exception. Utilizes the system error stylesheet to produce a nicely formatted HTML page.

Overrides:
genErrorPage in class TextServlet
Parameters:
req - The HTTP request we're responding to
res - The HTTP result to write to
exc - The exception producing the error. If it's a DynaXMLException, the attributes will be passed to the error stylesheet.