improving tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124807 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-03-04 13:28:36 +00:00
parent 7204f2574a
commit 2532ce59ca
5 changed files with 124 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import org.gcube.accounting.analytics.TemporalConstraint;
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.records.AggregatedRecord;
import org.gcube.testutility.ScopedTest;
@ -191,4 +192,31 @@ public class AccountingPersistenceQueryCouchDBTest extends ScopedTest {
printMap(newQuery);
}
@Test
public void getPossibleValuesForKeyTest() throws Exception {
int limit = 100;
Map<String, Integer> values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedServiceUsageRecord.class, AggregatedServiceUsageRecord.CONSUMER_ID);
logger.debug("Values and Occurrences for {} for key {} : {}",
AggregatedServiceUsageRecord.class.getSimpleName(),
AggregatedServiceUsageRecord.CONSUMER_ID, values);
values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedServiceUsageRecord.class, AggregatedServiceUsageRecord.CONSUMER_ID, limit);
logger.debug("Values and Occurrences (limit {}) for {} for key {} : {}",
limit, AggregatedServiceUsageRecord.class.getSimpleName(),
AggregatedServiceUsageRecord.CONSUMER_ID, values);
values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedStorageUsageRecord.class, AggregatedStorageUsageRecord.CONSUMER_ID);
logger.debug("Values and Occurrences for {} for key {} : {}",
AggregatedStorageUsageRecord.class.getSimpleName(),
AggregatedStorageUsageRecord.CONSUMER_ID, values);
values = accountingPersistenceQueryCouchDB.getValuesAndOccurrences(AggregatedStorageUsageRecord.class, AggregatedStorageUsageRecord.CONSUMER_ID, limit);
logger.debug("Values and Occurrences (limit {}) for {} for key {} : {}",
limit, AggregatedStorageUsageRecord.class.getSimpleName(),
AggregatedStorageUsageRecord.CONSUMER_ID, values);
}
}

View File

@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.testutility.ScopedTest;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
@ -34,6 +35,8 @@ public class CouchDBQueryPluginSmartExecutorSchedulerTest extends ScopedTest {
@Before
public void before() throws Exception{
super.before();
ScopeProvider.instance.reset(); // Comment this to run the test. this line has been added to avoid unwanted launch
proxy = ExecutorPlugin.getExecutorProxy(CouchDBQueryPluginDeclaration.NAME).build();
Assert.assertNotNull(proxy);
}

View File

@ -7,9 +7,11 @@ package org.gcube.documentstore.records;
import java.net.URI;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
@ -74,4 +76,21 @@ public class RecordUtilityTest {
logger.debug("{}", aggregatedStorageUsageRecord);
}
@Test
public void test() {
Assert.assertTrue(Record.class.isAssignableFrom(ServiceUsageRecord.class));
Assert.assertFalse(AggregatedRecord.class.isAssignableFrom(ServiceUsageRecord.class));
Assert.assertTrue(Record.class.isAssignableFrom(AggregatedServiceUsageRecord.class));
Assert.assertTrue(AggregatedRecord.class.isAssignableFrom(AggregatedServiceUsageRecord.class));
}
@Test
public void testNewReflection() {
RecordUtility.addRecordPackage(ServiceUsageRecord.class.getPackage());
logger.trace("{}", RecordUtility.recordClassesFound);
RecordUtility.addRecordPackage(AggregatedServiceUsageRecord.class.getPackage());
logger.trace("{}", RecordUtility.aggregatedRecordClassesFound);
logger.trace("{}", RecordUtility.recordAggregationMapping);
}
}

View File

@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.testutility.ScopedTest;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
@ -29,6 +30,8 @@ public class ISSweeperPluginSmartExecutorSchedulerTest extends ScopedTest {
@Before
public void before() throws Exception{
super.before();
ScopeProvider.instance.reset(); // Comment this to run the test. this line has been added to avoid unwanted launch
proxy = ExecutorPlugin.getExecutorProxy(ISSweeperPluginDeclaration.NAME).build();
Assert.assertNotNull(proxy);
}

View File

@ -0,0 +1,71 @@
/**
*
*/
package org.gcube.informationsystem.sweeper;
import java.util.List;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.informationsystem.publisher.RegistryPublisher;
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.testutility.ScopedTest;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class RemoveGoodRITest extends ScopedTest {
private static final Logger logger = LoggerFactory.getLogger(RemoveGoodRITest.class);
protected String getGCoreEndpointMinimalInfo(GCoreEndpoint gCoreEndpoint, String hostingNodeId) throws Exception{
return String.format("%s (ID : %s - ServiceClass : %s - ServiceName : %s. Was running on %s)",
GCoreEndpoint.class.getSimpleName(), gCoreEndpoint.id(),
gCoreEndpoint.profile().serviceClass(),
gCoreEndpoint.profile().serviceName(), hostingNodeId);
}
/*
* This test is used to check if smartgears republish a RI deleted
* from Is for mistake, when container instance is still up and running.
*/
@Test
public void test() throws Exception {
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
String hostingNodeID = "8199b56f-460f-4d1d-a4b2-44186681972c";
String condition = String.format("$resource/Profile/GHN/@UniqueID/string() eq '%s'", hostingNodeID);
SimpleQuery query = ICFactory.queryFor(GCoreEndpoint.class)
.addCondition(condition)
.setResult("$resource");
DiscoveryClient<GCoreEndpoint> client = ICFactory.clientFor(GCoreEndpoint.class);
List<GCoreEndpoint> gCoreEndpoints = client.submit(query);
for (GCoreEndpoint gCoreEndpoint : gCoreEndpoints) {
try {
logger.debug("Going to remove orphan {}",
getGCoreEndpointMinimalInfo(gCoreEndpoint, hostingNodeID));
registryPublisher.remove(gCoreEndpoint);
logger.debug("Request to remove {} successfully sent\n",
getGCoreEndpointMinimalInfo(gCoreEndpoint, hostingNodeID));
}catch(Exception e){
logger.error("Unable to remove {}",
getGCoreEndpointMinimalInfo(gCoreEndpoint, hostingNodeID), e);
}
}
}
}