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/private/luca.frosini/infrastructure-tests@124058 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b118d3e7ca
commit
b98fd9eebd
61
pom.xml
61
pom.xml
|
@ -23,66 +23,79 @@
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.data.publishing</groupId>
|
||||||
|
<artifactId>document-store-lib</artifactId>
|
||||||
|
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.accounting</groupId>
|
||||||
|
<artifactId>accounting-lib</artifactId>
|
||||||
|
<version>[2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.data.publishing</groupId>
|
||||||
|
<artifactId>document-store-lib-couchbase</artifactId>
|
||||||
|
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<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>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-analytics-persistence-couchdb</artifactId>
|
<artifactId>accounting-analytics-persistence-couchdb</artifactId>
|
||||||
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
|
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
|
||||||
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.data.publishing</groupId>
|
<groupId>org.gcube.vremanagement</groupId>
|
||||||
<artifactId>document-store-lib</artifactId>
|
<artifactId>smart-executor-client</artifactId>
|
||||||
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
<version>[1.3.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>accounting-lib</artifactId>
|
<artifactId>common-scope</artifactId>
|
||||||
<version>[2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
<version>[2.0.0-SNAPSHOT, 3.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>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources</groupId>
|
<groupId>org.gcube.resources</groupId>
|
||||||
<artifactId>registry-publisher</artifactId>
|
<artifactId>registry-publisher</artifactId>
|
||||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT]</version>
|
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT]</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-encryption</artifactId>
|
<artifactId>common-encryption</artifactId>
|
||||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT]</version>
|
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT]</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>4.11</version>
|
<version>1.7.5</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.0.13</version>
|
<version>1.0.13</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.couchdb.query;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
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.quartz.CronExpression;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
*/
|
||||||
|
public class CouchDBQueryPluginSmartExecutorSchedulerTest {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(CouchDBQueryPluginSmartExecutorSchedulerTest.class);
|
||||||
|
|
||||||
|
public static final String START = "START";
|
||||||
|
public static final String END = "END";
|
||||||
|
|
||||||
|
public static final String SCOPE = "";
|
||||||
|
|
||||||
|
private SmartExecutorProxy proxy;
|
||||||
|
|
||||||
|
//@Before
|
||||||
|
public void before() throws Exception{
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
proxy = ExecutorPlugin.getExecutorProxy(CouchDBQueryPluginDeclaration.NAME).build();
|
||||||
|
Assert.assertNotNull(proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
//@After
|
||||||
|
public void after(){
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID scheduleTest(Scheduling scheduling, Long sleepTime) throws Exception {
|
||||||
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||||
|
if(sleepTime==null){
|
||||||
|
sleepTime = new Long(10*1000); // 10 sec = 10 * 1000 millisec
|
||||||
|
}
|
||||||
|
inputs.put(CouchDBQueryPlugin.DELAY_MILLIS, sleepTime);
|
||||||
|
logger.debug("Inputs : {}", inputs);
|
||||||
|
|
||||||
|
LaunchParameter parameter = new LaunchParameter(CouchDBQueryPluginDeclaration.NAME, inputs);
|
||||||
|
parameter.setScheduling(scheduling);
|
||||||
|
|
||||||
|
String uuidString = proxy.launch(parameter);
|
||||||
|
return UUID.fromString(uuidString);
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void cronExpPreviousMustBeTerminated() throws Exception {
|
||||||
|
CronExpression cronExpression = new CronExpression("0 */10 * * * ?"); // every 10 minutes starting from now
|
||||||
|
Scheduling scheduling = new Scheduling(cronExpression, true);
|
||||||
|
scheduling.setGlobal(true);
|
||||||
|
UUID uuid = scheduleTest(scheduling, new Long(1000*60)); // 1 min
|
||||||
|
logger.debug("Launched with UUID : {}", uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void unSchedule() throws Exception {
|
||||||
|
proxy.unSchedule(null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package org.gcube.accounting.couchdb.query;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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 CouchDBQueryPluginTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger
|
||||||
|
*/
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(CouchDBQueryPluginTest.class);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() throws Exception{
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after(){
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunch() throws Exception {
|
||||||
|
logger.debug("Starting to test launch");
|
||||||
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||||
|
inputs.put(CouchDBQueryPlugin.DELAY_MILLIS, 1000*10); // Delay 10 sec
|
||||||
|
CouchDBQueryPlugin couchDBQueryPlugin = new CouchDBQueryPlugin(null);
|
||||||
|
couchDBQueryPlugin.launch(inputs);
|
||||||
|
logger.debug("-------------- launch test finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.couchdb.query;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.client.Constants;
|
||||||
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
|
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TestUtility {
|
||||||
|
|
||||||
|
public static final String TOKEN = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger
|
||||||
|
*/
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(TestUtility.class);
|
||||||
|
|
||||||
|
public static String getScopeFromToken(){
|
||||||
|
String token = SecurityTokenProvider.instance.get();
|
||||||
|
AuthorizationEntry authorizationEntry;
|
||||||
|
try {
|
||||||
|
authorizationEntry = Constants.authorizationService().get(token);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
String scope = authorizationEntry.getContext();
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish the provided resource on current scope
|
||||||
|
* @param resource to be published
|
||||||
|
* @throws RegistryNotFoundException if the Registry is not found so the
|
||||||
|
* resource has not be published
|
||||||
|
*/
|
||||||
|
public static void publishResource(Resource resource) throws Exception {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("Trying to publish to {}:\n{}", getScopeFromToken(), stringWriter);
|
||||||
|
registryPublisher.create(resource);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("The resource was not published", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the resource from IS from curretn scope
|
||||||
|
* @param resource to be unpublished
|
||||||
|
* @throws RegistryNotFoundException if the Registry is not found so the
|
||||||
|
* resource has not be published
|
||||||
|
*/
|
||||||
|
public static void unPublishResource(Resource resource) throws Exception {
|
||||||
|
//StringWriter stringWriter = new StringWriter();
|
||||||
|
//Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
String id = resource.id();
|
||||||
|
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, getScopeFromToken());
|
||||||
|
|
||||||
|
registryPublisher.remove(resource);
|
||||||
|
|
||||||
|
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,134 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.persistence;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceBackend;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceBackendFactory;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceCouchBase;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
|
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 PersistenceCouchBaseTest {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PersistenceCouchBaseTest.class);
|
||||||
|
|
||||||
|
public static final long timeout = 5000;
|
||||||
|
public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() throws Exception{
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after(){
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PersistenceBackend getPersistence(){
|
||||||
|
PersistenceBackendFactory.setFallbackLocation(null);
|
||||||
|
return PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void persistenceIsCouchBase() {
|
||||||
|
PersistenceBackend persistence = getPersistence();
|
||||||
|
Assert.assertTrue(persistence instanceof PersistenceCouchBase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void publishResource(Resource resource) throws Exception {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("Trying to publish to {}:\n{}", BasicUsageRecord.getScopeFromToken(), stringWriter);
|
||||||
|
registryPublisher.create(resource);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("The resource was not published", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unPublishResource(Resource resource) throws Exception {
|
||||||
|
//StringWriter stringWriter = new StringWriter();
|
||||||
|
//Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
String id = resource.id();
|
||||||
|
logger.debug("Trying to remove {} with ID {} from {}",
|
||||||
|
resource.getClass().getSimpleName(), id,
|
||||||
|
BasicUsageRecord.getScopeFromToken());
|
||||||
|
|
||||||
|
registryPublisher.remove(resource);
|
||||||
|
|
||||||
|
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testScopeRecheck() throws Exception {
|
||||||
|
ServiceEndpoint serviceEndpoint = null;
|
||||||
|
try {
|
||||||
|
AccountingPersistenceConfiguration persitenceConfiguration = new AccountingPersistenceConfiguration(PersistenceCouchBase.class);
|
||||||
|
serviceEndpoint = persitenceConfiguration.getServiceEndpoint(
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_CATEGORY,
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_NAME,
|
||||||
|
PersistenceCouchBase.class);
|
||||||
|
unPublishResource(serviceEndpoint);
|
||||||
|
}catch(IndexOutOfBoundsException e){
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.PARENT_TOKEN);
|
||||||
|
AccountingPersistenceConfiguration persitenceConfiguration = new AccountingPersistenceConfiguration(PersistenceCouchBase.class);
|
||||||
|
serviceEndpoint = persitenceConfiguration.getServiceEndpoint(
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_CATEGORY, AccountingPersistenceConfiguration.SERVICE_ENDPOINT_NAME,
|
||||||
|
PersistenceCouchBase.class);
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
long startTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
long endTime = startTime;
|
||||||
|
while(endTime <= (startTime + 10*1000)){ // 10 sec
|
||||||
|
endTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Going to check First Time");
|
||||||
|
PersistenceBackend first = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
logger.debug("First {} : {}", PersistenceBackend.class.getSimpleName(), first);
|
||||||
|
|
||||||
|
publishResource(serviceEndpoint);
|
||||||
|
|
||||||
|
startTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
endTime = startTime;
|
||||||
|
while(endTime <= (startTime + (PersistenceBackendFactory.FALLBACK_RETRY_TIME + 100))){
|
||||||
|
endTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Going to check Second Time");
|
||||||
|
PersistenceBackend second = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
logger.debug("Second {} : {}", PersistenceBackend.class.getSimpleName(), second);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first, second);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,134 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.persistence;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceBackend;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceBackendFactory;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceCouchDB;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
|
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 PersistenceCouchDBTest {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PersistenceCouchDBTest.class);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() throws Exception{
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after(){
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PersistenceBackend getPersistence(){
|
||||||
|
PersistenceBackendFactory.setFallbackLocation(null);
|
||||||
|
return PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void persistenceIsCouchDB() {
|
||||||
|
PersistenceBackend persistence = getPersistence();
|
||||||
|
Assert.assertTrue(persistence instanceof PersistenceCouchDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void publishResource(Resource resource) throws Exception {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("Trying to publish to {}:\n{}", BasicUsageRecord.getScopeFromToken(), stringWriter);
|
||||||
|
registryPublisher.create(resource);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("The resource was not published", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unPublishResource(Resource resource) throws Exception {
|
||||||
|
//StringWriter stringWriter = new StringWriter();
|
||||||
|
//Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
String id = resource.id();
|
||||||
|
logger.debug("Trying to remove {} with ID {} from {}",
|
||||||
|
resource.getClass().getSimpleName(), id,
|
||||||
|
BasicUsageRecord.getScopeFromToken());
|
||||||
|
|
||||||
|
registryPublisher.remove(resource);
|
||||||
|
|
||||||
|
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testScopeRecheck() throws Exception {
|
||||||
|
|
||||||
|
ServiceEndpoint serviceEndpoint = null;
|
||||||
|
try {
|
||||||
|
AccountingPersistenceConfiguration persitenceConfiguration =
|
||||||
|
new AccountingPersistenceConfiguration(PersistenceCouchDB.class);
|
||||||
|
serviceEndpoint = persitenceConfiguration.getServiceEndpoint(
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_CATEGORY,
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_NAME,
|
||||||
|
PersistenceCouchDB.class);
|
||||||
|
unPublishResource(serviceEndpoint);
|
||||||
|
} catch(IndexOutOfBoundsException e){
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.PARENT_TOKEN);
|
||||||
|
AccountingPersistenceConfiguration persitenceConfiguration =
|
||||||
|
new AccountingPersistenceConfiguration(PersistenceCouchDB.class);
|
||||||
|
serviceEndpoint = persitenceConfiguration.getServiceEndpoint(
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_CATEGORY,
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_NAME,
|
||||||
|
PersistenceCouchDB.class);
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long startTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
long endTime = startTime;
|
||||||
|
while(endTime <= (startTime + 10*1000)){ // 10 sec
|
||||||
|
endTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Going to check First Time");
|
||||||
|
PersistenceBackend first = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
logger.debug("First {} : {}", PersistenceBackend.class.getSimpleName(), first);
|
||||||
|
|
||||||
|
publishResource(serviceEndpoint);
|
||||||
|
|
||||||
|
startTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
endTime = startTime;
|
||||||
|
while(endTime <= (startTime + (PersistenceBackendFactory.FALLBACK_RETRY_TIME + 100))){
|
||||||
|
endTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Going to check Second Time");
|
||||||
|
PersistenceBackend second = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
logger.debug("Second {} : {}", PersistenceBackend.class.getSimpleName(), second);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first, second);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,130 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.persistence;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceBackend;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceBackendFactory;
|
||||||
|
import org.gcube.documentstore.persistence.PersistenceMongoDB;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
|
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 PersistenceMongoDBTest {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PersistenceMongoDBTest.class);
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() throws Exception {
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after(){
|
||||||
|
SecurityTokenProvider.instance.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PersistenceBackend getPersistence(){
|
||||||
|
PersistenceBackendFactory.setFallbackLocation(null);
|
||||||
|
return PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void persistenceIsMongoDB() {
|
||||||
|
PersistenceBackend accountingPersistence = getPersistence();
|
||||||
|
Assert.assertTrue(accountingPersistence instanceof PersistenceMongoDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void publishResource(Resource resource) throws Exception {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("Trying to publish to {}:\n{}", BasicUsageRecord.getScopeFromToken(), stringWriter);
|
||||||
|
registryPublisher.create(resource);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("The resource was not published", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void unPublishResource(Resource resource) throws Exception {
|
||||||
|
//StringWriter stringWriter = new StringWriter();
|
||||||
|
//Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
String id = resource.id();
|
||||||
|
logger.debug("Trying to remove {} with ID {} from {}",
|
||||||
|
resource.getClass().getSimpleName(), id,
|
||||||
|
BasicUsageRecord.getScopeFromToken());
|
||||||
|
|
||||||
|
registryPublisher.remove(resource);
|
||||||
|
|
||||||
|
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testScopeRecheck() throws Exception {
|
||||||
|
ServiceEndpoint serviceEndpoint = null;
|
||||||
|
try {
|
||||||
|
AccountingPersistenceConfiguration persitenceConfiguration = new AccountingPersistenceConfiguration(PersistenceMongoDB.class);
|
||||||
|
serviceEndpoint = persitenceConfiguration.getServiceEndpoint(
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_CATEGORY, AccountingPersistenceConfiguration.SERVICE_ENDPOINT_NAME,
|
||||||
|
PersistenceMongoDB.class);
|
||||||
|
unPublishResource(serviceEndpoint);
|
||||||
|
} catch(IndexOutOfBoundsException e){
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.PARENT_TOKEN);
|
||||||
|
AccountingPersistenceConfiguration persitenceConfiguration = new AccountingPersistenceConfiguration(PersistenceMongoDB.class);
|
||||||
|
serviceEndpoint = persitenceConfiguration.getServiceEndpoint(
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_CATEGORY,
|
||||||
|
AccountingPersistenceConfiguration.SERVICE_ENDPOINT_NAME,
|
||||||
|
PersistenceMongoDB.class);
|
||||||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long startTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
long endTime = startTime;
|
||||||
|
while(endTime <= (startTime + 10*1000)){ // 10 sec
|
||||||
|
endTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Going to check First Time");
|
||||||
|
PersistenceBackend first = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
logger.debug("First {} : {}", PersistenceBackend.class.getSimpleName(), first);
|
||||||
|
|
||||||
|
publishResource(serviceEndpoint);
|
||||||
|
|
||||||
|
startTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
endTime = startTime;
|
||||||
|
while(endTime <= (startTime + (PersistenceBackendFactory.FALLBACK_RETRY_TIME + 100))){
|
||||||
|
endTime = Calendar.getInstance().getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Going to check Second Time");
|
||||||
|
PersistenceBackend second = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||||
|
logger.debug("Second {} : {}", PersistenceBackend.class.getSimpleName(), second);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first, second);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.accounting.persistence;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.client.Constants;
|
||||||
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.resources.gcore.Resource;
|
||||||
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
|
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TestUtility {
|
||||||
|
|
||||||
|
public static final String TOKEN = "";
|
||||||
|
public static final String PARENT_TOKEN = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger
|
||||||
|
*/
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(TestUtility.class);
|
||||||
|
|
||||||
|
public static String getScopeFromToken(){
|
||||||
|
String token = SecurityTokenProvider.instance.get();
|
||||||
|
AuthorizationEntry authorizationEntry;
|
||||||
|
try {
|
||||||
|
authorizationEntry = Constants.authorizationService().get(token);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
String scope = authorizationEntry.getContext();
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish the provided resource on current scope
|
||||||
|
* @param resource to be published
|
||||||
|
* @throws RegistryNotFoundException if the Registry is not found so the
|
||||||
|
* resource has not be published
|
||||||
|
*/
|
||||||
|
public static void publishResource(Resource resource) throws Exception {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("Trying to publish to {}:\n{}", getScopeFromToken(), stringWriter);
|
||||||
|
registryPublisher.create(resource);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("The resource was not published", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the resource from IS from curretn scope
|
||||||
|
* @param resource to be unpublished
|
||||||
|
* @throws RegistryNotFoundException if the Registry is not found so the
|
||||||
|
* resource has not be published
|
||||||
|
*/
|
||||||
|
public static void unPublishResource(Resource resource) throws Exception {
|
||||||
|
//StringWriter stringWriter = new StringWriter();
|
||||||
|
//Resources.marshal(resource, stringWriter);
|
||||||
|
|
||||||
|
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
|
String id = resource.id();
|
||||||
|
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, getScopeFromToken());
|
||||||
|
|
||||||
|
registryPublisher.remove(resource);
|
||||||
|
|
||||||
|
logger.debug("{} with ID {} removed successfully", resource.getClass().getSimpleName(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.documentstore.persistence;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||||
|
import org.gcube.accounting.persistence.TestUtility;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.documentstore.records.Record;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PersistenceCouchBaseTest {
|
||||||
|
|
||||||
|
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.createTestServiceUsageRecordAutomaticScope();
|
||||||
|
logger.debug("UsageRecord : {}", record.toString());
|
||||||
|
JsonNode node = PersistenceCouchBase.usageRecordToJsonNode(record);
|
||||||
|
logger.debug("Node : {}", node.toString());
|
||||||
|
Record r = PersistenceCouchBase.jsonNodeToUsageRecord(node);
|
||||||
|
Assert.assertEquals(0, record.compareTo(r));
|
||||||
|
Assert.assertEquals(0, r.compareTo(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJsonNodeUsageRecordConversionsWithNestedMap() throws Exception {
|
||||||
|
Record record = TestUsageRecord.createTestTaskUsageRecordAutomaticScope();
|
||||||
|
logger.debug("UsageRecord : {}", record.toString());
|
||||||
|
JsonNode node = PersistenceCouchBase.usageRecordToJsonNode(record);
|
||||||
|
logger.debug("Node : {}", node.toString());
|
||||||
|
Record r = PersistenceCouchBase.jsonNodeToUsageRecord(node);
|
||||||
|
Assert.assertEquals(0, record.compareTo(r));
|
||||||
|
Assert.assertEquals(0, r.compareTo(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testProxyWithTestConfiguration() throws Exception{
|
||||||
|
// Production-Preproduction Nodes
|
||||||
|
URL url = new URL("http://pc-frosini.isti.cnr.it");
|
||||||
|
|
||||||
|
PersistenceBackendConfiguration persitenceConfiguration = PersistenceBackendConfiguration.getUnconfiguredInstance();
|
||||||
|
persitenceConfiguration.addProperty(PersistenceCouchBase.URL_PROPERTY_KEY, url.toString());
|
||||||
|
//persitenceConfiguration.addProperty(AccountingPersistenceCouchBase.USERNAME_PROPERTY_KEY, "");
|
||||||
|
persitenceConfiguration.addProperty(PersistenceCouchBase.PASSWORD_PROPERTY_KEY, "");
|
||||||
|
persitenceConfiguration.addProperty(PersistenceCouchBase.BUCKET_NAME_PROPERTY_KEY,"accounting");
|
||||||
|
|
||||||
|
PersistenceCouchBase couchBase = new PersistenceCouchBase();
|
||||||
|
couchBase.prepareConnection(persitenceConfiguration);
|
||||||
|
|
||||||
|
Record record = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||||
|
couchBase.reallyAccount(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.documentstore.persistence;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.codehaus.jackson.JsonNode;
|
||||||
|
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||||
|
import org.gcube.accounting.persistence.TestUtility;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.documentstore.records.Record;
|
||||||
|
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 PersistenceCouchDBTest {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PersistenceCouchDBTest.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.createTestServiceUsageRecordAutomaticScope();
|
||||||
|
logger.debug("UsageRecord : {}", record.toString());
|
||||||
|
JsonNode node = PersistenceCouchDB.usageRecordToJsonNode(record);
|
||||||
|
logger.debug("Node : {}", node.toString());
|
||||||
|
Record r = PersistenceCouchDB.jsonNodeToUsageRecord(node);
|
||||||
|
Assert.assertEquals(0, record.compareTo(r));
|
||||||
|
Assert.assertEquals(0, r.compareTo(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJsonNodeUsageRecordConversionsWithNestedMap() throws Exception {
|
||||||
|
Record record = TestUsageRecord.createTestTaskUsageRecordAutomaticScope();
|
||||||
|
logger.debug("UsageRecord : {}", record.toString());
|
||||||
|
JsonNode node = PersistenceCouchDB.usageRecordToJsonNode(record);
|
||||||
|
logger.debug("Node : {}", node.toString());
|
||||||
|
Record r = PersistenceCouchDB.jsonNodeToUsageRecord(node);
|
||||||
|
Assert.assertEquals(0, record.compareTo(r));
|
||||||
|
Assert.assertEquals(0, r.compareTo(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testProxyWithTestConfiguration() throws Exception{
|
||||||
|
// Production-Preproduction Nodes
|
||||||
|
//URL url = new URL("http://accounting-d4s.d4science.org");
|
||||||
|
//URL url = new URL("http://couchdb02-d4s.d4science.org:5984");
|
||||||
|
//URL url = new URL("http://couchdb01-d4s.d4science.org:5984");
|
||||||
|
|
||||||
|
URL url = new URL("http://accounting-d-d4s.d4science.org/_utils/");
|
||||||
|
//URL url = new URL("http://couchdb02-d-d4s.d4science.org:5984");
|
||||||
|
//URL url = new URL("http://couchdb01-d-d4s.d4science.org:5984");
|
||||||
|
|
||||||
|
PersistenceBackendConfiguration persitenceConfiguration = PersistenceBackendConfiguration.getUnconfiguredInstance();
|
||||||
|
persitenceConfiguration.addProperty(PersistenceCouchDB.URL_PROPERTY_KEY, url.toString());
|
||||||
|
persitenceConfiguration.addProperty(PersistenceCouchDB.USERNAME_PROPERTY_KEY, "");
|
||||||
|
persitenceConfiguration.addProperty(PersistenceCouchDB.PASSWORD_PROPERTY_KEY, "");
|
||||||
|
persitenceConfiguration.addProperty(PersistenceCouchDB.DB_NAME,"");
|
||||||
|
|
||||||
|
PersistenceCouchDB couch = new PersistenceCouchDB();
|
||||||
|
couch.prepareConnection(persitenceConfiguration);
|
||||||
|
|
||||||
|
Record record = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||||
|
couch.reallyAccount(record);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,100 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.documentstore.persistence;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
|
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType;
|
||||||
|
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||||
|
import org.gcube.accounting.persistence.TestUtility;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.documentstore.records.Record;
|
||||||
|
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 PersistenceMongoDBTest {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PersistenceMongoDBTest.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.createTestServiceUsageRecordAutomaticScope();
|
||||||
|
logger.debug("UsageRecord : {}", record.toString());
|
||||||
|
Document document = PersistenceMongoDB.usageRecordToDocument(record);
|
||||||
|
logger.debug("Document : {}", document.toString());
|
||||||
|
Record r = PersistenceMongoDB.documentToUsageRecord(document);
|
||||||
|
Assert.assertEquals(0, record.compareTo(r));
|
||||||
|
Assert.assertEquals(0, r.compareTo(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJsonNodeUsageRecordConversionsWithNestedMap() throws Exception {
|
||||||
|
Record record = TestUsageRecord.createTestTaskUsageRecordAutomaticScope();
|
||||||
|
logger.debug("UsageRecord : {}", record.toString());
|
||||||
|
Document document = PersistenceMongoDB.usageRecordToDocument(record);
|
||||||
|
logger.debug("Document : {}", document.toString());
|
||||||
|
Record r = PersistenceMongoDB.documentToUsageRecord(document);
|
||||||
|
Assert.assertEquals(0, record.compareTo(r));
|
||||||
|
Assert.assertEquals(0, r.compareTo(record));
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum AUX {
|
||||||
|
TEST, TESTER, TESTING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfiguration() throws Exception{
|
||||||
|
URL url = new URL("http://mongo-test.d4science.org");
|
||||||
|
|
||||||
|
PersistenceBackendConfiguration persitenceConfiguration = PersistenceBackendConfiguration.getUnconfiguredInstance();
|
||||||
|
persitenceConfiguration.addProperty(PersistenceMongoDB.URL_PROPERTY_KEY, url.toString());
|
||||||
|
persitenceConfiguration.addProperty(PersistenceMongoDB.USERNAME_PROPERTY_KEY, "accounting");
|
||||||
|
persitenceConfiguration.addProperty(PersistenceMongoDB.PASSWORD_PROPERTY_KEY, "testpwd");
|
||||||
|
persitenceConfiguration.addProperty(PersistenceMongoDB.DB_NAME,"accounting");
|
||||||
|
persitenceConfiguration.addProperty(PersistenceMongoDB.COLLECTION_NAME, UsageRecord.class.getSimpleName());
|
||||||
|
PersistenceMongoDB mongo = new PersistenceMongoDB();
|
||||||
|
mongo.prepareConnection(persitenceConfiguration);
|
||||||
|
|
||||||
|
|
||||||
|
Record record = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||||
|
record.setResourceProperty("Test", AUX.TESTER);
|
||||||
|
mongo.reallyAccount(record);
|
||||||
|
|
||||||
|
record = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||||
|
record.setResourceProperty("Test", AUX.TESTER);
|
||||||
|
mongo.reallyAccount(record);
|
||||||
|
|
||||||
|
record = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
|
||||||
|
mongo.reallyAccount(record);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
EnumCodec<OperationType> enumCodec = new EnumCodec<OperationType>(OperationType.class);
|
||||||
|
Assert.assertEquals(OperationType.class, enumCodec.getEncoderClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue