Skip to content

Commit

Permalink
Removed WireMock since it had some issues. Incorporated review feedba…
Browse files Browse the repository at this point in the history
…cks.
  • Loading branch information
shivam-maharshi committed Oct 21, 2016
1 parent 09902d8 commit 6341401
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 194 deletions.
4 changes: 3 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ LICENSE file.
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="EmptyBlock">
<property name="option" value="text"/>
</module>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
Expand Down
48 changes: 26 additions & 22 deletions core/src/main/java/com/yahoo/ycsb/workloads/RestWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
Expand Down Expand Up @@ -165,27 +164,32 @@ public static DiscreteGenerator createOperationGenerator(final Properties p) {
private static NumberGenerator getKeyChooser(String requestDistrib, int recordCount, double zipfContant,
Properties p) throws WorkloadException {
NumberGenerator keychooser = null;
if (requestDistrib.compareTo("exponential") == 0) {
double percentile = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_PERCENTILE_PROPERTY,
ExponentialGenerator.EXPONENTIAL_PERCENTILE_DEFAULT));
double frac = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_FRAC_PROPERTY,
ExponentialGenerator.EXPONENTIAL_FRAC_DEFAULT));
keychooser = new ExponentialGenerator(percentile, recordCount * frac);
} else if (requestDistrib.compareTo("uniform") == 0) {
keychooser = new UniformIntegerGenerator(0, recordCount - 1);
} else if (requestDistrib.compareTo("zipfian") == 0) {
keychooser = new ZipfianGenerator(recordCount, zipfContant);
} else if (requestDistrib.compareTo("latest") == 0) {
// TODO: To be implemented.
System.err.println("Latest request distribution is not supported");
} else if (requestDistrib.equals("hotspot")) {
double hotsetfraction = Double

switch(requestDistrib) {
case "exponential":
double percentile = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_PERCENTILE_PROPERTY,
ExponentialGenerator.EXPONENTIAL_PERCENTILE_DEFAULT));
double frac = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_FRAC_PROPERTY,
ExponentialGenerator.EXPONENTIAL_FRAC_DEFAULT));
keychooser = new ExponentialGenerator(percentile, recordCount * frac);
break;
case "uniform":
keychooser = new UniformIntegerGenerator(0, recordCount - 1);
break;
case "zipfian":
keychooser = new ZipfianGenerator(recordCount, zipfContant);
break;
case "latest":
throw new WorkloadException("Latest request distribution is not supported for RestWorkload.");
case "hotspot":
double hotsetfraction = Double
.parseDouble(p.getProperty(HOTSPOT_DATA_FRACTION, HOTSPOT_DATA_FRACTION_DEFAULT));
double hotopnfraction = Double
double hotopnfraction = Double
.parseDouble(p.getProperty(HOTSPOT_OPN_FRACTION, HOTSPOT_OPN_FRACTION_DEFAULT));
keychooser = new HotspotIntegerGenerator(0, recordCount - 1, hotsetfraction, hotopnfraction);
} else {
throw new WorkloadException("Unknown request distribution \"" + requestDistrib + "\"");
keychooser = new HotspotIntegerGenerator(0, recordCount - 1, hotsetfraction, hotopnfraction);
break;
default:
throw new WorkloadException("Unknown request distribution \"" + requestDistrib + "\"");
}
return keychooser;
}
Expand All @@ -209,9 +213,9 @@ protected static NumberGenerator getFieldLengthGenerator(Properties p) throws Wo
/**
* Reads the trace file and returns a URL map.
*/
private static synchronized Map<Integer, String> getTrace(String filePath, int recordCount)
private static Map<Integer, String> getTrace(String filePath, int recordCount)
throws WorkloadException {
Map<Integer, String> urlMap = new ConcurrentHashMap<Integer, String>();
Map<Integer, String> urlMap = new HashMap<Integer, String>();
int count = 0;
String line;
try {
Expand Down
37 changes: 1 addition & 36 deletions rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
<httpcore.version>4.4.4</httpcore.version>
<junit.version>4.12</junit.version>
<system-rules.version>1.16.0</system-rules.version>
<wiremock.version>1.57</wiremock.version>
<skipTests>true</skipTests>
</properties>

<dependencies>
Expand Down Expand Up @@ -60,17 +58,6 @@
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>${system-rules.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
Expand Down Expand Up @@ -124,27 +111,5 @@
<version>${tomcat.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
41 changes: 26 additions & 15 deletions rest/src/main/java/com/yahoo/ycsb/webservice/rest/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Vector;
import java.util.zip.GZIPInputStream;

import javax.ws.rs.HttpMethod;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
Expand All @@ -53,7 +55,7 @@
* Class responsible for making web service requests for benchmarking purpose.
* Using Apache HttpClient over standard Java HTTP API as this is more flexible
* and provides better functionality. For example HttpClient can automatically
* handle Redirects and Proxy Authentication which the standard Java API don't.
* handle redirects and proxy authentication which the standard Java API can't.
*/
public class RestClient extends DB {

Expand All @@ -64,21 +66,21 @@ public class RestClient extends DB {
private static final String LOG_ENABLED = "log.enable";
private static final String HEADERS = "headers";
private static final String COMPRESSED_RESPONSE = "response.compression";
private static boolean compressedResponse;
private static boolean logEnabled;
private boolean compressedResponse;
private boolean logEnabled;
private String urlPrefix;
private Properties props;
private String[] headers;
private CloseableHttpClient client;
private static int conTimeout = 10000;
private static int readTimeout = 10000;
private static int execTimeout = 10000;
private int conTimeout = 10000;
private int readTimeout = 10000;
private int execTimeout = 10000;
private volatile Criteria requestTimedout = new Criteria(false);

@Override
public void init() throws DBException {
props = getProperties();
urlPrefix = props.getProperty(URL_PREFIX, "127.0.0.1:8080");
urlPrefix = props.getProperty(URL_PREFIX, "http://127.0.0.1:8080");
conTimeout = Integer.valueOf(props.getProperty(CON_TIMEOUT, "10")) * 1000;
readTimeout = Integer.valueOf(props.getProperty(READ_TIMEOUT, "10")) * 1000;
execTimeout = Integer.valueOf(props.getProperty(EXEC_TIMEOUT, "10")) * 1000;
Expand All @@ -104,7 +106,7 @@ public Status read(String table, String endpoint, Set<String> fields, HashMap<St
try {
responseCode = httpGet(urlPrefix + endpoint, result);
} catch (Exception e) {
responseCode = handleExceptions(e);
responseCode = handleExceptions(e, urlPrefix + endpoint, HttpMethod.GET);
}
if (logEnabled) {
System.out.println(new StringBuilder("GET Request: ").append(urlPrefix).append(endpoint)
Expand All @@ -119,7 +121,7 @@ public Status insert(String table, String endpoint, HashMap<String, ByteIterator
try {
responseCode = httpExecute(new HttpPost(urlPrefix + endpoint), values.get("data").toString());
} catch (Exception e) {
responseCode = handleExceptions(e);
responseCode = handleExceptions(e, urlPrefix + endpoint, HttpMethod.POST);
}
if (logEnabled) {
System.out.println(new StringBuilder("POST Request: ").append(urlPrefix).append(endpoint)
Expand All @@ -134,7 +136,7 @@ public Status delete(String table, String endpoint) {
try {
responseCode = httpDelete(urlPrefix + endpoint);
} catch (Exception e) {
responseCode = handleExceptions(e);
responseCode = handleExceptions(e, urlPrefix + endpoint, HttpMethod.DELETE);
}
if (logEnabled) {
System.out.println(new StringBuilder("DELETE Request: ").append(urlPrefix).append(endpoint)
Expand All @@ -149,7 +151,7 @@ public Status update(String table, String endpoint, HashMap<String, ByteIterator
try {
responseCode = httpExecute(new HttpPut(urlPrefix + endpoint), values.get("data").toString());
} catch (Exception e) {
responseCode = handleExceptions(e);
responseCode = handleExceptions(e, urlPrefix + endpoint, HttpMethod.PUT);
}
if (logEnabled) {
System.out.println(new StringBuilder("PUT Request: ").append(urlPrefix).append(endpoint)
Expand Down Expand Up @@ -183,7 +185,13 @@ private Status getStatus(int responseCode) {
return Status.OK;
}

private int handleExceptions(Exception e) {
private int handleExceptions(Exception e, String url, String method) {
if (logEnabled) {
System.out.println(new StringBuilder(method).append(" Request: ").append(url).append(" | ")
.append(e.getClass().getName()).append(" occured | Error message: ")
.append(e.getMessage()).toString());
}

if (e instanceof ClientProtocolException) {
return 400;
}
Expand Down Expand Up @@ -315,9 +323,8 @@ public void run() {
try {
Thread.sleep(timeout);
this.timedout.setIsSatisfied(true);
} catch (InterruptedException e) {
// Do nothing. Kept just to remove Check-style build error.
byte a = 0;
} catch (InterruptedException myException) {
// Do nothing.
}
}

Expand Down Expand Up @@ -350,6 +357,10 @@ public void setIsSatisfied(boolean satisfied) {
class TimeoutException extends RuntimeException {

private static final long serialVersionUID = 1L;

public TimeoutException() {
super("HTTP Request exceeded execution time limit.");
}

}

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

import com.yahoo.ycsb.Client;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.webservice.rest.Utils;

/**
* Integration test cases to verify the end to end working of the rest-binding
Expand All @@ -64,12 +65,12 @@ public class IntegrationTest {
private static final String WORKLOAD_FILEPATH = IntegrationTest.class.getClassLoader().getResource("workload_rest").getPath();
private static final String TRACE_FILEPATH = IntegrationTest.class.getClassLoader().getResource("trace.txt").getPath();
private static final String ERROR_TRACE_FILEPATH = IntegrationTest.class.getClassLoader().getResource("error_trace.txt").getPath();
private static final String RESULTS_FILEPATH = IntegrationTest.class.getClassLoader().getResource("").getPath() + "results.txt";
private static final String RESULTS_FILEPATH = IntegrationTest.class.getClassLoader().getResource(".").getPath() + "results.txt";

@BeforeClass
public static void init() throws ServletException, LifecycleException, FileNotFoundException, IOException,
DBException, InterruptedException {
String webappDirLocation = IntegrationTest.class.getClassLoader().getResource("").getPath() + "/WebContent";
String webappDirLocation = IntegrationTest.class.getClassLoader().getResource("WebContent").getPath();
while (!Utils.available(port)) {
port++;
}
Expand Down
Loading

0 comments on commit 6341401

Please sign in to comment.