mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-17 14:21:39 +00:00
* MNT-21837 - License expires 23h earlier
* Original problem is that the remaining time to license expires is calculated in days (long, not double) and anything less then 24h computes to 0 days. The validation for license being valid is that the remaining days is more than zero.
* Added method calculateMs in DateUtil class to return the interval in ms considering 2 given dates and respective timezones
* Changed the validation to use the remaining milliseconds value instead of remaining days
* Added unit test where license expires 6 hours from now - repo is not supposed to enter read-only mode
* Added unit test where license expired 1 minute ago - repo is supposed to enter read-only mode
* Removed unused import
(cherry picked from commit 630cd99067
)
This commit is contained in:
@@ -25,9 +25,9 @@
|
||||
*/
|
||||
package org.alfresco.repo.usage;
|
||||
|
||||
import javax.transaction.UserTransaction;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -37,6 +37,7 @@ import org.alfresco.service.cmr.admin.RepoUsage;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage.LicenseMode;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage.UsageType;
|
||||
import org.alfresco.service.cmr.admin.RepoUsageStatus;
|
||||
import org.alfresco.service.cmr.admin.RepoUsageStatus.RepoUsageLevel;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
@@ -48,6 +49,8 @@ import org.junit.experimental.categories.Category;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests {@link RepoUsageComponent}
|
||||
*
|
||||
@@ -236,6 +239,64 @@ public class RepoUsageComponentTest extends TestCase
|
||||
RepoUsage usage = getUsage();
|
||||
}
|
||||
|
||||
public void testLicenceHoursBeforeExpiration() throws Exception
|
||||
{
|
||||
// Update usage
|
||||
updateUsage(UsageType.USAGE_ALL);
|
||||
|
||||
// Set the restrictions for license to expire in 6 hours
|
||||
RepoUsage restrictions = new RepoUsage(
|
||||
System.currentTimeMillis(),
|
||||
5000L,
|
||||
100000L,
|
||||
LicenseMode.TEAM,
|
||||
System.currentTimeMillis() + TimeUnit.HOURS.toMillis(6),
|
||||
false);
|
||||
repoUsageComponent.setRestrictions(restrictions);
|
||||
|
||||
// Update use
|
||||
updateUsage(UsageType.USAGE_ALL);
|
||||
|
||||
// Get the usage
|
||||
RepoUsage usage = getUsage();
|
||||
|
||||
// Check
|
||||
assertFalse("Usage is in read-only mode",usage.isReadOnly());
|
||||
assertTrue("System is in read-only mode",transactionService.getAllowWrite());
|
||||
|
||||
RepoUsageStatus status = repoUsageComponent.getUsageStatus();
|
||||
assertEquals("System is not at Warning All Level",status.getLevel(),RepoUsageLevel.WARN_ALL);
|
||||
}
|
||||
|
||||
public void testLicenceMinutesAfterExpiration() throws Exception
|
||||
{
|
||||
// Update usage
|
||||
updateUsage(UsageType.USAGE_ALL);
|
||||
|
||||
// Set the restrictions for license to expire in 6 hours
|
||||
RepoUsage restrictions = new RepoUsage(
|
||||
System.currentTimeMillis(),
|
||||
5000L,
|
||||
100000L,
|
||||
LicenseMode.TEAM,
|
||||
System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(1),
|
||||
false);
|
||||
repoUsageComponent.setRestrictions(restrictions);
|
||||
|
||||
// Update use
|
||||
updateUsage(UsageType.USAGE_ALL);
|
||||
|
||||
// Get the usage
|
||||
RepoUsage usage = getUsage();
|
||||
|
||||
// Check we are in read-only mode
|
||||
assertTrue("Usage is not in read-only mode",usage.isReadOnly());
|
||||
assertFalse("System is not in read-only mode",transactionService.getAllowWrite());
|
||||
|
||||
RepoUsageStatus status = repoUsageComponent.getUsageStatus();
|
||||
assertEquals("System is not at Locked Level",status.getLevel(),RepoUsageLevel.LOCKED_DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that concurrent updates are prevented
|
||||
*
|
||||
|
Reference in New Issue
Block a user