You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2017/06/14 22:06:52 UTC
[05/51] [abbrv] geode git commit: GEODE-2632: use immutable
SecurityService impls to improve performance
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
index b3d9675..5a4a3d7 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/IndexCommands.java
@@ -26,8 +26,6 @@ import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.execute.AbstractExecution;
import org.apache.geode.internal.lang.StringUtils;
-import org.apache.geode.internal.security.IntegratedSecurityService;
-import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.ConverterHint;
import org.apache.geode.management.cli.Result;
@@ -41,7 +39,6 @@ import org.apache.geode.management.internal.cli.functions.CreateIndexFunction;
import org.apache.geode.management.internal.cli.functions.DestroyIndexFunction;
import org.apache.geode.management.internal.cli.functions.ListIndexFunction;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.result.CommandResultException;
import org.apache.geode.management.internal.cli.result.ErrorResultData;
import org.apache.geode.management.internal.cli.result.InfoResultData;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
@@ -67,8 +64,7 @@ import java.util.concurrent.atomic.AtomicReference;
/**
* The IndexCommands class encapsulates all GemFire shell (Gfsh) commands related to indexes defined
* in GemFire.
- * </p>
- *
+ *
* @see GfshCommand
* @see org.apache.geode.management.internal.cli.domain.IndexDetails
* @see org.apache.geode.management.internal.cli.functions.ListIndexFunction
@@ -84,8 +80,6 @@ public class IndexCommands implements GfshCommand {
private static final Set<IndexInfo> indexDefinitions =
Collections.synchronizedSet(new HashSet<IndexInfo>());
- private SecurityService securityService = IntegratedSecurityService.getSecurityService();
-
@CliCommand(value = CliStrings.LIST_INDEX, help = CliStrings.LIST_INDEX__HELP)
@CliMetaData(shellOnly = false,
relatedTopic = {CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA})
@@ -196,7 +190,7 @@ public class IndexCommands implements GfshCommand {
Result result = null;
AtomicReference<XmlEntity> xmlEntity = new AtomicReference<>();
- this.securityService.authorizeRegionManage(regionPath);
+ getCache().getSecurityService().authorizeRegionManage(regionPath);
try {
final Cache cache = CacheFactory.getAnyInstance();
@@ -312,7 +306,6 @@ public class IndexCommands implements GfshCommand {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
-
if (xmlEntity.get() != null) {
persistClusterConfiguration(result,
() -> getSharedConfiguration().addXmlEntity(xmlEntity.get(), group));
@@ -355,9 +348,9 @@ public class IndexCommands implements GfshCommand {
// requires data manage permission on all regions
if (StringUtils.isNotBlank(regionPath)) {
regionName = regionPath.startsWith("/") ? regionPath.substring(1) : regionPath;
- this.securityService.authorizeRegionManage(regionName);
+ getCache().getSecurityService().authorizeRegionManage(regionName);
} else {
- this.securityService.authorizeDataManage();
+ getCache().getSecurityService().authorizeDataManage();
}
IndexInfo indexInfo = new IndexInfo(indexName, regionName);
@@ -479,7 +472,7 @@ public class IndexCommands implements GfshCommand {
Result result = null;
XmlEntity xmlEntity = null;
- this.securityService.authorizeRegionManage(regionPath);
+ getCache().getSecurityService().authorizeRegionManage(regionPath);
int idxType = IndexInfo.RANGE_INDEX;
@@ -641,14 +634,13 @@ public class IndexCommands implements GfshCommand {
final InfoResultData infoResult = ResultBuilder.createInfoResultData();
infoResult.addLine(CliStrings.CLEAR_DEFINED_INDEX__SUCCESS__MSG);
return ResultBuilder.buildResult(infoResult);
-
}
@CliAvailabilityIndicator({CliStrings.LIST_INDEX, CliStrings.CREATE_INDEX,
CliStrings.DESTROY_INDEX, CliStrings.CREATE_DEFINED_INDEXES, CliStrings.CLEAR_DEFINED_INDEXES,
CliStrings.DEFINE_INDEX})
public boolean indexCommandsAvailable() {
- return (!CliUtil.isGfshVM() || (getGfsh() != null && getGfsh().isConnectedAndReady()));
+ return !CliUtil.isGfshVM() || getGfsh() != null && getGfsh().isConnectedAndReady();
}
protected static class IndexStatisticsDetailsAdapter {
@@ -664,28 +656,28 @@ public class IndexCommands implements GfshCommand {
}
public String getNumberOfKeys() {
- return (getIndexStatisticsDetails() != null
- ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfKeys()) : "");
+ return getIndexStatisticsDetails() != null
+ ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfKeys()) : "";
}
public String getNumberOfUpdates() {
- return (getIndexStatisticsDetails() != null
- ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfUpdates()) : "");
+ return getIndexStatisticsDetails() != null
+ ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfUpdates()) : "";
}
public String getNumberOfValues() {
- return (getIndexStatisticsDetails() != null
- ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfValues()) : "");
+ return getIndexStatisticsDetails() != null
+ ? StringUtils.defaultString(getIndexStatisticsDetails().getNumberOfValues()) : "";
}
public String getTotalUpdateTime() {
- return (getIndexStatisticsDetails() != null
- ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUpdateTime()) : "");
+ return getIndexStatisticsDetails() != null
+ ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUpdateTime()) : "";
}
public String getTotalUses() {
- return (getIndexStatisticsDetails() != null
- ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUses()) : "");
+ return getIndexStatisticsDetails() != null
+ ? StringUtils.defaultString(getIndexStatisticsDetails().getTotalUses()) : "";
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
index e2164a3..20e2701 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/DataCommandFunction.java
@@ -94,9 +94,6 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
protected static final String SELECT_STEP_EXEC = "SELECT_EXEC";
private static final int NESTED_JSON_LENGTH = 20;
- // this needs to be static so that it won't get serialized
- private static SecurityService securityService = SecurityService.getSecurityService();
-
@Override
public String getId() {
return DataCommandFunction.class.getName();
@@ -136,7 +133,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
}
DataCommandResult result = null;
if (request.isGet()) {
- result = get(request);
+ result = get(request, cache.getSecurityService());
} else if (request.isLocateEntry()) {
result = locateEntry(request);
} else if (request.isPut()) {
@@ -169,13 +166,14 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
return remove(key, keyClass, regionName, removeAllKeys);
}
- public DataCommandResult get(DataCommandRequest request) {
+ public DataCommandResult get(DataCommandRequest request, SecurityService securityService) {
String key = request.getKey();
String keyClass = request.getKeyClass();
String valueClass = request.getValueClass();
String regionName = request.getRegionName();
Boolean loadOnCacheMiss = request.isLoadOnCacheMiss();
- return get(request.getPrincipal(), key, keyClass, valueClass, regionName, loadOnCacheMiss);
+ return get(request.getPrincipal(), key, keyClass, valueClass, regionName, loadOnCacheMiss,
+ securityService);
}
public DataCommandResult locateEntry(DataCommandRequest request) {
@@ -296,7 +294,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
List<SelectResultRow> list, AtomicInteger nestedObjectCount) throws GfJsonException {
for (Object object : selectResults) {
// Post processing
- object = securityService.postProcess(principal, null, null, object, false);
+ object = getCache().getSecurityService().postProcess(principal, null, null, object, false);
if (object instanceof Struct) {
StructImpl impl = (StructImpl) object;
@@ -434,7 +432,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
@SuppressWarnings({"rawtypes"})
public DataCommandResult get(Object principal, String key, String keyClass, String valueClass,
- String regionName, Boolean loadOnCacheMiss) {
+ String regionName, Boolean loadOnCacheMiss, SecurityService securityService) {
InternalCache cache = getCache();
@@ -836,7 +834,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
return list;
}
- private static DataCommandResult cachedResult = null;
+ static DataCommandResult cachedResult = null;
public static class SelectDisplayStep extends CLIMultiStepHelper.LocalStep {
@@ -916,13 +914,12 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
}
public static class SelectExecStep extends CLIMultiStepHelper.RemoteStep {
+ private static final Logger logger = LogService.getLogger();
private static final long serialVersionUID = 1L;
- private static SecurityService securityService = SecurityService.getSecurityService();
-
public SelectExecStep(Object[] arguments) {
- super(SELECT_STEP_EXEC, arguments);
+ super(DataCommandFunction.SELECT_STEP_EXEC, arguments);
}
@Override
@@ -931,19 +928,19 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
boolean interactive = (Boolean) commandArguments[2];
DataCommandResult result = _select(remainingQuery);
int endCount = 0;
- cachedResult = result;
+ DataCommandFunction.cachedResult = result;
if (interactive) {
- endCount = getPageSize();
+ endCount = DataCommandFunction.getPageSize();
} else {
if (result.getSelectResult() != null) {
endCount = result.getSelectResult().size();
}
}
if (interactive) {
- return result.pageResult(0, endCount, SELECT_STEP_DISPLAY);
+ return result.pageResult(0, endCount, DataCommandFunction.SELECT_STEP_DISPLAY);
} else {
return CLIMultiStepHelper.createBannerResult(new String[] {}, new Object[] {},
- SELECT_STEP_END);
+ DataCommandFunction.SELECT_STEP_END);
}
}
@@ -971,7 +968,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
// authorize data read on these regions
for (String region : regions) {
- securityService.authorizeRegionRead(region);
+ cache.getSecurityService().authorizeRegionRead(region);
}
regionsInQuery = Collections.unmodifiableSet(regions);
@@ -983,7 +980,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
DataCommandRequest request = new DataCommandRequest();
request.setCommand(CliStrings.QUERY);
request.setQuery(query);
- Subject subject = securityService.getSubject();
+ Subject subject = cache.getSecurityService().getSubject();
if (subject != null) {
request.setPrincipal(subject.getPrincipal());
}
@@ -1012,7 +1009,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
|| StringUtils.containsIgnoreCase(query, " count(")) {
return query;
}
- return query + " limit " + getFetchSize();
+ return query + " limit " + DataCommandFunction.getFetchSize();
}
}
@@ -1063,7 +1060,7 @@ public class DataCommandFunction extends FunctionAdapter implements InternalEnti
return pageSize;
}
- private static int getFetchSize() {
+ static int getFetchSize() {
return CommandExecutionContext.getShellFetchSize();
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandProcessor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandProcessor.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandProcessor.java
index c2c6e14..7ec7699 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandProcessor.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/CommandProcessor.java
@@ -14,8 +14,8 @@
*/
package org.apache.geode.management.internal.cli.remote;
-import org.apache.geode.internal.security.IntegratedSecurityService;
import org.apache.geode.internal.security.SecurityService;
+import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.management.cli.CommandProcessingException;
import org.apache.geode.management.cli.CommandStatement;
import org.apache.geode.management.cli.Result;
@@ -34,8 +34,6 @@ import java.util.Map;
import java.util.Properties;
/**
- *
- *
* @since GemFire 7.0
*/
public class CommandProcessor {
@@ -49,16 +47,18 @@ public class CommandProcessor {
private volatile boolean isStopped = false;
- private SecurityService securityService = IntegratedSecurityService.getSecurityService();
+ private final SecurityService securityService;
public CommandProcessor() throws ClassNotFoundException, IOException {
- this(null);
+ this(null, SecurityServiceFactory.create());
}
- public CommandProcessor(Properties cacheProperties) throws ClassNotFoundException, IOException {
+ public CommandProcessor(Properties cacheProperties, SecurityService securityService)
+ throws ClassNotFoundException, IOException {
this.gfshParser = new GfshParser(cacheProperties);
this.executionStrategy = new RemoteExecutionStrategy();
this.logWrapper = LogWrapper.getInstance();
+ this.securityService = securityService;
}
protected RemoteExecutionStrategy getExecutionStrategy() {
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/MemberCommandService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/MemberCommandService.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/MemberCommandService.java
index a19c5cb..25ff549 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/MemberCommandService.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/remote/MemberCommandService.java
@@ -17,24 +17,23 @@ package org.apache.geode.management.internal.cli.remote;
import java.io.IOException;
import java.util.Map;
-import org.apache.geode.cache.Cache;
+import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.management.cli.CommandService;
import org.apache.geode.management.cli.CommandServiceException;
import org.apache.geode.management.cli.CommandStatement;
import org.apache.geode.management.cli.Result;
-/**
- */
public class MemberCommandService extends CommandService {
private final Object modLock = new Object();
- private Cache cache;
+ private InternalCache cache;
private CommandProcessor commandProcessor;
- public MemberCommandService(Cache cache) throws CommandServiceException {
+ public MemberCommandService(InternalCache cache) throws CommandServiceException {
this.cache = cache;
try {
- this.commandProcessor = new CommandProcessor(cache.getDistributedSystem().getProperties());
+ this.commandProcessor = new CommandProcessor(cache.getDistributedSystem().getProperties(),
+ cache.getSecurityService());
} catch (ClassNotFoundException e) {
throw new CommandServiceException("Could not load commands.", e);
} catch (IOException e) {
@@ -70,12 +69,4 @@ public class MemberCommandService extends CommandService {
return (this.cache != null && !this.cache.isClosed());
}
- // @Override
- // public void stop() {
- // cache = null;
- // synchronized (modLock) {
- // this.commandProcessor.stop();
- // this.commandProcessor = null;
- // }
- // }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RecreateCacheFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RecreateCacheFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RecreateCacheFunction.java
index a00a79e..f25d1af 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RecreateCacheFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/RecreateCacheFunction.java
@@ -16,7 +16,7 @@ package org.apache.geode.management.internal.configuration.functions;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.internal.InternalEntity;
import org.apache.geode.internal.cache.CacheConfig;
import org.apache.geode.internal.cache.GemFireCacheImpl;
@@ -28,7 +28,7 @@ public class RecreateCacheFunction implements Function, InternalEntity {
public void execute(FunctionContext context) {
CliFunctionResult result = null;
InternalCache cache = GemFireCacheImpl.getInstance();
- DistributedSystem ds = cache.getDistributedSystem();
+ InternalDistributedSystem ds = cache.getInternalDistributedSystem();
CacheConfig cacheConfig = cache.getCacheConfig();
try {
cache.close("Re-create Cache", true, true);
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/security/AccessControlMBean.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/security/AccessControlMBean.java b/geode-core/src/main/java/org/apache/geode/management/internal/security/AccessControlMBean.java
index 6514a33..365c6ae 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/security/AccessControlMBean.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/security/AccessControlMBean.java
@@ -14,7 +14,6 @@
*/
package org.apache.geode.management.internal.security;
-import org.apache.geode.internal.security.IntegratedSecurityService;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.security.GemFireSecurityException;
@@ -26,7 +25,11 @@ import org.apache.geode.security.GemFireSecurityException;
*/
public class AccessControlMBean implements AccessControlMXBean {
- private SecurityService securityService = IntegratedSecurityService.getSecurityService();
+ private final SecurityService securityService;
+
+ public AccessControlMBean(SecurityService securityService) {
+ this.securityService = securityService;
+ }
@Override
public boolean authorize(String resource, String permission) {
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/security/MBeanServerWrapper.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/security/MBeanServerWrapper.java b/geode-core/src/main/java/org/apache/geode/management/internal/security/MBeanServerWrapper.java
index fe79efb..345d688 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/security/MBeanServerWrapper.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/security/MBeanServerWrapper.java
@@ -14,6 +14,11 @@
*/
package org.apache.geode.management.internal.security;
+import org.apache.geode.internal.security.SecurityService;
+import org.apache.geode.management.internal.ManagementConstants;
+import org.apache.geode.security.GemFireSecurityException;
+import org.apache.geode.security.ResourcePermission;
+
import java.io.ObjectInputStream;
import java.util.Set;
import javax.management.Attribute;
@@ -42,25 +47,22 @@ import javax.management.ReflectionException;
import javax.management.loading.ClassLoaderRepository;
import javax.management.remote.MBeanServerForwarder;
-import org.apache.geode.internal.security.IntegratedSecurityService;
-import org.apache.geode.internal.security.SecurityService;
-import org.apache.geode.management.internal.ManagementConstants;
-import org.apache.geode.security.GemFireSecurityException;
-import org.apache.geode.security.ResourcePermission;
-
/**
* This class intercepts all MBean requests for GemFire MBeans and passed it to
* ManagementInterceptor for authorization
*
* @since Geode 1.0
- *
*/
public class MBeanServerWrapper implements MBeanServerForwarder {
+
+ // TODO: make volatile or verify this is thread-safe
private MBeanServer mbs;
- private SecurityService securityService = IntegratedSecurityService.getSecurityService();
+ private final SecurityService securityService;
- public MBeanServerWrapper() {}
+ public MBeanServerWrapper(SecurityService securityService) {
+ this.securityService = securityService;
+ }
private void checkDomain(ObjectName name) {
if (ManagementConstants.OBJECTNAME__DEFAULTDOMAIN.equals(name.getDomain()))
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java
index 54c29f8..0a18ec5 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/AbstractCommandsController.java
@@ -12,7 +12,6 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.web.controllers;
import org.apache.geode.internal.cache.GemFireCacheImpl;
@@ -20,8 +19,6 @@ import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.lang.StringUtils;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.logging.log4j.LogMarker;
-import org.apache.geode.internal.security.IntegratedSecurityService;
-import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.internal.util.ArrayUtils;
import org.apache.geode.management.DistributedSystemMXBean;
import org.apache.geode.management.ManagementService;
@@ -85,8 +82,6 @@ public abstract class AbstractCommandsController {
private MemberMXBean managingMemberMXBeanProxy;
- private SecurityService securityService = IntegratedSecurityService.getSecurityService();
-
private Class accessControlKlass;
private InternalCache getCache() {
@@ -576,10 +571,9 @@ public abstract class AbstractCommandsController {
return new ResponseEntity<String>(result, HttpStatus.OK);
}
};
- return this.securityService.associateWith(callable);
+ return getCache().getSecurityService().associateWith(callable);
}
-
/**
* Executes the specified command as entered by the user using the GemFire Shell (Gfsh). Note,
* Gfsh performs validation of the command during parsing before sending the command to the
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptor.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptor.java
index 56d9b9e..5e502f5 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptor.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/support/LoginHandlerInterceptor.java
@@ -14,11 +14,14 @@
*/
package org.apache.geode.management.internal.web.controllers.support;
-import org.apache.geode.cache.Cache;
+import static org.apache.geode.internal.security.SecurityServiceFactory.findSecurityService;
+
import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.internal.security.IntegratedSecurityService;
import org.apache.geode.internal.security.SecurityService;
+import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.management.internal.cli.multistep.CLIMultiStepHelper;
import org.apache.geode.management.internal.security.ResourceConstants;
import org.apache.geode.management.internal.web.util.UriUtils;
@@ -48,9 +51,7 @@ public class LoginHandlerInterceptor extends HandlerInterceptorAdapter {
private static final Logger logger = LogService.getLogger();
- private Cache cache;
-
- private SecurityService securityService = IntegratedSecurityService.getSecurityService();
+ private final SecurityService securityService;
private static final ThreadLocal<Map<String, String>> ENV =
new ThreadLocal<Map<String, String>>() {
@@ -65,6 +66,14 @@ public class LoginHandlerInterceptor extends HandlerInterceptorAdapter {
protected static final String SECURITY_VARIABLE_REQUEST_HEADER_PREFIX =
DistributionConfig.SECURITY_PREFIX_NAME;
+ public LoginHandlerInterceptor() {
+ this(findSecurityService());
+ }
+
+ LoginHandlerInterceptor(SecurityService securityService) {
+ this.securityService = securityService;
+ }
+
public static Map<String, String> getEnvironment() {
return ENV.get();
}
@@ -104,11 +113,6 @@ public class LoginHandlerInterceptor extends HandlerInterceptorAdapter {
return true;
}
- public void setSecurityService(SecurityService securityService) {
- this.securityService = securityService;
- }
-
-
@Override
public void afterCompletion(final HttpServletRequest request, final HttpServletResponse response,
final Object handler, final Exception ex) throws Exception {
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/main/java/org/apache/geode/security/PostProcessor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/security/PostProcessor.java b/geode-core/src/main/java/org/apache/geode/security/PostProcessor.java
index 707e3cf..bad58d8 100644
--- a/geode-core/src/main/java/org/apache/geode/security/PostProcessor.java
+++ b/geode-core/src/main/java/org/apache/geode/security/PostProcessor.java
@@ -28,7 +28,7 @@ public interface PostProcessor {
* Given the security props of the server, properly initialize the post processor for the server.
* Initialized at cache creation
*
- * @param securityProps
+ * @param securityProps security properties
*/
default void init(Properties securityProps) {}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/codeAnalysis/AnalyzeSerializablesJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/codeAnalysis/AnalyzeSerializablesJUnitTest.java b/geode-core/src/test/java/org/apache/geode/codeAnalysis/AnalyzeSerializablesJUnitTest.java
index 2ba11a2..c9118e4 100644
--- a/geode-core/src/test/java/org/apache/geode/codeAnalysis/AnalyzeSerializablesJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/codeAnalysis/AnalyzeSerializablesJUnitTest.java
@@ -52,9 +52,19 @@ import java.util.Map;
@Category(IntegrationTest.class)
public class AnalyzeSerializablesJUnitTest {
+ private static final String NEW_LINE = System.getProperty("line.separator");
+
+ private static final String FAIL_MESSAGE = NEW_LINE + NEW_LINE
+ + "If the class is not persisted or sent over the wire add it to the file " + NEW_LINE + "%s"
+ + NEW_LINE + "Otherwise if this doesn't break backward compatibility, copy the file "
+ + NEW_LINE + "%s to " + NEW_LINE + "%s.";
+
/** all loaded classes */
private Map<String, CompiledClass> classes;
+ private File expectedDataSerializablesFile;
+ private File expectedSerializablesFile;
+
private List<ClassAndMethodDetails> expectedDataSerializables;
private List<ClassAndVariableDetails> expectedSerializables;
@@ -76,18 +86,18 @@ public class AnalyzeSerializablesJUnitTest {
// setup expectedDataSerializables
- File expectedDataSerializablesFile = getResourceAsFile("sanctionedDataSerializables.txt");
- assertThat(expectedDataSerializablesFile).exists().canRead();
+ this.expectedDataSerializablesFile = getResourceAsFile("sanctionedDataSerializables.txt");
+ assertThat(this.expectedDataSerializablesFile).exists().canRead();
- this.expectedDataSerializables = loadClassesAndMethods(expectedDataSerializablesFile);
+ this.expectedDataSerializables = loadClassesAndMethods(this.expectedDataSerializablesFile);
Collections.sort(this.expectedDataSerializables);
// setup expectedSerializables
- File expectedSerializablesFile = getResourceAsFile("sanctionedSerializables.txt");
- assertThat(expectedSerializablesFile).exists().canRead();
+ this.expectedSerializablesFile = getResourceAsFile("sanctionedSerializables.txt");
+ assertThat(this.expectedSerializablesFile).exists().canRead();
- this.expectedSerializables = loadClassesAndVariables(expectedSerializablesFile);
+ this.expectedSerializables = loadClassesAndVariables(this.expectedSerializablesFile);
Collections.sort(this.expectedSerializables);
}
@@ -111,15 +121,13 @@ public class AnalyzeSerializablesJUnitTest {
String diff =
diffSortedClassesAndMethods(this.expectedDataSerializables, actualDataSerializables);
- if (diff.length() > 0) {
+ if (!diff.isEmpty()) {
System.out.println(
"++++++++++++++++++++++++++++++testDataSerializables found discrepancies++++++++++++++++++++++++++++++++++++");
System.out.println(diff);
- fail(
- diff + "\n\nIf the class is not persisted or sent over the wire add it to the excludedClasses.txt file in the "
- + "\norg/apache/geode/codeAnalysis directory. Otherwise if this doesn't "
- + "\nbreak backward compatibility move the file actualDataSerializables.dat to the codeAnalysis "
- + "\ntest directory and rename to sanctionedDataSerializables.txt");
+ fail(diff + FAIL_MESSAGE, getSrcPathFor(getResourceAsFile("excludedClasses.txt")),
+ this.actualDataSerializablesFile.getAbsolutePath(),
+ getSrcPathFor(this.expectedDataSerializablesFile));
}
}
@@ -135,18 +143,22 @@ public class AnalyzeSerializablesJUnitTest {
storeClassesAndVariables(actualSerializables, this.actualSerializablesFile);
String diff = diffSortedClassesAndVariables(this.expectedSerializables, actualSerializables);
- if (diff.length() > 0) {
+ if (!diff.isEmpty()) {
System.out.println(
"++++++++++++++++++++++++++++++testSerializables found discrepancies++++++++++++++++++++++++++++++++++++");
System.out.println(diff);
- fail(
- diff + "\n\nIf the class is not persisted or sent over the wire add it to the excludedClasses.txt file in the "
- + "\n/org/apache/geode/codeAnalysis/ directory. Otherwise if this doesn't "
- + "\nbreak backward compatibility move the file actualSerializables.dat to the "
- + "\ncodeAnalysis test directory and rename to sanctionedSerializables.txt");
+ fail(diff + FAIL_MESSAGE, getSrcPathFor(getResourceAsFile("excludedClasses.txt")),
+ this.actualSerializablesFile.getAbsolutePath(),
+ getSrcPathFor(this.expectedSerializablesFile));
}
}
+ private String getSrcPathFor(File file) {
+ return file.getAbsolutePath().replace(
+ "build" + File.separator + "resources" + File.separator + "test",
+ "src" + File.separator + "test" + File.separator + "resources");
+ }
+
private void loadClasses() throws IOException {
System.out.println("loadClasses starting");
@@ -177,7 +189,7 @@ public class AnalyzeSerializablesJUnitTest {
loadClassesFromBuild(new File(buildDir), excludedClasses);
long finish = System.currentTimeMillis();
- System.out.println("done loading " + classes.size() + " classes. elapsed time = "
+ System.out.println("done loading " + this.classes.size() + " classes. elapsed time = "
+ (finish - start) / 1000 + " seconds");
}
@@ -189,7 +201,7 @@ public class AnalyzeSerializablesJUnitTest {
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
- if (line.length() > 0 && !line.startsWith("#")) {
+ if (!line.isEmpty() && !line.startsWith("#")) {
excludedClasses.add(line);
}
}
@@ -208,7 +220,7 @@ public class AnalyzeSerializablesJUnitTest {
// each line should have bug#,full-class-name
while ((line = br.readLine()) != null) {
line = line.trim();
- if (line.length() > 0 && !line.startsWith("#")) {
+ if (!line.isEmpty() && !line.startsWith("#")) {
String[] split = line.split(",");
if (split.length != 2) {
fail("unable to load classes due to malformed line in openBugs.txt: " + line);
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java
index f112d1a..a0c3cf3 100755
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/MembershipJUnitTest.java
@@ -14,6 +14,13 @@
*/
package org.apache.geode.distributed.internal.membership;
+import static org.apache.geode.distributed.ConfigurationProperties.DISABLE_TCP;
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.MEMBER_TIMEOUT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -22,57 +29,48 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.io.File;
-import java.net.InetAddress;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.logging.log4j.Level;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
import org.apache.geode.GemFireConfigException;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.*;
+import org.apache.geode.distributed.internal.DMStats;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.SerialAckedMessage;
import org.apache.geode.distributed.internal.membership.gms.GMSUtil;
import org.apache.geode.distributed.internal.membership.gms.ServiceConfig;
import org.apache.geode.distributed.internal.membership.gms.Services;
import org.apache.geode.distributed.internal.membership.gms.interfaces.JoinLeave;
import org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave;
-import org.apache.geode.distributed.internal.membership.gms.messages.*;
+import org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.RemoveMemberMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage;
+import org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage;
import org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager;
import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.internal.admin.remote.RemoteTransportConfig;
+import org.apache.geode.internal.net.SocketCreator;
+import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.logging.log4j.Level;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import java.io.File;
+import java.net.InetAddress;
+import java.util.List;
+import java.util.Properties;
@Category({IntegrationTest.class, MembershipJUnitTest.class})
public class MembershipJUnitTest {
- static Level baseLogLevel;
-
- @BeforeClass
- public static void setupClass() {
- // baseLogLevel = LogService.getBaseLogLevel();
- // LogService.setBaseLogLevel(Level.DEBUG);
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- // LogService.setBaseLogLevel(baseLogLevel);
- }
-
- // @Test
- // public void testRepeat() throws Exception {
- // for (int i=0; i<50; i++) {
- // System.out.println("--------------------run #" + i);
- // testMultipleManagersInSameProcess();
- // }
- // }
/**
* This test creates a locator with a colocated membership manager and then creates a second
@@ -152,7 +150,8 @@ public class MembershipJUnitTest {
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
System.out.println("creating 1st membership manager");
- m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
+ m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1,
+ SecurityServiceFactory.create());
m1.startEventProcessing();
} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
@@ -162,7 +161,8 @@ public class MembershipJUnitTest {
DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
DMStats stats2 = mock(DMStats.class);
System.out.println("creating 2nd membership manager");
- m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2);
+ m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2,
+ SecurityServiceFactory.create());
m2.startEventProcessing();
// we have to check the views with JoinLeave because the membership
@@ -292,7 +292,8 @@ public class MembershipJUnitTest {
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
System.out.println("creating 1st membership manager");
- m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
+ m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1,
+ SecurityServiceFactory.create());
m1.startEventProcessing();
} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
@@ -302,7 +303,8 @@ public class MembershipJUnitTest {
DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
DMStats stats2 = mock(DMStats.class);
System.out.println("creating 2nd membership manager");
- m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2);
+ m2 = MemberFactory.newMembershipManager(listener2, config, transport, stats2,
+ SecurityServiceFactory.create());
m2.startEventProcessing();
// we have to check the views with JoinLeave because the membership
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
index f17b40b..e8c4e73 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/AbstractGMSAuthenticatorTestCase.java
@@ -65,18 +65,19 @@ public abstract class AbstractGMSAuthenticatorTestCase {
clearStatics();
MockitoAnnotations.initMocks(this);
- props = new Properties();
- securityProps = new Properties();
-
- when(securityService.isIntegratedSecurity()).thenReturn(isIntegratedSecurity());
- when(securityService.isPeerSecurityRequired()).thenReturn(true);
- when(securityService.login(securityProps)).thenReturn(subject);
- when(distributionConfig.getSecurityProps()).thenReturn(securityProps);
- when(serviceConfig.getDistributionConfig()).thenReturn(distributionConfig);
- when(services.getSecurityLogWriter()).thenReturn(mock(InternalLogWriter.class));
- when(services.getConfig()).thenReturn(serviceConfig);
-
- authenticator.init(services);
+ this.props = new Properties();
+ this.securityProps = new Properties();
+
+ when(this.securityService.isIntegratedSecurity()).thenReturn(isIntegratedSecurity());
+ when(this.securityService.isPeerSecurityRequired()).thenReturn(true);
+ when(this.securityService.login(this.securityProps)).thenReturn(this.subject);
+ when(this.distributionConfig.getSecurityProps()).thenReturn(this.securityProps);
+ when(this.serviceConfig.getDistributionConfig()).thenReturn(this.distributionConfig);
+ when(this.services.getSecurityLogWriter()).thenReturn(mock(InternalLogWriter.class));
+ when(this.services.getConfig()).thenReturn(this.serviceConfig);
+ when(this.services.getSecurityService()).thenReturn(this.securityService);
+
+ this.authenticator.init(this.services);
}
protected abstract boolean isIntegratedSecurity();
@@ -135,11 +136,11 @@ public abstract class AbstractGMSAuthenticatorTestCase {
@Override
public void close() {
- closed = true;
+ this.closed = true;
}
public boolean isClosed() {
- return closed;
+ return this.closed;
}
public static int getCreateCount() {
@@ -284,11 +285,11 @@ public abstract class AbstractGMSAuthenticatorTestCase {
@Override
public void close() {
- closed = true;
+ this.closed = true;
}
public boolean isClosed() {
- return closed;
+ return this.closed;
}
public static int getCreateCount() {
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
index b9f6429..96a9a5f 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithAuthenticatorTest.java
@@ -38,26 +38,28 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void nullAuthenticatorShouldReturnNull() throws Exception {
- assertThat(securityProps).doesNotContainKey(SECURITY_PEER_AUTHENTICATOR);
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ assertThat(this.securityProps).doesNotContainKey(SECURITY_PEER_AUTHENTICATOR);
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
// assertThat(result).isNull(); NOTE: old security used to return null
assertThat(result).contains("Security check failed");
}
@Test
public void emptyAuthenticatorShouldReturnNull() throws Exception {
- securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ this.securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
// assertThat(result).isNull(); NOTE: old security used to return null
assertThat(result).contains("Security check failed");
}
@Test
public void shouldGetSecurityPropsFromDistributionConfig() throws Exception {
- securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
- securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "dummy2");
+ this.securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
+ this.securityProps.setProperty(SECURITY_PEER_AUTHENTICATOR, "dummy2");
- Properties secProps = authenticator.getSecurityProps();
+ Properties secProps = this.authenticator.getSecurityProps();
assertThat(secProps.size()).isEqualTo(2);
assertThat(secProps.getProperty(SECURITY_PEER_AUTH_INIT)).isEqualTo("dummy1");
@@ -66,73 +68,74 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void usesPeerAuthInitToGetCredentials() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
SpyAuthInit auth = new SpyAuthInit();
assertThat(auth.isClosed()).isFalse();
SpyAuthInit.setAuthInitialize(auth);
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
- assertThat(credentials).isEqualTo(props);
+ assertThat(credentials).isEqualTo(this.props);
assertThat(auth.isClosed()).isTrue();
assertThat(SpyAuthInit.getCreateCount()).isEqualTo(1);
}
@Test
public void getCredentialsShouldReturnNullIfNoPeerAuthInit() throws Exception {
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldReturnNullIfEmptyPeerAuthInit() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, "");
- Properties credentials = authenticator.getCredentials(member, props);
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, "");
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitDoesNotExist() throws Exception {
String authInit = getClass().getName() + "$NotExistAuth.create";
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained from");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitCreateReturnsNull() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitCreateReturnsNull.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained from");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsAndInitThrow() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsAndInitThrow.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("expected init error");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsThrows.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("expected get credential error");
}
@Test
public void authenticateShouldReturnNullIfSuccessful() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, SpyAuthenticator.class.getName() + ".create");
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ SpyAuthenticator.class.getName() + ".create");
SpyAuthenticator auth = new SpyAuthenticator();
assertThat(auth.isClosed()).isFalse();
SpyAuthenticator.setAuthenticator(auth);
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).isNull();
assertThat(auth.isClosed()).isTrue();
@@ -141,15 +144,15 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void authenticateShouldReturnNullIfPeerAuthenticatorIsNull() throws Exception {
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
// assertThat(result).isNull(); // NOTE: old security used to return null
assertThat(result).contains("Security check failed. Instance could not be obtained from null");
}
@Test
public void authenticateShouldReturnNullIfPeerAuthenticatorIsEmpty() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR, "");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
// assertThat(result).isNull(); // NOTE: old security used to return null
assertThat(result).contains("Security check failed. Instance could not be obtained from");
}
@@ -157,40 +160,41 @@ public class GMSAuthenticatorWithAuthenticatorTest extends AbstractGMSAuthentica
@Test
public void authenticateShouldReturnFailureMessageIfPeerAuthenticatorDoesNotExist()
throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, getClass().getName() + "$NotExistAuth.create");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ getClass().getName() + "$NotExistAuth.create");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. Instance could not be obtained from");
}
@Test
public void authenticateShouldReturnFailureMessageIfAuthenticateReturnsNull() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorReturnsNulls.class.getName() + ".create");
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. Instance could not be obtained");
}
@Test
public void authenticateShouldReturnFailureMessageIfNullCredentials() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorReturnsNulls.class.getName() + ".create");
- String result = authenticator.authenticate(member, null, props);
+ String result = this.authenticator.authenticate(this.member, null, this.props);
assertThat(result).startsWith("Failed to find credentials from");
}
@Test
public void authenticateShouldReturnFailureMessageIfAuthenticateInitThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorInitThrows.class.getName() + ".create");
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. expected init error");
}
@Test
public void authenticateShouldReturnFailureMessageIfAuthenticateThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTHENTICATOR,
+ this.props.setProperty(SECURITY_PEER_AUTHENTICATOR,
AuthenticatorAuthenticateThrows.class.getName() + ".create");
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. expected authenticate error");
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
index 0cb6994..01ebc81 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/auth/GMSAuthenticatorWithSecurityManagerTest.java
@@ -40,24 +40,26 @@ public class GMSAuthenticatorWithSecurityManagerTest extends AbstractGMSAuthenti
@Test
public void nullManagerShouldReturnNull() throws Exception {
- assertThat(securityProps).doesNotContainKey(SECURITY_MANAGER);
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ assertThat(this.securityProps).doesNotContainKey(SECURITY_MANAGER);
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
assertThat(result).isNull();
}
@Test
public void emptyAuthenticatorShouldReturnNull() throws Exception {
- securityProps.setProperty(SECURITY_MANAGER, "");
- String result = authenticator.authenticate(member, securityProps, securityProps);
+ this.securityProps.setProperty(SECURITY_MANAGER, "");
+ String result =
+ this.authenticator.authenticate(this.member, this.securityProps, this.securityProps);
assertThat(result).isNull();
}
@Test
public void shouldGetSecurityPropsFromDistributionConfig() throws Exception {
- securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
- securityProps.setProperty(SECURITY_MANAGER, "dummy2");
+ this.securityProps.setProperty(SECURITY_PEER_AUTH_INIT, "dummy1");
+ this.securityProps.setProperty(SECURITY_MANAGER, "dummy2");
- Properties secProps = authenticator.getSecurityProps();
+ Properties secProps = this.authenticator.getSecurityProps();
assertThat(secProps.size()).isEqualTo(2);
assertThat(secProps.getProperty(SECURITY_PEER_AUTH_INIT)).isEqualTo("dummy1");
@@ -66,91 +68,91 @@ public class GMSAuthenticatorWithSecurityManagerTest extends AbstractGMSAuthenti
@Test
public void usesPeerAuthInitToGetCredentials() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
- props.setProperty(SECURITY_MANAGER, "dummy");
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, SpyAuthInit.class.getName() + ".create");
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
SpyAuthInit auth = new SpyAuthInit();
assertThat(auth.isClosed()).isFalse();
SpyAuthInit.setAuthInitialize(auth);
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
- assertThat(credentials).isEqualTo(props);
+ assertThat(credentials).isEqualTo(this.props);
assertThat(auth.isClosed()).isTrue();
assertThat(SpyAuthInit.getCreateCount() == 1).isTrue();
}
@Test
public void getCredentialsShouldReturnNullIfNoPeerAuthInit() throws Exception {
- Properties credentials = authenticator.getCredentials(member, props);
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldReturnNullIfEmptyPeerAuthInit() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT, "");
- Properties credentials = authenticator.getCredentials(member, props);
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, "");
+ Properties credentials = this.authenticator.getCredentials(this.member, this.props);
assertThat(credentials).isNull();
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitDoesNotExist() throws Exception {
String authInit = getClass().getName() + "$NotExistAuth.create";
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitCreateReturnsNull() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitCreateReturnsNull.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessageContaining("Instance could not be obtained from");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsAndInitThrow() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsAndInitThrow.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessage("expected init error");
}
@Test
public void getCredentialsShouldThrowIfPeerAuthInitGetCredentialsThrows() throws Exception {
- props.setProperty(SECURITY_PEER_AUTH_INIT,
+ this.props.setProperty(SECURITY_PEER_AUTH_INIT,
AuthInitGetCredentialsThrows.class.getName() + ".create");
- assertThatThrownBy(() -> authenticator.getCredentials(member, props))
+ assertThatThrownBy(() -> this.authenticator.getCredentials(this.member, this.props))
.hasMessage("expected get credential error");
}
@Test
public void authenticateShouldReturnNullIfSuccessful() throws Exception {
- props.setProperty(SECURITY_MANAGER, "dummy");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).isNull();
}
@Test
public void authenticateShouldReturnNullIfNoSecurityManager() throws Exception {
- String result = authenticator.authenticate(member, props, props);
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).isNull();
}
@Test
public void authenticateShouldReturnFailureMessageIfLoginThrows() throws Exception {
- when(securityService.login(any(Properties.class)))
+ when(this.securityService.login(any(Properties.class)))
.thenThrow(new GemFireSecurityException("dummy"));
- props.setProperty(SECURITY_MANAGER, "dummy");
- String result = authenticator.authenticate(member, props, props);
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
+ String result = this.authenticator.authenticate(this.member, this.props, this.props);
assertThat(result).startsWith("Security check failed. dummy");
}
@Test
public void authenticateShouldReturnFailureMessageIfNullCredentials() throws Exception {
- props.setProperty(SECURITY_MANAGER, "dummy");
- String result = authenticator.authenticate(member, null, props);
+ this.props.setProperty(SECURITY_MANAGER, "dummy");
+ String result = this.authenticator.authenticate(this.member, null, this.props);
assertThat(result).startsWith("Failed to find credentials from");
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryJUnitTest.java
index 423d7e1..40c058b 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/membership/gms/locator/GMSLocatorRecoveryJUnitTest.java
@@ -14,18 +14,34 @@
*/
package org.apache.geode.distributed.internal.membership.gms.locator;
+import static org.apache.geode.distributed.ConfigurationProperties.BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.DISABLE_TCP;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
import org.apache.geode.DataSerializer;
import org.apache.geode.InternalGemFireException;
import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.*;
+import org.apache.geode.distributed.internal.DMStats;
+import org.apache.geode.distributed.internal.DistributionConfigImpl;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.distributed.internal.InternalLocator;
+import org.apache.geode.distributed.internal.LocatorStats;
import org.apache.geode.distributed.internal.membership.DistributedMembershipListener;
import org.apache.geode.distributed.internal.membership.MemberFactory;
import org.apache.geode.distributed.internal.membership.MembershipManager;
import org.apache.geode.distributed.internal.membership.NetView;
import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.internal.Version;
import org.apache.geode.internal.admin.remote.RemoteTransportConfig;
+import org.apache.geode.internal.net.SocketCreator;
+import org.apache.geode.internal.security.SecurityServiceFactory;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.test.junit.categories.MembershipTest;
import org.junit.After;
@@ -39,30 +55,27 @@ import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.util.Properties;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-
@Category({IntegrationTest.class, MembershipTest.class})
public class GMSLocatorRecoveryJUnitTest {
- File tempStateFile = null;
- GMSLocator locator = null;
+ private File tempStateFile;
+ private GMSLocator locator;
@Before
public void setUp() throws Exception {
- tempStateFile = new File("GMSLocatorJUnitTest_locator.dat");
- if (tempStateFile.exists()) {
- tempStateFile.delete();
+ this.tempStateFile = new File("GMSLocatorJUnitTest_locator.dat");
+ if (this.tempStateFile.exists()) {
+ this.tempStateFile.delete();
}
- locator = new GMSLocator(null, tempStateFile, null, false, false, new LocatorStats(), "");
+ this.locator =
+ new GMSLocator(null, this.tempStateFile, null, false, false, new LocatorStats(), "");
// System.out.println("temp state file: " + tempStateFile);
}
@After
public void tearDown() throws Exception {
- if (tempStateFile.exists()) {
- tempStateFile.delete();
+ if (this.tempStateFile.exists()) {
+ this.tempStateFile.delete();
}
}
@@ -78,31 +91,34 @@ public class GMSLocatorRecoveryJUnitTest {
@Test
public void testRecoverFromFileWithNonExistFile() throws Exception {
- tempStateFile.delete();
- assertFalse(tempStateFile.exists());
- assertFalse(locator.recoverFromFile(tempStateFile));
+ this.tempStateFile.delete();
+ assertFalse(this.tempStateFile.exists());
+ assertFalse(this.locator.recoverFromFile(this.tempStateFile));
}
@Test
public void testRecoverFromFileWithNormalFile() throws Exception {
NetView view = new NetView();
- populateStateFile(tempStateFile, GMSLocator.LOCATOR_FILE_STAMP, Version.CURRENT_ORDINAL, view);
- assertTrue(locator.recoverFromFile(tempStateFile));
+ populateStateFile(this.tempStateFile, GMSLocator.LOCATOR_FILE_STAMP, Version.CURRENT_ORDINAL,
+ view);
+ assertTrue(this.locator.recoverFromFile(this.tempStateFile));
}
@Test
public void testRecoverFromFileWithWrongFileStamp() throws Exception {
// add 1 to file stamp to make it invalid
- populateStateFile(tempStateFile, GMSLocator.LOCATOR_FILE_STAMP + 1, Version.CURRENT_ORDINAL, 1);
- assertFalse(locator.recoverFromFile(tempStateFile));
+ populateStateFile(this.tempStateFile, GMSLocator.LOCATOR_FILE_STAMP + 1,
+ Version.CURRENT_ORDINAL, 1);
+ assertFalse(this.locator.recoverFromFile(this.tempStateFile));
}
@Test
public void testRecoverFromFileWithWrongOrdinal() throws Exception {
// add 1 to ordinal to make it wrong
- populateStateFile(tempStateFile, GMSLocator.LOCATOR_FILE_STAMP, Version.CURRENT_ORDINAL + 1, 1);
+ populateStateFile(this.tempStateFile, GMSLocator.LOCATOR_FILE_STAMP,
+ Version.CURRENT_ORDINAL + 1, 1);
try {
- locator.recoverFromFile(tempStateFile);
+ this.locator.recoverFromFile(this.tempStateFile);
fail("expected an InternalGemFireException to be thrown");
} catch (InternalGemFireException e) {
// success
@@ -111,9 +127,10 @@ public class GMSLocatorRecoveryJUnitTest {
@Test
public void testRecoverFromFileWithInvalidViewObject() throws Exception {
- populateStateFile(tempStateFile, GMSLocator.LOCATOR_FILE_STAMP, Version.CURRENT_ORDINAL, 1);
+ populateStateFile(this.tempStateFile, GMSLocator.LOCATOR_FILE_STAMP, Version.CURRENT_ORDINAL,
+ 1);
try {
- locator.recoverFromFile(tempStateFile);
+ this.locator.recoverFromFile(this.tempStateFile);
fail("should catch InternalGemFileException");
} catch (InternalGemFireException e) {
assertTrue(e.getMessage().startsWith("Unable to recover previous membership view from"));
@@ -153,7 +170,8 @@ public class GMSLocatorRecoveryJUnitTest {
// start the first membership manager
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
- m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
+ m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1,
+ SecurityServiceFactory.create());
// hook up the locator to the membership manager
((InternalLocator) l).getLocatorHandler().setMembershipManager(m1);
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/internal/cache/ha/BlockingHARegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ha/BlockingHARegionJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ha/BlockingHARegionJUnitTest.java
index d0f5793..ee8b6fa 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/ha/BlockingHARegionJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ha/BlockingHARegionJUnitTest.java
@@ -390,7 +390,8 @@ public class BlockingHARegionJUnitTest {
}
} catch (Exception e) {
exceptionOccurred = true;
- exceptionString.append(" Exception occurred due to " + e);
+ exceptionString.append(" Exception occurred due to ").append(e);
+ break;
}
}
}
@@ -414,9 +415,13 @@ public class BlockingHARegionJUnitTest {
for (int i = 0; i < numberOfTakes; i++) {
try {
assertNotNull(this.regionQueue.take());
+ if (Thread.currentThread().isInterrupted()) {
+ break;
+ }
} catch (Exception e) {
exceptionOccurred = true;
- exceptionString.append(" Exception occurred due to " + e);
+ exceptionString.append(" Exception occurred due to ").append(e);
+ break;
}
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/HAStartupAndFailoverDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/HAStartupAndFailoverDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/HAStartupAndFailoverDUnitTest.java
index 98cb309..7b7f4a7 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/HAStartupAndFailoverDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/HAStartupAndFailoverDUnitTest.java
@@ -14,18 +14,14 @@
*/
package org.apache.geode.internal.cache.tier.sockets;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-import org.awaitility.Awaitility;
-import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.apache.geode.cache.AttributesFactory;
import org.apache.geode.cache.Cache;
@@ -53,8 +49,17 @@ import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.dunit.Wait;
import org.apache.geode.test.dunit.WaitCriterion;
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
+import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.FlakyTest;
+import org.awaitility.Awaitility;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
/**
* Test to verify Startup. and failover during startup.
@@ -334,7 +339,7 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
public void afterPrimaryIdentificationFromBackup(ServerLocation primaryEndpoint) {
synchronized (HAStartupAndFailoverDUnitTest.class) {
HAStartupAndFailoverDUnitTest.identifiedPrimary = true;
- HAStartupAndFailoverDUnitTest.class.notify();
+ HAStartupAndFailoverDUnitTest.class.notifyAll();
}
}
});
@@ -346,7 +351,6 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
HAStartupAndFailoverDUnitTest.identifiedPrimary = false;
ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter());
}
-
}
public static void stopServer() {
@@ -360,17 +364,6 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
}
}
- // public static void processException() {
- // assertIndexDetailsEquals(conn.getServer().getPort(), PORT1.intValue());
- // try {
- // pool.processException(new Exception("dummy"), conn);
- // //Thread.sleep(10000); // why sleep?
- // }
- // catch (Exception e) {
- // fail("While processException(): " + e, e);
- // }
- // }
-
public static void verifyPrimaryShouldNotBeNullAndEPListShouldNotBeEmpty() {
try {
assertNotNull(" Primary endpoint should not be null", pool.getPrimaryName());
@@ -386,7 +379,7 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
assertNull("Primary endpoint should be null as all server are dead", pool.getPrimaryName());
assertEquals("Endpoint List should be Empty as all server are dead", 0,
pool.getConnectedServerCount());
- fail("NoSubscriptionServersAvailableException is expected"); // TODO:KIRK: added this line
+ fail("NoSubscriptionServersAvailableException is expected");
} catch (NoSubscriptionServersAvailableException e) {
// pass
} catch (Exception e) {
@@ -406,9 +399,7 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
}
}
-
public static void waitForPrimaryIdentification() {
-
assertNotNull(cache);
if (!identifiedPrimary) {
synchronized (HAStartupAndFailoverDUnitTest.class) {
@@ -426,7 +417,6 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
}
}
}
-
}
public static void verifyDispatcherIsAlive() {
@@ -479,9 +469,6 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
}
};
Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
-
- // assertTrue("Dispatcher on primary should be alive",
- // proxy._messageDispatcher.isAlive());
}
} catch (Exception ex) {
@@ -566,7 +553,6 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
pool = p;
conn = pool.acquireConnection();
assertNotNull(conn);
-
}
public static void createClientCacheWithLargeRetryInterval(String testName, String host)
@@ -591,8 +577,6 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
pool = p;
conn = pool.acquireConnection();
assertNotNull(conn);
-
-
}
public static void createClientCacheWithLargeRetryIntervalAndWithoutCallbackConnection(
@@ -653,7 +637,6 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
pool = p;
conn = pool.acquireConnection();
assertNotNull(conn);
-
}
public static Integer createServerCache() throws Exception {
@@ -673,10 +656,8 @@ public class HAStartupAndFailoverDUnitTest extends JUnit4DistributedTestCase {
server1.setMaximumTimeBetweenPings(180000);
server1.start();
return new Integer(server1.getPort());
-
}
-
@Override
public final void preTearDown() throws Exception {
// close the clients first
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
index 153e77b..794c610 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionTest.java
@@ -27,7 +27,9 @@ import static org.mockito.Mockito.when;
import org.apache.geode.cache.Cache;
import org.apache.geode.internal.Version;
+import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.tier.Acceptor;
+import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.security.AuthenticationRequiredException;
import org.apache.geode.test.junit.categories.UnitTest;
import org.junit.Before;
@@ -64,10 +66,11 @@ public class ServerConnectionTest {
Socket socket = mock(Socket.class);
when(socket.getInetAddress()).thenReturn(inetAddress);
- Cache cache = mock(Cache.class);
+ InternalCache cache = mock(InternalCache.class);
+ SecurityService securityService = mock(SecurityService.class);
serverConnection = new ServerConnection(socket, cache, null, null, 0, 0, null,
- Acceptor.PRIMARY_SERVER_TO_CLIENT, acceptor);
+ Acceptor.PRIMARY_SERVER_TO_CLIENT, acceptor, securityService);
MockitoAnnotations.initMocks(this);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
index 3a6c2a3..591aba9 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKey66Test.java
@@ -100,7 +100,7 @@ public class ContainsKey66Test {
public void noSecurityShouldSucceed() throws Exception {
when(this.securityService.isClientSecurityRequired()).thenReturn(false);
- this.containsKey66.cmdExecute(this.message, this.serverConnection, 0);
+ this.containsKey66.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.responseMessage).send(this.serverConnection);
}
@@ -110,7 +110,7 @@ public class ContainsKey66Test {
when(this.securityService.isClientSecurityRequired()).thenReturn(true);
when(this.securityService.isIntegratedSecurity()).thenReturn(true);
- this.containsKey66.cmdExecute(this.message, this.serverConnection, 0);
+ this.containsKey66.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.securityService).authorizeRegionRead(eq(REGION_NAME), eq(KEY));
verify(this.responseMessage).send(this.serverConnection);
@@ -123,7 +123,7 @@ public class ContainsKey66Test {
doThrow(new NotAuthorizedException("")).when(this.securityService)
.authorizeRegionRead(eq(REGION_NAME), eq(KEY));
- this.containsKey66.cmdExecute(this.message, this.serverConnection, 0);
+ this.containsKey66.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.securityService).authorizeRegionRead(eq(REGION_NAME), eq(KEY));
verify(this.errorResponseMessage).send(eq(this.serverConnection));
@@ -134,7 +134,7 @@ public class ContainsKey66Test {
when(this.securityService.isClientSecurityRequired()).thenReturn(true);
when(this.securityService.isIntegratedSecurity()).thenReturn(false);
- this.containsKey66.cmdExecute(this.message, this.serverConnection, 0);
+ this.containsKey66.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.authzRequest).containsKeyAuthorize(eq(REGION_NAME), eq(KEY));
verify(this.responseMessage).send(this.serverConnection);
@@ -147,7 +147,7 @@ public class ContainsKey66Test {
doThrow(new NotAuthorizedException("")).when(this.authzRequest)
.containsKeyAuthorize(eq(REGION_NAME), eq(KEY));
- this.containsKey66.cmdExecute(this.message, this.serverConnection, 0);
+ this.containsKey66.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.authzRequest).containsKeyAuthorize(eq(REGION_NAME), eq(KEY));
verify(this.errorResponseMessage).send(eq(this.serverConnection));
http://git-wip-us.apache.org/repos/asf/geode/blob/0211029b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKeyTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKeyTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKeyTest.java
index bc1be3e..0492997 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKeyTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ContainsKeyTest.java
@@ -88,7 +88,7 @@ public class ContainsKeyTest {
public void noSecurityShouldSucceed() throws Exception {
when(this.securityService.isClientSecurityRequired()).thenReturn(false);
- containsKey.cmdExecute(this.message, this.serverConnection, 0);
+ containsKey.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.replyMessage).send(this.serverConnection);
}
@@ -98,7 +98,7 @@ public class ContainsKeyTest {
when(this.securityService.isClientSecurityRequired()).thenReturn(true);
when(this.securityService.isIntegratedSecurity()).thenReturn(true);
- containsKey.cmdExecute(this.message, this.serverConnection, 0);
+ containsKey.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.securityService).authorizeRegionRead(eq(REGION_NAME), eq(KEY));
verify(this.replyMessage).send(this.serverConnection);
@@ -111,7 +111,7 @@ public class ContainsKeyTest {
doThrow(new NotAuthorizedException("")).when(this.securityService)
.authorizeRegionRead(eq(REGION_NAME), eq(KEY));
- containsKey.cmdExecute(this.message, this.serverConnection, 0);
+ containsKey.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.securityService).authorizeRegionRead(eq(REGION_NAME), eq(KEY));
verify(this.errorResponseMessage).send(eq(this.serverConnection));
@@ -123,7 +123,7 @@ public class ContainsKeyTest {
when(this.securityService.isIntegratedSecurity()).thenReturn(false);
- containsKey.cmdExecute(this.message, this.serverConnection, 0);
+ containsKey.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.authzRequest).containsKeyAuthorize(eq(REGION_NAME), eq(KEY));
verify(this.replyMessage).send(this.serverConnection);
@@ -136,7 +136,7 @@ public class ContainsKeyTest {
doThrow(new NotAuthorizedException("")).when(this.authzRequest)
.containsKeyAuthorize(eq(REGION_NAME), eq(KEY));
- containsKey.cmdExecute(this.message, this.serverConnection, 0);
+ containsKey.cmdExecute(this.message, this.serverConnection, this.securityService, 0);
verify(this.authzRequest).containsKeyAuthorize(eq(REGION_NAME), eq(KEY));
verify(this.errorResponseMessage).send(eq(this.serverConnection));