mirror of https://github.com/apache/lucene.git
don't hang if Solr example fails to start
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1407083 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1897641123
commit
c85875c33e
|
@ -463,27 +463,29 @@ def cygwinifyPaths(command):
|
|||
if '; ant ' in command: command = reUnixPath.sub(unix2win, command)
|
||||
return command
|
||||
|
||||
def printFileContents(fileName):
|
||||
|
||||
# Assume log file was written in system's default encoding, but
|
||||
# even if we are wrong, we replace errors ... the ASCII chars
|
||||
# (which is what we mostly care about eg for the test seed) should
|
||||
# still survive:
|
||||
txt = codecs.open(fileName, 'r', encoding=sys.getdefaultencoding(), errors='replace').read()
|
||||
|
||||
# Encode to our output encoding (likely also system's default
|
||||
# encoding):
|
||||
bytes = txt.encode(sys.stdout.encoding, errors='replace')
|
||||
|
||||
# Decode back to string and print... we should hit no exception here
|
||||
# since all errors have been replaced:
|
||||
print(codecs.getdecoder(sys.stdout.encoding)(bytes)[0])
|
||||
print()
|
||||
|
||||
def run(command, logFile):
|
||||
if cygwin: command = cygwinifyPaths(command)
|
||||
if os.system('%s > %s 2>&1' % (command, logFile)):
|
||||
logPath = os.path.abspath(logFile)
|
||||
print('\ncommand "%s" failed:' % command)
|
||||
|
||||
# Assume log file was written in system's default encoding, but
|
||||
# even if we are wrong, we replace errors ... the ASCII chars
|
||||
# (which is what we mostly care about eg for the test seed) should
|
||||
# still survive:
|
||||
txt = codecs.open(logPath, 'r', encoding=sys.getdefaultencoding(), errors='replace').read()
|
||||
|
||||
# Encode to our output encoding (likely also system's default
|
||||
# encoding):
|
||||
bytes = txt.encode(sys.stdout.encoding, errors='replace')
|
||||
|
||||
# Decode back to string and print... we should hit no exception here
|
||||
# since all errors have been replaced:
|
||||
print(codecs.getdecoder(sys.stdout.encoding)(bytes)[0])
|
||||
print()
|
||||
|
||||
printFileContents(logFile)
|
||||
raise RuntimeError('command "%s" failed; see log file %s' % (command, logPath))
|
||||
|
||||
def verifyDigests(artifact, urlString, tmpDir):
|
||||
|
@ -762,19 +764,29 @@ def readSolrOutput(p, startupEvent, failureEvent, logFile):
|
|||
f = open(logFile, 'wb')
|
||||
try:
|
||||
while True:
|
||||
line = p.readline()
|
||||
line = p.stderr.readline()
|
||||
if len(line) == 0:
|
||||
p.poll()
|
||||
if not startupEvent.isSet():
|
||||
failureEvent.set()
|
||||
startupEvent.set()
|
||||
break
|
||||
f.write(line)
|
||||
f.flush()
|
||||
# print 'SOLR: %s' % line.strip()
|
||||
if not startupEvent.isSet() and line.find(b'Started SocketConnector@0.0.0.0:8983') != -1:
|
||||
startupEvent.set()
|
||||
#print('SOLR: %s' % line.strip())
|
||||
if not startupEvent.isSet():
|
||||
if line.find(b'Started SocketConnector@0.0.0.0:8983') != -1:
|
||||
startupEvent.set()
|
||||
elif p.poll() is not None:
|
||||
failureEvent.set()
|
||||
startupEvent.set()
|
||||
break
|
||||
except:
|
||||
print()
|
||||
print('Exception reading Solr output:')
|
||||
traceback.print_exc()
|
||||
failureEvent.set()
|
||||
startupEvent.set()
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
|
@ -786,16 +798,24 @@ def testSolrExample(unpackPath, javaPath, isSrc):
|
|||
env.update(os.environ)
|
||||
env['JAVA_HOME'] = javaPath
|
||||
env['PATH'] = '%s/bin:%s' % (javaPath, env['PATH'])
|
||||
server = subprocess.Popen(['java', '-jar', 'start.jar'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
|
||||
server = subprocess.Popen(['java', '-jar', 'start.jar'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, env=env)
|
||||
|
||||
startupEvent = threading.Event()
|
||||
failureEvent = threading.Event()
|
||||
serverThread = threading.Thread(target=readSolrOutput, args=(server.stderr, startupEvent, failureEvent, logFile))
|
||||
serverThread = threading.Thread(target=readSolrOutput, args=(server, startupEvent, failureEvent, logFile))
|
||||
serverThread.setDaemon(True)
|
||||
serverThread.start()
|
||||
|
||||
# Make sure Solr finishes startup:
|
||||
startupEvent.wait()
|
||||
if not startupEvent.wait(1800):
|
||||
raise RuntimeError('startup took more than 30 minutes')
|
||||
if failureEvent.isSet():
|
||||
logFile = os.path.abspath(logFile)
|
||||
print
|
||||
print('Startup failed; see log %s' % logFile)
|
||||
printFileContents(logFile)
|
||||
raise RuntimeError('failure on startup; see log %s' % logFile)
|
||||
|
||||
print(' startup done')
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue