@Before
 public void setUp() throws Exception {
   super.setUp();
   queue.clear();
   reset(workQueueMock);
   reset(runningMapMock);
   reset(completedMapMock);
   reset(failureMapMock);
   reset(shardHandlerFactoryMock);
   reset(shardHandlerMock);
   reset(zkStateReaderMock);
   reset(clusterStateMock);
   reset(solrZkClientMock);
   underTest =
       new OverseerCollectionProcessorToBeTested(
           zkStateReaderMock,
           "1234",
           shardHandlerFactoryMock,
           ADMIN_PATH,
           workQueueMock,
           runningMapMock,
           completedMapMock,
           failureMapMock);
   zkMap.clear();
   collectionsSet.clear();
 }
예제 #2
0
  @After
  public void tearDown() throws Exception {
    System.clearProperty("hadoop.log.dir");
    System.clearProperty("solr.hdfs.blockcache.enabled");

    super.tearDown();
  }
예제 #3
0
 @After
 public void tearDown() throws Exception {
   // if you override setUp or tearDown, you better call
   // the super classes version
   super.tearDown();
   deleteFile();
 }
예제 #4
0
 @Before
 public void setUp() throws Exception {
   // if you override setUp or tearDown, you better call
   // the super classes version
   super.setUp();
   cleanup();
 }
 @Override
 @Before
 public void setUp() throws Exception {
   super.setUp();
   clearIndex();
   assertU(commit());
 }
 @Override
 @Before
 public void setUp() throws Exception {
   super.setUp();
   clearIndex();
   index();
 }
  @Test
  public void testDeleteInstanceDirAfterCreateFailure() throws Exception {
    assumeFalse(
        "Ignore test on windows because it does not delete data directory immediately after unload",
        Constants.WINDOWS);
    File solrHomeDirectory =
        new File(initCoreDataDir, getClass().getName() + "-corex-" + System.nanoTime());
    solrHomeDirectory.mkdirs();
    copySolrHomeToTemp(solrHomeDirectory, "corex");
    File corex = new File(solrHomeDirectory, "corex");
    FileUtils.write(new File(corex, "core.properties"), "", StandardCharsets.UTF_8);
    JettySolrRunner runner =
        new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr"));
    runner.start();

    try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex")) {
      client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
      client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
      SolrInputDocument doc = new SolrInputDocument();
      doc.addField("id", "123");
      client.add(doc);
      client.commit();
    }

    Path dataDir = null;
    try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) {
      CoreStatus status = CoreAdminRequest.getCoreStatus("corex", true, client);
      String dataDirectory = status.getDataDirectory();
      dataDir = Paths.get(dataDirectory);
      assertTrue(Files.exists(dataDir));
    }

    File subHome = new File(solrHomeDirectory, "corex" + File.separator + "conf");
    String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
    FileUtils.copyFile(
        new File(top, "bad-error-solrconfig.xml"), new File(subHome, "solrconfig.xml"));

    try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) {
      client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
      client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
      try {
        CoreAdminRequest.reloadCore("corex", client);
      } catch (Exception e) {
        // this is expected because we put a bad solrconfig -- ignore
      }

      CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false);
      req.setDeleteDataDir(true);
      req.setDeleteInstanceDir(
          false); // important because the data directory is inside the instance directory
      req.setCoreName("corex");
      req.process(client);
    }

    runner.stop();

    assertTrue(
        "The data directory was not cleaned up on unload after a failed core reload",
        Files.notExists(dataDir));
  }
 public static void runConfigCommand(RestTestHarness harness, String uri, String payload)
     throws IOException {
   String json = SolrTestCaseJ4.json(payload);
   log.info("going to send config command. path {} , payload: {}", uri, payload);
   String response = harness.post(uri, json);
   Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
   assertNull(response, map.get("errors"));
 }
 @After
 public void tearDown() throws Exception {
   // printHits(new SolrQuery("*:*"));
   // tests have different repositories so let's see if they can use the same solr instance
   // //solrTestServer = null;
   // clear data from this test
   // getSolr().deleteByQuery("*:*");
   super.tearDown();
 }
예제 #10
0
  // Write out the cores' config files, both bad schema files, bad config files as well as some good
  // cores.
  private CoreContainer initGoodAndBad(
      List<String> goodCores, List<String> badSchemaCores, List<String> badConfigCores)
      throws Exception {

    // Don't pollute the log with exception traces when they're expected.
    ignoreException(Pattern.quote("SAXParseException"));

    if (solrHomeDirectory.exists()) {
      FileUtils.deleteDirectory(solrHomeDirectory);
    }
    assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());

    // Create the cores that should be fine.
    for (String coreName : goodCores) {
      File coreRoot = new File(solrHomeDirectory, coreName);
      copyMinConf(coreRoot, "name=" + coreName);
    }

    // Collect the files that we'll write to the config directories.
    String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
    String min_schema =
        FileUtils.readFileToString(new File(top, "schema-tiny.xml"), Charsets.UTF_8.toString());
    String min_config =
        FileUtils.readFileToString(
            new File(top, "solrconfig-minimal.xml"), Charsets.UTF_8.toString());
    String rand_snip =
        FileUtils.readFileToString(
            new File(top, "solrconfig.snippet.randomindexconfig.xml"), Charsets.UTF_8.toString());

    // Now purposely mess up the config files, introducing stupid syntax errors.
    String bad_config = min_config.replace("<requestHandler", "<reqsthalr");
    String bad_schema = min_schema.replace("<field", "<filed");

    // Create the cores with bad configs
    for (String coreName : badConfigCores) {
      writeCustomConfig(coreName, bad_config, min_schema, rand_snip);
    }

    // Create the cores with bad schemas.
    for (String coreName : badSchemaCores) {
      writeCustomConfig(coreName, min_config, bad_schema, rand_snip);
    }

    // Write the solr.xml file. Cute how minimal it can be now....
    File solrXml = new File(solrHomeDirectory, "solr.xml");
    FileUtils.write(solrXml, "<solr/>", Charsets.UTF_8.toString());

    SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
    ConfigSolrXml config = (ConfigSolrXml) ConfigSolr.fromFile(loader, solrXml);

    CoresLocator locator = new CorePropertiesLocator(solrHomeDirectory.getAbsolutePath());

    // OK this should succeed, but at the end we should have recorded a series of errors.
    final CoreContainer cores = new CoreContainer(loader, config, locator);
    cores.load();
    return cores;
  }
 @Override
 @After
 public void tearDown() throws Exception {
   // remove dataimport.properties
   File f = new File("solr/conf/dataimport.properties");
   log.info("Looking for dataimport.properties at: " + f.getAbsolutePath());
   if (f.exists()) {
     log.info("Deleting dataimport.properties");
     if (!f.delete()) log.warn("Could not delete dataimport.properties");
   }
   super.tearDown();
 }
예제 #12
0
  private void setUpZkAndDiskXml(boolean toZk, boolean leaveOnLocal) throws Exception {

    createTempDir();
    File solrHome = new File(dataDir, "home");
    copyMinConf(new File(solrHome, "myCollect"));
    if (leaveOnLocal) {
      FileUtils.copyFile(
          new File(SolrTestCaseJ4.TEST_HOME(), "solr-stress-new.xml"),
          new File(solrHome, "solr.xml"));
    }

    System.setProperty("solr.solr.home", solrHome.getAbsolutePath());

    ignoreException("No UpdateLog found - cannot sync");
    ignoreException("No UpdateLog found - cannot recover");

    System.setProperty("zkClientTimeout", "8000");

    zkDir =
        dataDir.getAbsolutePath()
            + File.separator
            + "zookeeper"
            + System.currentTimeMillis()
            + "/server1/data";
    zkServer = new ZkTestServer(zkDir);
    zkServer.run();
    System.setProperty("zkHost", zkServer.getZkAddress());
    AbstractZkTestCase.buildZooKeeper(
        zkServer.getZkHost(), zkServer.getZkAddress(), "solrconfig.xml", "schema.xml");

    zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);

    if (toZk) {
      zkClient.makePath("solr.xml", XML_FOR_ZK.getBytes(Charsets.UTF_8), true);
    }

    zkClient.close();

    log.info("####SETUP_START " + getTestName());

    // set some system properties for use by tests
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");

    Method method =
        SolrDispatchFilter.class.getDeclaredMethod("loadConfigSolr", SolrResourceLoader.class);
    method.setAccessible(true);

    Object obj = method.invoke(new SolrDispatchFilter(), new SolrResourceLoader(null));
    cfg = (ConfigSolr) obj;

    log.info("####SETUP_END " + getTestName());
  }
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    AYE = new LinkedHashMap<String, Integer>();
    AYE.put("I", 0);
    AYE.put("II", 0);
    AYE.put("III", 0);
    AYE.put("IV", 0);
    AYE.put("V", 0);
    AYE.put("VI", 0);
    AYE.put("VII", 0);
    AYE.put("VIII", 0);

    BEE = new LinkedHashMap<String, Integer>();
    BEE.put("alpha", 0);
    BEE.put("beta", 0);
    BEE.put("gamma", 0);
    BEE.put("delta", 0);
    BEE.put("epsilon", 0);
    BEE.put("zeta", 0);
    BEE.put("eta", 0);
    BEE.put("theta", 0);
    BEE.put("iota", 0);

    AYE_BEE = new LinkedHashMap<String, Integer>();
    AYE_BEE.put("one-alpha", 0);
    AYE_BEE.put("two-beta", 0);
    AYE_BEE.put("three-gamma", 0);
    AYE_BEE.put("four-delta", 0);
    AYE_BEE.put("five-epsilon", 0);
    AYE_BEE.put("six-zeta", 0);
    AYE_BEE.put("seven-eta", 0);
    AYE_BEE.put("eight-theta", 0);
    AYE_BEE.put("nine-iota", 0);

    CEE = new LinkedHashMap<String, Integer>();
    CEE.put("one", 0);
    CEE.put("two", 0);
    CEE.put("three", 0);
    CEE.put("four", 0);
    CEE.put("five", 0);
    CEE.put("six", 0);
    CEE.put("seven", 0);
    CEE.put("eight", 0);
    CEE.put("nine", 0);
    CEE.put("ten", 0);
  }
 @BeforeClass
 public static void beforeTests() throws Exception {
   try {
     SolrTestCaseJ4.initCore(
         solrhome + "/repositem/conf/solrconfig.xml",
         solrhome + "/repositem/conf/schema.xml",
         "src/test/resources/"
             + solrhome); // has to be in classpath because "collection1" is hardcoded in
                          // TestHarness initCore/createCore
   } catch (Exception e) {
     System.out.println("getSolrConfigFile()=" + getSolrConfigFile());
     System.out.println("testSolrHome=" + testSolrHome);
     throw e;
   }
 }
예제 #15
0
  @Before
  public void setUp() throws Exception {
    super.setUp();
    resolver = new VariableResolverImpl();

    sqlTests = new HashMap<String, String>();

    sqlTests.put("foo\"", "foo\"\"");
    sqlTests.put("foo\\", "foo\\\\");
    sqlTests.put("foo'", "foo''");
    sqlTests.put("foo''", "foo''''");
    sqlTests.put("'foo\"", "''foo\"\"");
    sqlTests.put("\"Albert D'souza\"", "\"\"Albert D''souza\"\"");

    urlTests = new HashMap<String, String>();

    urlTests.put("*:*", URLEncoder.encode("*:*", ENCODING));
    urlTests.put("price:[* TO 200]", URLEncoder.encode("price:[* TO 200]", ENCODING));
    urlTests.put("review:\"hybrid sedan\"", URLEncoder.encode("review:\"hybrid sedan\"", ENCODING));
  }
 @Override
 @After
 public void tearDown() throws Exception {
   solrCluster.shutdown();
   super.tearDown();
 }
 @Override
 @Before
 public void setUp() throws Exception {
   super.setUp();
   solrCluster = new MiniSolrCloudCluster(1, createTempDir(), buildJettyConfig("/solr"));
 }
예제 #18
0
 // We want to see that the core "heals itself" if an un-corrupted file is written to the
 // directory.
 private void copyGoodConf(String coreName, String srcName, String dstName) throws IOException {
   File coreRoot = new File(solrHomeDirectory, coreName);
   File subHome = new File(coreRoot, "conf");
   String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
   FileUtils.copyFile(new File(top, srcName), new File(subHome, dstName));
 }
 @After
 public void tearDown() throws Exception {
   stopComponentUnderTest();
   super.tearDown();
 }
 public void tearDown() throws Exception {
   SolrConfig.severeErrors.clear();
   super.tearDown();
 }
예제 #21
0
 @AfterClass
 public static void afterClassAbstractSolrTestCase() throws Exception {
   SolrTestCaseJ4.endTrackingSearchers();
 }
예제 #22
0
 /** Subclasses can override this to change a test's solr home (default is in test-files) */
 public String getSolrHome() {
   return SolrTestCaseJ4.TEST_HOME();
 }
예제 #23
0
 public void setUp() throws Exception {
   super.setUp();
   assertU(delQ("*:*"));
 }
예제 #24
0
 @Override
 public void tearDown() throws Exception {
   deleteCore();
   super.tearDown();
 }
  @Test
  public void testCreateWithSysVars() throws Exception {
    useFactory(null); // I require FS-based indexes for this test.

    final File workDir = createTempDir(getCoreName()).toFile();

    String coreName = "with_sys_vars";
    File instDir = new File(workDir, coreName);
    File subHome = new File(instDir, "conf");
    assertTrue("Failed to make subdirectory ", subHome.mkdirs());

    // Be sure we pick up sysvars when we create this
    String srcDir = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
    FileUtils.copyFile(new File(srcDir, "schema-tiny.xml"), new File(subHome, "schema_ren.xml"));
    FileUtils.copyFile(
        new File(srcDir, "solrconfig-minimal.xml"), new File(subHome, "solrconfig_ren.xml"));
    FileUtils.copyFile(
        new File(srcDir, "solrconfig.snippet.randomindexconfig.xml"),
        new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));

    final CoreContainer cores = h.getCoreContainer();

    final CoreAdminHandler admin = new CoreAdminHandler(cores);

    // create a new core (using CoreAdminHandler) w/ properties
    System.setProperty("INSTDIR_TEST", instDir.getAbsolutePath());
    System.setProperty("CONFIG_TEST", "solrconfig_ren.xml");
    System.setProperty("SCHEMA_TEST", "schema_ren.xml");

    File dataDir = new File(workDir.getAbsolutePath(), "data_diff");
    System.setProperty("DATA_TEST", dataDir.getAbsolutePath());

    SolrQueryResponse resp = new SolrQueryResponse();
    admin.handleRequestBody(
        req(
            CoreAdminParams.ACTION,
            CoreAdminParams.CoreAdminAction.CREATE.toString(),
            CoreAdminParams.NAME,
            getCoreName(),
            CoreAdminParams.INSTANCE_DIR,
            "${INSTDIR_TEST}",
            CoreAdminParams.CONFIG,
            "${CONFIG_TEST}",
            CoreAdminParams.SCHEMA,
            "${SCHEMA_TEST}",
            CoreAdminParams.DATA_DIR,
            "${DATA_TEST}"),
        resp);
    assertNull("Exception on create", resp.getException());

    // Now assert that certain values are properly dereferenced in the process of creating the core,
    // see
    // SOLR-4982.

    // Should NOT be a datadir named ${DATA_TEST} (literal). This is the bug after all
    File badDir = new File(instDir, "${DATA_TEST}");
    assertFalse(
        "Should have substituted the sys var, found file " + badDir.getAbsolutePath(),
        badDir.exists());

    // For the other 3 vars, we couldn't get past creating the core fi dereferencing didn't work
    // correctly.

    // Should have segments in the directory pointed to by the ${DATA_TEST}.
    File test = new File(dataDir, "index");
    assertTrue("Should have found index dir at " + test.getAbsolutePath(), test.exists());
  }
  @Test
  public void testProperties() throws Exception {

    UpdateRequest up = new UpdateRequest();
    up.setAction(ACTION.COMMIT, true, true);
    up.deleteByQuery("*:*");
    up.process(getSolrCore0());
    up.process(getSolrCore1());
    up.clear();

    // Add something to each core
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "AAA");
    doc.setField("core0", "yup stopfra stopfrb stopena stopenb");

    // Add to core0
    up.add(doc);
    up.process(getSolrCore0());

    SolrTestCaseJ4.ignoreException("unknown field");

    // You can't add it to core1
    try {
      up.process(getSolrCore1());
      fail("Can't add core0 field to core1!");
    } catch (Exception ex) {
    }

    // Add to core1
    doc.setField("id", "BBB");
    doc.setField("core1", "yup stopfra stopfrb stopena stopenb");
    doc.removeField("core0");
    up.add(doc);
    up.process(getSolrCore1());

    // You can't add it to core1
    try {
      SolrTestCaseJ4.ignoreException("core0");
      up.process(getSolrCore0());
      fail("Can't add core1 field to core0!");
    } catch (Exception ex) {
    }

    SolrTestCaseJ4.resetExceptionIgnores();

    // now Make sure AAA is in 0 and BBB in 1
    SolrQuery q = new SolrQuery();
    QueryRequest r = new QueryRequest(q);
    q.setQuery("id:AAA");
    assertEquals(1, r.process(getSolrCore0()).getResults().size());
    assertEquals(0, r.process(getSolrCore1()).getResults().size());

    // Now test Changing the default core
    assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());

    assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());

    // Now test reloading it should have a newer open time
    String name = "core0";
    SolrClient coreadmin = getSolrAdmin();
    CoreAdminResponse mcr = CoreAdminRequest.getStatus(name, coreadmin);
    long before = mcr.getStartTime(name).getTime();
    CoreAdminRequest.reloadCore(name, coreadmin);

    mcr = CoreAdminRequest.getStatus(name, coreadmin);
    long after = mcr.getStartTime(name).getTime();
    assertTrue("should have more recent time: " + after + "," + before, after > before);
  }
예제 #27
0
 /** @see SolrTestCaseJ4#getFile */
 public static File getFile(String name) throws IOException {
   return SolrTestCaseJ4.getFile(name);
 }
예제 #28
0
 @BeforeClass
 public static void beforeClassAbstractSolrTestCase() throws Exception {
   SolrTestCaseJ4.startTrackingSearchers();
 }
 @Before
 @Override
 public void setUp() throws Exception {
   super.setUp();
 }
예제 #30
0
 @Override
 public void setUp() throws Exception {
   super.setUp();
   initCore("solrconfig.xml", "schema.xml");
 }