-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of RUBiS workload rewriting (see #8).
- Loading branch information
Showing
11 changed files
with
1,137 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,40 +27,62 @@ | |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Author: Marco Guazzone ([email protected]), 2013. | ||
*/ | ||
|
||
package radlab.rain.workload.rubis; | ||
|
||
import java.io.IOException; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.http.client.methods.HttpGet; | ||
import radlab.rain.IScoreboard; | ||
import radlab.rain.workload.rubis.model.RubisCategory; | ||
import radlab.rain.workload.rubis.model.RubisUser; | ||
|
||
|
||
/** | ||
* BrowseCategories operation. | ||
* Browse-Categories operation. | ||
* | ||
* @author Marco Guazzone ([email protected]) | ||
*/ | ||
public class BrowseCategoriesOperation extends RubisOperation | ||
{ | ||
|
||
public BrowseCategoriesOperation( boolean interactive, IScoreboard scoreboard ) | ||
public BrowseCategoriesOperation(boolean interactive, IScoreboard scoreboard) | ||
{ | ||
super( interactive, scoreboard ); | ||
super(interactive, scoreboard); | ||
|
||
this._operationName = "Browse Categories"; | ||
this._operationIndex = RubisGenerator.BROWSE_CATEGORIES; | ||
this._mustBeSync = true; | ||
this._operationIndex = RubisGenerator.BROWSE_CATEGORIES_OP; | ||
} | ||
|
||
@Override | ||
public void execute() throws Throwable | ||
{ | ||
RubisCategory category = this.getGenerator().generateCategory(); | ||
|
||
StringBuilder response = this._http.fetchUrl( this.getGenerator().browseCategoriesURL ); | ||
this.trace( this.getGenerator().browseCategoriesURL ); | ||
if ( response.length() == 0 ) | ||
Map<String,String> headers = new HashMap<String,String>(); | ||
headers.put("category", Integer.toString(category.id)); | ||
headers.put("categoryName", category.name); | ||
headers.put("page", "1"); | ||
headers.put("nbOfItems", Integer.toString(this.getGenerator().getNumItemsPerPage())); | ||
if (this.getGenerator().isUserLoggedIn()) | ||
{ | ||
throw new IOException( "Received empty response" ); | ||
RubisUser user = this.getGenerator().getLoggedUser(); | ||
headers.put("nickname", user.nickname); | ||
headers.put("password", user.password); | ||
} | ||
|
||
this.setFailed( false ); | ||
|
||
HttpGet request = new HttpGet(this.getGenerator().getBrowseCategoriesURL()); | ||
StringBuilder response = this.getHttpTransport().fetch(request, headers); | ||
this.trace(this.getGenerator().getBrowseCategoriesURL()); | ||
if (response.length() == 0) | ||
{ | ||
throw new IOException("Received empty response"); | ||
} | ||
|
||
this.setFailed(false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2010, Regents of the University of California | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of the University of California, Berkeley | ||
* nor the names of its contributors may be used to endorse or promote | ||
* products derived from this software without specific prior written | ||
* permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Author: Marco Guazzone ([email protected]), 2013. | ||
*/ | ||
|
||
package radlab.rain.workload.rubis; | ||
|
||
|
||
import java.io.IOException; | ||
import radlab.rain.IScoreboard; | ||
|
||
|
||
/** | ||
* BrowseCategories operation. | ||
* | ||
* @author Marco Guazzone ([email protected]) | ||
*/ | ||
public class BrowseOperation extends RubisOperation | ||
{ | ||
public BrowseOperation(boolean interactive, IScoreboard scoreboard) | ||
{ | ||
super(interactive, scoreboard); | ||
|
||
this._operationName = "Browse"; | ||
this._operationIndex = RubisGenerator.BROWSE_OP; | ||
} | ||
|
||
@Override | ||
public void execute() throws Throwable | ||
{ | ||
StringBuilder response = this.getHttpTransport().fetchUrl(this.getGenerator().getBrowseURL()); | ||
this.trace(this.getGenerator().getBrowseURL()); | ||
if (response.length() == 0) | ||
{ | ||
throw new IOException("Received empty response"); | ||
} | ||
|
||
this.setFailed(false); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/radlab/rain/workload/rubis/BrowseRegionsOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2010, Regents of the University of California | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of the University of California, Berkeley | ||
* nor the names of its contributors may be used to endorse or promote | ||
* products derived from this software without specific prior written | ||
* permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Author: Marco Guazzone ([email protected]), 2013. | ||
*/ | ||
|
||
package radlab.rain.workload.rubis; | ||
|
||
|
||
import java.io.IOException; | ||
import radlab.rain.IScoreboard; | ||
|
||
|
||
/** | ||
* Browse-Regions operation. | ||
* | ||
* @author Marco Guazzone ([email protected]) | ||
*/ | ||
public class BrowseRegionsOperation extends RubisOperation | ||
{ | ||
public BrowseRegionsOperation(boolean interactive, IScoreboard scoreboard) | ||
{ | ||
super(interactive, scoreboard); | ||
|
||
this._operationName = "Browse Regions"; | ||
this._operationIndex = RubisGenerator.BROWSE_REGIONS_OP; | ||
} | ||
|
||
@Override | ||
public void execute() throws Throwable | ||
{ | ||
StringBuilder response = this.getHttpTransport().fetchUrl(this.getGenerator().getBrowseRegionsURL()); | ||
this.trace(this.getGenerator().getBrowseRegionsURL()); | ||
if (response.length() == 0) | ||
{ | ||
throw new IOException("Received empty response"); | ||
} | ||
|
||
this.setFailed(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,41 +27,40 @@ | |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Author: Marco Guazzone ([email protected]), 2013. | ||
*/ | ||
|
||
package radlab.rain.workload.rubis; | ||
|
||
import java.io.IOException; | ||
|
||
import java.io.IOException; | ||
import radlab.rain.IScoreboard; | ||
|
||
|
||
/** | ||
* The Home Page operation is a sample operation. | ||
*/ | ||
public class HomePageOperation extends RubisOperation | ||
{ | ||
public HomePageOperation( boolean interactive, IScoreboard scoreboard ) | ||
public HomePageOperation(boolean interactive, IScoreboard scoreboard) | ||
{ | ||
super( interactive, scoreboard ); | ||
super(interactive, scoreboard); | ||
|
||
this._operationName = "Home Page"; | ||
this._operationIndex = RubisGenerator.HOME_PAGE; | ||
this._operationIndex = RubisGenerator.HOME_PAGE_OP; | ||
} | ||
|
||
@Override | ||
public void execute() throws Throwable | ||
{ | ||
// TODO: Make a request. | ||
//this.trace( "Log a retraceable string for the request." ); | ||
|
||
// TODO: Fill me in. | ||
StringBuilder homeResponse = this._http.fetchUrl( this.getGenerator().homepageURL ); | ||
this.trace( this.getGenerator().homepageURL ); | ||
if( homeResponse.length() == 0 ) | ||
StringBuilder response = this.getHttpTransport().fetchUrl(this.getGenerator().getHomepageURL()); | ||
this.trace(this.getGenerator().getHomepageURL()); | ||
if (response.length() == 0) | ||
{ | ||
throw new IOException( "Received empty response" ); | ||
throw new IOException("Received empty response"); | ||
} | ||
this.setFailed( false ); | ||
|
||
this.setFailed(false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,70 +27,77 @@ | |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
* OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Author: Marco Guazzone ([email protected]), 2013. | ||
*/ | ||
|
||
package radlab.rain.workload.rubis; | ||
|
||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.entity.mime.MultipartEntity; | ||
import org.apache.http.entity.mime.content.StringBody; | ||
import org.apache.http.HttpStatus; | ||
import java.io.IOException; | ||
|
||
import radlab.rain.IScoreboard; | ||
import radlab.rain.workload.rubis.model.RubisUser; | ||
|
||
|
||
/** | ||
* Register operation. | ||
* | ||
* @author Marco Guazzone ([email protected]) | ||
*/ | ||
public class RegisterOperation extends RubisOperation | ||
{ | ||
|
||
public RegisterOperation( boolean interactive, IScoreboard scoreboard ) | ||
{ | ||
super( interactive, scoreboard ); | ||
this._operationName = "Register"; | ||
this._operationIndex = RubisGenerator.REGISTER; | ||
this._operationIndex = RubisGenerator.REGISTER_OP; | ||
this._mustBeSync = true; | ||
} | ||
|
||
@Override | ||
public void execute() throws Throwable | ||
{ | ||
StringBuilder response = this._http.fetchUrl( this.getGenerator().registerURL ); | ||
this.trace( this.getGenerator().registerURL ); | ||
StringBuilder response = null; | ||
|
||
response = this.getHttpTransport().fetchUrl( this.getGenerator().getRegisterURL() ); | ||
this.trace( this.getGenerator().getRegisterURL() ); | ||
if ( response.length() == 0 ) | ||
{ | ||
throw new IOException( "Received empty response" ); | ||
} | ||
|
||
// Decide on the username and password; parse the authenticity token. | ||
// String firstname = "cercs_" + counter; | ||
// String lastname = "cercs_" + counter; | ||
// String nickname = "cercs_" + counter; | ||
// String password = "cercs"; | ||
// String email = "[email protected]"; | ||
// String region = "GA--Atlanta"; | ||
|
||
// Make the POST request to log in. | ||
// StringBuilder postBody = new StringBuilder(); | ||
// postBody.append( "firstname=" ).append( firstname ); | ||
// postBody.append( "&lastname=" ).append( lastname ); | ||
// postBody.append( "&nickname=" ).append( nickname ); | ||
// postBody.append( "&password=" ).append( password ); | ||
// postBody.append( "&email=" ).append( email ); | ||
// postBody.append( "®ion=" ).append( region ); | ||
// | ||
// System.out.println( "Counter - " + counter ); | ||
// | ||
// StringBuilder postResponse = this._http.fetchUrl( this.getGenerator().postRegisterURL, postBody.toString()); | ||
// this.trace(this.getGenerator().postRegisterURL); | ||
// | ||
// counter += 1; | ||
|
||
|
||
// Generate a user | ||
RubisUser user = this.getGenerator().newUser(); | ||
|
||
// Construct the POST request | ||
HttpPost httpPost = new HttpPost(this.getGenerator().getPostRegisterURL()); | ||
MultipartEntity entity = new MultipartEntity(); | ||
entity.addPart("firstname", new StringBody(user.firstname)); | ||
entity.addPart("lastname", new StringBody(user.lastname)); | ||
entity.addPart("nickname", new StringBody(user.nickname)); | ||
entity.addPart("email", new StringBody(user.email)); | ||
entity.addPart("password", new StringBody(user.password)); | ||
entity.addPart("region", new StringBody(user.region.name)); | ||
//entity.addPart("Submit", new StringBody("Register now!")); | ||
httpPost.setEntity(entity); | ||
|
||
response = this.getHttpTransport().fetch(httpPost); | ||
this.trace(this.getGenerator().getPostRegisterURL()); | ||
|
||
// Check that the user was successfully register in. | ||
// if ( postResponse.indexOf( "Your registration has been processed successfully" ) < 0 ) { | ||
// System.out.println( "Did not register properly." ); | ||
// throw new Exception( "Registration did not happen for unknown reason" ); | ||
// } | ||
|
||
this.setFailed( false ); | ||
int status = this.getHttpTransport().getStatusCode(); | ||
if (HttpStatus.SC_OK != status) | ||
{ | ||
throw new IOException("Multipart POST did not work for URL: " + this.getGenerator().getPostRegisterURL() + ". Resturned status code: " + status + "!"); | ||
} | ||
if (-1 != response.indexOf("ERROR")) | ||
{ | ||
throw new IOException("Registration did not happen due to errors"); | ||
} | ||
|
||
this.setFailed(false); | ||
} | ||
|
||
} |
Oops, something went wrong.