コード例 #1
0
 /** Checks the success or failure of an update message */
 private void checkUpdateU(String message, String update, boolean shouldSucceed) {
   try {
     String m = (null == message) ? "" : message + " ";
     if (shouldSucceed) {
       String res = h.validateUpdate(update);
       if (res != null) fail(m + "update was not successful: " + res);
     } else {
       String res = h.validateErrorUpdate(update);
       if (res != null) fail(m + "update succeeded, but should have failed: " + res);
     }
   } catch (SAXException e) {
     throw new RuntimeException("Invalid XML", e);
   }
 }
コード例 #2
0
  /**
   * Shuts down the test harness, and makes the best attempt possible to delete dataDir, unless the
   * system property "solr.test.leavedatadir" is set.
   */
  @Override
  public void tearDown() throws Exception {
    log.info("####TEARDOWN_START " + getTestName());
    if (factoryProp == null) {
      System.clearProperty("solr.directoryFactory");
    }

    if (h != null) {
      h.close();
    }
    String skip = System.getProperty("solr.test.leavedatadir");
    if (null != skip && 0 != skip.trim().length()) {
      System.err.println(
          "NOTE: per solr.test.leavedatadir, dataDir will not be removed: "
              + dataDir.getAbsolutePath());
    } else {
      if (!recurseDelete(dataDir)) {
        System.err.println(
            "!!!! WARNING: best effort to remove " + dataDir.getAbsolutePath() + " FAILED !!!!!");
      }
    }

    resetExceptionIgnores();
    super.tearDown();
  }
コード例 #3
0
 public void assertQEx(String message, SolrQueryRequest req, SolrException.ErrorCode code) {
   try {
     h.query(req);
     fail(message);
   } catch (SolrException e) {
     assertEquals(code.code, e.code());
   } catch (Exception e2) {
     throw new RuntimeException("Exception during query", e2);
   }
 }
コード例 #4
0
 /** Validates a query matches some XPath test expressions and closes the query */
 public void assertQ(String message, SolrQueryRequest req, String... tests) {
   try {
     String m = (null == message) ? "" : message + " ";
     String response = h.query(req);
     String results = h.validateXPath(response, tests);
     if (null != results) {
       fail(
           m
               + "query failed XPath: "
               + results
               + "\n xml response was: "
               + response
               + "\n request was: "
               + req.getParamString());
     }
   } catch (XPathExpressionException e1) {
     throw new RuntimeException("XPath is invalid", e1);
   } catch (Exception e2) {
     throw new RuntimeException("Exception during query", e2);
   }
 }
コード例 #5
0
  /**
   * Initializes things your test might need
   *
   * <ul>
   *   <li>Creates a dataDir in the "java.io.tmpdir"
   *   <li>initializes the TestHarness h using this data directory, and getSchemaPath()
   *   <li>initializes the LocalRequestFactory lrf using sensible defaults.
   * </ul>
   */
  @Override
  public void setUp() throws Exception {
    super.setUp();
    log.info("####SETUP_START " + getTestName());
    ignoreException("ignore_exception");
    factoryProp = System.getProperty("solr.directoryFactory");
    if (factoryProp == null) {
      System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");
    }
    dataDir = new File(TEMP_DIR, getClass().getName() + "-" + System.currentTimeMillis());
    dataDir.mkdirs();
    String configFile = getSolrConfigFile();
    System.setProperty("solr.solr.home", getSolrHome());
    if (configFile != null) {

      solrConfig = TestHarness.createConfig(getSolrConfigFile());
      h = new TestHarness(dataDir.getAbsolutePath(), solrConfig, getSchemaFile());
      lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");
    }
    log.info("####SETUP_END " + getTestName());
  }
コード例 #6
0
 /**
  * Generates a simple &lt;doc&gt;... XML String with no options
  *
  * @param fieldsAndValues 0th and Even numbered args are fields names, Odds are field values.
  * @see TestHarness#makeSimpleDoc
  */
 public Doc doc(String... fieldsAndValues) {
   Doc d = new Doc();
   d.xml = TestHarness.makeSimpleDoc(fieldsAndValues).toString();
   return d;
 }
コード例 #7
0
 /**
  * Generates a &lt;delete&gt;... XML string for an query
  *
  * @see TestHarness#deleteByQuery
  */
 public String delQ(String q, String... args) {
   return TestHarness.deleteByQuery(q, args);
 }
コード例 #8
0
 /**
  * Generates a &lt;delete&gt;... XML string for an ID
  *
  * @see TestHarness#deleteById
  */
 public String delI(String id, String... args) {
   return TestHarness.deleteById(id, args);
 }
コード例 #9
0
 /** @see TestHarness#commit */
 public String commit(String... args) {
   return TestHarness.commit(args);
 }
コード例 #10
0
 /** @see TestHarness#optimize */
 public String optimize(String... args) {
   return TestHarness.optimize(args);
 }