Search in sources :

Example 1 with ZkWriteCommand

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

the class NodeMutatorTest method downNodeReportsAllImpactedCollectionsAndNothingElse.

@Test
public void downNodeReportsAllImpactedCollectionsAndNothingElse() throws IOException {
    NodeMutator nm = new NodeMutator();
    ZkNodeProps props = new ZkNodeProps(ZkStateReader.NODE_NAME_PROP, NODE1);
    //We use 2 nodes with maxShardsPerNode as 1
    //Collection1: 2 shards X 1 replica = replica1 on node1 and replica2 on node2
    //Collection2: 1 shard X 1 replica = replica1 on node2
    ClusterStateMockUtil.Result result = ClusterStateMockUtil.buildClusterState(null, "csrr2rD*csr2", 1, 1, NODE1, NODE2);
    ClusterState clusterState = result.reader.getClusterState();
    assertEquals(clusterState.getCollection("collection1").getReplica("replica1").getBaseUrl(), NODE1_URL);
    assertEquals(clusterState.getCollection("collection1").getReplica("replica2").getBaseUrl(), NODE2_URL);
    assertEquals(clusterState.getCollection("collection2").getReplica("replica4").getBaseUrl(), NODE2_URL);
    props = new ZkNodeProps(ZkStateReader.NODE_NAME_PROP, NODE1);
    List<ZkWriteCommand> writes = nm.downNode(clusterState, props);
    assertEquals(writes.size(), 1);
    assertEquals(writes.get(0).name, "collection1");
    assertEquals(writes.get(0).collection.getReplica("replica1").getState(), Replica.State.DOWN);
    assertEquals(writes.get(0).collection.getReplica("replica2").getState(), Replica.State.ACTIVE);
    result.close();
    //We use 3 nodes with maxShardsPerNode as 1
    //Collection1: 2 shards X 1 replica = replica1 on node1 and replica2 on node2
    //Collection2: 1 shard X 1 replica = replica1 on node2
    //Collection3: 1 shard X 3 replica = replica1 on node1 , replica2 on node2, replica3 on node3
    result = ClusterStateMockUtil.buildClusterState(null, "csrr2rD*csr2csr1r2r3", 1, 1, NODE1, NODE2, NODE3);
    clusterState = result.reader.getClusterState();
    assertEquals(clusterState.getCollection("collection1").getReplica("replica1").getBaseUrl(), NODE1_URL);
    assertEquals(clusterState.getCollection("collection1").getReplica("replica2").getBaseUrl(), NODE2_URL);
    assertEquals(clusterState.getCollection("collection2").getReplica("replica4").getBaseUrl(), NODE2_URL);
    assertEquals(clusterState.getCollection("collection3").getReplica("replica5").getBaseUrl(), NODE1_URL);
    assertEquals(clusterState.getCollection("collection3").getReplica("replica6").getBaseUrl(), NODE2_URL);
    assertEquals(clusterState.getCollection("collection3").getReplica("replica7").getBaseUrl(), NODE3_URL);
    writes = nm.downNode(clusterState, props);
    assertEquals(writes.size(), 2);
    for (ZkWriteCommand write : writes) {
        if (write.name.equals("collection1")) {
            assertEquals(write.collection.getReplica("replica1").getState(), Replica.State.DOWN);
            assertEquals(write.collection.getReplica("replica2").getState(), Replica.State.ACTIVE);
        } else if (write.name.equals("collection3")) {
            assertEquals(write.collection.getReplica("replica5").getState(), Replica.State.DOWN);
            assertEquals(write.collection.getReplica("replica6").getState(), Replica.State.ACTIVE);
            assertEquals(write.collection.getReplica("replica7").getState(), Replica.State.ACTIVE);
        } else {
            fail("No other collection needs to be changed");
        }
    }
    result.close();
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ZkWriteCommand(org.apache.solr.cloud.overseer.ZkWriteCommand) NodeMutator(org.apache.solr.cloud.overseer.NodeMutator) SolrTestCaseJ4Test(org.apache.solr.SolrTestCaseJ4Test) Test(org.junit.Test)

Aggregations

SolrTestCaseJ4Test (org.apache.solr.SolrTestCaseJ4Test)1 NodeMutator (org.apache.solr.cloud.overseer.NodeMutator)1 ZkWriteCommand (org.apache.solr.cloud.overseer.ZkWriteCommand)1 ClusterState (org.apache.solr.common.cloud.ClusterState)1 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)1 Test (org.junit.Test)1