refs #2222: Move infrastructure tests outside of components junit tests
https://support.d4science.org/issues/2222 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics-persistence-couchbase@124037 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4b36e7ba5f
commit
e1dffda5a1
36
pom.xml
36
pom.xml
|
@ -23,44 +23,25 @@
|
||||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</url>
|
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.distribution</groupId>
|
|
||||||
<artifactId>maven-smartgears-bom</artifactId>
|
|
||||||
<version>LATEST</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-analytics</artifactId>
|
<artifactId>accounting-analytics</artifactId>
|
||||||
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.data.publishing</groupId>
|
|
||||||
<artifactId>document-store-lib</artifactId>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-lib</artifactId>
|
<artifactId>accounting-lib</artifactId>
|
||||||
|
<version>[2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.5</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<version>20090211</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- CouchBase libraries -->
|
<!-- CouchBase libraries -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -71,16 +52,6 @@
|
||||||
<!-- END CouchBase libraries -->
|
<!-- END CouchBase libraries -->
|
||||||
|
|
||||||
<!-- Test Dependency -->
|
<!-- Test Dependency -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.resources</groupId>
|
|
||||||
<artifactId>registry-publisher</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.core</groupId>
|
|
||||||
<artifactId>common-encryption</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -94,6 +65,7 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -116,6 +88,4 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,38 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.accounting.analytics.persistence;
|
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.persistence.couchbase.AccountingPersistenceQueryCouchBase;
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class AccountingPersistenceQueryConfigurationTest {
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryConfigurationTest.class);
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before(){
|
|
||||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void after(){
|
|
||||||
SecurityTokenProvider.instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() throws Exception {
|
|
||||||
AccountingPersistenceBackendQueryConfiguration acbqc = new AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
|
|
||||||
logger.debug("{}", acbqc);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,259 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.accounting.analytics.persistence;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.Filter;
|
|
||||||
import org.gcube.accounting.analytics.Info;
|
|
||||||
import org.gcube.accounting.analytics.ResourceRecordQuery;
|
|
||||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
|
||||||
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
|
||||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
|
||||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
|
||||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class AccountingPersistenceQueryFactoryTest {
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryFactoryTest.class);
|
|
||||||
|
|
||||||
protected AccountingPersistenceBackendQuery apq;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() throws Exception{
|
|
||||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
|
||||||
apq = AccountingPersistenceBackendQueryFactory.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void after(){
|
|
||||||
SecurityTokenProvider.instance.reset();
|
|
||||||
apq = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNullFilters() throws Exception {
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
|
|
||||||
//startTime.setTimeInMillis(new Long("1449829933665"));
|
|
||||||
startTime.set(Calendar.YEAR, 2015);
|
|
||||||
startTime.set(Calendar.MONTH, 1);
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
|
|
||||||
Map<Calendar, Info> infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, null);
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
for(Info info : infos.values()){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEmptyFilters() throws Exception {
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
|
|
||||||
List<Filter> filters = new ArrayList<Filter>();
|
|
||||||
Map<Calendar, Info> infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
for(Info info : infos.values()){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected=Exception.class)
|
|
||||||
public void testFakeFilters() throws Exception {
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
|
|
||||||
List<Filter> filters = new ArrayList<Filter>();
|
|
||||||
filters.add(new Filter("AUX", "AUX"));
|
|
||||||
apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFiltersGoodKeyFakeValue() throws Exception {
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
|
|
||||||
List<Filter> filters = new ArrayList<Filter>();
|
|
||||||
filters.add(new Filter(ServiceUsageRecord.SERVICE_CLASS, "AUX"));
|
|
||||||
Map<Calendar, Info> infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
Assert.assertTrue(infos.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static final long timeout = 5000;
|
|
||||||
public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFiltersGoodKeyGoodValue() throws Exception {
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*365));
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
|
|
||||||
List<Filter> filters = new ArrayList<Filter>();
|
|
||||||
filters.add(new Filter(ServiceUsageRecord.SERVICE_CLASS, TestUsageRecord.TEST_SERVICE_CLASS));
|
|
||||||
Map<Calendar, Info> infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
Assert.assertTrue(!infos.isEmpty());
|
|
||||||
for(Info info : infos.values()){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
filters = new ArrayList<Filter>();
|
|
||||||
filters.add(new Filter(StorageUsageRecord.RESOURCE_OWNER, TestUsageRecord.TEST_RESOUCE_OWNER));
|
|
||||||
infos = apq.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
Assert.assertTrue(!infos.isEmpty());
|
|
||||||
for(Info info : infos.values()){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//@ Test
|
|
||||||
public void testRange() throws Exception {
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.set(Calendar.MONTH, Calendar.AUGUST);
|
|
||||||
startTime.set(Calendar.DAY_OF_MONTH, 7);
|
|
||||||
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
endTime.set(Calendar.MONTH, Calendar.SEPTEMBER);
|
|
||||||
endTime.set(Calendar.DAY_OF_MONTH, 7);
|
|
||||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.DAILY);
|
|
||||||
logger.trace("{} : {}", TemporalConstraint.class.getSimpleName(), temporalConstraint.toString());
|
|
||||||
|
|
||||||
|
|
||||||
List<Filter> filters = new ArrayList<Filter>();
|
|
||||||
/*
|
|
||||||
filters.add(new Filter(ServiceUsageRecord.SERVICE_CLASS, TestUsageRecord.TEST_SERVICE_CLASS));
|
|
||||||
Map<Calendar, Info> infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
Assert.assertTrue(!infos.isEmpty());
|
|
||||||
for(Info info : infos.values()){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
filters = new ArrayList<Filter>();
|
|
||||||
filters.add(new Filter(UsageRecord.CONSUMER_ID, "gianpaolo.coro"));
|
|
||||||
|
|
||||||
AccountingPersistenceBackendQuery apq = AccountingPersistenceBackendQueryFactory.getInstance();
|
|
||||||
Map<Calendar, Info> infos = apq.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
Assert.assertTrue(!infos.isEmpty());
|
|
||||||
|
|
||||||
for(Info info : infos.values()){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
ResourceRecordQuery resourceRecordQuery = new ResourceRecordQuery();
|
|
||||||
List<Info> padded = resourceRecordQuery.getInfo(AggregatedStorageUsageRecord.class, temporalConstraint, filters, true);
|
|
||||||
Assert.assertTrue(padded!=null);
|
|
||||||
Assert.assertTrue(!padded.isEmpty());
|
|
||||||
|
|
||||||
for(Info info : padded){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getKeysTest() throws Exception {
|
|
||||||
Set<String> keys = apq.getKeys(AggregatedServiceUsageRecord.class);
|
|
||||||
logger.debug("Got keys : {}", keys);
|
|
||||||
|
|
||||||
Set<String> required = AggregatedServiceUsageRecord.class.newInstance().getRequiredFields();
|
|
||||||
logger.debug("Required fields : {}", required);
|
|
||||||
|
|
||||||
Assert.assertTrue(required.containsAll(keys));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getPossibileValuesTest() throws Exception {
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
Class[] classes = new Class[]{
|
|
||||||
AggregatedServiceUsageRecord.class,
|
|
||||||
AggregatedStorageUsageRecord.class
|
|
||||||
};
|
|
||||||
|
|
||||||
for(@SuppressWarnings("rawtypes") Class cls : classes){
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Set<String> keys = apq.getKeys(cls);
|
|
||||||
for(String key : keys){
|
|
||||||
logger.debug("Querying Possible values of {} for key {}", cls.getSimpleName(), key);
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Set<String> values = apq.getPossibleValuesForKey(cls, key);
|
|
||||||
logger.debug("Possible values of {} for key {} : {}", cls.getSimpleName(), key, values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMontly() throws Exception {
|
|
||||||
Calendar startTime = Calendar.getInstance();
|
|
||||||
startTime.set(Calendar.MONTH, Calendar.JANUARY);
|
|
||||||
startTime.set(Calendar.DAY_OF_MONTH, 1);
|
|
||||||
|
|
||||||
Calendar endTime = Calendar.getInstance();
|
|
||||||
endTime.set(Calendar.MONTH, Calendar.DECEMBER);
|
|
||||||
endTime.set(Calendar.DAY_OF_MONTH, 31);
|
|
||||||
|
|
||||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.MONTHLY);
|
|
||||||
logger.trace("{} : {}", TemporalConstraint.class.getSimpleName(), temporalConstraint.toString());
|
|
||||||
|
|
||||||
|
|
||||||
List<Filter> filters = new ArrayList<Filter>();
|
|
||||||
AccountingPersistenceBackendQuery apq = AccountingPersistenceBackendQueryFactory.getInstance();
|
|
||||||
Map<Calendar, Info> infos = apq.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
|
|
||||||
|
|
||||||
Assert.assertTrue(infos!=null);
|
|
||||||
Assert.assertTrue(!infos.isEmpty());
|
|
||||||
|
|
||||||
for(Info info : infos.values()){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
ResourceRecordQuery resourceRecordQuery = new ResourceRecordQuery();
|
|
||||||
List<Info> padded = resourceRecordQuery.getInfo(AggregatedStorageUsageRecord.class, temporalConstraint, filters, true);
|
|
||||||
Assert.assertTrue(padded!=null);
|
|
||||||
Assert.assertTrue(!padded.isEmpty());
|
|
||||||
|
|
||||||
for(Info info : padded){
|
|
||||||
logger.debug(info.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.accounting.analytics.persistence;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class TestUtility {
|
|
||||||
|
|
||||||
public static final String TOKEN = "";
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package org.gcube.accounting.analytics.utils;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public abstract class IOUtility {
|
|
||||||
|
|
||||||
public static String readFile(String filePath) throws IOException {
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(filePath));
|
|
||||||
String line = null;
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
String ls = System.getProperty("line.separator");
|
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
stringBuilder.append(line);
|
|
||||||
stringBuilder.append(ls);
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.accounting.testutility;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class StressTestUtility {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(StressTestUtility.class);
|
|
||||||
|
|
||||||
protected final static int DEFAULT_NUMBER_OF_RECORDS = 3000;
|
|
||||||
|
|
||||||
public static void stressTest(TestOperation operation) throws Exception {
|
|
||||||
stressTest(operation, DEFAULT_NUMBER_OF_RECORDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void stressTest(TestOperation operation, int runs) throws Exception {
|
|
||||||
Calendar startTestTime = new GregorianCalendar();
|
|
||||||
for(int i=0; i< runs; i++){
|
|
||||||
operation.operate(i);
|
|
||||||
}
|
|
||||||
Calendar stopTestTime = new GregorianCalendar();
|
|
||||||
double startMillis = startTestTime.getTimeInMillis();
|
|
||||||
double stopMillis = stopTestTime.getTimeInMillis();
|
|
||||||
double duration = stopMillis - startMillis;
|
|
||||||
double average = (duration/runs);
|
|
||||||
logger.debug("Duration (in millisec) : " + duration);
|
|
||||||
logger.debug("Average (in millisec) : " + average);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.accounting.testutility;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface TestOperation {
|
|
||||||
|
|
||||||
public void operate(int i) throws Exception;
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue