2015-11-17 09:32:41 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-12-18 17:09:05 +01:00
|
|
|
package org.gcube.documentstore.persistence;
|
2015-11-17 09:32:41 +01:00
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2016-02-09 18:46:23 +01:00
|
|
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
2015-12-18 17:09:05 +01:00
|
|
|
import org.gcube.accounting.datamodel.UsageRecord;
|
2015-11-17 09:32:41 +01:00
|
|
|
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
|
|
|
import org.gcube.accounting.testutility.StressTestUtility;
|
|
|
|
import org.gcube.accounting.testutility.TestOperation;
|
2016-02-09 18:55:16 +01:00
|
|
|
import org.gcube.accounting.testutility.TestUtility;
|
2016-02-09 18:46:23 +01:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2015-12-18 17:09:05 +01:00
|
|
|
import org.gcube.documentstore.exception.InvalidValueException;
|
2016-02-09 18:46:23 +01:00
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Before;
|
2015-11-17 09:32:41 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
|
|
*
|
|
|
|
*/
|
2015-12-18 17:09:05 +01:00
|
|
|
public class PersistenceBackendMonitorTest {
|
2015-11-17 09:32:41 +01:00
|
|
|
|
2015-12-18 17:09:05 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(PersistenceBackendMonitorTest.class);
|
2015-11-17 09:32:41 +01:00
|
|
|
|
|
|
|
public static final long timeout = 5000;
|
|
|
|
public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
|
|
|
|
|
2016-02-09 18:46:23 +01:00
|
|
|
@Before
|
|
|
|
public void before() throws Exception{
|
2016-02-09 18:55:16 +01:00
|
|
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
2016-02-09 18:46:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
2016-02-09 18:55:16 +01:00
|
|
|
public void after() throws Exception{
|
2016-02-09 18:46:23 +01:00
|
|
|
SecurityTokenProvider.instance.reset();
|
|
|
|
}
|
|
|
|
|
2015-11-17 09:32:41 +01:00
|
|
|
@Test
|
|
|
|
public void parsingTest() throws Exception {
|
2015-12-18 17:09:05 +01:00
|
|
|
PersistenceBackendFactory.setFallbackLocation(null);
|
2016-02-09 18:46:23 +01:00
|
|
|
final PersistenceBackend persistence = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
2015-11-17 09:32:41 +01:00
|
|
|
|
|
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void operate(int i) {
|
2015-12-18 17:09:05 +01:00
|
|
|
UsageRecord usageRecord = null;
|
2015-11-17 09:32:41 +01:00
|
|
|
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 -----------------------------------------------");
|
|
|
|
|
2016-02-09 18:46:23 +01:00
|
|
|
PersistenceBackend persistenceBackend = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
2015-12-18 17:09:05 +01:00
|
|
|
persistenceBackend.setFallback((FallbackPersistenceBackend) persistenceBackend);
|
|
|
|
PersistenceBackendMonitor temporalDataPersistenceBackendMonitor = new PersistenceBackendMonitor(persistenceBackend);
|
2015-11-17 09:32:41 +01:00
|
|
|
|
2015-12-18 17:09:05 +01:00
|
|
|
temporalDataPersistenceBackendMonitor.run();
|
2015-11-17 09:32:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-19 15:51:47 +01:00
|
|
|
@Test
|
|
|
|
public void singleParsingTest() throws Exception {
|
2015-12-18 17:09:05 +01:00
|
|
|
PersistenceBackendFactory.setFallbackLocation(null);
|
2016-02-09 18:46:23 +01:00
|
|
|
PersistenceBackend persistenceBackend = PersistenceBackendFactory.getPersistenceBackend(BasicUsageRecord.getScopeFromToken());
|
2015-12-18 17:09:05 +01:00
|
|
|
persistenceBackend.setFallback((FallbackPersistenceBackend) persistenceBackend);
|
|
|
|
PersistenceBackendMonitor temporalDataPersistenceBackendMonitor = new PersistenceBackendMonitor(persistenceBackend);
|
|
|
|
|
|
|
|
temporalDataPersistenceBackendMonitor.run();
|
2015-11-19 15:51:47 +01:00
|
|
|
}
|
|
|
|
|
2015-11-17 09:32:41 +01:00
|
|
|
}
|