refs #1282: New Accounting: IS-Collector doesn't start correctly after upgrade to ghn 6.0.0

https://support.d4science.org/issues/1282

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@120287 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-11-17 10:58:16 +00:00
parent c5134be2b6
commit 6ef06f9ecd
3 changed files with 17 additions and 10 deletions

View File

@ -113,6 +113,7 @@ public abstract class AccountingPersistenceBackendFactory {
protected static AccountingPersistenceBackend rediscoverAccountingPersistenceBackend(AccountingPersistenceBackend actual, String scope){
long now = Calendar.getInstance().getTimeInMillis();
Long lastCheckTimestamp = fallbackLastCheck.get(scope);
logger.trace("Last check was {}", lastCheckTimestamp);
if( (lastCheckTimestamp + FALLBACK_RETRY_TIME) <= now ){
logger.debug("The {} for scope {} is {}. Is time to rediscover if there is another possibility.",
@ -138,12 +139,18 @@ public abstract class AccountingPersistenceBackendFactory {
}else{
// Renewing timestamp
logger.trace("Renewing Last check Timestamp. The new one will be {}", now);
fallbackLastCheck.put(scope, now);
lastCheckTimestamp = fallbackLastCheck.get(scope);
}
}
logger.debug("The {} for scope {} is going to be used is {}. Next retry in {} msec",
AccountingPersistenceBackend.class.getSimpleName(), scope, actual.getClass().getSimpleName(), FALLBACK_RETRY_TIME);
long nextCheck = (lastCheckTimestamp + FALLBACK_RETRY_TIME) - Calendar.getInstance().getTimeInMillis();
float nextCheckInSec = nextCheck/1000;
logger.debug("The {} for scope {} is going to be used is {}. Next retry in {} msec (about {} sec)",
AccountingPersistenceBackend.class.getSimpleName(), scope,
actual.getClass().getSimpleName(), nextCheck, nextCheckInSec);
return actual;
}

View File

@ -103,22 +103,27 @@ public class AccountingPersistenceBackendTest {
@Test
public void testScopeRecheck() throws Exception {
ScopeProvider.instance.set("/fakeScope");
AccountingPersistenceBackendFactory.getPersistenceBackend();
logger.debug("Going to check First Time");
AccountingPersistenceBackend first = AccountingPersistenceBackendFactory.getPersistenceBackend();
logger.debug("First {} : {}", AccountingPersistenceBackend.class.getSimpleName(), first);
Long firstCheck = AccountingPersistenceBackendFactory.getFallbackLastCheck(ScopeProvider.instance.get());
logger.debug("First Check Time {}", firstCheck);
long startTime = Calendar.getInstance().getTimeInMillis();
long endTime = startTime;
while(endTime <= (startTime + (AccountingPersistenceBackendFactory.FALLBACK_RETRY_TIME+1000))){
while(endTime <= (startTime + (AccountingPersistenceBackendFactory.FALLBACK_RETRY_TIME + 100))){
endTime = Calendar.getInstance().getTimeInMillis();
}
AccountingPersistenceBackendFactory.getPersistenceBackend();
logger.debug("Going to check Second Time");
AccountingPersistenceBackend second = AccountingPersistenceBackendFactory.getPersistenceBackend();
logger.debug("Second {} : {}", AccountingPersistenceBackend.class.getSimpleName(), second);
Long secondCheck = AccountingPersistenceBackendFactory.getFallbackLastCheck(ScopeProvider.instance.get());
logger.debug("Second Check Time {}", secondCheck);
Assert.assertNotEquals(firstCheck, secondCheck);
Assert.assertEquals(first, second);
}
}

View File

@ -3,11 +3,6 @@
*/
package org.gcube.accounting.persistence;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.Arrays;