mirror of https://github.com/apache/lucene.git
Add try-with-resources to CloudManager in tests (#1315)
This commit is contained in:
parent
dd9b9f2f7f
commit
2cabeb924d
|
@ -42,7 +42,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||||
import org.apache.solr.common.params.ShardParams;
|
import org.apache.solr.common.params.ShardParams;
|
||||||
import org.apache.solr.common.util.CommonTestInjection;
|
import org.apache.solr.common.util.CommonTestInjection;
|
||||||
import org.apache.solr.common.util.NamedList;
|
|
||||||
import org.apache.solr.common.util.SimpleOrderedMap;
|
import org.apache.solr.common.util.SimpleOrderedMap;
|
||||||
import org.apache.solr.common.util.TimeSource;
|
import org.apache.solr.common.util.TimeSource;
|
||||||
import org.apache.solr.handler.component.TrackingShardHandlerFactory;
|
import org.apache.solr.handler.component.TrackingShardHandlerFactory;
|
||||||
|
@ -85,7 +84,7 @@ public class RoutingToNodesWithPropertiesTest extends SolrCloudTestCase {
|
||||||
" 'sysprop.zone':'#EACH'}]}";
|
" 'sysprop.zone':'#EACH'}]}";
|
||||||
|
|
||||||
SolrRequest req = CloudTestUtils.AutoScalingRequest.create(SolrRequest.METHOD.POST, commands);
|
SolrRequest req = CloudTestUtils.AutoScalingRequest.create(SolrRequest.METHOD.POST, commands);
|
||||||
NamedList<Object> response = cluster.getSolrClient().request(req);
|
cluster.getSolrClient().request(req);
|
||||||
|
|
||||||
CollectionAdminRequest.createCollection(COLLECTION, 2, 2)
|
CollectionAdminRequest.createCollection(COLLECTION, 2, 2)
|
||||||
.process(cluster.getSolrClient());
|
.process(cluster.getSolrClient());
|
||||||
|
@ -107,36 +106,37 @@ public class RoutingToNodesWithPropertiesTest extends SolrCloudTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check inject props
|
// check inject props
|
||||||
SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(cluster.getZkClient()),
|
try (SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(cluster.getZkClient()),
|
||||||
cluster.getSolrClient());
|
cluster.getSolrClient())) {
|
||||||
for (String zone1Node: zone1Nodes) {
|
for (String zone1Node: zone1Nodes) {
|
||||||
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
|
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
|
||||||
Map<String, Object> map = nodeStateProvider.getNodeValues(zone1Node, Collections.singletonList(PROP_NAME));
|
Map<String, Object> map = nodeStateProvider.getNodeValues(zone1Node, Collections.singletonList(PROP_NAME));
|
||||||
assertEquals("us-west1", map.get(PROP_NAME));
|
assertEquals("us-west1", map.get(PROP_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String zone2Node: zone2Nodes) {
|
for (String zone2Node: zone2Nodes) {
|
||||||
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
|
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
|
||||||
Map<String, Object> map = nodeStateProvider.getNodeValues(zone2Node, Collections.singletonList(PROP_NAME));
|
Map<String, Object> map = nodeStateProvider.getNodeValues(zone2Node, Collections.singletonList(PROP_NAME));
|
||||||
assertEquals("us-west2", map.get(PROP_NAME));
|
assertEquals("us-west2", map.get(PROP_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
|
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
|
||||||
if (zone1Nodes.contains(jetty.getNodeName())) {
|
if (zone1Nodes.contains(jetty.getNodeName())) {
|
||||||
((TrackingShardHandlerFactory)jetty.getCoreContainer().getShardHandlerFactory()).setTrackingQueue(zone1Queue);
|
((TrackingShardHandlerFactory)jetty.getCoreContainer().getShardHandlerFactory()).setTrackingQueue(zone1Queue);
|
||||||
} else {
|
} else {
|
||||||
((TrackingShardHandlerFactory)jetty.getCoreContainer().getShardHandlerFactory()).setTrackingQueue(zone2Queue);
|
((TrackingShardHandlerFactory)jetty.getCoreContainer().getShardHandlerFactory()).setTrackingQueue(zone2Queue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
new UpdateRequest()
|
||||||
|
.add("id", String.valueOf(i))
|
||||||
|
.process(cluster.getSolrClient(), COLLECTION);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++) {
|
|
||||||
new UpdateRequest()
|
new UpdateRequest()
|
||||||
.add("id", String.valueOf(i))
|
.commit(cluster.getSolrClient(), COLLECTION);
|
||||||
.process(cluster.getSolrClient(), COLLECTION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new UpdateRequest()
|
|
||||||
.commit(cluster.getSolrClient(), COLLECTION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -71,31 +71,31 @@ public class MetricTriggerTest extends SolrCloudTestCase {
|
||||||
final List<TriggerEvent> events = new ArrayList<>();
|
final List<TriggerEvent> events = new ArrayList<>();
|
||||||
SolrZkClient zkClient = cluster.getSolrClient().getZkStateReader().getZkClient();
|
SolrZkClient zkClient = cluster.getSolrClient().getZkStateReader().getZkClient();
|
||||||
SolrResourceLoader loader = cluster.getJettySolrRunner(0).getCoreContainer().getResourceLoader();
|
SolrResourceLoader loader = cluster.getJettySolrRunner(0).getCoreContainer().getResourceLoader();
|
||||||
SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(zkClient), cluster.getSolrClient());
|
try (SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(zkClient), cluster.getSolrClient())) {
|
||||||
|
try (MetricTrigger metricTrigger = new MetricTrigger("metricTrigger")) {
|
||||||
|
metricTrigger.configure(loader, cloudManager, props);
|
||||||
|
metricTrigger.setProcessor(noFirstRunProcessor);
|
||||||
|
metricTrigger.run();
|
||||||
|
metricTrigger.setProcessor(event -> events.add(event));
|
||||||
|
assertEquals(0, events.size());
|
||||||
|
Thread.sleep(waitForSeconds * 1000 + 2000);
|
||||||
|
metricTrigger.run();
|
||||||
|
assertEquals(1, events.size());
|
||||||
|
}
|
||||||
|
|
||||||
try (MetricTrigger metricTrigger = new MetricTrigger("metricTrigger")) {
|
events.clear();
|
||||||
metricTrigger.configure(loader, cloudManager, props);
|
tag = "metrics:" + registry + ":ADMIN./admin/file.handlerStart";
|
||||||
metricTrigger.setProcessor(noFirstRunProcessor);
|
props = createTriggerProps(waitForSeconds, tag, null, 100.0d, DEFAULT_TEST_COLLECTION_NAME, null, null);
|
||||||
metricTrigger.run();
|
try (MetricTrigger metricTrigger = new MetricTrigger("metricTrigger")) {
|
||||||
metricTrigger.setProcessor(event -> events.add(event));
|
metricTrigger.configure(loader, cloudManager, props);
|
||||||
assertEquals(0, events.size());
|
metricTrigger.setProcessor(noFirstRunProcessor);
|
||||||
Thread.sleep(waitForSeconds * 1000 + 2000);
|
metricTrigger.run();
|
||||||
metricTrigger.run();
|
metricTrigger.setProcessor(event -> events.add(event));
|
||||||
assertEquals(1, events.size());
|
assertEquals(0, events.size());
|
||||||
}
|
Thread.sleep(waitForSeconds * 1000 + 2000);
|
||||||
|
metricTrigger.run();
|
||||||
events.clear();
|
assertEquals(1, events.size());
|
||||||
tag = "metrics:" + registry + ":ADMIN./admin/file.handlerStart";
|
}
|
||||||
props = createTriggerProps(waitForSeconds, tag, null, 100.0d, DEFAULT_TEST_COLLECTION_NAME, null, null);
|
|
||||||
try (MetricTrigger metricTrigger = new MetricTrigger("metricTrigger")) {
|
|
||||||
metricTrigger.configure(loader, cloudManager, props);
|
|
||||||
metricTrigger.setProcessor(noFirstRunProcessor);
|
|
||||||
metricTrigger.run();
|
|
||||||
metricTrigger.setProcessor(event -> events.add(event));
|
|
||||||
assertEquals(0, events.size());
|
|
||||||
Thread.sleep(waitForSeconds * 1000 + 2000);
|
|
||||||
metricTrigger.run();
|
|
||||||
assertEquals(1, events.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue