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@124071 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-10 15:49:09 +00:00
parent d82be9431a
commit 4f15d5b3b0
13 changed files with 151 additions and 44 deletions

57
pom.xml
View File

@ -27,73 +27,110 @@
<dependency> <dependency>
<groupId>org.gcube.data.publishing</groupId> <groupId>org.gcube.data.publishing</groupId>
<artifactId>document-store-lib</artifactId> <artifactId>document-store-lib</artifactId>
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency> <scope>test</scope>
<dependency>
<groupId>org.gcube.accounting</groupId>
<artifactId>accounting-lib</artifactId>
<version>[2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.data.publishing</groupId> <groupId>org.gcube.data.publishing</groupId>
<artifactId>document-store-lib-couchbase</artifactId> <artifactId>document-store-lib-couchbase</artifactId>
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.data.publishing</groupId>
<artifactId>document-store-lib-couchdb</artifactId>
<version>[1.1.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.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency> </dependency>
<dependency>
<dependency>
<groupId>org.gcube.accounting</groupId>
<artifactId>accounting-lib</artifactId>
<version>[2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>test</scope>
</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.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.vremanagement</groupId> <groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor-client</artifactId> <artifactId>smart-executor-client</artifactId>
<version>[1.3.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> <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>
</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>
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId> <artifactId>common-scope</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.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>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.7.5</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> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.11</version> <version>4.11</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -7,7 +7,6 @@ import java.io.StringWriter;
import java.net.URL; import java.net.URL;
import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.testutility.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.Resources; import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint;
@ -18,6 +17,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
import org.gcube.common.resources.gcore.common.Platform; import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.common.resources.gcore.utils.Group; import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.documentstore.persistence.PersistenceBackend; import org.gcube.documentstore.persistence.PersistenceBackend;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;

View File

@ -17,6 +17,7 @@ import org.gcube.documentstore.persistence.PersistenceBackendFactory;
import org.gcube.documentstore.persistence.PersistenceCouchBase; import org.gcube.documentstore.persistence.PersistenceCouchBase;
import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;

View File

@ -16,6 +16,7 @@ import org.gcube.documentstore.persistence.PersistenceBackendFactory;
import org.gcube.documentstore.persistence.PersistenceCouchDB; import org.gcube.documentstore.persistence.PersistenceCouchDB;
import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;

View File

@ -16,6 +16,7 @@ import org.gcube.documentstore.persistence.PersistenceBackendFactory;
import org.gcube.documentstore.persistence.PersistenceMongoDB; import org.gcube.documentstore.persistence.PersistenceMongoDB;
import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;

View File

@ -8,11 +8,15 @@ import java.util.concurrent.TimeUnit;
import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.testutility.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.persistence.FallbackPersistenceBackend;
import org.gcube.documentstore.persistence.PersistenceBackend;
import org.gcube.documentstore.persistence.PersistenceBackendFactory;
import org.gcube.documentstore.persistence.PersistenceBackendMonitor;
import org.gcube.utils.StressTestUtility; import org.gcube.utils.StressTestUtility;
import org.gcube.utils.TestOperation; import org.gcube.utils.TestOperation;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -52,13 +56,13 @@ public class PersistenceBackendMonitorTest {
UsageRecord usageRecord = null; UsageRecord usageRecord = null;
switch (i%3) { switch (i%3) {
case 0: case 0:
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestServiceUsageRecord();
break; break;
case 1: case 1:
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestStorageUsageRecord();
break; break;
case 2: case 2:
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestJobUsageRecord();
break; break;
} }
try { try {

View File

@ -9,11 +9,10 @@ import java.util.concurrent.TimeUnit;
import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.testutility.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.utils.StressTestUtility; import org.gcube.utils.StressTestUtility;
import org.gcube.utils.TestOperation; import org.gcube.utils.TestOperation;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -60,13 +59,8 @@ public class PersistenceBackendTest {
StressTestUtility.stressTest(new TestOperation() { StressTestUtility.stressTest(new TestOperation() {
@Override @Override
public void operate(int i) { public void operate(int i) {
UsageRecord usageRecord; UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
try { persistence.accountValidateAggregate(usageRecord, true, false);
usageRecord = TestUsageRecord.createTestServiceUsageRecordExplicitScope();
persistence.accountValidateAggregate(usageRecord, true, false);
} catch (InvalidValueException e) {
throw new RuntimeException(e);
}
} }
}, 1); }, 1);
@ -79,7 +73,7 @@ public class PersistenceBackendTest {
StressTestUtility.stressTest(new TestOperation() { StressTestUtility.stressTest(new TestOperation() {
@Override @Override
public void operate(int i) { public void operate(int i) {
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
persistence.accountValidateAggregate(usageRecord, true, false); persistence.accountValidateAggregate(usageRecord, true, false);
} }
}, 1); }, 1);
@ -93,7 +87,7 @@ public class PersistenceBackendTest {
StressTestUtility.stressTest(new TestOperation() { StressTestUtility.stressTest(new TestOperation() {
@Override @Override
public void operate(int i) { public void operate(int i) {
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
persistence.accountValidateAggregate(usageRecord, true, false); persistence.accountValidateAggregate(usageRecord, true, false);
} }
}); });
@ -106,7 +100,7 @@ public class PersistenceBackendTest {
StressTestUtility.stressTest(new TestOperation() { StressTestUtility.stressTest(new TestOperation() {
@Override @Override
public void operate(int i) throws Exception { public void operate(int i) throws Exception {
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
persistence.account(usageRecord); persistence.account(usageRecord);
} }
}); });

View File

@ -6,7 +6,6 @@ package org.gcube.documentstore.persistence;
import java.net.URL; import java.net.URL;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.persistence.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.Record;
import org.junit.After; import org.junit.After;

View File

@ -7,9 +7,9 @@ import java.net.URL;
import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonNode;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.persistence.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.Record;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;

View File

@ -9,7 +9,6 @@ import org.bson.Document;
import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType; import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.persistence.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.Record;
import org.junit.After; import org.junit.After;

View File

@ -10,13 +10,13 @@ import java.util.Map;
import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.testutility.TestUtility;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.documentstore.persistence.PersistenceExecutor; import org.gcube.documentstore.persistence.PersistenceExecutor;
import org.gcube.documentstore.records.AggregatedRecord; import org.gcube.documentstore.records.AggregatedRecord;
import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.Record;
import org.gcube.utils.StressTestUtility; import org.gcube.utils.StressTestUtility;
import org.gcube.utils.TestOperation; import org.gcube.utils.TestOperation;
import org.gcube.utils.TestUtility;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -78,12 +78,12 @@ public class AggregationSchedulerTest {
StressTestUtility.stressTest(new TestOperation() { StressTestUtility.stressTest(new TestOperation() {
@Override @Override
public void operate(int i) throws Exception { public void operate(int i) throws Exception {
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
aggregationScheduler.aggregate(usageRecord, persistenceExecutor); aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
} }
}); });
List<String> types = new ArrayList<String>(); List<String> types = new ArrayList<String>();
String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecordAutomaticScope().getRecordType(); String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecord().getRecordType();
types.add(serviceUsageRecordtype); types.add(serviceUsageRecordtype);
madeAssertion(aggregationScheduler.bufferedRecords, types, 1, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS); madeAssertion(aggregationScheduler.bufferedRecords, types, 1, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS);
aggregationScheduler.flush(persistenceExecutor); aggregationScheduler.flush(persistenceExecutor);
@ -97,7 +97,7 @@ public class AggregationSchedulerTest {
StressTestUtility.stressTest(new TestOperation() { StressTestUtility.stressTest(new TestOperation() {
@Override @Override
public void operate(int i) throws Exception { public void operate(int i) throws Exception {
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
if(i%2==0){ if(i%2==0){
usageRecord.setServiceClass(ALTERNATIVE_SERVICE_CLASS); usageRecord.setServiceClass(ALTERNATIVE_SERVICE_CLASS);
} }
@ -105,7 +105,7 @@ public class AggregationSchedulerTest {
} }
}); });
List<String> types = new ArrayList<String>(); List<String> types = new ArrayList<String>();
String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecordAutomaticScope().getRecordType(); String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecord().getRecordType();
types.add(serviceUsageRecordtype); types.add(serviceUsageRecordtype);
madeAssertion(aggregationScheduler.bufferedRecords, types, 2, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS/2); madeAssertion(aggregationScheduler.bufferedRecords, types, 2, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS/2);
@ -121,17 +121,17 @@ public class AggregationSchedulerTest {
public void operate(int i) throws Exception { public void operate(int i) throws Exception {
UsageRecord usageRecord; UsageRecord usageRecord;
if(i%2==0){ if(i%2==0){
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestServiceUsageRecord();
}else{ }else{
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestStorageUsageRecord();
} }
aggregationScheduler.aggregate(usageRecord, persistenceExecutor); aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
} }
}); });
List<String> types = new ArrayList<String>(); List<String> types = new ArrayList<String>();
String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecordAutomaticScope().getRecordType(); String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecord().getRecordType();
String storageUsageRecordtype = TestUsageRecord.createTestStorageUsageRecordAutomaticScope().getRecordType(); String storageUsageRecordtype = TestUsageRecord.createTestStorageUsageRecord().getRecordType();
types.add(serviceUsageRecordtype); types.add(serviceUsageRecordtype);
types.add(storageUsageRecordtype); types.add(storageUsageRecordtype);
@ -149,16 +149,16 @@ public class AggregationSchedulerTest {
UsageRecord usageRecord; UsageRecord usageRecord;
switch (i%3) { switch (i%3) {
case 0: case 0:
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestServiceUsageRecord();
break; break;
case 1: case 1:
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestStorageUsageRecord();
break; break;
case 2: case 2:
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestJobUsageRecord();
break; break;
default: default:
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope(); usageRecord = TestUsageRecord.createTestJobUsageRecord();
} }
aggregationScheduler.aggregate(usageRecord, persistenceExecutor); aggregationScheduler.aggregate(usageRecord, persistenceExecutor);

View File

@ -18,7 +18,7 @@ public class StressTestUtility {
private static final Logger logger = LoggerFactory.getLogger(StressTestUtility.class); private static final Logger logger = LoggerFactory.getLogger(StressTestUtility.class);
protected final static int DEFAULT_NUMBER_OF_RECORDS = 3000; public final static int DEFAULT_NUMBER_OF_RECORDS = 3000;
public static void stressTest(TestOperation operation) throws Exception { public static void stressTest(TestOperation operation) throws Exception {
stressTest(operation, DEFAULT_NUMBER_OF_RECORDS); stressTest(operation, DEFAULT_NUMBER_OF_RECORDS);

View File

@ -3,6 +3,19 @@
*/ */
package org.gcube.utils; package org.gcube.utils;
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/ * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
* *
@ -11,4 +24,62 @@ public class TestUtility {
public static final String TOKEN = ""; 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);
}
} }