Skip to content

Commit

Permalink
Incorporated Risdenk code feedbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-maharshi committed Oct 8, 2016
1 parent 2be10a4 commit 075f789
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
18 changes: 9 additions & 9 deletions core/src/main/java/com/yahoo/ycsb/workloads/RestWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public class RestWorkload extends CoreWorkload {
private static final String UPDATE_ZIPFIAN_CONSTANT_DEAFULT = "0.99";
private static final String UPDATE_RECORD_COUNT_PROPERTY = "updaterecordcount";

private static Map<Integer, String> readUrlMap;
private static Map<Integer, String> insertUrlMap;
private static Map<Integer, String> deleteUrlMap;
private static Map<Integer, String> updateUrlMap;
private static int readRecordCount;
private static int insertRecordCount;
private static int deleteRecordCount;
private static int updateRecordCount;
private Map<Integer, String> readUrlMap;
private Map<Integer, String> insertUrlMap;
private Map<Integer, String> deleteUrlMap;
private Map<Integer, String> updateUrlMap;
private int readRecordCount;
private int insertRecordCount;
private int deleteRecordCount;
private int updateRecordCount;
private NumberGenerator readKeyChooser;
private NumberGenerator insertKeyChooser;
private NumberGenerator deleteKeyChooser;
Expand Down Expand Up @@ -275,7 +275,7 @@ else if (opType == 3)
public void doTransactionRead(DB db) {
HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
db.read(null, getNextURL(1), null, result);
}
}

@Override
public void doTransactionInsert(DB db) {
Expand Down
2 changes: 1 addition & 1 deletion rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Clone the YCSB git repository and compile:

git clone git://github.com/brianfrankcooper/YCSB.git
cd YCSB
mvn -pl com.yahoo.ycsb:solr-binding -am clean package
mvn -pl com.yahoo.ycsb:rest-binding -am clean package

### 2. Set Up an HTTP Web Service

Expand Down
18 changes: 12 additions & 6 deletions rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<properties>
<tomcat.version>8.0.28</tomcat.version>
<jersey.version>2.6</jersey.version>
<httpclient.version>4.5.1</httpclient.version>
<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 All @@ -37,28 +43,28 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.4</version>
<version>${httpcore.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.16.0</version>
<version>${system-rules.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>1.57</version>
<version>${wiremock.version}</version>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
Expand Down Expand Up @@ -118,12 +124,12 @@
<version>${tomcat.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.version}</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ public class IntegrationTest {
public final ExpectedSystemExit exit = ExpectedSystemExit.none();

private static int port = 8080;
private static Tomcat tomcat = new Tomcat();
private static final String BASE_DIR = System.getProperty("user.dir");
private static final String WORKLOAD_FILEPATH = new File(BASE_DIR + "/src/test/resources/workload_rest").getAbsolutePath();
private static final String TRACE_FILEPATH = new File(BASE_DIR + "/src/test/resources/trace.txt").getAbsolutePath();
private static final String ERROR_TRACE_FILEPATH = new File(BASE_DIR + "/src/test/resources/error_trace.txt").getAbsolutePath();
private static final String RESULTS_FILEPATH = new File(BASE_DIR + "/src/test/resources/results.txt").getAbsolutePath();
private static Tomcat tomcat;
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";

@BeforeClass
public static void init() throws ServletException, LifecycleException, FileNotFoundException, IOException,
DBException, InterruptedException {
String webappDirLocation = "WebContent/";
String webappDirLocation = IntegrationTest.class.getClassLoader().getResource("").getPath() + "/WebContent";
while (!Utils.available(port)) {
port++;
}
tomcat = new Tomcat();
tomcat.setPort(Integer.valueOf(port));
Context context = tomcat.addWebapp("/webService", new File(webappDirLocation).getAbsolutePath());
Tomcat.addServlet(context, "jersey-container-servlet", resourceConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.zip.GZIPOutputStream;

import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
Expand All @@ -48,7 +50,6 @@
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import com.yahoo.ycsb.webservice.rest.Utils;

/**
* Mocking REST services with the easiest and the most straight forward usage
Expand All @@ -58,8 +59,6 @@
* Various cases like - success, failure, timeout, non-implemented etc have been
* demonstrated.
*/
// Test cases pass for JDK8 but fail for JDK7 due to WireMock.
@Ignore
public class RestClientTest {

@ClassRule
Expand All @@ -82,7 +81,7 @@ public class RestClientTest {
@BeforeClass
public static void init() throws FileNotFoundException, IOException, DBException {
Properties props = new Properties();
props.load(new FileReader("src/test/resources/workload_rest"));
props.load(new FileReader(RestClientTest.class.getClassLoader().getResource("workload_rest").getPath()));
rc.setProperties(props);
rc.init();
ByteArrayOutputStream out = new ByteArrayOutputStream(SUCCESS_RESPONSE.length());
Expand All @@ -103,6 +102,12 @@ public static void cleanUp() throws DBException {
rc.cleanup();
wireMockRule.shutdownServer();
}

// WireMock requires JDK 1.8+ version. Hence must run tests only for JDK > 1.7.
@Before
public void beforeMethod() {
Assume.assumeTrue(Float.parseFloat(System.getProperty("java.specification.version")) > 1.7);
}

// Read success.
@Test
Expand Down
File renamed without changes.

0 comments on commit 075f789

Please sign in to comment.