Search in sources :

Example 1 with MockZkStateReader

use of org.apache.solr.cloud.MockZkStateReader in project lucene-solr by apache.

the class TestClusterStateMutator method testCreateCollection.

public void testCreateCollection() throws Exception {
    ClusterState state = new ClusterState(-1, Collections.<String>emptySet(), Collections.<String, DocCollection>emptyMap());
    MockZkStateReader zkStateReader = new MockZkStateReader(state, Collections.<String>emptySet());
    ClusterState clusterState = zkStateReader.getClusterState();
    ClusterStateMutator mutator = new ClusterStateMutator(zkStateReader);
    ZkNodeProps message = new ZkNodeProps(Utils.makeMap("name", "xyz", "numShards", "1"));
    ZkWriteCommand cmd = mutator.createCollection(clusterState, message);
    DocCollection collection = cmd.collection;
    assertEquals("xyz", collection.getName());
    assertEquals(1, collection.getSlicesMap().size());
    assertEquals(1, collection.getMaxShardsPerNode());
    state = new ClusterState(-1, Collections.<String>emptySet(), Collections.singletonMap("xyz", collection));
    message = new ZkNodeProps(Utils.makeMap("name", "abc", "numShards", "2", "router.name", "implicit", "shards", "x,y", "replicationFactor", "3", "maxShardsPerNode", "4"));
    cmd = mutator.createCollection(state, message);
    collection = cmd.collection;
    assertEquals("abc", collection.getName());
    assertEquals(2, collection.getSlicesMap().size());
    assertNotNull(collection.getSlicesMap().get("x"));
    assertNotNull(collection.getSlicesMap().get("y"));
    assertNull(collection.getSlicesMap().get("x").getRange());
    assertNull(collection.getSlicesMap().get("y").getRange());
    assertSame(Slice.State.ACTIVE, collection.getSlicesMap().get("x").getState());
    assertSame(Slice.State.ACTIVE, collection.getSlicesMap().get("y").getState());
    assertEquals(4, collection.getMaxShardsPerNode());
    assertEquals(ImplicitDocRouter.class, collection.getRouter().getClass());
    // we still have the old collection
    assertNotNull(state.getCollectionOrNull("xyz"));
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) DocCollection(org.apache.solr.common.cloud.DocCollection) MockZkStateReader(org.apache.solr.cloud.MockZkStateReader)

Aggregations

MockZkStateReader (org.apache.solr.cloud.MockZkStateReader)1 ClusterState (org.apache.solr.common.cloud.ClusterState)1 DocCollection (org.apache.solr.common.cloud.DocCollection)1 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)1