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

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.policy.mgt.core.enforcement; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.Device;
@ -50,7 +51,8 @@ public class DelegationTask extends DynamicPartitionedScheduleTask {
UpdatedPolicyDeviceListBean updatedPolicyDeviceList = policyManager.applyChangesMadeToPolicies(); UpdatedPolicyDeviceListBean updatedPolicyDeviceList = policyManager.applyChangesMadeToPolicies();
List<String> deviceTypes = updatedPolicyDeviceList.getChangedDeviceTypes(); List<String> deviceTypes = updatedPolicyDeviceList.getChangedDeviceTypes();
if (policyConfiguration.getCacheEnable()) { if (policyConfiguration.getCacheEnable()) {
PolicyCacheManagerImpl.getInstance().rePopulateCache(); //PolicyCacheManagerImpl.getInstance().rePopulateCache();
GuavaPolicyCacheManagerImpl.getInstance().rePopulateCache();
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Number of device types which policies are changed .......... : " + deviceTypes.size()); 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; 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.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.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -511,7 +512,8 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
List<Policy> existingPolicies; List<Policy> existingPolicies;
if (policyConfiguration.getCacheEnable()) { if (policyConfiguration.getCacheEnable()) {
existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies(); //existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
existingPolicies = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else { } else {
existingPolicies = this.getPolicies(); existingPolicies = this.getPolicies();
} }
@ -795,11 +797,22 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
policy = policyDAO.getPolicy(policyId); policy = policyDAO.getPolicy(policyId);
if(policy == null) {
return null;
}
roleNames = policyDAO.getPolicyAppliedRoles(policyId); roleNames = policyDAO.getPolicyAppliedRoles(policyId);
userNames = policyDAO.getPolicyAppliedUsers(policyId); userNames = policyDAO.getPolicyAppliedUsers(policyId);
policy.setRoles(roleNames); policy.setRoles(roleNames);
policy.setUsers(userNames); 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()) { if (log.isDebugEnabled()) {
log.debug("Retrieving corrective actions of policy " + policy.getPolicyName() + log.debug("Retrieving corrective actions of policy " + policy.getPolicyName() +
" having policy id " + policy.getId()); " having policy id " + policy.getId());
@ -810,6 +823,8 @@ public class PolicyManagerImpl implements PolicyManager {
policyId + ")", e); policyId + ")", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new PolicyManagementException("Error occurred while opening a connection to the data source", 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 { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
@ -915,7 +930,8 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> tempPolicyList; List<Policy> tempPolicyList;
if (policyConfiguration.getCacheEnable()) { if (policyConfiguration.getCacheEnable()) {
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies(); //tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
tempPolicyList = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else { } else {
tempPolicyList = this.getPolicies(); tempPolicyList = this.getPolicies();
} }
@ -937,7 +953,8 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> policies = new ArrayList<>(); List<Policy> policies = new ArrayList<>();
List<Policy> allPolicies; List<Policy> allPolicies;
if (policyConfiguration.getCacheEnable()) { if (policyConfiguration.getCacheEnable()) {
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies(); //allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
allPolicies = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else { } else {
allPolicies = this.getPolicies(); allPolicies = this.getPolicies();
} }
@ -968,7 +985,8 @@ public class PolicyManagerImpl implements PolicyManager {
List<Policy> tempPolicyList; List<Policy> tempPolicyList;
if (policyConfiguration.getCacheEnable()) { if (policyConfiguration.getCacheEnable()) {
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies(); //tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
tempPolicyList = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else { } else {
tempPolicyList = this.getPolicies(); tempPolicyList = this.getPolicies();
} }
@ -1000,7 +1018,8 @@ public class PolicyManagerImpl implements PolicyManager {
} }
List<Policy> tempPolicyList; List<Policy> tempPolicyList;
if (policyConfiguration.getCacheEnable()) { if (policyConfiguration.getCacheEnable()) {
tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies(); //tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies();
tempPolicyList = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else { } else {
tempPolicyList = this.getPolicies(); tempPolicyList = this.getPolicies();
} }
@ -1098,7 +1117,8 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
List<Policy> allPolicies; List<Policy> allPolicies;
if (policyConfiguration.getCacheEnable()) { if (policyConfiguration.getCacheEnable()) {
allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies(); //allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies();
allPolicies = GuavaPolicyCacheManagerImpl.getInstance().getAllPolicies();
} else { } else {
allPolicies = this.getPolicies(); allPolicies = this.getPolicies();
} }

Loading…
Cancel
Save