parent
710f3eed56
commit
67b0a9e206
|
@ -163,23 +163,6 @@ public class Scenario {
|
|||
}
|
||||
}
|
||||
|
||||
// private static Behavior extractBehavior(BehaviorModel behaviorModel) {
|
||||
// Behavior behavior = Behavior.buildWith(behaviorModel);
|
||||
// behavior.setName(behaviorModel.getName());
|
||||
// behavior.setUse(behaviorModel.getUse());
|
||||
// behavior.setId(behaviorModel.getId());
|
||||
// behavior.setParameters(new Parameter[behaviorModel.getParameters()
|
||||
// .size()]);
|
||||
//
|
||||
// for (int k = 0; k < behaviorModel.getParameters().size(); k++) {
|
||||
// ParameterModel parameterModel = behaviorModel.getParameters()
|
||||
// .get(k);
|
||||
// Parameter parameter = extractParameter(parameterModel);
|
||||
// behavior.getParameters()[k] = parameter;
|
||||
// }
|
||||
// return behavior;
|
||||
// }
|
||||
|
||||
private static UsePlugin extractUsePlugin(UsePluginModel usePluginModel) {
|
||||
UsePlugin usePlugin = new UsePlugin();
|
||||
usePlugin.setId(usePluginModel.getId());
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testResult")
|
||||
public class TestResult implements Serializable {
|
||||
private static final long serialVersionUID = -370091935554266546L;
|
||||
private UUID runId;
|
||||
private int poolSize;
|
||||
private int totalCount;
|
||||
private Date startDate;
|
||||
private long elapsedTime;
|
||||
private int successCount;
|
||||
private int failCount;
|
||||
private int finishedCount;
|
||||
private double averageResponseTime;
|
||||
private List<TestResultItem> results;
|
||||
|
||||
@XmlElement
|
||||
public UUID getRunId() {
|
||||
return runId;
|
||||
}
|
||||
|
||||
public void setRunId(UUID runId) {
|
||||
this.runId = runId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getPoolSize() {
|
||||
return poolSize;
|
||||
}
|
||||
|
||||
public void setPoolSize(int poolSize) {
|
||||
this.poolSize = poolSize;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public long getElapsedTime() {
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
public void setElapsedTime(long elapsedTime) {
|
||||
this.elapsedTime = elapsedTime;
|
||||
}
|
||||
|
||||
public int getSuccessCount() {
|
||||
return successCount;
|
||||
}
|
||||
|
||||
public void setSuccessCount(int successCount) {
|
||||
this.successCount = successCount;
|
||||
}
|
||||
|
||||
public int getFailCount() {
|
||||
return failCount;
|
||||
}
|
||||
|
||||
public void setFailCount(int failCount) {
|
||||
this.failCount = failCount;
|
||||
}
|
||||
|
||||
public int getFinishedCount() {
|
||||
return finishedCount;
|
||||
}
|
||||
|
||||
public void setFinishedCount(int finishedCount) {
|
||||
this.finishedCount = finishedCount;
|
||||
}
|
||||
|
||||
public double getAverageResponseTime() {
|
||||
return averageResponseTime;
|
||||
}
|
||||
|
||||
public void setAverageResponseTime(double averageResponseTime) {
|
||||
this.averageResponseTime = averageResponseTime;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name = "results")
|
||||
@XmlElement(name = "result")
|
||||
public List<TestResultItem> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(List<TestResultItem> results) {
|
||||
this.results = results;
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package org.bench4q.agent.scenario;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "testResultItem")
|
||||
public class TestResultItem implements Serializable {
|
||||
private static final long serialVersionUID = 3307951299814477213L;
|
||||
private UUID id;
|
||||
private String pluginId;
|
||||
private String pluginName;
|
||||
private String behaviorName;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
private long responseTime;
|
||||
private boolean success;
|
||||
|
||||
@XmlElement
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getPluginId() {
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public void setPluginId(String pluginId) {
|
||||
this.pluginId = pluginId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getPluginName() {
|
||||
return pluginName;
|
||||
}
|
||||
|
||||
public void setPluginName(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getBehaviorName() {
|
||||
return behaviorName;
|
||||
}
|
||||
|
||||
public void setBehaviorName(String behaviorName) {
|
||||
this.behaviorName = behaviorName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Date startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Date endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public long getResponseTime() {
|
||||
return responseTime;
|
||||
}
|
||||
|
||||
public void setResponseTime(long responseTime) {
|
||||
this.responseTime = responseTime;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
}
|
|
@ -34,4 +34,121 @@ public class MainTest {
|
|||
.get("isToSaveDetailResult")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertEquals(2, threeSumClosest(new int[] { -1, -4, 1, 2 }, 1));
|
||||
}
|
||||
|
||||
public int threeSumClosest(int[] num, int target) {
|
||||
int[] arrayAfterSort = sort(num);
|
||||
int result = Integer.MAX_VALUE;
|
||||
int indexOfJustGEtarget = indexOfJustGEtarget(target, arrayAfterSort,
|
||||
-1, -1);
|
||||
// LeftSide
|
||||
for (int i = indexOfJustGEtarget; i >= 0; i--) {
|
||||
result = whichCloser(
|
||||
target,
|
||||
result,
|
||||
towSumClosest(i, arrayAfterSort, target - arrayAfterSort[i])
|
||||
+ arrayAfterSort[i]);
|
||||
}
|
||||
// RightSide
|
||||
for (int i = indexOfJustGEtarget + 1; i < arrayAfterSort.length; i++) {
|
||||
result = whichCloser(
|
||||
target,
|
||||
result,
|
||||
towSumClosest(i, arrayAfterSort, target - arrayAfterSort[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int whichCloser(int target, int param1, int param2) {
|
||||
return getDistance(target, param1) > getDistance(target, param2) ? param2
|
||||
: param1;
|
||||
}
|
||||
|
||||
private int getDistance(int target, int param1) {
|
||||
return (target - param1) > 0 ? target - param1 : param1 - target;
|
||||
}
|
||||
|
||||
private int indexOfJustGEtarget(int target, int[] arrayAfterSort,
|
||||
int firstIndexCannotBeUsed, int secondIndexCannotBeUsed) {
|
||||
int i = 0;
|
||||
for (; i < arrayAfterSort.length; i++) {
|
||||
if (i == firstIndexCannotBeUsed || i == secondIndexCannotBeUsed) {
|
||||
continue;
|
||||
}
|
||||
if (arrayAfterSort[i] >= target)
|
||||
break;
|
||||
}
|
||||
if (i == arrayAfterSort.length) {
|
||||
for (int j = arrayAfterSort.length - 1; j >= arrayAfterSort.length - 3; j--) {
|
||||
if (j == firstIndexCannotBeUsed || j == secondIndexCannotBeUsed) {
|
||||
continue;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
return -1;
|
||||
} else {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// find twoSumClosest from num, target is num[index], and the index can't be
|
||||
// used.
|
||||
private int towSumClosest(final int firstLoopIndex, int[] arrayAfterSort,
|
||||
int realTarget) {
|
||||
int result = Integer.MAX_VALUE;
|
||||
int indexJustGETarget = indexOfJustGEtarget(realTarget, arrayAfterSort,
|
||||
firstLoopIndex, -1);
|
||||
// Left side
|
||||
for (int i = indexJustGETarget; i >= 0; i--) {
|
||||
if (i == firstLoopIndex) {
|
||||
continue;
|
||||
}
|
||||
result = whichCloser(realTarget, result,
|
||||
oneClosest(firstLoopIndex, i, arrayAfterSort, realTarget)
|
||||
+ arrayAfterSort[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int oneClosest(int firstLoopIndex, int secondLoopIndex,
|
||||
int[] arrayAfterSort, int realTarget) {
|
||||
int indexJustGETarget = indexOfJustGEtarget(realTarget, arrayAfterSort,
|
||||
firstLoopIndex, secondLoopIndex);
|
||||
int indexJustLETarget = -1;
|
||||
// Just find Left side one
|
||||
for (int i = indexJustGETarget - 1; i >= 0
|
||||
&& i >= indexJustGETarget - 3; i--) {
|
||||
if (i == firstLoopIndex || i == secondLoopIndex) {
|
||||
continue;
|
||||
}
|
||||
indexJustLETarget = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (indexJustLETarget == -1) {
|
||||
return arrayAfterSort[indexJustGETarget];
|
||||
} else if (indexJustGETarget == arrayAfterSort.length
|
||||
|| indexJustGETarget == -1) {
|
||||
return arrayAfterSort[indexJustLETarget];
|
||||
} else {
|
||||
return whichCloser(realTarget, arrayAfterSort[indexJustGETarget],
|
||||
arrayAfterSort[indexJustLETarget]);
|
||||
}
|
||||
}
|
||||
|
||||
private int[] sort(int[] num) {
|
||||
for (int j = 1; j <= num.length - 1; j++) {
|
||||
for (int i = 0; i < num.length - j; i++) {
|
||||
if (num[i] > num[i + 1]) {
|
||||
int temp = num[i + 1];
|
||||
num[i + 1] = num[i];
|
||||
num[i] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue