Fixing tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@125663 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-03-17 16:26:43 +00:00
parent 829e3fa4a5
commit 76881ba240
1 changed files with 124 additions and 132 deletions

View File

@ -33,221 +33,213 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*
*/
public class AccountingPersistenceQueryFactoryTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryFactoryTest.class);
private static Logger logger = LoggerFactory
.getLogger(AccountingPersistenceQueryFactoryTest.class);
protected AccountingPersistenceQuery apq;
@Before
public void before() throws NoAvailableScopeException, NoUsableAccountingPersistenceQueryFound{
public void before() throws NoAvailableScopeException,
NoUsableAccountingPersistenceQueryFound {
apq = AccountingPersistenceQueryFactory.getInstance();
}
@Test
public void testNullFilters() throws Exception {
Calendar startTime = Calendar.getInstance();
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
startTime.setTimeInMillis(startTime.getTimeInMillis()
- (1000 * 60 * 60 * 24 * 3));
Calendar endTime = Calendar.getInstance();
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
TemporalConstraint temporalConstraint = new TemporalConstraint(
startTime.getTimeInMillis(), endTime.getTimeInMillis(),
AggregationMode.SECONDLY);
List<Filter> filters = null;
Map<Calendar, Info> infos = apq.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
Assert.assertTrue(infos!=null);
for(Info info : infos.values()){
Class<? extends AggregatedRecord<?, ?>> clz = AggregatedServiceUsageRecord.class;
Map<Calendar, Info> infos = apq.getTimeSeries(clz, temporalConstraint,
filters, true);
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));
startTime.setTimeInMillis(startTime.getTimeInMillis()
- (1000 * 60 * 60 * 24 * 3));
Calendar endTime = Calendar.getInstance();
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
TemporalConstraint temporalConstraint = new TemporalConstraint(
startTime.getTimeInMillis(), endTime.getTimeInMillis(),
AggregationMode.SECONDLY);
List<Filter> filters = new ArrayList<Filter>();
Class<? extends AggregatedRecord<?,?>> clz = AggregatedServiceUsageRecord.class;
Map<Calendar, Info> infos = apq.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
Assert.assertTrue(infos!=null);
for(Info info : infos.values()){
Class<? extends AggregatedRecord<?, ?>> clz = AggregatedServiceUsageRecord.class;
Map<Calendar, Info> infos = apq.getTimeSeries(clz, temporalConstraint,
filters, true);
Assert.assertTrue(infos != null);
for (Info info : infos.values()) {
logger.debug(info.toString());
}
}
@Test(expected=DocumentNotFoundException.class)
@Test(expected = DocumentNotFoundException.class)
public void testFakeFilters() throws Exception {
Calendar startTime = Calendar.getInstance();
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
startTime.setTimeInMillis(startTime.getTimeInMillis()
- (1000 * 60 * 60 * 24 * 3));
Calendar endTime = Calendar.getInstance();
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
TemporalConstraint temporalConstraint = new TemporalConstraint(
startTime.getTimeInMillis(), endTime.getTimeInMillis(),
AggregationMode.SECONDLY);
List<Filter> filters = new ArrayList<Filter>();
filters.add(new Filter("AUX", "AUX"));
apq.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
Class<? extends AggregatedRecord<?, ?>> clz = AggregatedServiceUsageRecord.class;
apq.getTimeSeries(clz, temporalConstraint, filters, true);
}
@Test
public void testFiltersGoodKeyFakeValue() throws Exception {
Calendar startTime = Calendar.getInstance();
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
startTime.setTimeInMillis(startTime.getTimeInMillis()
- (1000 * 60 * 60 * 24 * 3));
Calendar endTime = Calendar.getInstance();
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
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.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
Assert.assertTrue(infos!=null);
Class<? extends AggregatedRecord<?, ?>> clz = AggregatedServiceUsageRecord.class;
Map<Calendar, Info> infos = apq.getTimeSeries(clz, temporalConstraint,
filters, true);
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));
startTime.setTimeInMillis(startTime.getTimeInMillis()
- (1000 * 60 * 60 * 24 * 365));
Calendar endTime = Calendar.getInstance();
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
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.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
Assert.assertTrue(infos!=null);
filters.add(new Filter(ServiceUsageRecord.SERVICE_CLASS,
TestUsageRecord.TEST_SERVICE_CLASS));
Class<? extends AggregatedRecord<?, ?>> clz = AggregatedServiceUsageRecord.class;
Map<Calendar, Info> infos = apq.getTimeSeries(clz, temporalConstraint,
filters, true);
Assert.assertTrue(infos != null);
Assert.assertTrue(!infos.isEmpty());
for(Info info : infos.values()){
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.getTimeSeries(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
Assert.assertTrue(infos!=null);
filters.add(new Filter(StorageUsageRecord.RESOURCE_OWNER,
TestUsageRecord.TEST_RESOUCE_OWNER));
clz = AggregatedStorageUsageRecord.class;
infos = apq.getTimeSeries(clz, temporalConstraint, filters, true);
Assert.assertTrue(infos != null);
Assert.assertTrue(!infos.isEmpty());
for(Info info : infos.values()){
for (Info info : infos.values()) {
logger.debug(info.toString());
}
}
//@ Test
// @ 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());
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.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.getTimeSeries(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
Assert.assertTrue(infos!=null);
Class<? extends AggregatedRecord<?, ?>> clz = AggregatedStorageUsageRecord.class;
Map<Calendar, Info> infos = apq.getTimeSeries(clz, temporalConstraint,
filters, true);
Assert.assertTrue(infos != null);
Assert.assertTrue(!infos.isEmpty());
for(Info info : infos.values()){
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);
Set<String> keys = AccountingPersistenceQuery
.getQuerableKeys(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);
}
}
Set<String> required = AggregatedServiceUsageRecord.class.newInstance()
.getRequiredFields();
logger.debug("Required fields : {}", required);
Assert.assertTrue(required.containsAll(keys));
}
@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());
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);
AccountingPersistenceBackendQuery apq = AccountingPersistenceBackendQueryFactory
.getInstance();
Map<Calendar, Info> infos = apq.getTimeSeries(
AggregatedStorageUsageRecord.class, temporalConstraint,
filters);
Assert.assertTrue(infos != null);
Assert.assertTrue(!infos.isEmpty());
for(Info info : infos.values()){
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());
}
}
}