This commit is contained in:
Alessandro Pieve 2017-03-27 08:25:49 +00:00
parent 286fafcdb9
commit d3bfd36e0c
3 changed files with 95 additions and 1 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.accounting</groupId>
<artifactId>accounting-lib</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.1-SNAPSHOT</version>
<name>Accounting Library</name>
<description>Accounting Library</description>
<packaging>jar</packaging>

View File

@ -48,4 +48,9 @@ public class AccountingPersistenceFactory {
PersistenceBackendFactory.flushAll(timeout, timeUnit);
}
public static void shutDown(long timeout, TimeUnit timeUnit){
//flush all and shutdown connection and thread
PersistenceBackendFactory.flushAll(timeout, timeUnit);
PersistenceBackendFactory.shutdown();
}
}

View File

@ -0,0 +1,89 @@
package org.gcube.testutility;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.gcube.accounting.datamodel.BasicUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.persistence.AccountingPersistence;
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.documentstore.records.Record;
import org.gcube.documentstore.records.RecordUtility;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyTest {
private static final Logger logger = LoggerFactory.getLogger(MyTest.class);
@Before
public void beforeClass() throws Exception{
SecurityTokenProvider.instance.set("36501a0d-a205-4bf1-87ad-4c7185faa0d6-98187548");
ScopeProvider.instance.set("/gcube/devNext");
}
@Test
public void test() throws Exception{
AccountingPersistence apq= AccountingPersistenceFactory.getPersistence();
//Record record=TestUsageRecord.createTestServiceUsageRecord();
//Record record2=TestUsageRecord.createTestServiceUsageRecord();
Record record=TestUsageRecord.createTestStorageVolumeUsageRecord();
logger.debug("----record:{}",record);
apq.account(record);
//apq.account(record);
//apq.account(record2);
Thread.sleep(3000);
apq.flush(3000, TimeUnit.MILLISECONDS);
logger.debug("end flush");
File elaborationFile = new File("/home/pieve/_gcube_devNext.fallback.log");
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFile))) {
for(String line; (line = br.readLine()) != null; ) {
try {
//Record r =DSMapper.unmarshal(Record.class, line);
Record r = RecordUtility.getRecord( line);
logger.debug("{}", r);
} catch(Exception e){
logger.error("Was not possible parse line {} to obtain a valid Record. Going to writing back this line as string fallback file.", line, e);
}
}
} catch (FileNotFoundException e) {
logger.error("File non trovato", e);
} catch (IOException e) {
logger.error("IOException", e);
}
}
}