Fix test failure

guava-cache-improvements
Rajitha Kumara 1 year ago
parent ef1b3d28ea
commit 2f68e0c1cd

@ -1006,7 +1006,7 @@ public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
Policy policy = new Policy();
Policy policy = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
@ -1017,6 +1017,7 @@ public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
resultSet = stmt.executeQuery();
while (resultSet.next()) {
policy = new Policy();
policy.setId(policyId);
policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(resultSet.getInt("TENANT_ID"));

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.policy.mgt.core.enforcement;
import io.entgra.device.mgt.core.policy.mgt.core.cache.guava.impl.GuavaPolicyCacheManagerImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.Device;
@ -50,7 +51,8 @@ public class DelegationTask extends DynamicPartitionedScheduleTask {
UpdatedPolicyDeviceListBean updatedPolicyDeviceList = policyManager.applyChangesMadeToPolicies();
List<String> deviceTypes = updatedPolicyDeviceList.getChangedDeviceTypes();
if (policyConfiguration.getCacheEnable()) {
PolicyCacheManagerImpl.getInstance().rePopulateCache();
//PolicyCacheManagerImpl.getInstance().rePopulateCache();
GuavaPolicyCacheManagerImpl.getInstance().rePopulateCache();
}
if (log.isDebugEnabled()) {
log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size());

@ -19,6 +19,7 @@
package io.entgra.device.mgt.core.policy.mgt.core.mgt.impl;
import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest;
import io.entgra.device.mgt.core.policy.mgt.core.cache.guava.impl.GuavaPolicyCacheManagerImpl;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -511,7 +512,8 @@ public class PolicyManagerImpl implements PolicyManager {
try {
List<Policy> existingPolicies;
if (policyConfiguration.getCacheEnable()) {
existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
//existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
existingPolicies = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else {
existingPolicies = this.getPolicies();
}
@ -795,11 +797,22 @@ public class PolicyManagerImpl implements PolicyManager {
try {
PolicyManagementDAOFactory.openConnection();
policy = policyDAO.getPolicy(policyId);
if(policy == null) {
return null;
}
roleNames = policyDAO.getPolicyAppliedRoles(policyId);
userNames = policyDAO.getPolicyAppliedUsers(policyId);
policy.setRoles(roleNames);
policy.setUsers(userNames);
policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policyId));
List<DeviceGroupWrapper> deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policyId);
if(!deviceGroupWrappers.isEmpty()) {
deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers);
}
policy.setDeviceGroups(deviceGroupWrappers);
if (log.isDebugEnabled()) {
log.debug("Retrieving corrective actions of policy " + policy.getPolicyName() +
" having policy id " + policy.getId());
@ -810,6 +823,8 @@ public class PolicyManagerImpl implements PolicyManager {
policyId + ")", e);
} catch (SQLException e) {
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
} catch (GroupManagementException e) {
throw new PolicyManagementException("Error occurred while getting device groups", e);
} finally {
PolicyManagementDAOFactory.closeConnection();
}
@ -915,7 +930,8 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> tempPolicyList;
if (policyConfiguration.getCacheEnable()) {
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
//tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
tempPolicyList = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else {
tempPolicyList = this.getPolicies();
}
@ -937,7 +953,8 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> policies = new ArrayList<>();
List<Policy> allPolicies;
if (policyConfiguration.getCacheEnable()) {
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
//allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
allPolicies = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else {
allPolicies = this.getPolicies();
}
@ -968,7 +985,8 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> tempPolicyList;
if (policyConfiguration.getCacheEnable()) {
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
//tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
tempPolicyList = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else {
tempPolicyList = this.getPolicies();
}
@ -1000,7 +1018,8 @@ public class PolicyManagerImpl implements PolicyManager {
}
List<Policy> tempPolicyList;
if (policyConfiguration.getCacheEnable()) {
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
//tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
tempPolicyList = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else {
tempPolicyList = this.getPolicies();
}
@ -1098,7 +1117,8 @@ public class PolicyManagerImpl implements PolicyManager {
try {
List<Policy> allPolicies;
if (policyConfiguration.getCacheEnable()) {
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
//allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
allPolicies = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else {
allPolicies = this.getPolicies();
}

Loading…
Cancel
Save