Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhrobbins committed Sep 5, 2015
1 parent 90242ff commit 6eab79a
Show file tree
Hide file tree
Showing 36 changed files with 833 additions and 134 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package org.robbins.flashcards.facade.base;

import org.robbins.flashcards.dto.BulkLoadingReceiptDto;
import org.robbins.flashcards.exceptions.FlashcardsException;

import java.util.List;
Expand All @@ -17,7 +18,7 @@ List<D> list(Integer page, Integer size, String sort, String direction,
D findOne(final ID id) throws FlashcardsException;
D findOne(final ID id, Set<String> fields) throws FlashcardsException;
D save(final D entity) throws FlashcardsException;
void save(final List<D> entities) throws FlashcardsException;
BulkLoadingReceiptDto save(final List<D> entities) throws FlashcardsException;
void delete(final ID id);
List<D> findByCreatedBy(final ID userId, final Set<String> fields) throws FlashcardsException;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.robbins.flashcards.client;

import java.util.*;

import org.robbins.flashcards.dto.AbstractPersistableDto;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.dto.BulkLoadingReceiptDto;
import org.robbins.flashcards.exceptions.FlashcardsException;
import org.robbins.flashcards.exceptions.ServiceException;
import org.springframework.http.HttpEntity;
Expand All @@ -12,6 +10,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;

import java.util.*;

public abstract class AbstractCrudClient<E extends AbstractPersistableDto, ID> extends AbstractClient implements GenericRestCrudFacade<E, ID> {

public static final String BULK = "bulk/";
Expand Down Expand Up @@ -149,8 +149,7 @@ public E save(final E entity) throws ServiceException {
final HttpEntity httpEntity = new HttpEntity(entity, getAuthHeaders());

try {
E result = getRestTemplate().postForObject(postEntityUrl(), httpEntity, getClazz());
return result;
return getRestTemplate().postForObject(postEntityUrl(), httpEntity, getClazz());
}
catch (HttpClientErrorException e) {
throw new ServiceException("Unble to save '" + entity.getClass().getSimpleName() + "' " + e.getMessage());
Expand All @@ -161,17 +160,16 @@ public E save(final E entity) throws ServiceException {
}

@Override
public void save(List<E> entities) throws FlashcardsException {
public BulkLoadingReceiptDto save(List<E> entities) throws FlashcardsException {
// set the Authentication header
@SuppressWarnings({ "unchecked", "rawtypes" })
final HttpEntity httpEntity = new HttpEntity(entities, getAuthHeaders());

try {
getRestTemplate().exchange(postBulkEntitiesUrl(), HttpMethod.POST,
httpEntity, ResponseEntity.class);
return getRestTemplate().postForObject(postBulkEntitiesUrl(), httpEntity, BulkLoadingReceiptDto.class);
}
catch (HttpClientErrorException e) {
throw new ServiceException("Unble to save '" + entities.getClass().getSimpleName() + "' " + e.getMessage());
throw new ServiceException("Unable to save '" + entities.getClass().getSimpleName() + "' " + e.getMessage());
}
catch (Exception e) {
throw new ServiceException("Unexpected exception" + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

package org.robbins.flashcards.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Date;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(value = Include.NON_NULL)
@XmlRootElement(name = "bulkloadingreceipt")
@XmlAccessorType(XmlAccessType.FIELD)
public class BulkLoadingReceiptDto extends AbstractAuditableDto implements Serializable {

private String type;
private int successCount;
private int failureCount;
private Date startTime;
private Date endTime;

public BulkLoadingReceiptDto() {
}

public BulkLoadingReceiptDto(final String id) {
setId(id);
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public int getSuccessCount() {
return successCount;
}

public void setSuccessCount(int successCount) {
this.successCount = successCount;
}

public int getFailureCount() {
return failureCount;
}

public void setFailureCount(int failureCount) {
this.failureCount = failureCount;
}

public Date getStartTime() {
return startTime;
}

public void setStartTime(Date startTime) {
this.startTime = startTime;
}

public Date getEndTime() {
return endTime;
}

public void setEndTime(Date endTime) {
this.endTime = endTime;
}

@Override
public String toString() {
return "BulkLoadingReceiptDto{" +
"type='" + type + '\'' +
", successCount=" + successCount +
", failureCount=" + failureCount +
", startTime=" + startTime +
", endTime=" + endTime +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.robbins.load.tester;

import akka.actor.ActorSystem;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
import org.junit.runner.RunWith;
import org.robbins.load.tester.message.LoadTestResult;
import org.robbins.load.tester.message.LoadTestStart;
Expand All @@ -24,7 +21,8 @@ public class TagLoadTesterIT {

private static final Logger LOGGER = LoggerFactory.getLogger(TagLoadTesterIT.class);

private final Long numberOfRequests = 10000L;
private final Integer totalLoadCount = 1000000;
private final Integer batchSize = 10000;
private final String ENDPOINT_NAME = "tagClient";
private StopWatch stopWatch;

Expand All @@ -48,20 +46,36 @@ public void before() {
@After
public void after() {
stopWatch.stop();
LOGGER.info("Test duration: {} seconds", Math.ceil(stopWatch.getLastTaskTimeMillis()/1000));
LOGGER.info("Test duration: {} seconds", Math.ceil(stopWatch.getLastTaskTimeMillis() / 1000));
}

@Ignore
@Test
public void testAkkaLoadTest() throws Exception {

final LoadTestResult result = akkaLoadTestingService.doLoadTest(new LoadTestStart(numberOfRequests, ENDPOINT_NAME));
Assert.assertEquals(numberOfRequests, result.getEndPointInvocationCount());
final LoadTestResult result = akkaLoadTestingService.doLoadTest(new LoadTestStart(totalLoadCount, 1, ENDPOINT_NAME));
Assert.assertEquals(totalLoadCount, result.getGetTotalLoadCount());
}

@Ignore
@Test
public void testDefaultLoadTest() throws Exception {

final LoadTestResult result = defaultLoadTestingService.doLoadTest(new LoadTestStart(numberOfRequests, ENDPOINT_NAME));
Assert.assertEquals(numberOfRequests, result.getEndPointInvocationCount());
final LoadTestResult result = defaultLoadTestingService.doLoadTest(new LoadTestStart(totalLoadCount, 1, ENDPOINT_NAME));
Assert.assertEquals(totalLoadCount, result.getGetTotalLoadCount());
}

@Test
public void testDefaultLoadTestInBatch() throws Exception {

final LoadTestResult result = defaultLoadTestingService.doLoadTest(new LoadTestStart(totalLoadCount, batchSize, ENDPOINT_NAME));
Assert.assertEquals(totalLoadCount, result.getGetTotalLoadCount());
}

@Test
public void testAkkaLoadTestInBatch() throws Exception {

final LoadTestResult result = akkaLoadTestingService.doLoadTest(new LoadTestStart(totalLoadCount, batchSize, ENDPOINT_NAME));
Assert.assertEquals(totalLoadCount, result.getGetTotalLoadCount());
}
}
5 changes: 5 additions & 0 deletions FlashCards_Load_Tester/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>javax.inject</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<!-- logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.robbins.load.tester.actor;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.japi.pf.ReceiveBuilder;
import org.robbins.flashcards.client.TagClient;
import org.robbins.flashcards.dto.BulkLoadingReceiptDto;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.exceptions.FlashcardsException;
import org.robbins.load.tester.message.BatchTestResult;
import org.robbins.load.tester.message.BatchTestStart;
import org.robbins.load.tester.message.SingleTestResult;
import org.robbins.load.tester.message.TestStart;
import org.robbins.load.tester.util.LoadingTestingUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;
import scala.PartialFunction;
import scala.runtime.BoxedUnit;

import java.util.UUID;

public class BatchLoadTester extends AbstractActor {

private static final Logger LOGGER = LoggerFactory.getLogger(BatchLoadTester.class);

private final TagClient tagClient;

public BatchLoadTester(final TagClient tagClient) {
LOGGER.debug("Creating BatchLoadTester");

this.tagClient = tagClient;
}

public static Props props(final TagClient tagClient) {
return Props.create(BatchLoadTester.class, () -> new BatchLoadTester(tagClient));
}

@Override
public PartialFunction<Object, BoxedUnit> receive() {
return ReceiveBuilder
.match(BatchTestStart.class, startLoadTest -> doLoadTest(startLoadTest, sender()))
.matchAny(o -> LOGGER.error("Received Unknown message"))
.build();
}

private void doLoadTest(final BatchTestStart testStartMessage, final ActorRef sender) {
LOGGER.debug("Received BatchTestStart message: {}", testStartMessage.toString());

final BulkLoadingReceiptDto receipt = tagClient.save(testStartMessage.getBatch());
final BatchTestResult testResult = new BatchTestResult(testStartMessage.getEndPointName(), receipt);

LOGGER.debug("Sending BatchTestResult message: {}", testResult.toString());
sender.tell(testResult, self());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.robbins.flashcards.dto.builder.TagDtoBuilder;
import org.robbins.flashcards.exceptions.FlashcardsException;
import org.robbins.load.tester.message.TestStart;
import org.robbins.load.tester.message.TestResult;
import org.robbins.load.tester.message.SingleTestResult;
import org.robbins.load.tester.util.LoadingTestingUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;
Expand All @@ -25,7 +26,7 @@ public class LoadTester extends AbstractActor {
private final TagClient tagClient;

public LoadTester(final TagClient tagClient) {
LOGGER.debug("Creating LoadTestingActor");
LOGGER.info("Creating LoadTestingActor");

this.tagClient = tagClient;
}
Expand All @@ -43,18 +44,18 @@ public PartialFunction<Object, BoxedUnit> receive() {
}

private void doLoadTest(final TestStart testStartMessage, final ActorRef sender) {
LOGGER.debug("Received TestStart message: {}", testStartMessage.toString());
LOGGER.info("Received TestStart message: {}", testStartMessage.toString());

final TagDto tag = new TagDtoBuilder().withName("load-tester-" + UUID.randomUUID().toString() + "-" + testStartMessage.getTestId()).build();
TestResult result = saveItem(testStartMessage, tag);
final TagDto tag = LoadingTestingUtil.createTagDto("load-tester-" + UUID.randomUUID().toString() + "-" + testStartMessage.getTestId());
SingleTestResult result = saveItem(testStartMessage, tag);

LOGGER.debug("Sending TestResult message: {}", result.toString());
LOGGER.info("Sending TestResult message: {}", result.toString());
sender.tell(result, self());
}

private TestResult saveItem(final TestStart testStartMessage, final TagDto tag) {
private SingleTestResult saveItem(final TestStart testStartMessage, final TagDto tag) {
long duration;
TestResult.TestResultStatus resultStatus = TestResult.TestResultStatus.SUCCESS;
SingleTestResult.TestResultStatus resultStatus = SingleTestResult.TestResultStatus.SUCCESS;

final StopWatch stopWatch = new StopWatch();
stopWatch.start();
Expand All @@ -64,12 +65,12 @@ private TestResult saveItem(final TestStart testStartMessage, final TagDto tag)

} catch (FlashcardsException e) {
LOGGER.error("Unable to create Tag {}, error: {}", tag.toString(), e.getMessage());
resultStatus = TestResult.TestResultStatus.FAILURE;
resultStatus = SingleTestResult.TestResultStatus.FAILURE;
}

stopWatch.stop();
duration = stopWatch.getLastTaskTimeMillis();

return new TestResult(testStartMessage.getEndPointName(), duration, resultStatus);
return new SingleTestResult(testStartMessage.getEndPointName(), duration, resultStatus);
}
}
Loading

0 comments on commit 6eab79a

Please sign in to comment.