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/trunk/accounting/accounting-lib@124044 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
426355ce88
commit
9a3f477262
6
pom.xml
6
pom.xml
|
@ -69,12 +69,6 @@
|
|||
</dependency>
|
||||
|
||||
<!-- Test Dependency -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -63,22 +63,11 @@ public class TestUsageRecord {
|
|||
return min + (int)(Math.random() * ((max - min) + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a valid #ServiceUsageRecord
|
||||
* @return the created #ServiceUsageRecord
|
||||
* @throws InvalidValueException
|
||||
*/
|
||||
public static ServiceUsageRecord createTestServiceUsageRecordExplicitScope() throws InvalidValueException {
|
||||
ServiceUsageRecord usageRecord = createTestServiceUsageRecordAutomaticScope();
|
||||
return usageRecord;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a valid #ServiceUsageRecord with scope set automatically.
|
||||
* @return the created #ServiceUsageRecord
|
||||
*/
|
||||
public static ServiceUsageRecord createTestServiceUsageRecordAutomaticScope() {
|
||||
public static ServiceUsageRecord createTestServiceUsageRecord() {
|
||||
ServiceUsageRecord usageRecord = new ServiceUsageRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
|
@ -93,8 +82,6 @@ public class TestUsageRecord {
|
|||
|
||||
usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION));
|
||||
|
||||
|
||||
|
||||
} catch (InvalidValueException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
throw new RuntimeException(e);
|
||||
|
@ -110,21 +97,12 @@ public class TestUsageRecord {
|
|||
|
||||
private final static long MIN_DATA_VOLUME = 1024;
|
||||
private final static long MAX_DATA_VOLUME = 10240;
|
||||
/**
|
||||
* Create a valid #StorageUsageRecord
|
||||
* @return the created #StorageUsageRecord
|
||||
*/
|
||||
public static StorageUsageRecord createTestStorageUsageRecordExplicitScope() {
|
||||
StorageUsageRecord usageRecord = createTestStorageUsageRecordAutomaticScope();
|
||||
return usageRecord;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a valid #StorageUsageRecord with scope set automatically.
|
||||
* @return the created #StorageUsageRecord
|
||||
*/
|
||||
public static StorageUsageRecord createTestStorageUsageRecordAutomaticScope() {
|
||||
public static StorageUsageRecord createTestStorageUsageRecord() {
|
||||
StorageUsageRecord usageRecord = new StorageUsageRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
|
@ -151,19 +129,11 @@ public class TestUsageRecord {
|
|||
return usageRecord;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static JobUsageRecord createTestJobUsageRecordExplicitScope() {
|
||||
JobUsageRecord usageRecord = createTestJobUsageRecordAutomaticScope();
|
||||
return usageRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static JobUsageRecord createTestJobUsageRecordAutomaticScope() {
|
||||
public static JobUsageRecord createTestJobUsageRecord() {
|
||||
|
||||
JobUsageRecord usageRecord = new JobUsageRecord();
|
||||
try {
|
||||
|
@ -192,19 +162,10 @@ public class TestUsageRecord {
|
|||
return usageRecord;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static TaskUsageRecord createTestTaskUsageRecordExplicitScope() {
|
||||
TaskUsageRecord usageRecord = createTestTaskUsageRecordAutomaticScope();
|
||||
return usageRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static TaskUsageRecord createTestTaskUsageRecordAutomaticScope() {
|
||||
public static TaskUsageRecord createTestTaskUsageRecord() {
|
||||
|
||||
TaskUsageRecord usageRecord = new TaskUsageRecord();
|
||||
try {
|
||||
|
|
|
@ -17,7 +17,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToSameObject() throws InvalidValueException {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = usageRecord;
|
||||
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
||||
|
@ -25,7 +25,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToEqualsObject() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = (UsageRecord) RecordUtility.getRecord(usageRecord.getResourceProperties());
|
||||
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
||||
|
@ -33,7 +33,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToComparedAddedProperty() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = (UsageRecord) RecordUtility.getRecord(usageRecord.getResourceProperties());
|
||||
for(int i=1; i<31; i++){
|
||||
ur.setResourceProperty(Integer.toString(i), i);
|
||||
|
@ -44,7 +44,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToDifferentForAddedProperties() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = (UsageRecord) RecordUtility.getRecord(usageRecord.getResourceProperties());
|
||||
usageRecord.setResourceProperty(Integer.toString(1), 2);
|
||||
ur.setResourceProperty(Integer.toString(2), 2);
|
||||
|
@ -54,8 +54,8 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToDifferentFromCreation() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
UsageRecord ur = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertEquals(1, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(1, ur.compareTo(usageRecord));
|
||||
}
|
||||
|
|
|
@ -8,11 +8,9 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -29,17 +27,14 @@ public class AggregatedServiceUsageRecordTest {
|
|||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
AggregatedServiceUsageRecord aggregatedServiceUsageRecord = new AggregatedServiceUsageRecord(serviceUsageRecord);
|
||||
|
||||
|
@ -61,7 +56,10 @@ public class AggregatedServiceUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
serviceUsageRecord.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
serviceUsageRecord.validate();
|
||||
logger.debug("ServiceUsageRecord : {}", serviceUsageRecord);
|
||||
|
@ -70,7 +68,10 @@ public class AggregatedServiceUsageRecordTest {
|
|||
logger.debug("ServiceUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
ServiceUsageRecord serviceUsageRecord2 = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord serviceUsageRecord2 = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord2.getScope()==null);
|
||||
serviceUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
serviceUsageRecord2.validate();
|
||||
logger.debug("ServiceUsageRecord 2 : {}", serviceUsageRecord2);
|
||||
|
||||
|
@ -100,7 +101,9 @@ public class AggregatedServiceUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
serviceUsageRecord.validate();
|
||||
logger.debug("ServiceUsageRecord : {}", serviceUsageRecord);
|
||||
|
||||
|
@ -108,7 +111,9 @@ public class AggregatedServiceUsageRecordTest {
|
|||
logger.debug("ServiceUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
ServiceUsageRecord serviceUsageRecord2 = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord serviceUsageRecord2 = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord2.getScope()==null);
|
||||
serviceUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
serviceUsageRecord2.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
serviceUsageRecord2.validate();
|
||||
logger.debug("ServiceUsageRecord 2 : {}", serviceUsageRecord2);
|
||||
|
@ -144,7 +149,9 @@ public class AggregatedServiceUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
serviceUsageRecord.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
serviceUsageRecord.validate();
|
||||
logger.debug("ServiceUsageRecord : {}", serviceUsageRecord);
|
||||
|
@ -155,7 +162,7 @@ public class AggregatedServiceUsageRecordTest {
|
|||
|
||||
for(int i=2; i<1002; i++){
|
||||
|
||||
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
|
||||
sur.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
sur.validate();
|
||||
logger.debug("Cycle ServiceUsageRecord {}: {}", i, sur);
|
||||
|
|
|
@ -3,14 +3,11 @@
|
|||
*/
|
||||
package org.gcube.accounting.datamodel.aggregation;
|
||||
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -27,17 +24,15 @@ public class AggregatedStorageUsageRecordTest {
|
|||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
storageUsageRecord.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
storageUsageRecord.validate();
|
||||
logger.debug("StorageUsageRecord : {}", storageUsageRecord);
|
||||
|
@ -46,7 +41,7 @@ public class AggregatedStorageUsageRecordTest {
|
|||
logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
StorageUsageRecord storageUsageRecord2 = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord storageUsageRecord2 = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord2.validate();
|
||||
logger.debug("StorageUsageRecord 2 : {}", storageUsageRecord2);
|
||||
|
||||
|
@ -65,7 +60,9 @@ public class AggregatedStorageUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
storageUsageRecord.validate();
|
||||
logger.debug("StorageUsageRecord : {}", storageUsageRecord);
|
||||
|
||||
|
@ -73,7 +70,9 @@ public class AggregatedStorageUsageRecordTest {
|
|||
logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
StorageUsageRecord storageUsageRecord2 = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord storageUsageRecord2 = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord2.getScope()==null);
|
||||
storageUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
storageUsageRecord2.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
storageUsageRecord2.validate();
|
||||
logger.debug("StorageUsageRecord 2 : {}", storageUsageRecord2);
|
||||
|
@ -95,7 +94,9 @@ public class AggregatedStorageUsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
storageUsageRecord.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
storageUsageRecord.validate();
|
||||
logger.debug("StorageUsageRecord : {}", storageUsageRecord);
|
||||
|
@ -106,7 +107,7 @@ public class AggregatedStorageUsageRecordTest {
|
|||
|
||||
for(int i=2; i<1002; i++){
|
||||
|
||||
StorageUsageRecord sur = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord sur = TestUsageRecord.createTestStorageUsageRecord();
|
||||
sur.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
sur.validate();
|
||||
logger.debug("Cycle StorageUsageRecord {}: {}", i, sur);
|
||||
|
|
|
@ -9,11 +9,9 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -30,11 +28,6 @@ public class JobUsageRecordTest {
|
|||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
|
@ -49,20 +42,21 @@ public class JobUsageRecordTest {
|
|||
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_ID);
|
||||
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_START_TIME);
|
||||
expectedRequiredFields.add(AbstractJobUsageRecord.JOB_END_TIME);
|
||||
|
||||
return expectedRequiredFields;
|
||||
}
|
||||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
|
||||
|
@ -77,19 +71,4 @@ public class JobUsageRecordTest {
|
|||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFieldsWithScopeSetExplicitely() throws InvalidValueException{
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
Set<String> gotRequiredFields = usageRecord.getRequiredFields();
|
||||
|
||||
Assert.assertTrue(expectedRequiredFields.containsAll(gotRequiredFields));
|
||||
Assert.assertTrue(gotRequiredFields.containsAll(expectedRequiredFields));
|
||||
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,9 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -30,11 +28,6 @@ public class ServiceUsageRecordTest {
|
|||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
|
@ -57,15 +50,16 @@ public class ServiceUsageRecordTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
|
||||
|
@ -79,22 +73,5 @@ public class ServiceUsageRecordTest {
|
|||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFieldsWithScopeSetExplicitely() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
Set<String> gotRequiredFields = usageRecord.getRequiredFields();
|
||||
|
||||
Assert.assertTrue(expectedRequiredFields.containsAll(gotRequiredFields));
|
||||
Assert.assertTrue(gotRequiredFields.containsAll(expectedRequiredFields));
|
||||
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,9 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -30,11 +28,6 @@ public class StorageUsageRecordTest {
|
|||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
|
@ -59,15 +52,16 @@ public class StorageUsageRecordTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
|
||||
|
@ -82,21 +76,4 @@ public class StorageUsageRecordTest {
|
|||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFieldsWithScopeSetExplicitely() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecordExplicitScope();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
Set<String> gotRequiredFields = usageRecord.getRequiredFields();
|
||||
|
||||
Assert.assertTrue(expectedRequiredFields.containsAll(gotRequiredFields));
|
||||
Assert.assertTrue(gotRequiredFields.containsAll(expectedRequiredFields));
|
||||
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,9 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -30,14 +28,9 @@ public class TaskUsageRecordTest {
|
|||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
|
||||
public static Set<String> getExpectedRequiredFields(){
|
||||
Set<String> expectedRequiredFields = new HashSet<String>();
|
||||
expectedRequiredFields.add(Record.ID);
|
||||
|
@ -55,15 +48,16 @@ public class TaskUsageRecordTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecordAutomaticScope();
|
||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecordAutomaticScope();
|
||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
|
||||
|
@ -78,20 +72,4 @@ public class TaskUsageRecordTest {
|
|||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFieldsWithScopeSetExplicitely() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecordExplicitScope();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
Set<String> expectedRequiredFields = getExpectedRequiredFields();
|
||||
Set<String> gotRequiredFields = usageRecord.getRequiredFields();
|
||||
|
||||
Assert.assertTrue(expectedRequiredFields.containsAll(gotRequiredFields));
|
||||
Assert.assertTrue(gotRequiredFields.containsAll(expectedRequiredFields));
|
||||
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,170 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.persistence;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.Resources;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Profile;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
|
||||
import org.gcube.common.resources.gcore.common.Platform;
|
||||
import org.gcube.common.resources.gcore.utils.Group;
|
||||
import org.gcube.documentstore.persistence.PersistenceBackend;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class AccountingPersistenceConfigurationTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccountingPersistenceConfigurationTest.class);
|
||||
|
||||
private static final String PROFILE_DESCRIPTION = "This ServiceEndpoint contains the parameter to connect to DB to persist log accounting";
|
||||
private static final String HOSTED_ON = "pc-frosini.isti.cnr.it";
|
||||
private static final String ENDPOINT = "http://localhost:5984";
|
||||
|
||||
private static final String READY = "READY";
|
||||
|
||||
private static final String PLATFORM_NAME = "Platform Name";
|
||||
private static final String TEST_VERSION = "1.0.0";
|
||||
private static final short[] VERSION_SLICES = new short[]{1,6,0,0};
|
||||
|
||||
private static final String DESCRIPTION = "Persistence Configuration Test";
|
||||
|
||||
private static final String FAKE_USERNAME = "fakeusername";
|
||||
private static final String FAKE_PASSWORD = "fakepassword";
|
||||
|
||||
private static final String DB_NAME_PROPERTY_KEY = "dbName";
|
||||
private static final String DB_NAME_PROPERTY_VALUE = "accounting";
|
||||
|
||||
private abstract class AccountingPersistenceFakeDB extends PersistenceBackend {
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Service Endpoint using information related to discovered
|
||||
* available plugins and their own discovered capabilities
|
||||
* @return the created {@link ServiceEndpoint}
|
||||
*/
|
||||
protected static ServiceEndpoint createServiceEndpoint(){
|
||||
logger.debug("Getting Available Plugins and their own supported capabilities");
|
||||
|
||||
logger.debug("Creating ServiceEndpoint to publish on IS available plugins and their own supported capabilities");
|
||||
ServiceEndpoint serviceEndpoint = new ServiceEndpoint();
|
||||
Profile profile = serviceEndpoint.newProfile();
|
||||
profile.category(AccountingPersistenceConfiguration.SERVICE_ENDPOINT_CATEGORY);
|
||||
profile.name(AccountingPersistenceConfiguration.SERVICE_ENDPOINT_NAME);
|
||||
profile.version(TEST_VERSION);
|
||||
profile.description(PROFILE_DESCRIPTION);
|
||||
|
||||
|
||||
Platform platform = profile.newPlatform();
|
||||
platform.name(PLATFORM_NAME);
|
||||
|
||||
platform.version(VERSION_SLICES[0]);
|
||||
platform.minorVersion(VERSION_SLICES[1]);
|
||||
platform.buildVersion(VERSION_SLICES[2]);
|
||||
platform.revisionVersion(VERSION_SLICES[3]);
|
||||
|
||||
Runtime runtime = profile.newRuntime();
|
||||
runtime.hostedOn(HOSTED_ON);
|
||||
runtime.status(READY);
|
||||
|
||||
Group<AccessPoint> accessPoints = profile.accessPoints();
|
||||
|
||||
AccessPoint accessPointElement = new AccessPoint();
|
||||
accessPoints.add(accessPointElement);
|
||||
accessPointElement.description(DESCRIPTION);
|
||||
accessPointElement.credentials(FAKE_USERNAME, FAKE_PASSWORD);
|
||||
|
||||
accessPointElement.address(ENDPOINT);
|
||||
accessPointElement.name(AccountingPersistenceFakeDB.class.getSimpleName());
|
||||
|
||||
Group<Property> properties = accessPointElement.properties();
|
||||
|
||||
Property dbName = new Property();
|
||||
dbName.nameAndValue(DB_NAME_PROPERTY_KEY, DB_NAME_PROPERTY_VALUE);
|
||||
dbName.encrypted(false);
|
||||
properties.add(dbName);
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
Resources.marshal(serviceEndpoint, stringWriter);
|
||||
logger.debug("The created ServiceEndpoint profile is\n{}", stringWriter.toString());
|
||||
|
||||
return serviceEndpoint;
|
||||
}
|
||||
|
||||
public void testPersistenceConfigurationFromIS() throws Exception{
|
||||
boolean createResource = true;
|
||||
ServiceEndpoint serviceEndpoint = null;
|
||||
|
||||
if(createResource){
|
||||
serviceEndpoint = createServiceEndpoint();
|
||||
TestUtility.publishResource(serviceEndpoint);
|
||||
}
|
||||
|
||||
Thread.sleep(5000); // Waiting 5 sec
|
||||
|
||||
try {
|
||||
AccountingPersistenceConfiguration persitenceConfiguration = new AccountingPersistenceConfiguration(AccountingPersistenceFakeDB.class);
|
||||
if(createResource){
|
||||
String uri = persitenceConfiguration.getProperty(AccountingPersistenceConfiguration.URL_PROPERTY_KEY);
|
||||
Assert.assertTrue(uri.compareTo(new URL(ENDPOINT).toString())==0);
|
||||
String username = persitenceConfiguration.getProperty(AccountingPersistenceConfiguration.USERNAME_PROPERTY_KEY);
|
||||
Assert.assertTrue(username.compareTo(FAKE_USERNAME)==0);
|
||||
String password = persitenceConfiguration.getProperty(AccountingPersistenceConfiguration.PASSWORD_PROPERTY_KEY);
|
||||
Assert.assertTrue(password.compareTo(FAKE_PASSWORD)==0);
|
||||
|
||||
String dbName = persitenceConfiguration.getProperty(DB_NAME_PROPERTY_KEY);
|
||||
Assert.assertTrue(dbName.compareTo(DB_NAME_PROPERTY_VALUE)==0);
|
||||
}
|
||||
} finally {
|
||||
if(createResource){
|
||||
TestUtility.unPublishResource(serviceEndpoint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void getUsernamePasswordForScopes() throws Exception{
|
||||
logger.debug("START ======================================================");
|
||||
try {
|
||||
AccountingPersistenceConfiguration persitenceConfiguration = new AccountingPersistenceConfiguration(AccountingPersistenceFakeDB.class);
|
||||
String uri = persitenceConfiguration.getProperty(AccountingPersistenceConfiguration.URL_PROPERTY_KEY);
|
||||
String username = persitenceConfiguration.getProperty(AccountingPersistenceConfiguration.USERNAME_PROPERTY_KEY);
|
||||
String password = persitenceConfiguration.getProperty(AccountingPersistenceConfiguration.PASSWORD_PROPERTY_KEY);
|
||||
logger.debug("{} - {} - {} - {}", BasicUsageRecord.getScopeFromToken(), uri, username, password);
|
||||
}catch(IndexOutOfBoundsException e){
|
||||
logger.debug("No AccountingPersistenceConfiguration : \n {} {} \n\n", e.getClass().getName(), e.getMessage());
|
||||
} catch(Exception e){
|
||||
logger.error("Error getting AccountingPersistenceConfiguration", e);
|
||||
throw e;
|
||||
} finally {
|
||||
logger.debug(" END ======================================================");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.testutility;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.documentstore.persistence;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.testutility.StressTestUtility;
|
||||
import org.gcube.accounting.testutility.TestOperation;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
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 PersistenceBackendMonitorTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PersistenceBackendMonitorTest.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() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsingTest() throws Exception {
|
||||
PersistenceBackendFactory.setFallbackLocation(null);
|
||||
final PersistenceBackend persistence = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
|
||||
@Override
|
||||
public void operate(int i) {
|
||||
UsageRecord usageRecord = null;
|
||||
switch (i%3) {
|
||||
case 0:
|
||||
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
break;
|
||||
case 1:
|
||||
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
break;
|
||||
case 2:
|
||||
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
|
||||
break;
|
||||
}
|
||||
try {
|
||||
persistence.account(usageRecord);
|
||||
} catch (InvalidValueException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
logger.debug(" START -----------------------------------------------");
|
||||
logger.debug("Flushing the buffered records");
|
||||
persistence.flush(timeout, timeUnit);
|
||||
logger.debug(" END -----------------------------------------------");
|
||||
|
||||
PersistenceBackend persistenceBackend = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||
persistenceBackend.setFallback((FallbackPersistenceBackend) persistenceBackend);
|
||||
PersistenceBackendMonitor temporalDataPersistenceBackendMonitor = new PersistenceBackendMonitor(persistenceBackend);
|
||||
|
||||
temporalDataPersistenceBackendMonitor.run();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleParsingTest() throws Exception {
|
||||
PersistenceBackendFactory.setFallbackLocation(null);
|
||||
PersistenceBackend persistenceBackend = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||
persistenceBackend.setFallback((FallbackPersistenceBackend) persistenceBackend);
|
||||
PersistenceBackendMonitor temporalDataPersistenceBackendMonitor = new PersistenceBackendMonitor(persistenceBackend);
|
||||
|
||||
temporalDataPersistenceBackendMonitor.run();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.documentstore.persistence;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.testutility.StressTestUtility;
|
||||
import org.gcube.accounting.testutility.TestOperation;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
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 PersistenceBackendTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(PersistenceBackendTest.class);
|
||||
|
||||
public static final String[] SCOPES = new String[]{"/gcube", "/gcube/devNext"};
|
||||
public static final String GCUBE_SCOPE = SCOPES[0];
|
||||
public static final String GCUBE_DEVNEXT_SCOPE = SCOPES[1];
|
||||
|
||||
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() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
public static PersistenceBackend getPersistence(){
|
||||
PersistenceBackendFactory.setFallbackLocation(null);
|
||||
return PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleTestNoScope() throws Exception {
|
||||
PersistenceBackendFactory.setFallbackLocation(null);
|
||||
final PersistenceBackend persistence = PersistenceBackendFactory.getPersistenceBackend(null);
|
||||
Assert.assertTrue(persistence instanceof FallbackPersistenceBackend);
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) {
|
||||
UsageRecord usageRecord;
|
||||
try {
|
||||
usageRecord = TestUsageRecord.createTestServiceUsageRecordExplicitScope();
|
||||
persistence.accountValidateAggregate(usageRecord, true, false);
|
||||
} catch (InvalidValueException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
|
||||
persistence.flush(timeout, timeUnit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleTest() throws Exception {
|
||||
final PersistenceBackend persistence = getPersistence();
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
persistence.accountValidateAggregate(usageRecord, true, false);
|
||||
}
|
||||
}, 1);
|
||||
|
||||
persistence.flush(timeout, timeUnit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stressTestNoAggregation() throws Exception {
|
||||
final PersistenceBackend persistence = getPersistence();
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
persistence.accountValidateAggregate(usageRecord, true, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stressTestWithAggregation() throws Exception {
|
||||
final PersistenceBackend persistence = getPersistence();
|
||||
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
persistence.account(usageRecord);
|
||||
}
|
||||
});
|
||||
persistence.flush(timeout, timeUnit);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testScopeRecheck() throws Exception {
|
||||
PersistenceBackendFactory.setFallbackLocation(null);
|
||||
logger.debug("Going to check First Time");
|
||||
PersistenceBackend first = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
||||
logger.debug("First {} : {}", PersistenceBackend.class.getSimpleName(), first);
|
||||
Long firstCheck = PersistenceBackendFactory.getFallbackLastCheck(BasicUsageRecord.getScopeFromToken());
|
||||
logger.debug("First Check Time {}", firstCheck);
|
||||
|
||||
long startTime = Calendar.getInstance().getTimeInMillis();
|
||||
long 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);
|
||||
Long secondCheck = PersistenceBackendFactory.getFallbackLastCheck(BasicUsageRecord.getScopeFromToken());
|
||||
logger.debug("Second Check Time {}", secondCheck);
|
||||
|
||||
Assert.assertNotEquals(firstCheck, secondCheck);
|
||||
Assert.assertEquals(first, second);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,180 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.documentstore.records.aggregation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.testutility.StressTestUtility;
|
||||
import org.gcube.accounting.testutility.TestOperation;
|
||||
import org.gcube.accounting.testutility.TestUtility;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.persistence.PersistenceExecutor;
|
||||
import org.gcube.documentstore.records.AggregatedRecord;
|
||||
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 AggregationSchedulerTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AggregationSchedulerTest.class);
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
public static AggregationScheduler getAggregationScheduler(){
|
||||
return AggregationScheduler.newInstance();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static PersistenceExecutor persistenceExecutor = new PersistenceExecutor(){
|
||||
@Override
|
||||
public void persist(Record... records) throws Exception {
|
||||
for(Record record : records){
|
||||
logger.debug("Storing : {}", record.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected void madeAssertion(Map<String, List<Record>> bufferedRecords, List<String> types, int size, int count) {
|
||||
for(String type : types){
|
||||
Assert.assertTrue(bufferedRecords.containsKey(type));
|
||||
List<Record> records = bufferedRecords.get(type);
|
||||
Assert.assertTrue(records.size()==size);
|
||||
for(Record record : records){
|
||||
Assert.assertTrue(record.getRecordType().compareTo(type)==0);
|
||||
Assert.assertTrue(record instanceof AggregatedRecord);
|
||||
@SuppressWarnings("rawtypes")
|
||||
AggregatedRecord aggregatedRecord = (AggregatedRecord) record;
|
||||
Assert.assertTrue(aggregatedRecord.getOperationCount()==count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stressTestAggregableURSingleType() throws Exception {
|
||||
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
|
||||
}
|
||||
});
|
||||
List<String> types = new ArrayList<String>();
|
||||
String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecordAutomaticScope().getRecordType();
|
||||
types.add(serviceUsageRecordtype);
|
||||
madeAssertion(aggregationScheduler.bufferedRecords, types, 1, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS);
|
||||
aggregationScheduler.flush(persistenceExecutor);
|
||||
}
|
||||
|
||||
public static final String ALTERNATIVE_SERVICE_CLASS = "AlternativeServiceClass";
|
||||
|
||||
@Test
|
||||
public void stressTestDifferentAggregableURSingleType() throws Exception {
|
||||
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) throws Exception {
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
if(i%2==0){
|
||||
usageRecord.setServiceClass(ALTERNATIVE_SERVICE_CLASS);
|
||||
}
|
||||
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
|
||||
}
|
||||
});
|
||||
List<String> types = new ArrayList<String>();
|
||||
String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecordAutomaticScope().getRecordType();
|
||||
types.add(serviceUsageRecordtype);
|
||||
|
||||
madeAssertion(aggregationScheduler.bufferedRecords, types, 2, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS/2);
|
||||
|
||||
aggregationScheduler.flush(persistenceExecutor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stressTestDifferentAggregableURTwoType() throws Exception {
|
||||
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) throws Exception {
|
||||
UsageRecord usageRecord;
|
||||
if(i%2==0){
|
||||
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
}else{
|
||||
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
}
|
||||
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
|
||||
}
|
||||
});
|
||||
|
||||
List<String> types = new ArrayList<String>();
|
||||
String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecordAutomaticScope().getRecordType();
|
||||
String storageUsageRecordtype = TestUsageRecord.createTestStorageUsageRecordAutomaticScope().getRecordType();
|
||||
types.add(serviceUsageRecordtype);
|
||||
types.add(storageUsageRecordtype);
|
||||
|
||||
madeAssertion(aggregationScheduler.bufferedRecords, types, 1, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS/2);
|
||||
|
||||
aggregationScheduler.flush(persistenceExecutor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stressTestDifferentAggregableURMultipleType() throws Exception {
|
||||
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) throws Exception {
|
||||
UsageRecord usageRecord;
|
||||
switch (i%3) {
|
||||
case 0:
|
||||
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
||||
break;
|
||||
case 1:
|
||||
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
|
||||
break;
|
||||
case 2:
|
||||
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
|
||||
break;
|
||||
default:
|
||||
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
|
||||
}
|
||||
|
||||
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
List<String> types = new ArrayList<String>();
|
||||
String serviceUsageRecordtype = TestUsageRecord.createTestServiceUsageRecordAutomaticScope().getRecordType();
|
||||
String storageUsageRecordtype = TestUsageRecord.createTestStorageUsageRecordAutomaticScope().getRecordType();
|
||||
types.add(serviceUsageRecordtype);
|
||||
types.add(storageUsageRecordtype);
|
||||
madeAssertion(aggregationScheduler.bufferedRecords, types, 1, StressTestUtility.DEFAULT_NUMBER_OF_RECORDS/4);
|
||||
*/
|
||||
|
||||
aggregationScheduler.flush(persistenceExecutor);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue