Exemplo n.º 1
0
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    lilyProxy = new LilyProxy();

    InputStream is = BatchBuildTest.class.getResourceAsStream("solrschema.xml");
    byte[] solrSchema = IOUtils.toByteArray(is);
    IOUtils.closeQuietly(is);

    lilyProxy.start(solrSchema);

    solrProxy = lilyProxy.getSolrProxy();
    solrServer = solrProxy.getSolrServer();
    lilyServerProxy = lilyProxy.getLilyServerProxy();
    lilyClient = lilyServerProxy.getClient();
    repository = lilyClient.getRepository();

    typeManager = repository.getTypeManager();
    FieldType ft1 =
        typeManager.createFieldType(
            "STRING", new QName("batchindex-test", "field1"), Scope.NON_VERSIONED);
    FieldType ft2 =
        typeManager.createFieldType(
            "LINK", new QName("batchindex-test", "linkField"), Scope.NON_VERSIONED);
    typeManager
        .recordTypeBuilder()
        .defaultNamespace("batchindex-test")
        .name("rt1")
        .fieldEntry()
        .use(ft1)
        .add()
        .fieldEntry()
        .use(ft2)
        .add()
        .create();

    model = lilyServerProxy.getIndexerModel();

    is = BatchBuildTest.class.getResourceAsStream("indexerconf.xml");
    byte[] indexerConfiguration = IOUtils.toByteArray(is);
    IOUtils.closeQuietly(is);

    IndexDefinition index = model.newIndex(INDEX_NAME);
    Map<String, String> solrShards = new HashMap<String, String>();
    solrShards.put("shard1", "http://localhost:8983/solr");
    index.setSolrShards(solrShards);
    index.setConfiguration(indexerConfiguration);
    index.setUpdateState(IndexUpdateState.DO_NOT_SUBSCRIBE);
    model.addIndex(index);
  }
Exemplo n.º 2
0
  @Test
  public void testSomeBasics() throws Exception {
    ZooKeeperItf zk1 = ZkUtil.connect("localhost:" + ZK_CLIENT_PORT, 3000);
    ZooKeeperItf zk2 = ZkUtil.connect("localhost:" + ZK_CLIENT_PORT, 3000);
    WriteableIndexerModel model1 = null;
    WriteableIndexerModel model2 = null;
    try {

      TestListener listener = new TestListener();

      model1 = new IndexerModelImpl(zk1);
      model1.registerListener(listener);

      // Create an index
      IndexDefinition index1 = model1.newIndex("index1");
      index1.setConfiguration("<indexer/>".getBytes("UTF-8"));
      index1.setSolrShards(Collections.singletonMap("shard1", "http://localhost:8983/solr"));
      model1.addIndex(index1);

      listener.waitForEvents(1);
      listener.verifyEvents(new IndexerModelEvent(IndexerModelEventType.INDEX_ADDED, "index1"));

      // Verify that a fresh indexer model has the index
      model2 = new IndexerModelImpl(zk2);
      assertEquals(1, model2.getIndexes().size());
      assertTrue(model2.hasIndex("index1"));

      // Update the index
      index1.setGeneralState(IndexGeneralState.DISABLED);
      String lock = model1.lockIndex("index1");
      model1.updateIndex(index1, lock);

      listener.waitForEvents(1);
      listener.verifyEvents(new IndexerModelEvent(IndexerModelEventType.INDEX_UPDATED, "index1"));

      // Do not release the lock, updating through model2 should fail
      index1.setConfiguration("<indexer></indexer>".getBytes("UTF-8"));
      try {
        model2.updateIndex(index1, lock + "foo");
        fail("expected exception");
      } catch (IndexUpdateException e) {
        // verify the exception says something about locks
        assertTrue(e.getMessage().indexOf("lock") != -1);
      }

      model1.unlockIndex(lock);

      model1.deleteIndex("index1");

      listener.waitForEvents(1);
      listener.verifyEvents(new IndexerModelEvent(IndexerModelEventType.INDEX_REMOVED, "index1"));

      // Create some more indexes
      IndexerModelEvent[] expectedEvents = new IndexerModelEvent[9];
      for (int i = 2; i <= 10; i++) {
        String name = "index" + i;
        IndexDefinition index = model1.newIndex(name);
        index.setConfiguration("<indexer/>".getBytes("UTF-8"));
        index.setSolrShards(Collections.singletonMap("shard1", "http://localhost:8983/solr"));
        model1.addIndex(index);
        expectedEvents[i - 2] = new IndexerModelEvent(IndexerModelEventType.INDEX_ADDED, name);
      }

      listener.waitForEvents(9);
      listener.verifyEvents(expectedEvents);
    } finally {
      Closer.close(model1);
      Closer.close(model2);
      Closer.close(zk1);
      Closer.close(zk2);
    }
  }