fixing tests
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@155095 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e45546b9b3
commit
bdb95417a3
14
pom.xml
14
pom.xml
|
@ -97,6 +97,12 @@
|
|||
-->
|
||||
<!-- END Document Store Lib -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>context-creation</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Accounting Libraries -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
|
@ -167,6 +173,14 @@
|
|||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.accounting.aggregator.aggregation.AggregationType;
|
|||
import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPlugin.ElaborationType;
|
||||
import org.gcube.accounting.aggregator.utility.Utility;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.testutility.ScopedTest;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||||
|
@ -31,47 +32,12 @@ public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends Scoped
|
|||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
setContext(ROOT);
|
||||
proxy = ExecutorPlugin.getExecutorProxy(AccountingAggregatorPluginDeclaration.NAME).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
}
|
||||
|
||||
private Map<String, Object> getRecoveryInputs() throws Exception {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(4, 0));
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(20, 0));
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
private Map<String, Object> getAggregateInputs() throws Exception {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.DAILY.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(3, 0));
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(19, 00));
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER,
|
||||
ServiceUsageRecord.class.newInstance().getRecordType());
|
||||
|
||||
// Start Aggregation Date
|
||||
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.APRIL,
|
||||
17);
|
||||
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT
|
||||
.format(aggregationStartCalendar.getTime());
|
||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER,
|
||||
aggregationStartDate);
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, false);
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
private void launch(Scheduling scheduling, Map<String, Object> inputs) throws Exception {
|
||||
|
||||
LaunchParameter launchParameter = new LaunchParameter(AccountingAggregatorPluginDeclaration.NAME, inputs);
|
||||
|
@ -86,6 +52,35 @@ public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends Scoped
|
|||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> getAggregateInputs() throws Exception {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.DAILY.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(3, 0));
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(19, 00));
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER,
|
||||
ServiceUsageRecord.class.newInstance().getRecordType());
|
||||
|
||||
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.SEPTEMBER, 22);
|
||||
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||
|
||||
/*
|
||||
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.SEPTEMBER, 23);
|
||||
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||
*/
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, false);
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aggregate() throws Exception {
|
||||
// Every 5 minutes
|
||||
|
@ -99,16 +94,83 @@ public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends Scoped
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Map<String, Object> getMonthlyAggregateInputs() throws Exception {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.MONTHLY.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(3, 0));
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(19, 00));
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER,
|
||||
StorageUsageRecord.class.newInstance().getRecordType());
|
||||
|
||||
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2016, Calendar.JANUARY, 1);
|
||||
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||
/*
|
||||
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JUNE, 30);
|
||||
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||
*/
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, true);
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aggregateMonthly() throws Exception {
|
||||
CronExpression cronExpression = new CronExpression("0 0/5 * 1/1 * ? *");
|
||||
Scheduling scheduling = new Scheduling(cronExpression, true);
|
||||
scheduling.setGlobal(false);
|
||||
|
||||
Map<String, Object> inputs = getMonthlyAggregateInputs();
|
||||
launch(scheduling, inputs);
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
private Map<String, Object> getRecoveryInputs() throws Exception {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name());
|
||||
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_START_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(3, 0));
|
||||
inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, Utility.getPersistTimeParameter(19, 0));
|
||||
|
||||
|
||||
Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.AUGUST, 1);
|
||||
String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationStartCalendar.getTime());
|
||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate);
|
||||
|
||||
/*
|
||||
Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JUNE, 22);
|
||||
String aggregationEndDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT.format(aggregationEndCalendar.getTime());
|
||||
logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||
inputs.put(AccountingAggregatorPlugin.AGGREGATION_END_DATE_INPUT_PARAMETER, aggregationEndDate);
|
||||
*/
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recovery() throws Exception {
|
||||
// Every Day at 8:00
|
||||
CronExpression cronExpression = new CronExpression("0 0/15 4-19 1/1 * ? *");
|
||||
CronExpression cronExpression = new CronExpression("0 0/5 3-19 1/1 * ? *");
|
||||
Scheduling scheduling = new Scheduling(cronExpression, true);
|
||||
scheduling.setGlobal(false);
|
||||
|
||||
Map<String, Object> inputs = getRecoveryInputs();
|
||||
|
||||
launch(null, inputs);
|
||||
launch(scheduling, inputs);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class RemoveOldRecords extends ScopedTest {
|
|||
|
||||
List<Bucket> buckets = new ArrayList<Bucket>();
|
||||
|
||||
buckets.add(accountingPersistenceQueryCouchBase.connectionMa.get("ServiceUsageRecord"));
|
||||
buckets.add(accountingPersistenceQueryCouchBase.connectionMap.get("ServiceUsageRecord"));
|
||||
|
||||
for(Bucket bucket : buckets){
|
||||
|
||||
|
|
|
@ -106,4 +106,5 @@ public class PersistenceCouchBaseTest extends ScopedTest {
|
|||
Assert.assertNotEquals(first, second);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package org.gcube.documentstore.persistence;
|
||||
|
||||
import org.gcube.accounting.datamodel.usagerecords.TestUsageRecord;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.documentstore.records.DSMapper;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
|
@ -35,11 +36,15 @@ public class PersistenceCouchBaseTest extends ScopedTest {
|
|||
|
||||
@Test
|
||||
public void persistenceIsCouchBaseForcingImmediateRediscovery() throws ObjectNotFound, Exception {
|
||||
|
||||
AccountingPersistenceFactory.initAccountingPackages();
|
||||
|
||||
PersistenceBackendFactory.setFallbackLocation(null);
|
||||
String context = ScopedTest.getCurrentContext();
|
||||
PersistenceBackendFactory.forceImmediateRediscovery(context);
|
||||
PersistenceBackend persistenceBackend = PersistenceBackendFactory.getPersistenceBackend(context);
|
||||
Assert.assertTrue(persistenceBackend instanceof PersistenceCouchBase);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package org.gcube.informationsystem.exporter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -19,6 +20,9 @@ import org.quartz.CronExpression;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
|
@ -49,6 +53,52 @@ public class ISExporterPluginSmartExecutorSchedulerTest extends ScopedTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void production() throws Exception {
|
||||
File src = new File("src");
|
||||
File test = new File(src, "test");
|
||||
File resources = new File(test, "resources");
|
||||
|
||||
File tokenFile = new File(resources, "production-tokens-is-exporter.json");
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(tokenFile);
|
||||
|
||||
Map<String, String> contextSecondMinutes = new HashMap<>();
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu", "0 0");
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu/ParthenosVO", "30 7");
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu/ParthenosVO/RubRIcA", "0 15");
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry", "30 22");
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu/gCubeApps", "0 30");
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu/gCubeApps/Parthenos", "30 37");
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu/D4Research", "0 45");
|
||||
contextSecondMinutes.put("/d4science.research-infrastructures.eu/D4Research/NERLiX", "30 52");
|
||||
|
||||
for(String context : contextSecondMinutes.keySet()){
|
||||
logger.info("\n\n\n-------------------------------------------------------------------------");
|
||||
|
||||
String token = jsonNode.get(context).asText();
|
||||
|
||||
ScopedTest.setContext(token);
|
||||
|
||||
CronExpression cronExpression = new CronExpression(contextSecondMinutes.get(context) + " 0/1 * * ?"); // every hour at contextSecondMinutes.get(token)
|
||||
Scheduling scheduling = new Scheduling(cronExpression, true);
|
||||
scheduling.setGlobal(true);
|
||||
|
||||
logger.debug("{} : {} : {}", context, token, cronExpression.getCronExpression());
|
||||
|
||||
|
||||
|
||||
//UUID uuid = scheduleTest(scheduling);
|
||||
//logger.debug("Launched with UUID : {}", uuid);
|
||||
|
||||
logger.info("\n\n\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void cronExpPreviousMustBeTerminated() throws Exception {
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.gcube.resourceregistry;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.context.ContextElaborator;
|
||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ContextManagementImpl;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ContextCreator extends ContextElaborator {
|
||||
|
||||
protected Map<String, UUID> contexts;
|
||||
|
||||
protected ContextManagement contextManagement;
|
||||
|
||||
public ContextCreator() {
|
||||
super();
|
||||
contexts = new HashMap<>();
|
||||
contextManagement = new ContextManagementImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void elaborateContext(ScopeBean scopeBean) throws Exception {
|
||||
UUID parentUUID = null;
|
||||
switch(scopeBean.type()) {
|
||||
case INFRASTRUCTURE:
|
||||
parentUUID = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
parentUUID = getParentUUID(scopeBean);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
String created = contextManagement.create(parentUUID, scopeBean.name());
|
||||
Context context = ISMapper.unmarshal(Context.class, created);
|
||||
contexts.put(scopeBean.toString(), context.getHeader().getUUID());
|
||||
}
|
||||
|
||||
private UUID getParentUUID(ScopeBean scopeBean) {
|
||||
String parent = scopeBean.toString().replace("/" + scopeBean.name(), "");
|
||||
return contexts.get(parent);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.resourceregistry;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ContextCreatorTest extends org.gcube.ScopedTest {
|
||||
|
||||
@Test
|
||||
public void createAll() throws Exception {
|
||||
File src = new File("src");
|
||||
File test = new File(src, "test");
|
||||
File resources = new File(test, "resources");
|
||||
|
||||
File voFile = new File(resources, "scopedata.xml");
|
||||
|
||||
ContextCreator contextCreator = new ContextCreator();
|
||||
contextCreator.all(voFile);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -42,6 +42,9 @@ public class ScopedTest {
|
|||
public static final String GCUBE_VARNAME = "GCUBE";
|
||||
public static final String GCUBE;
|
||||
|
||||
public static final String ROOT_VARNAME = "ROOT";
|
||||
public static final String ROOT;
|
||||
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE;
|
||||
public static final String ALTERNATIVE_TEST_SCOPE;
|
||||
|
@ -65,8 +68,10 @@ public class ScopedTest {
|
|||
|
||||
GCUBE = properties.getProperty(GCUBE_VARNAME);
|
||||
|
||||
ROOT = properties.getProperty(ROOT_VARNAME);
|
||||
|
||||
DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE;
|
||||
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC;
|
||||
}
|
||||
|
||||
public static String getCurrentContext() throws Exception{
|
||||
|
|
Loading…
Reference in New Issue