Skip to content
This repository has been archived by the owner on Jan 1, 2019. It is now read-only.

Commit

Permalink
#25 diff ports on diff hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Pei committed Jul 23, 2016
1 parent 0d1ed9b commit 0a37b41
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/main/java/io/parallec/core/ParallelTaskBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,19 @@ public ParallelTaskBuilder setHttpPort(int port) {

}


/**
* Sets the port variable name such as $PORT
*
* @param port
* the port
* @return the parallel task builder
*/
public ParallelTaskBuilder setHttpPortReplaceable(String portVar) {
this.httpMeta.setRequestPort(portVar);
return this;

}



Expand Down
20 changes: 17 additions & 3 deletions src/main/java/io/parallec/core/actor/ExecutionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ public void onReceive(Object message) {
final String requestUrlPrefixOrig = httpMeta
.getRequestUrlPostfix();
final HttpMethod httpMethod = httpMeta.getHttpMethod();
final int requestPort = Integer.parseInt(httpMeta
.getRequestPort());

String requestPortStrOrig = httpMeta
.getRequestPort();


final boolean pollable = httpMeta.isPollable();

final int maxConcurrency = task.getConcurrency();
Expand Down Expand Up @@ -241,7 +244,18 @@ public void onReceive(Object message) {
.replaceStrByMap(
nodeReqResponse.getRequestParameters(),
requestUrlPrefixOrig);

//add support for port replacement
final String requestPortStr = NodeReqResponse
.replaceStrByMap(
nodeReqResponse.getRequestParameters(),
requestPortStrOrig);
int requestPort = 80;
try{
requestPort = Integer.parseInt(requestPortStr);
}catch(NumberFormatException nfe){
logger.error("Error parsing replacable port with NumberFormatException. "
+ "No valid port for host {}. Now use default port 80", targetHost);
}
//only pass when it is not in manager
final ParallecResponseHandler handler =
task.getConfig().getHandlerExecutionLocation()==HandlerExecutionLocation.MANAGER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ public Channel sessionConnectGenerateChannel(Session session)

ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand(sshMeta.getCommandLine());
// X Forwarding
// channel.setXForwarding(true);

// if run as super user, assuming the input stream expecting a password
if (sshMeta.isRunAsSuperUser()) {
Expand All @@ -183,7 +181,7 @@ public Channel sessionConnectGenerateChannel(Session session)
out.write((sshMeta.getPassword()+"\n").getBytes());
out.flush();
} catch (IOException e) {
e.printStackTrace();
logger.error("error in sessionConnectGenerateChannel for super user", e);
}
} else {
channel.setInputStream(null);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/parallec/core/util/PcErrorMsgUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package io.parallec.core.util;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.http.util.Asserts;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
Expand All @@ -35,6 +36,73 @@ public static void shutdown() throws Exception {
pc.releaseExternalResources();
}

/**
* TODO 20160721 git issue #25
* different requests to different ports
* http://www.jeffpei.com:80/job_b.html http://www.portquiz.com:8080/job_b.html
*/
@Test
public void hitWebsitesMinTargetHostSpecificPortReplacement() {

Map<String, StrStrMap> replacementVarMapNodeSpecific = new HashMap<String, StrStrMap>();
replacementVarMapNodeSpecific.put("portquiz.net",
new StrStrMap().addPair("PORT", "8080"));
replacementVarMapNodeSpecific.put("www.jeffpei.com",
new StrStrMap().addPair("PORT", "80"));

pc.prepareHttpGet("/job_b.html")
.setHttpPortReplaceable("$PORT")
.setConcurrency(1700)
.setTargetHostsFromString(
"portquiz.net www.jeffpei.com")
.setReplacementVarMapNodeSpecific(replacementVarMapNodeSpecific)
.execute(new ParallecResponseHandler() {
@Override
public void onCompleted(ResponseOnSingleTask res,
Map<String, Object> responseContext) {
if(res.getRequest().getHost()=="portquiz.net"){
Assert.assertTrue(
res.getStatusCodeInt()==404);
}else if(res.getRequest().getHost()=="www.jeffpei.com"){
Assert.assertTrue(
res.getStatusCodeInt()==200);
}
logger.info(res.toString());
}
});

}

/**
* trigger the NumberFormatException in execution manager.
*/
@Test
public void hitWebsitesMinTargetHostSpecificPortReplacementErrorCase() {

Map<String, StrStrMap> replacementVarMapNodeSpecific = new HashMap<String, StrStrMap>();
replacementVarMapNodeSpecific.put("portquiz.net",
new StrStrMap().addPair("PORT", "8080"));
replacementVarMapNodeSpecific.put("www.jeffpei.com",
new StrStrMap().addPair("PORT", "80"));

pc.prepareHttpGet("/job_b.html")
.setHttpPortReplaceable("$PORT")
.setConcurrency(1700)
.setTargetHostsFromString(
"localhost www.jeffpei.com")
.setReplacementVarMapNodeSpecific(replacementVarMapNodeSpecific)
.execute(new ParallecResponseHandler() {
@Override
public void onCompleted(ResponseOnSingleTask res,
Map<String, Object> responseContext) {
logger.info(""+res.isError());
}
});

}



/**
* different requests to different target URLs
* http://www.jeffpei.com/job_b.html http://www.restsuperman.com/job_c.html
Expand Down

0 comments on commit 0a37b41

Please sign in to comment.