Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crud test #2

Open
wants to merge 1 commit into
base: feature/unittest_80
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,28 @@
import org.apache.http.entity.BasicHttpEntity;
import org.junit.Test;

/**
* This "test" is a utility for collecting the timing of concurrent operations operations.
* It takes roughly 2 minutes to complete and should only be run if the timing metrics are wanted.
* In order to activate this utility, the following System Property must be set:
*
* mvn -DRUN_TEST_CRUD_CONCURRENT install
*
* @author lsitu
*/
public class FedoraCrudConcurrentIT extends AbstractResourceIT {

private static final String TEST_ACTIVATION_PROPERTY = "RUN_TEST_CRUD_CONCURRENT";

@Test
public void testConcurrentIngest() throws Exception {
setLogger();

if (System.getProperty(TEST_ACTIVATION_PROPERTY) == null) {
logger.info("Not running tests because system property not set: {}", TEST_ACTIVATION_PROPERTY);
return;
}

int[] numThreadsToTest = {2, 4, 8, 16, 32};
logger.info("# Start CRUD concurrent performance testing...");
for (int i=0; i < numThreadsToTest.length; i++) {
Expand All @@ -48,7 +66,7 @@ public void testConcurrentIngest() throws Exception {
* @param numThreads
* @throws Exception
*/
protected void startCrudConcurrentPerformanceTest(int numThreads) throws Exception {
private void startCrudConcurrentPerformanceTest(final int numThreads) throws Exception {
String pid = null;

// Tasks to run
Expand All @@ -68,11 +86,7 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
tasks.add(task);
}
startThreads(tasks) ;
Thread.sleep(1000);
int totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
long totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to CREATE object: {} ms", numThreads, totalResponseTime/numThreads);

tasks.clear();
Expand All @@ -87,19 +101,15 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
final BasicHttpEntity e = new BasicHttpEntity();
e.setContent(new ByteArrayInputStream(
("INSERT { <" + subjectUri + "> <http://purl.org/dc/elements/1.1/title> "
+ "\"Ttile: " + taskName + pid + "\" } WHERE {}"
+ "\"Title: " + taskName + pid + "\" } WHERE {}"
).getBytes()));
request.setEntity(e);
final HttpRunner task = new HttpRunner(request, taskName);
task.setExpectedStatusCode(204);
tasks.add(task);
}
startThreads(tasks) ;
Thread.sleep(1000);
totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to UPDATE object: {} ms", numThreads, totalResponseTime/numThreads);


Expand All @@ -115,11 +125,7 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
tasks.add(task);
}
startThreads(tasks) ;
Thread.sleep(1000);
totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to INGEST content file: {} ms", numThreads, totalResponseTime/numThreads);


Expand All @@ -135,11 +141,7 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
tasks.add(task);
}
startThreads(tasks) ;
Thread.sleep(1000);
totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to UPDATE content file: {} ms", numThreads, totalResponseTime/numThreads);


Expand All @@ -155,11 +157,7 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
tasks.add(task);
}
startThreads(tasks) ;
Thread.sleep(1000);
totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to RETRIEVE content file: {} ms", numThreads, totalResponseTime/numThreads);


Expand All @@ -175,15 +173,10 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
tasks.add(task);
}
startThreads(tasks) ;
Thread.sleep(1000);
totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to DELETE content file: {} ms", numThreads, totalResponseTime/numThreads);



tasks.clear();
// Retrieve objects
logger.info("# Starting " + numThreads + " concurrent threads to retrieve object...");
Expand All @@ -196,11 +189,7 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
tasks.add(task);
}
startThreads(tasks) ;
Thread.sleep(1000);
totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to RETRIEVE object: {} ms", numThreads, totalResponseTime/numThreads);


Expand All @@ -216,17 +205,23 @@ protected void startCrudConcurrentPerformanceTest(int numThreads) throws Excepti
tasks.add(task);
}
startThreads(tasks) ;
totalResponseTime = getTotalResponseTime(numThreads, tasks);
logger.info("** Average response time for {} concurrent threads to DELETE object: {} ms", numThreads, totalResponseTime/numThreads);

}

private long getTotalResponseTime(final int numThreads,
final List<HttpRunner> tasks) throws InterruptedException {
Thread.sleep(1000);
totalResponseTime = 0;
long totalResponseTime = 0;
for (int i = 0; i< numThreads; i++) {
totalResponseTime += tasks.get(i).responseTime;
}
logger.info("** Average response time for {} concurrent threads to DELETE object: {} ms", numThreads, totalResponseTime/numThreads);

return totalResponseTime;
}

private void startThreads(List<HttpRunner> tasks) throws InterruptedException{
int taskSize = tasks.size();
private void startThreads(final List<HttpRunner> tasks) throws InterruptedException{
final int taskSize = tasks.size();
for (int i = 0; i < taskSize; i++) {

final Thread thread = new Thread(tasks.get(i));
Expand Down Expand Up @@ -257,7 +252,7 @@ class HttpRunner implements Runnable {

private int expectedStatusCode = 0;

public HttpRunner (HttpRequestBase request, String taskName) {
public HttpRunner (final HttpRequestBase request, final String taskName) {
this.taskName = taskName;
this.request = request;
// Use its own HttpClient instance to make sure each performance test
Expand All @@ -274,7 +269,7 @@ public void run() {
responseTime = endTime - startTime;
statusCode = response.getStatusLine().getStatusCode();
logger.info("{} {} with status {} in {} ms.", taskName, request.getURI().toString(), statusCode, String.valueOf(responseTime));
assertEquals(taskName + " existed absnormally.", expectedStatusCode, statusCode);
assertEquals(taskName + " exited abnormally.", expectedStatusCode, statusCode);
} catch (IOException e) {
logger.error("Error {} {} got IOException: {}", taskName, request.getURI().toString(), e.getMessage());
} finally {
Expand All @@ -292,29 +287,14 @@ public HttpRequestBase getRequest() {
}


public String getTaskName() {
return taskName;
}


public void setTaskName(String taskName) {
this.taskName = taskName;
}


public int getStatusCode() {
return statusCode;
}


public void setExpectedStatusCode(int expectedStatusCode) {
public void setExpectedStatusCode(final int expectedStatusCode) {
this.expectedStatusCode = expectedStatusCode;
}


public long getResponseTime() {
return responseTime;
}

}
}