Skip to content

Commit

Permalink
Automatically handle multicore
Browse files Browse the repository at this point in the history
  • Loading branch information
do3cc committed Sep 4, 2015
1 parent 0e28cca commit f1e7024
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/collective/solr/testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import json
from Products.CMFCore.utils import getToolByName
from collective.solr.configlet import SolrControlPanelAdapter
from collective.solr.utils import activate
Expand Down Expand Up @@ -85,17 +86,20 @@ def setUp(self):
http_error = None
for i in range(1, 10):
try:
result = urllib2.urlopen(solr_ping_url)
request = urllib2.Request(
'{0}/admin/cores?wt=json'.format(self.solr_url))
core_data = json.load(urllib2.urlopen(request))
cores = [x['name'] for x in core_data['status'].values()]
for core in cores:
solr_ping_url = '{0}/{1}/admin/ping'.format(
self.solr_url, core)
result = urllib2.urlopen(solr_ping_url)
if result.code == 200:
if '<str name="status">OK</str>' in result.read():
os.environ['SOLR_HOST'] = '{0}:{1}'.format(
self.solr_host, self.solr_port)
break
except urllib2.URLError, http_error:
if getattr(http_error, 'code', 200) == 404:
raise Exception("Solr is not configured correctly. "
"If you are using a multicore setup, "
"refer to the documentation")
sleep(3)
sys.stdout.write('.')
if i == 9:
Expand Down

0 comments on commit f1e7024

Please sign in to comment.