Java Code Examples for org.apache.lucene.util.LuceneTestCase.Slow

The following examples show how to use org.apache.lucene.util.LuceneTestCase.Slow. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   Source File: ZkControllerTest.java    License: Apache License 2.0 4 votes vote down vote up
@Slow
@LogLevel(value = "org.apache.solr.cloud=DEBUG;org.apache.solr.cloud.overseer=DEBUG")
public void testPublishAndWaitForDownStates() throws Exception  {

  /*
  This test asserts that if zkController.publishAndWaitForDownStates uses only core name to check if all local
  cores are down then the method will return immediately but if it uses coreNodeName (as it does after SOLR-6665 then
  the method will timeout).
  We setup the cluster state in such a way that two replicas with same core name exist on non-existent nodes
  and core container also has a dummy core that has the same core name. The publishAndWaitForDownStates before SOLR-6665
  would only check the core names and therefore return immediately but after SOLR-6665 it should time out.
   */

  assumeWorkingMockito();
  final String collectionName = "testPublishAndWaitForDownStates";
  Path zkDir = createTempDir(collectionName);
  CoreContainer cc = null;

  String nodeName = "127.0.0.1:8983_solr";

  ZkTestServer server = new ZkTestServer(zkDir);
  try {
    server.run();

    AtomicReference<ZkController> zkControllerRef = new AtomicReference<>();
    cc = new MockCoreContainer()  {
      @Override
      public List<CoreDescriptor> getCoreDescriptors() {
        CoreDescriptor descriptor = new CoreDescriptor(collectionName, TEST_PATH(), Collections.emptyMap(), new Properties(), zkControllerRef.get());
        // non-existent coreNodeName, this will cause zkController.publishAndWaitForDownStates to wait indefinitely
        // when using coreNodeName but usage of core name alone will return immediately
        descriptor.getCloudDescriptor().setCoreNodeName("core_node0");
        return Collections.singletonList(descriptor);
      }
    };
    ZkController zkController = null;

    try {
      CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder("127.0.0.1", 8983, "solr").build();
      zkController = new ZkController(cc, server.getZkAddress(), TIMEOUT, cloudConfig, () -> null);
      zkControllerRef.set(zkController);

      zkController.getZkClient().makePath(ZkStateReader.getCollectionPathRoot(collectionName), new byte[0], CreateMode.PERSISTENT, true);

      ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION,
          CollectionParams.CollectionAction.CREATE.toLower(), ZkStateReader.NODE_NAME_PROP, nodeName, ZkStateReader.NUM_SHARDS_PROP, "1",
          "name", collectionName);
      zkController.getOverseerJobQueue().offer(Utils.toJSON(m));

      HashMap<String, Object> propMap = new HashMap<>();
      propMap.put(Overseer.QUEUE_OPERATION, ADDREPLICA.toLower());
      propMap.put(COLLECTION_PROP, collectionName);
      propMap.put(SHARD_ID_PROP, "shard1");
      propMap.put(ZkStateReader.NODE_NAME_PROP, "non_existent_host1");
      propMap.put(ZkStateReader.CORE_NAME_PROP, collectionName);
      propMap.put(ZkStateReader.STATE_PROP, "active");
      zkController.getOverseerJobQueue().offer(Utils.toJSON(propMap));

      propMap = new HashMap<>();
      propMap.put(Overseer.QUEUE_OPERATION, ADDREPLICA.toLower());
      propMap.put(COLLECTION_PROP, collectionName);
      propMap.put(SHARD_ID_PROP, "shard1");
      propMap.put(ZkStateReader.NODE_NAME_PROP, "non_existent_host2");
      propMap.put(ZkStateReader.CORE_NAME_PROP, collectionName);
      propMap.put(ZkStateReader.STATE_PROP, "down");
      zkController.getOverseerJobQueue().offer(Utils.toJSON(propMap));

      zkController.getZkStateReader().forciblyRefreshAllClusterStateSlow();

      long now = System.nanoTime();
      long timeout = now + TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS);
      zkController.publishAndWaitForDownStates(5);
      assertTrue("The ZkController.publishAndWaitForDownStates should have timed out but it didn't", System.nanoTime() >= timeout);
    } finally {
      if (zkController != null)
        zkController.close();
    }
  } finally {
    if (cc != null) {
      cc.shutdown();
    }
    server.shutdown();
  }
}