Awaiting termination of pool in flush

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@117212 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-07-14 10:20:36 +00:00
parent 21e648a08e
commit 80101b5b7c
2 changed files with 13 additions and 4 deletions

View File

@ -5,6 +5,7 @@ package org.gcube.accounting.persistence;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.gcube.accounting.aggregation.scheduler.AggregationScheduler; import org.gcube.accounting.aggregation.scheduler.AggregationScheduler;
import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.SingleUsageRecord;
@ -136,7 +137,9 @@ public abstract class AccountingPersistence {
} }
public void flush() throws Exception { public void flush(long timeout, TimeUnit timeUnit) throws Exception {
pool.awaitTermination(timeout, timeUnit);
final AccountingPersistence persistence = this; final AccountingPersistence persistence = this;
aggregationScheduler.flush(new AccountingPersistenceExecutor(){ aggregationScheduler.flush(new AccountingPersistenceExecutor(){
@ -146,6 +149,7 @@ public abstract class AccountingPersistence {
} }
}); });
} }

View File

@ -3,6 +3,8 @@
*/ */
package org.gcube.accounting.persistence; package org.gcube.accounting.persistence;
import java.util.concurrent.TimeUnit;
import org.gcube.accounting.datamodel.SingleUsageRecord; import org.gcube.accounting.datamodel.SingleUsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.testutility.StressTestUtility; import org.gcube.accounting.testutility.StressTestUtility;
@ -17,6 +19,9 @@ import org.junit.Test;
*/ */
public class PersistenceTest { public class PersistenceTest {
public static final long timeout = 5000;
public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
public static AccountingPersistence getPersistence(){ public static AccountingPersistence getPersistence(){
ScopeProvider.instance.set(PersistenceConfigurationTest.GCUBE_DEVNEXT_SCOPE); ScopeProvider.instance.set(PersistenceConfigurationTest.GCUBE_DEVNEXT_SCOPE);
AccountingPersistenceFactory.setFallbackLocation(null); AccountingPersistenceFactory.setFallbackLocation(null);
@ -36,7 +41,7 @@ public class PersistenceTest {
} }
}, 1); }, 1);
persistence.flush(); persistence.flush(timeout, timeUnit);
} }
@Test @Test
@ -50,7 +55,7 @@ public class PersistenceTest {
} }
}, 1); }, 1);
persistence.flush(); persistence.flush(timeout, timeUnit);
} }
@Test @Test
@ -76,7 +81,7 @@ public class PersistenceTest {
persistence.account(usageRecord); persistence.account(usageRecord);
} }
}); });
persistence.flush(); persistence.flush(timeout, timeUnit);
} }
} }