diff --git a/pom.xml b/pom.xml index 98efe71..f54c986 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,12 @@ test - + + org.gcube.accounting + accounting-aggregator-se-plugin + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + test + diff --git a/src/test/java/org/gcube/aggregator/plugin/AggregatorAccountingPluginSmartExecutorSchedulerTest.java b/src/test/java/org/gcube/aggregator/plugin/AggregatorAccountingPluginSmartExecutorSchedulerTest.java new file mode 100644 index 0000000..224faf3 --- /dev/null +++ b/src/test/java/org/gcube/aggregator/plugin/AggregatorAccountingPluginSmartExecutorSchedulerTest.java @@ -0,0 +1,208 @@ +/** + * + */ +package org.gcube.aggregator.plugin; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.gcube.testutility.ScopedTest; +import org.gcube.vremanagement.executor.api.types.LaunchParameter; +import org.gcube.vremanagement.executor.api.types.Scheduling; +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; + +public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends ScopedTest { + + private static Logger logger = LoggerFactory.getLogger(AggregatorAccountingPluginSmartExecutorSchedulerTest.class); + + private SmartExecutorProxy proxy; + + @Before + public void before() throws Exception{ + //ScopeProvider.instance.reset(); // Comment this to run the test. this line has been added to avoid unwanted launch + //SecurityTokenProvider.instance.set(TestUtility.TOKEN); + //ScopeProvider.instance.set("/gcube/devNext"); + proxy = ExecutorPlugin.getExecutorProxy("Accouting-Aggregator-Plugin").build(); + Assert.assertNotNull(proxy); + + } + + public UUID scheduleTest(Scheduling scheduling) throws Exception { + + Map inputs = new HashMap(); + logger.debug("Inputs : {}", inputs); + inputs.put("type","DAILY"); + //period to be processed + inputs.put("interval",3); + //change to time + inputs.put("startTime", 14); + //specify bucket + inputs.put("bucket","accounting_service"); + //current scope + inputs.put("currentScope",false); + //specify user for save to workspace + inputs.put("user","alessandro.pieve"); + //specify a recovery 0 default recovery and aggregate, 1 only aggregate, 2 only recovery + inputs.put("recovery",0); + + + //optional if present interval is not considered and elaborate a specificy step + //e.g if type is daily and set input.put("intervalStep",10), this plugin elaborate a 10 hour + // inputs.put("intervalStep",24); + //optional if exist and true no backup, but start elaborate immediately +// inputs.put("backup",false); +// inputs.put("typePersisted",1); + LaunchParameter parameter = new LaunchParameter("Accouting-Aggregator-Plugin", inputs); + parameter.setScheduling(scheduling); + + try { + String uuidString = proxy.launch(parameter); + + + return UUID.fromString(uuidString); + } catch(Exception e){ + logger.error("Error launching sheduled task", e); + throw e; + } + + } + + + + @Test + public void launch() { + Map inputs = new HashMap(); + LaunchParameter launchParameter = new LaunchParameter("Test", inputs); + try { + proxy.launch(launchParameter); + } catch (Exception e) { + logger.error("Error launching sheduled task", e); + //throw e; + } + + } + @Test + public void LaunchTest() throws Exception { + + Map inputs = new HashMap(); + logger.debug("Inputs : {}", inputs); + + //inputs.put("type","DAILY"); + inputs.put("type","MONTHLY"); + //period to be processed + inputs.put("interval",1); + //change to time + //novembre 6 + //ottobre 7 + //settembre 8 + //agosto 9 + //luglio 10 + //giugno e' 11 + + + inputs.put("startTime",7); + //inputs.put("startTime",173); + inputs.put("intervalStep",4); + + + + //specify bucket + inputs.put("bucket","accounting_service"); + //current scope + inputs.put("currentScope",false); + //specify user for save to workspace + inputs.put("user","alessandro.pieve"); + //specify a recovery 0 default recovery and aggregate, 1 only aggregate, 2 only recovery + inputs.put("recovery",0); + //optional if present interval is not considered and elaborate a specificy step + //e.g if type is daily and set input.put("intervalStep",10), this plugin elaborate a 10 hour + + //optional if exist and true no backup, but start elaborate immediately + //inputs.put("backup",false); + //inputs.put("typePersisted",1); + + LaunchParameter parameter = new LaunchParameter("Accouting-Aggregator-Plugin", inputs); + try { + String uuidString = proxy.launch(parameter); + logger.debug("Launched with UUID : {}", uuidString); + } catch(Exception e){ + logger.error("Error launching sheduled task", e); + throw e; + } + + } + + + + + + @Test + public void LaunchTestAutomatic() throws Exception { + + Map inputs = new HashMap(); + logger.debug("Inputs : {}", inputs); + + inputs.put("type","DAILY"); + //period to be processed + inputs.put("interval",1); + //change to time + //load a file for start time + inputs.put("pathFile","/home/gcube/SmartGears/startTime"); + + //specify bucket + inputs.put("bucket","accounting_service"); + inputs.put("endScriptTime","18:30"); + //current scope + inputs.put("currentScope",false); + //specify user for save to workspace + inputs.put("user","alessandro.pieve"); + //specify a recovery 0 default recovery and aggregate, 1 only aggregate, 2 only recovery + inputs.put("recovery",0); + + LaunchParameter parameter = new LaunchParameter("Accouting-Aggregator-Plugin", inputs); + try { + String uuidString = proxy.launch(parameter); + logger.debug("Launched with UUID : {}", uuidString); + } catch(Exception e){ + logger.error("Error launching sheduled task", e); + throw e; + } + + } + + + + + + + @Test + public void cronExpPreviousMustBeTerminated() throws Exception { + CronExpression cronExpression = new CronExpression("0 0 2 * * ?"); // every day at 2:00 + Scheduling scheduling = new Scheduling(cronExpression, true); + scheduling.setGlobal(true); + UUID uuid = scheduleTest(scheduling); + logger.debug("Launched with UUID : {}", uuid); + } + + + + @Test + public void unSchedule() throws Exception { + //proxy.unSchedule("", true); + + } + + @Test + public void stop() throws Exception { + proxy.stop("Accouting-Aggregator-Plugin"); + } + +} diff --git a/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java b/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java index 3cb91a5..39b8f1b 100644 --- a/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java +++ b/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java @@ -5,14 +5,10 @@ package org.gcube.documentstore.persistence; import java.net.URL; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.records.Record; import org.gcube.testutility.ScopedTest; import org.gcube.testutility.TestUsageRecord; -import org.gcube.testutility.TestUtility; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,16 +23,6 @@ public class PersistenceCouchBaseTest extends ScopedTest { private static final Logger logger = LoggerFactory.getLogger(PersistenceCouchBaseTest.class); - @Before - public void before() throws Exception{ - SecurityTokenProvider.instance.set(TestUtility.TOKEN); - } - - @After - public void after(){ - SecurityTokenProvider.instance.reset(); - } - @Test public void testJsonNodeUsageRecordConversions() throws Exception { Record record = TestUsageRecord.createTestServiceUsageRecord(); diff --git a/src/test/java/org/gcube/documentstore/records/DSMapperTest.java b/src/test/java/org/gcube/documentstore/records/DSMapperTest.java new file mode 100644 index 0000000..a3087f2 --- /dev/null +++ b/src/test/java/org/gcube/documentstore/records/DSMapperTest.java @@ -0,0 +1,5 @@ +package org.gcube.documentstore.records; + +public class DSMapperTest { + +} diff --git a/src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java b/src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java index 51cb670..138c712 100644 --- a/src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java +++ b/src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java @@ -93,4 +93,8 @@ public class RecordUtilityTest { logger.trace("{}", RecordUtility.recordAggregationMapping); } + + + + }