From 6ef06f9ecd55f1e4285ab53f2bde730b47dca468 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 17 Nov 2015 10:58:16 +0000 Subject: [PATCH] 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 --- .../AccountingPersistenceBackendFactory.java | 11 +++++++++-- .../persistence/AccountingPersistenceBackendTest.java | 11 ++++++++--- .../AccountingPersistenceConfigurationTest.java | 5 ----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java index dda84b7..f039caa 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceBackendFactory.java @@ -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; } diff --git a/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceBackendTest.java b/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceBackendTest.java index 717fd47..676564c 100644 --- a/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceBackendTest.java +++ b/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceBackendTest.java @@ -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); } } diff --git a/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceConfigurationTest.java b/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceConfigurationTest.java index 119efb1..b473bcc 100644 --- a/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceConfigurationTest.java +++ b/src/test/java/org/gcube/accounting/persistence/AccountingPersistenceConfigurationTest.java @@ -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;