Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ class ReposeContainerLauncher extends ReposeLauncher {
String rootWarLocation
String[] appWars
String debugPort
def classPaths = []

def boolean debugEnabled
def boolean doSuspend
boolean debugEnabled
boolean doSuspend

def clock = new SystemClock()

def ReposeConfigurationProvider configurationProvider
ReposeConfigurationProvider configurationProvider

ReposeContainerLauncher(ReposeConfigurationProvider configurationProvider, String containerJar,
String clusterId, String nodeId,
Expand All @@ -54,15 +53,14 @@ class ReposeContainerLauncher extends ReposeLauncher {
this.nodeId = nodeId
this.reposePort = reposePort
this.rootWarLocation = rootWarLocation

this.appWars = appWars
}

@Override
void start() {
String configDirectory = configurationProvider.getReposeConfigDir()

String webXmlOverrides = "";
String webXmlOverrides = ""

if (debugEnabled) {
if (!debugPort) {
Expand Down Expand Up @@ -91,8 +89,8 @@ class ReposeContainerLauncher extends ReposeLauncher {
def th = new Thread({
this.process = cmd.execute()
// TODO: This should probably go somewhere else and not just be consumed to the garbage.
this.process.consumeProcessOutput(System.out, System.err)
});
this.process.consumeProcessOutput(System.out as Appendable, System.err as Appendable)
})

th.run()
th.join()
Expand All @@ -116,7 +114,7 @@ class ReposeContainerLauncher extends ReposeLauncher {

void stop(int timeout, boolean throwExceptionOnKill) {
try {
println("Stopping Repose");
println("Stopping Repose")
this.process.destroy()

print("Waiting for Repose Container to shutdown")
Expand All @@ -128,39 +126,12 @@ class ReposeContainerLauncher extends ReposeLauncher {
println()
} catch (IOException ioex) {
this.process.waitForOrKill(5000)
killIfUp()
if (throwExceptionOnKill) {
throw new TimeoutException("An error occurred while attempting to stop Repose Controller. Reason: " + ioex.getMessage());
}
}
}

private void killIfUp() {
String processes = TestUtils.getJvmProcesses()
def regex = /(\d*) ROOT.war .*/
def matcher = (processes =~ regex)
if (matcher.size() > 0) {

for (int i = 1; i <= matcher.size(); i++) {
String pid = matcher[0][i]

if (pid != null && !pid.isEmpty()) {
println("Killing running repose-valve process: " + pid)
Runtime rt = Runtime.getRuntime();
if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1)
rt.exec("taskkill " + pid.toInteger());
else
rt.exec("kill -9 " + pid.toInteger());
}
throw new TimeoutException("An error occurred while attempting to stop Repose Controller. Reason: " + ioex.getMessage())
}
}
}

@Override
boolean areAnyUp() {
return TestUtils.getJvmProcesses().contains("ROOT.war")
}

@Override
void enableDebug() {
this.debugEnabled = true
Expand All @@ -171,9 +142,4 @@ class ReposeContainerLauncher extends ReposeLauncher {
this.debugEnabled = true
this.doSuspend = true
}

@Override
void addToClassPath(String path) {
classPaths.add(path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
*/
package org.openrepose.framework.test

import org.apache.http.client.ClientProtocolException
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.DefaultHttpClient
import org.linkedin.util.clock.SystemClock

import static org.linkedin.groovy.util.concurrent.GroovyConcurrentUtils.waitForCondition

Expand All @@ -36,8 +36,6 @@ abstract class ReposeLauncher {

abstract void enableDebug()

abstract boolean areAnyUp()

boolean isUp() {
this.process?.isAlive() ?: false
}
Expand All @@ -49,28 +47,22 @@ abstract class ReposeLauncher {
*/
abstract void enableSuspend()

abstract void addToClassPath(String path)

def waitForNon500FromUrl(url, int timeoutInSeconds = 60, int intervalInSeconds = 2) {

static def waitForNon500FromUrl(String url, int timeoutInSeconds = 60, int intervalInSeconds = 2) {
waitForResponseCodeFromUrl(url, timeoutInSeconds, intervalInSeconds) { code -> code < 500 }
}

def waitForDesiredResponseCodeFromUrl(url, desiredCodes, timeoutInSeconds = 60, int intervalInSeconds = 2) {

static def waitForDesiredResponseCodeFromUrl(String url, desiredCodes, timeoutInSeconds = 60, int intervalInSeconds = 2) {
waitForResponseCodeFromUrl(url, timeoutInSeconds, intervalInSeconds) { code -> code in desiredCodes }
}

def waitForResponseCodeFromUrl(url, timeoutInSeconds, int intervalInSeconds, isResponseAcceptable) {

static def waitForResponseCodeFromUrl(String url, timeoutInSeconds, int intervalInSeconds, isResponseAcceptable) {
print("\n\nWaiting for repose to start at ${url} \n\n")
waitForCondition(clock, "${timeoutInSeconds}s", "${intervalInSeconds}s") {
waitForCondition(SystemClock.INSTANCE, "${timeoutInSeconds}s", "${intervalInSeconds}s") {
try {
print(".")
HttpClient client = new DefaultHttpClient()
isResponseAcceptable(client.execute(new HttpGet(url)).statusLine.statusCode)
} catch (IOException ignored) {
} catch (ClientProtocolException ignored) {
}
}
println()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ class ReposeValveLauncher extends ReposeLauncher {
}

void start(Map params) {

boolean killOthersBeforeStarting = true
if (params.containsKey("killOthersBeforeStarting")) {
killOthersBeforeStarting = params.killOthersBeforeStarting
}
boolean waitOnJmxAfterStarting = true
if (params.containsKey("waitOnJmxAfterStarting")) {
waitOnJmxAfterStarting = params.waitOnJmxAfterStarting
Expand All @@ -92,15 +87,14 @@ class ReposeValveLauncher extends ReposeLauncher {
String clusterId = params.get('clusterId', "")
String nodeId = params.get('nodeId', "")

start(killOthersBeforeStarting, waitOnJmxAfterStarting, clusterId, nodeId)
start(waitOnJmxAfterStarting, clusterId, nodeId)
}

/**
* TODO: need to know what node in the system model we care about. There might be many, for multiple local node testing...
* @param killOthersBeforeStarting
* @param waitOnJmxAfterStarting
*/
void start(boolean killOthersBeforeStarting, boolean waitOnJmxAfterStarting, String clusterId, String nodeId) {
void start(boolean waitOnJmxAfterStarting, String clusterId, String nodeId) {

File jarFile = new File(reposeJar)
if (!jarFile.exists() || !jarFile.isFile()) {
Expand All @@ -112,14 +106,6 @@ class ReposeValveLauncher extends ReposeLauncher {
throw new FileNotFoundException("Missing or invalid configuration folder.")
}

if (killOthersBeforeStarting) {
waitForCondition(clock, '5s', '1s') {
killIfUp()
!isUp()
}
}

def jmxprops = ""
def debugProps = ""
def jacocoProps = ""
def classPath = ""
Expand All @@ -140,7 +126,7 @@ class ReposeValveLauncher extends ReposeLauncher {
if (!jmxPort) {
jmxPort = PortFinder.instance.getNextOpenPort()
}
jmxprops = "-Dspock=spocktest -Dcom.sun.management.jmxremote.port=${jmxPort} -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=true"
def jmxprops = "-Dspock=spocktest -Dcom.sun.management.jmxremote.port=${jmxPort} -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=true"

if (!classPaths.isEmpty()) {
classPath = "-cp " + (classPaths as Set).join(";")
Expand All @@ -162,11 +148,11 @@ class ReposeValveLauncher extends ReposeLauncher {
newEnv.putAll(System.getenv())

additionalEnvironment.each { k, v ->
newEnv.put(k, v) //Should override anything, if there's anything to override
newEnv.put(k as String, v as String) //Should override anything, if there's anything to override
}
def envList = newEnv.collect { k, v -> "$k=$v" }
this.process = cmd.execute(envList, null)
this.process.consumeProcessOutput(System.out, System.err)
this.process.consumeProcessOutput(System.out as Appendable, System.err as Appendable)
})

th.run()
Expand All @@ -184,17 +170,17 @@ class ReposeValveLauncher extends ReposeLauncher {
print("Waiting for repose auto-guessed node to start: ")
}

waitForCondition(clock, '60s', '1s') {
waitForCondition(clock, '180s', '1s') {
isReposeNodeUp(clusterId, nodeId)
}
}
}

def connectViaJmxRemote(jmxUrl) {
def connectViaJmxRemote(String jmxUrl) {
try {
jmx = new JmxClient(jmxUrl)
return true
} catch (Exception ex) {
} catch (Exception ignored) {
return false
}
}
Expand All @@ -217,7 +203,7 @@ class ReposeValveLauncher extends ReposeLauncher {

void stop(int timeout, boolean throwExceptionOnKill) {
try {
println("Stopping Repose");
println("Stopping Repose")
this.process?.destroy()

print("Waiting for Repose to shutdown")
Expand All @@ -229,12 +215,9 @@ class ReposeValveLauncher extends ReposeLauncher {
println()
} catch (IOException ioex) {
this.process.waitForOrKill(5000)
killIfUp()
if (throwExceptionOnKill) {
throw new TimeoutException("An error occurred while attempting to stop Repose Controller. Reason: ${ioex.getMessage()}", ioex)
throw new TimeoutException("An error occurred while attempting to stop Repose Controller. Reason: ${ioex.getMessage()}")
}
} finally {
configurationProvider.cleanConfigDirectory()
}
}

Expand All @@ -249,11 +232,6 @@ class ReposeValveLauncher extends ReposeLauncher {
this.doSuspend = true
}

@Override
void addToClassPath(String path) {
classPaths.add(path)
}

/**
* This takes a single string and will append it to the list of environment vars to be set for the .execute() method
* Following docs from: http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#execute%28java.util.List,%20java.io.File%29
Expand Down Expand Up @@ -296,12 +274,12 @@ class ReposeValveLauncher extends ReposeLauncher {
}

// First query for the mbean. The name of the mbean is partially configurable, so search for a match.
def HashSet cfgBean = (HashSet) jmx.getMBeans("*org.openrepose.core.services.jmx:type=ConfigurationInformation")
HashSet cfgBean = (HashSet) jmx.getMBeans("*org.openrepose.core.services.jmx:type=ConfigurationInformation")
if (cfgBean == null || cfgBean.isEmpty()) {
return false
}

def String beanName = cfgBean.iterator().next().name.toString()
String beanName = cfgBean.iterator().next().name.toString()

//Doing the JMX invocation here, because it's kinda ugly
Object[] opParams = [clusterId, nodeId]
Expand All @@ -311,31 +289,4 @@ class ReposeValveLauncher extends ReposeLauncher {
def nodeIsReady = jmx.server.invoke(new ObjectName(beanName), "isNodeReady", opParams, opSignature)
return nodeIsReady
}

@Override
boolean areAnyUp() {
println TestUtils.getJvmProcesses()
return TestUtils.getJvmProcesses().contains("repose-valve.jar")
}

private static void killIfUp() {
String processes = TestUtils.getJvmProcesses()
def regex = /(\d*) repose-valve.jar .*spocktest .*/
def matcher = (processes =~ regex)
if (matcher.size() > 0) {

for (int i = 1; i <= matcher.size(); i++) {
String pid = matcher[0][i]

if (pid != null && !pid.isEmpty()) {
println("Killing running repose-valve process: " + pid)
Runtime rt = Runtime.getRuntime();
if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1)
rt.exec("taskkill " + pid.toInteger());
else
rt.exec("kill -9 " + pid.toInteger());
}
}
}
}
}
Loading