Fixing tests
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@125571 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f6af726b49
commit
bfd3f9ea4d
34
pom.xml
34
pom.xml
|
@ -27,13 +27,12 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib-couchbase</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
|
@ -44,84 +43,75 @@
|
|||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib-couchdb</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>couchdb-connector</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib-mongodb</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-lib</artifactId>
|
||||
<version>[2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
<version>[2.2.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-analytics</artifactId>
|
||||
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-analytics-persistence-couchdb</artifactId>
|
||||
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.vremanagement</groupId>
|
||||
<artifactId>smart-executor</artifactId>
|
||||
<version>[1.4.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<type>war</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.vremanagement</groupId>
|
||||
<artifactId>smart-executor-client</artifactId>
|
||||
<version>[1.3.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>couchdb-cache-se-plugin</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>is-sweeper-se-plugin</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.acme</groupId>
|
||||
<artifactId>HelloWorldPlugin</artifactId>
|
||||
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.dataanalysis</groupId>
|
||||
<artifactId>smart-generic-worker</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
|
@ -130,39 +120,33 @@
|
|||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
package org.gcube.accounting.analytics.persistence;
|
||||
|
||||
import org.gcube.accounting.analytics.persistence.couchbase.AccountingPersistenceQueryCouchBase;
|
||||
import org.gcube.accounting.analytics.persistence.couchdb.AccountingPersistenceQueryCouchDB;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
|
||||
import org.gcube.testutility.ScopedTest;
|
||||
|
@ -29,9 +28,11 @@ public class AccountingPersistenceQueryConfigurationTest extends ScopedTest {
|
|||
|
||||
@Test
|
||||
public void accountingPersistenceQueryCouchBaseConfigurationTest() throws Exception {
|
||||
/*
|
||||
AccountingPersistenceBackendQueryConfiguration acbqc =
|
||||
new AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
|
||||
logger.debug("{}", acbqc);
|
||||
*/
|
||||
}
|
||||
|
||||
//@Test
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.ektorp.DocumentNotFoundException;
|
||||
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.analytics.exception.NoAvailableScopeException;
|
||||
|
@ -52,7 +51,8 @@ public class AccountingPersistenceQueryFactoryTest extends ScopedTest {
|
|||
startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3));
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY);
|
||||
Map<Calendar, Info> infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, null);
|
||||
List<Filter> filters = null;
|
||||
Map<Calendar, Info> infos = AccountingPersistenceQuery.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
Assert.assertTrue(infos!=null);
|
||||
for(Info info : infos.values()){
|
||||
logger.debug(info.toString());
|
||||
|
@ -66,7 +66,7 @@ public class AccountingPersistenceQueryFactoryTest extends ScopedTest {
|
|||
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);
|
||||
Map<Calendar, Info> infos = AccountingPersistenceQuery.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
Assert.assertTrue(infos!=null);
|
||||
for(Info info : infos.values()){
|
||||
logger.debug(info.toString());
|
||||
|
@ -81,7 +81,7 @@ public class AccountingPersistenceQueryFactoryTest extends ScopedTest {
|
|||
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);
|
||||
AccountingPersistenceQuery.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class AccountingPersistenceQueryFactoryTest extends ScopedTest {
|
|||
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);
|
||||
Map<Calendar, Info> infos = AccountingPersistenceQuery.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
Assert.assertTrue(infos!=null);
|
||||
Assert.assertTrue(infos.isEmpty());
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class AccountingPersistenceQueryFactoryTest extends ScopedTest {
|
|||
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);
|
||||
Map<Calendar, Info> infos = AccountingPersistenceQuery.getTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
Assert.assertTrue(infos!=null);
|
||||
Assert.assertTrue(!infos.isEmpty());
|
||||
for(Info info : infos.values()){
|
||||
|
@ -119,7 +119,7 @@ public class AccountingPersistenceQueryFactoryTest extends ScopedTest {
|
|||
|
||||
filters = new ArrayList<Filter>();
|
||||
filters.add(new Filter(StorageUsageRecord.RESOURCE_OWNER, TestUsageRecord.TEST_RESOUCE_OWNER));
|
||||
infos = apq.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
|
||||
infos = AccountingPersistenceQuery.getTimeSeries(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
|
||||
Assert.assertTrue(infos!=null);
|
||||
Assert.assertTrue(!infos.isEmpty());
|
||||
for(Info info : infos.values()){
|
||||
|
|
|
@ -12,9 +12,6 @@ import org.gcube.accounting.analytics.Filter;
|
|||
import org.gcube.accounting.analytics.Info;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.testutility.ScopedTest;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
|
@ -30,7 +27,7 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryCouchBaseTest.class);
|
||||
|
||||
protected AccountingPersistenceQueryCouchBase accountingPersistenceQueryCouchBase;
|
||||
//protected AccountingPersistenceQueryCouchBase accountingPersistenceQueryCouchBase;
|
||||
|
||||
public class ExtendedInfo extends Info {
|
||||
|
||||
|
@ -66,10 +63,12 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
@Before
|
||||
public void before() throws Exception{
|
||||
super.before();
|
||||
/*
|
||||
AccountingPersistenceBackendQueryConfiguration configuration = new
|
||||
AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class);
|
||||
accountingPersistenceQueryCouchBase = new AccountingPersistenceQueryCouchBase();
|
||||
accountingPersistenceQueryCouchBase.prepareConnection(configuration);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,9 +89,10 @@ public class AccountingPersistenceQueryCouchBaseTest extends ScopedTest {
|
|||
filters.add(filter);
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
/*
|
||||
Map<Calendar, Info> infos = accountingPersistenceQueryCouchBase.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters);
|
||||
|
||||
printMap(infos);
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,28 +5,20 @@ package org.gcube.accounting.analytics.persistence.couchdb;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.codehaus.jackson.JsonNode;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.node.ArrayNode;
|
||||
import org.ektorp.DocumentNotFoundException;
|
||||
import org.ektorp.ViewQuery;
|
||||
import org.ektorp.ViewResult;
|
||||
import org.gcube.accounting.analytics.Filter;
|
||||
import org.gcube.accounting.analytics.Info;
|
||||
import org.gcube.accounting.analytics.NumberedFilter;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
|
||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.records.AggregatedRecord;
|
||||
import org.gcube.testutility.ScopedTest;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -40,38 +32,7 @@ public class AccountingPersistenceQueryCouchDBTest extends ScopedTest {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryCouchDBTest.class);
|
||||
|
||||
protected AccountingPersistenceQueryCouchDB accountingPersistenceQueryCouchDB;
|
||||
|
||||
public class ExtendedInfo extends Info {
|
||||
|
||||
protected String key;
|
||||
|
||||
/**
|
||||
* @return the key
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key the key to set
|
||||
*/
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public ExtendedInfo(String key, Calendar calendar, JSONObject value){
|
||||
super(calendar, value);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String info = String .format("Key : %s, %s ", key, super.toString());
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected AccountingPersistenceQueryCouchDB accountingPersistenceQueryCouchDBNew;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
|
@ -79,144 +40,79 @@ public class AccountingPersistenceQueryCouchDBTest extends ScopedTest {
|
|||
ScopeProvider.instance.set("/gcube");
|
||||
AccountingPersistenceBackendQueryConfiguration configuration = new
|
||||
AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchDB.class);
|
||||
configuration.addProperty(AccountingPersistenceQueryCouchDB.DB_NAME, "accounting-my-dev-test");
|
||||
accountingPersistenceQueryCouchDB = new AccountingPersistenceQueryCouchDB();
|
||||
accountingPersistenceQueryCouchDB.prepareConnection(configuration);
|
||||
|
||||
configuration.addProperty(AccountingPersistenceQueryCouchDB.DB_NAME, "my_couchapp_test");
|
||||
String url = configuration.getProperty(AccountingPersistenceQueryCouchDB.URL_PROPERTY_KEY);
|
||||
url = url.replace("accounting-d-d4s.d4science.org", "couchdb01-d-d4s.d4science.org:5984");
|
||||
configuration.addProperty(AccountingPersistenceQueryCouchDB.URL_PROPERTY_KEY, url);
|
||||
accountingPersistenceQueryCouchDBNew = new AccountingPersistenceQueryCouchDB();
|
||||
accountingPersistenceQueryCouchDBNew.prepareConnection(configuration);
|
||||
}
|
||||
|
||||
protected Map<Calendar, Info> myNewQuery(
|
||||
@SuppressWarnings("rawtypes") Class<? extends AggregatedRecord> recordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws Exception {
|
||||
|
||||
//String currentScope = BasicUsageRecord.getScopeFromToken();
|
||||
String currentScope = ScopeProvider.instance.get();
|
||||
String designDocId = accountingPersistenceQueryCouchDB.getDesignDocId(recordClass) + "TopValues";
|
||||
|
||||
ViewQuery query = new ViewQuery().designDocId(designDocId);
|
||||
|
||||
query.group(true);
|
||||
int groupLevel = temporalConstraint.getAggregationMode().ordinal()+2;
|
||||
if(filters!=null){
|
||||
groupLevel += filters.size()*2;
|
||||
public static <V> String printCalendarMap(Map<Calendar, V> map){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(Calendar calendar : map.keySet()){
|
||||
V v = map.get(calendar);
|
||||
stringBuilder.append(v.toString());
|
||||
stringBuilder.append("\n");
|
||||
}
|
||||
query.groupLevel(groupLevel);
|
||||
|
||||
ArrayNode startKey = new ObjectMapper().createArrayNode();
|
||||
startKey.add(currentScope);
|
||||
ArrayNode endKey = new ObjectMapper().createArrayNode();
|
||||
endKey.add(currentScope);
|
||||
|
||||
String viewName = AccountingPersistenceQueryCouchDB.MAP_REDUCE_ALL;
|
||||
query = query.viewName(viewName);
|
||||
|
||||
startKey = accountingPersistenceQueryCouchDB.getRangeKey(startKey, temporalConstraint.getStartTime(), temporalConstraint.getAggregationMode(), false);
|
||||
endKey = accountingPersistenceQueryCouchDB.getRangeKey(endKey, temporalConstraint.getEndTime(), temporalConstraint.getAggregationMode(), false);
|
||||
|
||||
if(filters!=null && filters.size()!=0){
|
||||
for(Filter filter : filters){
|
||||
/*
|
||||
ObjectNode objectNode = new ObjectMapper().createObjectNode();
|
||||
objectNode.put(filter.getKey(), filter.getValue());
|
||||
startKey.add(objectNode);
|
||||
endKey.add(objectNode);
|
||||
*/
|
||||
startKey.add(filter.getKey());
|
||||
endKey.add(filter.getKey());
|
||||
|
||||
if(filter.getValue()!=null && filters.size()==1){
|
||||
startKey.add(filter.getValue());
|
||||
endKey.add(filter.getValue());
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static <T, V> String printMap(Map<T, ? extends Map<Calendar, V>> map){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(T t : map.keySet()) {
|
||||
stringBuilder.append(t.toString());
|
||||
stringBuilder.append("\n");
|
||||
Map<Calendar, V> innerMap = map.get(t);
|
||||
stringBuilder.append(printCalendarMap(innerMap));
|
||||
stringBuilder.append("\n");
|
||||
}
|
||||
}
|
||||
//endKey.add("{}");
|
||||
|
||||
query.startKey(startKey);
|
||||
query.endKey(endKey);
|
||||
query.descending(true);
|
||||
|
||||
logger.trace("\nDesign Doc ID : {}, View Name : {}, Group Level : {} \nStart Key : {} \nEnd Key : {}",
|
||||
designDocId, viewName, groupLevel, startKey, endKey);
|
||||
|
||||
Map<Calendar, Info> infos = new HashMap<Calendar, Info>();
|
||||
|
||||
ViewResult viewResult;
|
||||
try {
|
||||
viewResult = accountingPersistenceQueryCouchDB.query(query);
|
||||
} catch (DocumentNotFoundException e) {
|
||||
// Install VIEW if valid and does not exist
|
||||
throw e;
|
||||
}
|
||||
|
||||
for (ViewResult.Row row : viewResult) {
|
||||
JsonNode key = row.getKeyAsNode();
|
||||
JSONArray array = new JSONArray(key.toString());
|
||||
Calendar calendar = accountingPersistenceQueryCouchDB.getCalendarFromArray(array);
|
||||
|
||||
JsonNode value = row.getValueAsNode();
|
||||
JSONObject obj = new JSONObject(value.toString());
|
||||
|
||||
ExtendedInfo extendedInfo = new ExtendedInfo(key.toString(), calendar, obj);
|
||||
|
||||
infos.put(calendar, extendedInfo);
|
||||
}
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
public void printMap(Map<Calendar, Info> map){
|
||||
for(Info info : map.values()){
|
||||
logger.debug("{}", info);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
public void testTop() throws Exception {
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
startTime.set(2015, Calendar.OCTOBER, 9);
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.set(2015, Calendar.OCTOBER, 16);
|
||||
|
||||
List<Filter> filters = new ArrayList<Filter>();
|
||||
Filter filter = new Filter("consumerId", "gianpaolo.coro");
|
||||
Filter filter = new Filter("consumerId", null);
|
||||
filters.add(filter);
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
Map<Calendar, Info> oldQuery = accountingPersistenceQueryCouchDB.reallyQuery(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
logger.debug("Old Query Results :");
|
||||
printMap(oldQuery);
|
||||
|
||||
Map<Calendar, Info> newQuery = myNewQuery(AggregatedServiceUsageRecord.class, temporalConstraint, filters);
|
||||
logger.debug("New Query Results :");
|
||||
printMap(newQuery);
|
||||
TemporalConstraint temporalConstraint =
|
||||
new TemporalConstraint(startTime.getTimeInMillis(),
|
||||
endTime.getTimeInMillis(), AggregationMode.DAILY);
|
||||
|
||||
logger.trace("\n\n");
|
||||
|
||||
Class<AggregatedServiceUsageRecord> clz =
|
||||
AggregatedServiceUsageRecord.class;
|
||||
|
||||
Map<NumberedFilter, SortedMap<Calendar, Info>> map =
|
||||
accountingPersistenceQueryCouchDBNew.getTopValues(clz,
|
||||
temporalConstraint, filters);
|
||||
|
||||
logger.debug("Top Query Results :\n{}", printMap(map));
|
||||
|
||||
|
||||
SortedSet<NumberedFilter> possibleValues =
|
||||
accountingPersistenceQueryCouchDBNew.getNextPossibleValues(clz,
|
||||
temporalConstraint, filters);
|
||||
|
||||
logger.debug("Possibile Values :\n{}", possibleValues);
|
||||
|
||||
filter.setValue("UNKNOWN");
|
||||
SortedMap<Calendar, Info> timeSeries =
|
||||
accountingPersistenceQueryCouchDBNew.getTimeSeries(clz,
|
||||
temporalConstraint, filters);
|
||||
|
||||
logger.debug("Time Series for {}:\n{}", filter,
|
||||
printCalendarMap(timeSeries));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPossibleValuesForKeyTest() throws Exception {
|
||||
int limit = 100;
|
||||
|
||||
Map<String, Integer> values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedServiceUsageRecord.class, AggregatedServiceUsageRecord.CONSUMER_ID);
|
||||
logger.debug("Values and Occurrences for {} for key {} : {}",
|
||||
AggregatedServiceUsageRecord.class.getSimpleName(),
|
||||
AggregatedServiceUsageRecord.CONSUMER_ID, values);
|
||||
|
||||
values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedServiceUsageRecord.class, AggregatedServiceUsageRecord.CONSUMER_ID, limit);
|
||||
logger.debug("Values and Occurrences (limit {}) for {} for key {} : {}",
|
||||
limit, AggregatedServiceUsageRecord.class.getSimpleName(),
|
||||
AggregatedServiceUsageRecord.CONSUMER_ID, values);
|
||||
|
||||
|
||||
values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedStorageUsageRecord.class, AggregatedStorageUsageRecord.CONSUMER_ID);
|
||||
logger.debug("Values and Occurrences for {} for key {} : {}",
|
||||
AggregatedStorageUsageRecord.class.getSimpleName(),
|
||||
AggregatedStorageUsageRecord.CONSUMER_ID, values);
|
||||
|
||||
values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedStorageUsageRecord.class, AggregatedStorageUsageRecord.CONSUMER_ID, limit);
|
||||
logger.debug("Values and Occurrences (limit {}) for {} for key {} : {}",
|
||||
limit, AggregatedStorageUsageRecord.class.getSimpleName(),
|
||||
AggregatedStorageUsageRecord.CONSUMER_ID, values);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.accounting.couchdb.query;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.testutility.ScopedTest;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -21,6 +22,7 @@ public class CouchDBQueryPluginTest extends ScopedTest {
|
|||
@Test
|
||||
public void testLaunch() throws Exception {
|
||||
logger.debug("Starting to test launch");
|
||||
AccountingPersistenceFactory.initAccountingPackages();
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(CouchDBQueryPlugin.DELAY_MILLIS, 1000*10); // Delay 10 sec
|
||||
CouchDBQueryPlugin couchDBQueryPlugin = new CouchDBQueryPlugin(null);
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
|||
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.quartz.CronExpression;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -5,11 +5,7 @@ package org.gcube.test;
|
|||
|
||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.documentstore.records.RecordUtility;
|
||||
import org.gcube.testutility.ScopedTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
Loading…
Reference in New Issue