Add try-with-resources to CloudManager in tests (#1315)

This commit is contained in:
Tomas Fernandez Lobbe 2020-03-04 13:32:44 -08:00 committed by GitHub
parent dd9b9f2f7f
commit 2cabeb924d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 52 deletions

View File

@ -42,7 +42,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
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.TimeSource;
import org.apache.solr.handler.component.TrackingShardHandlerFactory;
@ -85,7 +84,7 @@ public class RoutingToNodesWithPropertiesTest extends SolrCloudTestCase {
" 'sysprop.zone':'#EACH'}]}";
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)
.process(cluster.getSolrClient());
@ -107,36 +106,37 @@ public class RoutingToNodesWithPropertiesTest extends SolrCloudTestCase {
}
// check inject props
SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(cluster.getZkClient()),
cluster.getSolrClient());
for (String zone1Node: zone1Nodes) {
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
Map<String, Object> map = nodeStateProvider.getNodeValues(zone1Node, Collections.singletonList(PROP_NAME));
assertEquals("us-west1", map.get(PROP_NAME));
}
for (String zone2Node: zone2Nodes) {
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
Map<String, Object> map = nodeStateProvider.getNodeValues(zone2Node, Collections.singletonList(PROP_NAME));
assertEquals("us-west2", map.get(PROP_NAME));
}
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
if (zone1Nodes.contains(jetty.getNodeName())) {
((TrackingShardHandlerFactory)jetty.getCoreContainer().getShardHandlerFactory()).setTrackingQueue(zone1Queue);
} else {
((TrackingShardHandlerFactory)jetty.getCoreContainer().getShardHandlerFactory()).setTrackingQueue(zone2Queue);
try (SolrCloudManager cloudManager = new SolrClientCloudManager(new ZkDistributedQueueFactory(cluster.getZkClient()),
cluster.getSolrClient())) {
for (String zone1Node: zone1Nodes) {
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
Map<String, Object> map = nodeStateProvider.getNodeValues(zone1Node, Collections.singletonList(PROP_NAME));
assertEquals("us-west1", map.get(PROP_NAME));
}
for (String zone2Node: zone2Nodes) {
NodeStateProvider nodeStateProvider = cloudManager.getNodeStateProvider();
Map<String, Object> map = nodeStateProvider.getNodeValues(zone2Node, Collections.singletonList(PROP_NAME));
assertEquals("us-west2", map.get(PROP_NAME));
}
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
if (zone1Nodes.contains(jetty.getNodeName())) {
((TrackingShardHandlerFactory)jetty.getCoreContainer().getShardHandlerFactory()).setTrackingQueue(zone1Queue);
} else {
((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()
.add("id", String.valueOf(i))
.process(cluster.getSolrClient(), COLLECTION);
.commit(cluster.getSolrClient(), COLLECTION);
}
new UpdateRequest()
.commit(cluster.getSolrClient(), COLLECTION);
}
@After

View File

@ -71,31 +71,31 @@ public class MetricTriggerTest extends SolrCloudTestCase {
final List<TriggerEvent> events = new ArrayList<>();
SolrZkClient zkClient = cluster.getSolrClient().getZkStateReader().getZkClient();
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")) {
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());
}
events.clear();
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());
events.clear();
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());
}
}
}