示例#1
0
 public void setUp() throws Exception {
   // if you override setUp or tearDown, you better call
   // the super classes version
   super.setUp();
   solrConfig = TestHarness.createConfig(getSolrConfigFile());
 }
  @Test
  public void testPersistence() throws Exception {
    final CoreContainer cc = init();
    try {
      copyMinConf(new File(solrHomeDirectory, "core1"));
      copyMinConf(new File(solrHomeDirectory, "core2"));
      copyMinConf(new File(solrHomeDirectory, "core3"));
      copyMinConf(new File(solrHomeDirectory, "core4"));

      final CoreDescriptor cd1 =
          buildCoreDescriptor(cc, "core1", "./core1").isTransient(true).loadOnStartup(true).build();
      final CoreDescriptor cd2 =
          buildCoreDescriptor(cc, "core2", "./core2")
              .isTransient(true)
              .loadOnStartup(false)
              .build();
      final CoreDescriptor cd3 =
          buildCoreDescriptor(cc, "core3", "./core3")
              .isTransient(false)
              .loadOnStartup(true)
              .build();
      final CoreDescriptor cd4 =
          buildCoreDescriptor(cc, "core4", "./core4")
              .isTransient(false)
              .loadOnStartup(false)
              .build();

      SolrCore core1 = cc.create(cd1);
      SolrCore core2 = cc.create(cd2);
      SolrCore core3 = cc.create(cd3);
      SolrCore core4 = cc.create(cd4);

      SolrXMLCoresLocator.NonPersistingLocator locator =
          (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();

      TestHarness.validateXPath(
          locator.xml,
          "/solr/cores/core[@name='collection1']",
          "/solr/cores/core[@name='collectionLazy2']",
          "/solr/cores/core[@name='collectionLazy3']",
          "/solr/cores/core[@name='collectionLazy4']",
          "/solr/cores/core[@name='collectionLazy5']",
          "/solr/cores/core[@name='collectionLazy6']",
          "/solr/cores/core[@name='collectionLazy7']",
          "/solr/cores/core[@name='collectionLazy8']",
          "/solr/cores/core[@name='collectionLazy9']",
          "/solr/cores/core[@name='core1']",
          "/solr/cores/core[@name='core2']",
          "/solr/cores/core[@name='core3']",
          "/solr/cores/core[@name='core4']",
          "13=count(/solr/cores/core)");

      removeOne(cc, "collectionLazy2");
      removeOne(cc, "collectionLazy3");
      removeOne(cc, "collectionLazy4");
      removeOne(cc, "collectionLazy5");
      removeOne(cc, "collectionLazy6");
      removeOne(cc, "collectionLazy7");
      removeOne(cc, "core1");
      removeOne(cc, "core2");
      removeOne(cc, "core3");
      removeOne(cc, "core4");

      // now test that unloading a core means the core is not persisted
      TestHarness.validateXPath(locator.xml, "3=count(/solr/cores/core)");

    } finally {
      cc.shutdown();
    }
  }