Repository: geode Updated Branches: refs/heads/feature/GEODE-3299 067531776 -> 7956fb424
http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/MembersForRegionFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/MembersForRegionFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/MembersForRegionFunction.java index 72d37e7..d0668b7 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/MembersForRegionFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/MembersForRegionFunction.java @@ -38,13 +38,11 @@ public class MembersForRegionFunction implements Function, InternalEntity { private static final long serialVersionUID = 8746830191680509335L; - private static final String ID = MembersForRegionFunction.class.getName(); - @Override public void execute(FunctionContext context) { Map<String, String> resultMap = new HashMap<String, String>(); try { - Cache cache = CacheFactory.getAnyInstance(); + Cache cache = context.getCache(); String memberNameOrId = cache.getDistributedSystem().getDistributedMember().getId(); Object args = (Object) context.getArguments(); String regionName = ((String) args); @@ -71,11 +69,6 @@ public class MembersForRegionFunction implements Function, InternalEntity { } @Override - public String getId() { - return MembersForRegionFunction.ID; - } - - @Override public boolean isHA() { return false; } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/NetstatFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/NetstatFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/NetstatFunction.java index 5c1cb29..7ee42cf 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/NetstatFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/NetstatFunction.java @@ -14,7 +14,12 @@ */ package org.apache.geode.management.internal.cli.functions; -import static org.apache.geode.internal.lang.SystemUtils.*; +import static org.apache.geode.internal.lang.SystemUtils.getOsArchitecture; +import static org.apache.geode.internal.lang.SystemUtils.getOsName; +import static org.apache.geode.internal.lang.SystemUtils.getOsVersion; +import static org.apache.geode.internal.lang.SystemUtils.isLinux; +import static org.apache.geode.internal.lang.SystemUtils.isMacOSX; +import static org.apache.geode.internal.lang.SystemUtils.isSolaris; import java.io.BufferedReader; import java.io.IOException; @@ -29,7 +34,6 @@ import org.apache.logging.log4j.Logger; 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.logging.LogService; import org.apache.geode.management.internal.cli.CliUtil; @@ -42,14 +46,11 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings; * * @since GemFire 7.0 */ -@SuppressWarnings({"serial"}) public class NetstatFunction implements Function, InternalEntity { - private static final Logger logger = LogService.getLogger(); - private static final long serialVersionUID = 1L; - public static final NetstatFunction INSTANCE = new NetstatFunction(); + private static final long serialVersionUID = 1L; - private static final String ID = NetstatFunction.class.getName(); + private static final Logger logger = LogService.getLogger(); private static final String NETSTAT_COMMAND = "netstat"; private static final String LSOF_COMMAND = "lsof"; @@ -61,7 +62,7 @@ public class NetstatFunction implements Function, InternalEntity { @Override public void execute(final FunctionContext context) { - DistributedSystem ds = InternalDistributedSystem.getConnectedInstance(); + DistributedSystem ds = context.getCache().getDistributedSystem(); if (ds == null || !ds.isConnected()) { return; } @@ -139,6 +140,7 @@ public class NetstatFunction implements Function, InternalEntity { // TODO: move to finally-block netstat.destroy(); + } catch (IOException e) { // TODO: change this to keep the full stack trace netstatInfo.append(CliStrings.format(CliStrings.NETSTAT__MSG__COULD_NOT_EXECUTE_0_REASON_1, @@ -154,7 +156,6 @@ public class NetstatFunction implements Function, InternalEntity { .append(" output ###################").append(lineSeparator); if (isLinux() || isMacOSX() || isSolaris()) { - ProcessBuilder procBuilder = new ProcessBuilder(LSOF_COMMAND); try { Process lsof = procBuilder.start(); @@ -167,6 +168,7 @@ public class NetstatFunction implements Function, InternalEntity { } // TODO: move this to finally-block lsof.destroy(); + } catch (IOException e) { // TODO: change this to keep the full stack trace String message = e.getMessage(); @@ -201,11 +203,6 @@ public class NetstatFunction implements Function, InternalEntity { } @Override - public String getId() { - return ID; - } - - @Override public boolean optimizeForWrite() { return false; } @@ -221,6 +218,7 @@ public class NetstatFunction implements Function, InternalEntity { } public static class NetstatFunctionArgument implements Serializable { + private static final long serialVersionUID = 1L; private final String lineSeparator; @@ -241,6 +239,7 @@ public class NetstatFunction implements Function, InternalEntity { } public static class NetstatFunctionResult implements Serializable { + private static final long serialVersionUID = 1L; private final String host; @@ -266,4 +265,5 @@ public class NetstatFunction implements Function, InternalEntity { return compressedBytes; } } + } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RebalanceFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RebalanceFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RebalanceFunction.java index 218f212..a914d07 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RebalanceFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RebalanceFunction.java @@ -21,7 +21,6 @@ import java.util.concurrent.CancellationException; import org.apache.logging.log4j.Logger; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.control.RebalanceFactory; import org.apache.geode.cache.control.RebalanceOperation; import org.apache.geode.cache.control.RebalanceResults; @@ -32,23 +31,15 @@ import org.apache.geode.cache.partition.PartitionRebalanceInfo; import org.apache.geode.internal.InternalEntity; import org.apache.geode.internal.logging.LogService; - - public class RebalanceFunction implements Function, InternalEntity { - private static final Logger logger = LogService.getLogger(); - - public static final String ID = RebalanceFunction.class.getName(); - private static final long serialVersionUID = 1L; + private static final Logger logger = LogService.getLogger(); + @Override public void execute(FunctionContext context) { - - RebalanceOperation op = null; - String[] str = new String[0]; - - Cache cache = CacheFactory.getAnyInstance(); + Cache cache = context.getCache(); ResourceManager manager = cache.getResourceManager(); Object[] args = (Object[]) context.getArguments(); String simulate = ((String) args[0]); @@ -59,6 +50,7 @@ public class RebalanceFunction implements Function, InternalEntity { rbFactory.includeRegions(includeRegionNames); RebalanceResults results = null; + RebalanceOperation op; if (simulate.equals("true")) { op = rbFactory.simulate(); } else { @@ -81,8 +73,10 @@ public class RebalanceFunction implements Function, InternalEntity { PartitionRebalanceInfo rgn = (PartitionRebalanceInfo) it.next(); str1.append(rgn.getRegionPath() + ","); } + logger.info("Starting RebalanceFunction str1={}", str1); context.getResultSender().lastResult(str1.toString()); + } catch (CancellationException e) { logger.info("Starting RebalanceFunction CancellationException: ", e.getMessage(), e); context.getResultSender().lastResult("CancellationException1 " + e.getMessage()); @@ -93,11 +87,6 @@ public class RebalanceFunction implements Function, InternalEntity { } @Override - public String getId() { - return RebalanceFunction.ID; - } - - @Override public boolean hasResult() { return true; } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java index 79dcbd4..05228af 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionAlterFunction.java @@ -21,14 +21,13 @@ import org.apache.logging.log4j.Logger; import org.apache.geode.SystemFailure; import org.apache.geode.cache.AttributesMutator; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.CacheListener; import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheWriter; import org.apache.geode.cache.ExpirationAction; import org.apache.geode.cache.ExpirationAttributes; import org.apache.geode.cache.Region; -import org.apache.geode.cache.execute.FunctionAdapter; +import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.cache.execute.ResultSender; import org.apache.geode.internal.ClassPathLoader; @@ -46,11 +45,12 @@ import org.apache.geode.management.internal.configuration.domain.XmlEntity; * * @since GemFire 8.0 */ -public class RegionAlterFunction extends FunctionAdapter implements InternalEntity { - private static final Logger logger = LogService.getLogger(); +public class RegionAlterFunction implements InternalEntity, Function { private static final long serialVersionUID = -4846425364943216425L; + private static final Logger logger = LogService.getLogger(); + @Override public boolean isHA() { return false; @@ -60,7 +60,7 @@ public class RegionAlterFunction extends FunctionAdapter implements InternalEnti public void execute(FunctionContext context) { ResultSender<Object> resultSender = context.getResultSender(); - Cache cache = CacheFactory.getAnyInstance(); + Cache cache = context.getCache(); String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember()); @@ -313,7 +313,6 @@ public class RegionAlterFunction extends FunctionAdapter implements InternalEnti return new ExpirationAttributes(timeout, action); } - @SuppressWarnings("unchecked") private static <K> Class<K> forName(String classToLoadName, String neededFor) { Class<K> loadedClass = null; try { @@ -337,7 +336,7 @@ public class RegionAlterFunction extends FunctionAdapter implements InternalEnti } private static <K> K newInstance(Class<K> klass, String neededFor) { - K instance = null; + K instance; try { instance = klass.newInstance(); } catch (InstantiationException e) { @@ -354,8 +353,4 @@ public class RegionAlterFunction extends FunctionAdapter implements InternalEnti return instance; } - @Override - public String getId() { - return RegionAlterFunction.class.getName(); - } } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java index 6ae10a3..a976157 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionCreateFunction.java @@ -20,7 +20,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.Logger; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.CacheListener; import org.apache.geode.cache.CacheLoader; import org.apache.geode.cache.CacheWriter; @@ -33,7 +32,7 @@ import org.apache.geode.cache.RegionAttributes; import org.apache.geode.cache.RegionExistsException; import org.apache.geode.cache.RegionFactory; import org.apache.geode.cache.RegionShortcut; -import org.apache.geode.cache.execute.FunctionAdapter; +import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.cache.execute.ResultSender; import org.apache.geode.compression.Compressor; @@ -50,18 +49,13 @@ import org.apache.geode.management.internal.cli.util.RegionPath; import org.apache.geode.management.internal.configuration.domain.XmlEntity; /** - * * @since GemFire 7.0 */ -public class RegionCreateFunction extends FunctionAdapter implements InternalEntity { - - private static final Logger logger = LogService.getLogger(); +public class RegionCreateFunction implements InternalEntity, Function { private static final long serialVersionUID = 8746830191680509335L; - private static final String ID = RegionCreateFunction.class.getName(); - - public static RegionCreateFunction INSTANCE = new RegionCreateFunction(); + private static final Logger logger = LogService.getLogger(); @Override public boolean isHA() { @@ -72,7 +66,7 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt public void execute(FunctionContext context) { ResultSender<Object> resultSender = context.getResultSender(); - Cache cache = CacheFactory.getAnyInstance(); + Cache cache = context.getCache(); String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember()); @@ -95,6 +89,7 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format(CliStrings.CREATE_REGION__MSG__REGION_0_CREATED_ON_1, new Object[] {createdRegion.getFullPath(), memberNameOrId}))); + } catch (IllegalStateException e) { String exceptionMsg = e.getMessage(); String localizedString = @@ -136,8 +131,6 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt } public static <K, V> Region<?, ?> createRegion(Cache cache, RegionFunctionArgs regionCreateArgs) { - Region<K, V> createdRegion = null; - final String regionPath = regionCreateArgs.getRegionPath(); final RegionShortcut regionShortcut = regionCreateArgs.getRegionShortcut(); final String useAttributesFrom = regionCreateArgs.getUseAttributesFrom(); @@ -352,6 +345,7 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt String regionName = regionPathData.getName(); + Region<K, V> createdRegion = null; if (parentRegion != null) { createdRegion = factory.createSubregion(parentRegion, regionName); } else { @@ -361,7 +355,6 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt return createdRegion; } - @SuppressWarnings("unchecked") private static <K, V> PartitionAttributes<K, V> extractPartitionAttributes(Cache cache, RegionAttributes<K, V> regionAttributes, RegionFunctionArgs regionCreateArgs) { RegionFunctionArgs.PartitionArgs partitionArgs = regionCreateArgs.getPartitionArgs(); @@ -418,7 +411,6 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt return prAttrFactory.create(); } - private static Class<PartitionResolver> forName(String className, String neededFor) { if (StringUtils.isBlank(className)) { throw new IllegalArgumentException( @@ -452,8 +444,4 @@ public class RegionCreateFunction extends FunctionAdapter implements InternalEnt } } - @Override - public String getId() { - return ID; - } } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionDestroyFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionDestroyFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionDestroyFunction.java index 5e4af3d..0b69000 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionDestroyFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionDestroyFunction.java @@ -15,7 +15,6 @@ package org.apache.geode.management.internal.cli.functions; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; @@ -25,15 +24,11 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings; import org.apache.geode.management.internal.configuration.domain.XmlEntity; /** - * * @since GemFire 7.0 */ public class RegionDestroyFunction implements Function, InternalEntity { - private static final long serialVersionUID = 9172773671865750685L; - - public static final RegionDestroyFunction INSTANCE = new RegionDestroyFunction(); - private static final String ID = RegionDestroyFunction.class.getName(); + private static final long serialVersionUID = 9172773671865750685L; @Override public boolean hasResult() { @@ -49,7 +44,7 @@ public class RegionDestroyFunction implements Function, InternalEntity { Object arguments = context.getArguments(); if (arguments != null) { regionPath = (String) arguments; - Cache cache = CacheFactory.getAnyInstance(); + Cache cache = context.getCache(); Region<?, ?> region = cache.getRegion(regionPath); region.destroyRegion(); String regionName = @@ -59,8 +54,10 @@ public class RegionDestroyFunction implements Function, InternalEntity { } } context.getResultSender().lastResult(new CliFunctionResult("", false, "FAILURE")); + } catch (IllegalStateException e) { context.getResultSender().lastResult(new CliFunctionResult("", e, null)); + } catch (Exception ex) { context.getResultSender() .lastResult(new CliFunctionResult("", @@ -72,11 +69,6 @@ public class RegionDestroyFunction implements Function, InternalEntity { } @Override - public String getId() { - return ID; - } - - @Override public boolean optimizeForWrite() { return false; } @@ -85,4 +77,5 @@ public class RegionDestroyFunction implements Function, InternalEntity { public boolean isHA() { return false; } + } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java index 3af79eb..3d0ba12 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/RegionFunctionArgs.java @@ -36,6 +36,7 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings; * @since GemFire 7.0 */ public class RegionFunctionArgs implements Serializable { + private static final long serialVersionUID = -5158224572470173267L; private final String regionPath; @@ -93,6 +94,7 @@ public class RegionFunctionArgs implements Serializable { Long prRecoveryDelay, Integer prRedundantCopies, Long prStartupRecoveryDelay, Long prTotalMaxMemory, Integer prTotalNumBuckets, Integer evictionMax, String compressor, Boolean offHeap, Boolean mcastEnabled, final String partitionResolver) { + this.regionPath = regionPath; this.regionShortcut = regionShortcut; this.useAttributesFrom = useAttributesFrom; @@ -506,12 +508,12 @@ public class RegionFunctionArgs implements Serializable { /** * @return the regionAttributes */ - @SuppressWarnings("unchecked") public <K, V> RegionAttributes<K, V> getRegionAttributes() { return (RegionAttributes<K, V>) this.regionAttributes; } public static class ExpirationAttrs implements Serializable { + private static final long serialVersionUID = 1474255033398008062L; private ExpirationFor type; @@ -596,6 +598,7 @@ public class RegionFunctionArgs implements Serializable { } public static class PartitionArgs implements Serializable { + private static final long serialVersionUID = 5907052187323280919L; private final String prColocatedWith; @@ -775,4 +778,5 @@ public class RegionFunctionArgs implements Serializable { return isSetPRTotalNumBuckets; } } + } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShowMissingDiskStoresFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShowMissingDiskStoresFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShowMissingDiskStoresFunction.java index 2a1b746..18def96 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShowMissingDiskStoresFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShowMissingDiskStoresFunction.java @@ -19,11 +19,10 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.geode.cache.execute.FunctionAdapter; +import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.internal.InternalEntity; -import org.apache.geode.internal.cache.GemFireCacheImpl; import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.cache.PartitionedRegion; import org.apache.geode.internal.cache.partitioned.ColocatedRegionDetails; @@ -31,16 +30,17 @@ import org.apache.geode.internal.cache.persistence.PersistentMemberID; import org.apache.geode.internal.cache.persistence.PersistentMemberManager; import org.apache.geode.internal.cache.persistence.PersistentMemberPattern; -public class ShowMissingDiskStoresFunction extends FunctionAdapter implements InternalEntity { +public class ShowMissingDiskStoresFunction implements InternalEntity, Function { @Override public void execute(FunctionContext context) { - final Set<PersistentMemberPattern> memberMissingIDs = new HashSet<PersistentMemberPattern>(); - Set<ColocatedRegionDetails> missingColocatedRegions = new HashSet<ColocatedRegionDetails>(); - if (context == null) { throw new RuntimeException(); } + + final Set<PersistentMemberPattern> memberMissingIDs = new HashSet<>(); + Set<ColocatedRegionDetails> missingColocatedRegions = new HashSet<>(); + try { final InternalCache cache = (InternalCache) context.getCache(); @@ -80,13 +80,10 @@ public class ShowMissingDiskStoresFunction extends FunctionAdapter implements In context.getResultSender().lastResult(missingColocatedRegions); } } + } catch (Exception e) { context.getResultSender().sendException(e); } } - @Override - public String getId() { - return getClass().getName(); - } } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShutDownFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShutDownFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShutDownFunction.java index 83d694f..8fcc6fe 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShutDownFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ShutDownFunction.java @@ -14,56 +14,52 @@ */ package org.apache.geode.management.internal.cli.functions; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.logging.log4j.Logger; + +import org.apache.geode.cache.Cache; import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; -import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.internal.InternalEntity; import org.apache.geode.internal.logging.LogService; import org.apache.geode.internal.tcp.ConnectionTable; -import org.apache.logging.log4j.Logger; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; /** - * * Class for Shutdown function - * - * - * */ public class ShutDownFunction implements Function, InternalEntity { - private static final Logger logger = LogService.getLogger(); - public static final String ID = ShutDownFunction.class.getName(); private static final long serialVersionUID = 1L; + private static final Logger logger = LogService.getLogger(); + @Override public void execute(FunctionContext context) { try { - final InternalDistributedSystem system = InternalDistributedSystem.getConnectedInstance(); - if (system == null) { - return; - } - String memberName = system.getDistributedMember().getId(); + Cache cache = context.getCache(); + String memberName = cache.getDistributedSystem().getDistributedMember().getId(); logger.info("Received GFSH shutdown. Shutting down member " + memberName); - disconnectInNonDaemonThread(system); + disconnectInNonDaemonThread(cache.getDistributedSystem()); context.getResultSender().lastResult("SUCCESS: succeeded in shutting down " + memberName); + } catch (Exception ex) { logger.warn("Error during shutdown", ex); context.getResultSender().lastResult("FAILURE: failed in shutting down " + ex.getMessage()); } } - /* + /** * The shutdown is performed in a separate, non-daemon thread so that the JVM does not shut down * prematurely before the full process has completed. */ - private void disconnectInNonDaemonThread(final InternalDistributedSystem ids) + private void disconnectInNonDaemonThread(final DistributedSystem ids) throws InterruptedException, ExecutionException { ExecutorService exec = Executors.newSingleThreadExecutor(); Future future = exec.submit(() -> { @@ -80,12 +76,6 @@ public class ShutDownFunction implements Function, InternalEntity { } @Override - public String getId() { - return ShutDownFunction.ID; - - } - - @Override public boolean hasResult() { return true; } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java index fbb60a0..02ae1ac 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/SizeExportLogsFunction.java @@ -17,9 +17,6 @@ package org.apache.geode.management.internal.cli.functions; import java.io.File; import java.io.IOException; -import org.apache.geode.management.ManagementException; -import org.apache.geode.management.internal.cli.util.BytesToString; -import org.apache.geode.management.internal.cli.util.LogExporter; import org.apache.logging.log4j.Logger; import org.apache.geode.cache.execute.Function; @@ -27,15 +24,19 @@ import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.distributed.DistributedMember; import org.apache.geode.distributed.internal.DistributionConfig; import org.apache.geode.internal.InternalEntity; -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.management.ManagementException; +import org.apache.geode.management.internal.cli.util.BytesToString; +import org.apache.geode.management.internal.cli.util.LogExporter; import org.apache.geode.management.internal.cli.util.LogFilter; public class SizeExportLogsFunction extends ExportLogsFunction implements Function, InternalEntity { - private static final Logger LOGGER = LogService.getLogger(); + private static final long serialVersionUID = 1L; + private static final Logger logger = LogService.getLogger(); + @Override public void execute(final FunctionContext context) { try { @@ -58,8 +59,7 @@ public class SizeExportLogsFunction extends ExportLogsFunction implements Functi } } catch (Exception e) { - e.printStackTrace(); - LOGGER.error(e.getMessage()); + logger.error(e); context.getResultSender().sendException(e); } } @@ -70,8 +70,8 @@ public class SizeExportLogsFunction extends ExportLogsFunction implements Functi long estimateLogFileSize(final DistributedMember member, final File logFile, final File statArchive, final Args args) throws IOException { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("SizeExportLogsFunction started for member {}", member); + if (logger.isDebugEnabled()) { + logger.debug("SizeExportLogsFunction started for member {}", member); } File baseLogFile = null; @@ -90,8 +90,9 @@ public class SizeExportLogsFunction extends ExportLogsFunction implements Functi long estimatedSize = new LogExporter(logFilter, baseLogFile, baseStatsFile).estimateFilteredSize(); - LOGGER.info("Estimated log file size: " + estimatedSize); + logger.info("Estimated log file size: " + estimatedSize); return estimatedSize; } + } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java index 031c855..6f9e0e0 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java @@ -16,34 +16,27 @@ package org.apache.geode.management.internal.cli.functions; import java.util.ArrayList; import java.util.List; -import java.util.StringTokenizer; import org.apache.commons.lang.ArrayUtils; -import org.apache.geode.internal.ClassPathLoader; import org.apache.logging.log4j.Logger; import org.apache.geode.SystemFailure; +import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheClosedException; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.InternalEntity; +import org.apache.geode.internal.ClassPathLoader; import org.apache.geode.internal.DeployedJar; +import org.apache.geode.internal.InternalEntity; import org.apache.geode.internal.JarDeployer; -import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.logging.LogService; public class UndeployFunction implements Function, InternalEntity { - private static final Logger logger = LogService.getLogger(); - - public static final String ID = UndeployFunction.class.getName(); private static final long serialVersionUID = 1L; - private InternalCache getCache() { - return (InternalCache) CacheFactory.getAnyInstance(); - } + private static final Logger logger = LogService.getLogger(); @Override public void execute(FunctionContext context) { @@ -53,7 +46,7 @@ public class UndeployFunction implements Function, InternalEntity { try { final Object[] args = (Object[]) context.getArguments(); final String[] jarFilenameList = (String[]) args[0]; // Comma separated - InternalCache cache = getCache(); + Cache cache = context.getCache(); final JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer(); @@ -114,11 +107,6 @@ public class UndeployFunction implements Function, InternalEntity { } @Override - public String getId() { - return ID; - } - - @Override public boolean hasResult() { return true; } @@ -132,4 +120,5 @@ public class UndeployFunction implements Function, InternalEntity { public boolean isHA() { return false; } + } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UnregisterFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UnregisterFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UnregisterFunction.java index 18e16ac..7471586 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UnregisterFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UnregisterFunction.java @@ -14,26 +14,16 @@ */ package org.apache.geode.management.internal.cli.functions; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.cache.execute.FunctionService; -import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.internal.InternalEntity; -import org.apache.geode.internal.admin.remote.ShutdownAllRequest; /** - * * Class for Unregister function - * - * - * */ - - public class UnregisterFunction implements Function, InternalEntity { - public static final String ID = UnregisterFunction.class.getName(); + private static final long serialVersionUID = 1L; @Override @@ -42,16 +32,11 @@ public class UnregisterFunction implements Function, InternalEntity { String functionId = (String) args[0]; try { FunctionService.unregisterFunction(functionId); + context.getResultSender().lastResult("Succeeded in unregistering"); + } catch (Exception e) { context.getResultSender().lastResult("Failed in unregistering " + e.getMessage()); } - context.getResultSender().lastResult("Succeeded in unregistering"); - } - - @Override - public String getId() { - return UnregisterFunction.ID; - } @Override http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UserFunctionExecution.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UserFunctionExecution.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UserFunctionExecution.java index 1f9a607..ad86393 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UserFunctionExecution.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/UserFunctionExecution.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Set; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.Function; @@ -33,18 +32,16 @@ import org.apache.geode.management.internal.cli.GfshParser; import org.apache.geode.management.internal.cli.i18n.CliStrings; /** - * * @since GemFire 7.0 */ public class UserFunctionExecution implements Function, InternalEntity { - public static final String ID = UserFunctionExecution.class.getName(); private static final long serialVersionUID = 1L; @Override public void execute(FunctionContext context) { try { - Cache cache = CacheFactory.getAnyInstance(); + Cache cache = context.getCache(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); String[] functionArgs = null; Object[] args = (Object[]) context.getArguments(); @@ -146,11 +143,6 @@ public class UserFunctionExecution implements Function, InternalEntity { } @Override - public String getId() { - return UserFunctionExecution.ID; - } - - @Override public boolean hasResult() { return true; } http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/TimeParser.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/TimeParser.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/TimeParser.java new file mode 100644 index 0000000..7cb00d6 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/TimeParser.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.geode.management.internal.cli.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; + +import org.apache.geode.management.internal.cli.commands.ExportLogsCommand; + +/** + * Extracted from {@link org.apache.geode.management.internal.cli.functions.ExportLogsFunction}. + */ +public class TimeParser { + + public static LocalDateTime parseTime(String dateString) { + if (dateString == null) { + return null; + } + + try { + SimpleDateFormat df = new SimpleDateFormat(ExportLogsCommand.FORMAT); + return df.parse(dateString).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + } catch (ParseException e) { + try { + SimpleDateFormat df = new SimpleDateFormat(ExportLogsCommand.ONLY_DATE_FORMAT); + return df.parse(dateString).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + } catch (ParseException e1) { + return null; + } + } + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/DescribeDiskStoreFunctionJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/DescribeDiskStoreFunctionJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/DescribeDiskStoreFunctionJUnitTest.java index 4c1f2cb..9d6ff52 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/DescribeDiskStoreFunctionJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/DescribeDiskStoreFunctionJUnitTest.java @@ -48,7 +48,6 @@ import org.apache.geode.cache.execute.ResultSender; import org.apache.geode.cache.server.CacheServer; import org.apache.geode.cache.server.ClientSubscriptionConfig; import org.apache.geode.cache.wan.GatewaySender; -import org.apache.geode.distributed.DistributedMember; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.lang.Filter; @@ -204,8 +203,8 @@ public class DescribeDiskStoreFunctionJUnitTest { return cacheServerDetails; } - private DescribeDiskStoreFunction createDescribeDiskStoreFunction(final Cache cache) { - return new TestDescribeDiskStoreFunction(cache); + private DescribeDiskStoreFunction createDescribeDiskStoreFunction() { + return new DescribeDiskStoreFunction(); } private File[] createFileArray(final String... locations) { @@ -520,6 +519,8 @@ public class DescribeDiskStoreFunctionJUnitTest { will(returnValue(diskStoreName)); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); @@ -535,7 +536,7 @@ public class DescribeDiskStoreFunctionJUnitTest { final Set<DiskStoreDetails.AsyncEventQueueDetails> expectedAsyncEventQueueDetails = setupAsyncEventQueuesForTestExecute(mockCache, diskStoreName); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.execute(mockFunctionContext); @@ -585,32 +586,6 @@ public class DescribeDiskStoreFunctionJUnitTest { } @Test - public void testExecuteOnMemberHavingANonGemFireCache() throws Throwable { - final Cache mockCache = mockContext.mock(Cache.class, "Cache"); - - final FunctionContext mockFunctionContext = - mockContext.mock(FunctionContext.class, "FunctionContext"); - - final TestResultSender testResultSender = new TestResultSender(); - - mockContext.checking(new Expectations() { - { - exactly(0).of(mockFunctionContext).getResultSender(); - will(returnValue(testResultSender)); - } - }); - - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); - - function.execute(mockFunctionContext); - - final List<?> results = testResultSender.getResults(); - - assertNotNull(results); - assertTrue(results.isEmpty()); - } - - @Test public void testExecuteThrowingDiskStoreNotFoundException() throws Exception { final String diskStoreName = "testDiskStore"; final String memberId = "mockMemberId"; @@ -640,10 +615,12 @@ public class DescribeDiskStoreFunctionJUnitTest { will(returnValue(diskStoreName)); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.execute(mockFunctionContext); @@ -683,10 +660,12 @@ public class DescribeDiskStoreFunctionJUnitTest { will(returnValue(diskStoreName)); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.execute(mockFunctionContext); @@ -740,10 +719,12 @@ public class DescribeDiskStoreFunctionJUnitTest { will(returnValue(diskStoreName)); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.execute(mockFunctionContext); @@ -769,7 +750,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(expectedDiskStoreName, function.getDiskStoreName(mockRegion)); } @@ -789,7 +770,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(DiskStoreDetails.DEFAULT_DISK_STORE_NAME, function.getDiskStoreName(mockRegion)); } @@ -813,7 +794,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isOverflowToDisk(mockRegion)); } @@ -837,7 +818,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isOverflowToDisk(mockRegion)); } @@ -857,7 +838,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isOverflowToDisk(mockRegion)); } @@ -877,7 +858,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isPersistent(mockRegion)); } @@ -897,7 +878,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isPersistent(mockRegion)); } @@ -917,7 +898,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isPersistent(mockRegion)); } @@ -937,7 +918,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isPersistent(mockRegion)); } @@ -957,7 +938,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isPersistent(mockRegion)); } @@ -977,7 +958,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isPersistent(mockRegion)); } @@ -1002,7 +983,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockRegion, mockDiskStore)); } @@ -1029,7 +1010,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockRegion, mockDiskStore)); } @@ -1062,7 +1043,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockRegion, mockDiskStore)); } @@ -1087,7 +1068,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isUsingDiskStore(mockRegion, mockDiskStore)); } @@ -1237,7 +1218,7 @@ public class DescribeDiskStoreFunctionJUnitTest { final DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStoreName, "memberOne"); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.setRegionDetails(mockCache, mockDiskStore, diskStoreDetails); @@ -1261,7 +1242,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(expectedDiskStoreName, function.getDiskStoreName(mockCacheServer)); } @@ -1281,7 +1262,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(DiskStoreDetails.DEFAULT_DISK_STORE_NAME, function.getDiskStoreName(mockCacheServer)); @@ -1298,7 +1279,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertNull(function.getDiskStoreName(mockCacheServer)); } @@ -1323,7 +1304,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockCacheServer, mockDiskStore)); } @@ -1346,7 +1327,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isUsingDiskStore(mockCacheServer, mockDiskStore)); } @@ -1369,7 +1350,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockCacheServer, mockDiskStore)); } @@ -1421,7 +1402,7 @@ public class DescribeDiskStoreFunctionJUnitTest { final DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStoreName, "memberOne"); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.setCacheServerDetails(mockCache, mockDiskStore, diskStoreDetails); @@ -1441,7 +1422,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(expectedDiskStoreName, function.getDiskStoreName(mockGatewaySender)); } @@ -1457,7 +1438,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(DiskStoreDetails.DEFAULT_DISK_STORE_NAME, function.getDiskStoreName(mockGatewaySender)); @@ -1474,7 +1455,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isPersistent(mockGatewaySender)); } @@ -1490,7 +1471,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isPersistent(mockGatewaySender)); } @@ -1512,7 +1493,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockGatewaySender, mockDiskStore)); } @@ -1532,7 +1513,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isUsingDiskStore(mockGatewaySender, mockDiskStore)); } @@ -1552,7 +1533,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockGatewaySender, mockDiskStore)); } @@ -1578,7 +1559,7 @@ public class DescribeDiskStoreFunctionJUnitTest { final DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStoreName, "memberOne"); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.setPdxSerializationDetails(mockCache, mockDiskStore, diskStoreDetails); @@ -1604,7 +1585,7 @@ public class DescribeDiskStoreFunctionJUnitTest { final DiskStoreDetails diskStoreDetails = new DiskStoreDetails("testDiskStore", "memberOne"); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.setPdxSerializationDetails(mockCache, mockDiskStore, diskStoreDetails); @@ -1626,7 +1607,7 @@ public class DescribeDiskStoreFunctionJUnitTest { final DiskStoreDetails diskStoreDetails = new DiskStoreDetails("testDiskStore", "memberOne"); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.setPdxSerializationDetails(mockCache, mockDiskStore, diskStoreDetails); @@ -1646,7 +1627,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(expectedDiskStoreName, function.getDiskStoreName(mockQueue)); } @@ -1662,7 +1643,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertEquals(DiskStoreDetails.DEFAULT_DISK_STORE_NAME, function.getDiskStoreName(mockQueue)); } @@ -1686,7 +1667,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockQueue, mockDiskStore)); } @@ -1708,7 +1689,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isUsingDiskStore(mockQueue, mockDiskStore)); } @@ -1728,7 +1709,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertFalse(function.isUsingDiskStore(mockQueue, mockDiskStore)); } @@ -1750,7 +1731,7 @@ public class DescribeDiskStoreFunctionJUnitTest { } }); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); assertTrue(function.isUsingDiskStore(mockQueue, mockDiskStore)); } @@ -1793,27 +1774,13 @@ public class DescribeDiskStoreFunctionJUnitTest { final DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStoreName, "memberOne"); - final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache); + final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(); function.setAsyncEventQueueDetails(mockCache, mockDiskStore, diskStoreDetails); assertAsyncEventQueueDetails(expectedAsyncEventQueueDetails, diskStoreDetails); } - private static class TestDescribeDiskStoreFunction extends DescribeDiskStoreFunction { - - private final Cache cache; - - public TestDescribeDiskStoreFunction(final Cache cache) { - this.cache = cache; - } - - @Override - protected Cache getCache() { - return this.cache; - } - } - private static class TestResultSender implements ResultSender { private final List<Object> results = new LinkedList<>(); http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListDiskStoresFunctionJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListDiskStoresFunctionJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListDiskStoresFunctionJUnitTest.java index a8b9193..67c9503 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListDiskStoresFunctionJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListDiskStoresFunctionJUnitTest.java @@ -34,11 +34,9 @@ import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.cache.execute.ResultSender; -import org.apache.geode.distributed.DistributedMember; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; import org.apache.geode.internal.cache.DiskStoreImpl; import org.apache.geode.internal.cache.InternalCache; @@ -85,8 +83,8 @@ public class ListDiskStoresFunctionJUnitTest { return new DiskStoreDetails(id, name, memberId, memberName); } - private ListDiskStoresFunction createListDiskStoresFunction(final Cache cache) { - return new TestListDiskStoresFunction(cache); + private ListDiskStoresFunction createListDiskStoresFunction() { + return new ListDiskStoresFunction(); } @Test @@ -144,10 +142,12 @@ public class ListDiskStoresFunctionJUnitTest { will(returnValue("ds-persistence")); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache); + final ListDiskStoresFunction function = createListDiskStoresFunction(); function.execute(mockFunctionContext); @@ -171,13 +171,7 @@ public class ListDiskStoresFunctionJUnitTest { final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "MockFunctionContext"); - final ListDiskStoresFunction testListDiskStoresFunction = - new TestListDiskStoresFunction(mockContext.mock(Cache.class, "MockCache")) { - @Override - protected Cache getCache() { - throw new CacheClosedException("Expected"); - } - }; + final ListDiskStoresFunction testListDiskStoresFunction = new ListDiskStoresFunction(); final TestResultSender testResultSender = new TestResultSender(); @@ -185,6 +179,9 @@ public class ListDiskStoresFunctionJUnitTest { { oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + + allowing(mockFunctionContext).getCache(); + will(throwException(new CacheClosedException("Expected"))); } }); @@ -219,10 +216,12 @@ public class ListDiskStoresFunctionJUnitTest { will(returnValue(Collections.emptyList())); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache); + final ListDiskStoresFunction function = createListDiskStoresFunction(); function.execute(mockFunctionContext); @@ -240,7 +239,7 @@ public class ListDiskStoresFunctionJUnitTest { @Test @SuppressWarnings("unchecked") public void testExecuteOnMemberWithANonGemFireCache() throws Throwable { - final Cache mockCache = mockContext.mock(Cache.class, "Cache"); + final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache"); final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext"); @@ -251,10 +250,14 @@ public class ListDiskStoresFunctionJUnitTest { { oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); + allowing(mockCache).getMyId(); + allowing(mockCache).listDiskStoresIncludingRegionOwned(); } }); - final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache); + final ListDiskStoresFunction function = createListDiskStoresFunction(); function.execute(mockFunctionContext); @@ -289,10 +292,12 @@ public class ListDiskStoresFunctionJUnitTest { will(throwException(new RuntimeException("expected"))); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache); + final ListDiskStoresFunction function = createListDiskStoresFunction(); function.execute(mockFunctionContext); @@ -305,21 +310,6 @@ public class ListDiskStoresFunctionJUnitTest { } } - private static class TestListDiskStoresFunction extends ListDiskStoresFunction { - - private final Cache cache; - - public TestListDiskStoresFunction(final Cache cache) { - assert cache != null : "The Cache cannot be null!"; - this.cache = cache; - } - - @Override - protected Cache getCache() { - return cache; - } - } - private static class TestResultSender implements ResultSender { private final List<Object> results = new LinkedList<Object>(); http://git-wip-us.apache.org/repos/asf/geode/blob/c3c639df/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListIndexFunctionJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListIndexFunctionJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListIndexFunctionJUnitTest.java index 583aa56..335598c 100644 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListIndexFunctionJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/ListIndexFunctionJUnitTest.java @@ -155,8 +155,8 @@ public class ListIndexFunctionJUnitTest { return indexStatisticsDetails; } - private ListIndexFunction createListIndexFunction(final Cache cache) { - return new TestListIndexFunction(cache); + private ListIndexFunction createListIndexFunction() { + return new ListIndexFunction(); } private Index createMockIndex(final IndexDetails indexDetails) { @@ -297,10 +297,12 @@ public class ListIndexFunctionJUnitTest { createMockIndex(indexDetailsThree), createMockIndex(indexDetailsFour)))); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final ListIndexFunction function = createListIndexFunction(mockCache); + final ListIndexFunction function = createListIndexFunction(); function.execute(mockFunctionContext); @@ -357,10 +359,12 @@ public class ListIndexFunctionJUnitTest { will(returnValue(Collections.emptyList())); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final ListIndexFunction function = createListIndexFunction(mockCache); + final ListIndexFunction function = createListIndexFunction(); function.execute(mockFunctionContext); @@ -403,10 +407,12 @@ public class ListIndexFunctionJUnitTest { will(throwException(new RuntimeException("expected"))); oneOf(mockFunctionContext).getResultSender(); will(returnValue(testResultSender)); + allowing(mockFunctionContext).getCache(); + will(returnValue(mockCache)); } }); - final ListIndexFunction function = createListIndexFunction(mockCache); + final ListIndexFunction function = createListIndexFunction(); function.execute(mockFunctionContext); @@ -419,21 +425,6 @@ public class ListIndexFunctionJUnitTest { } } - private static class TestListIndexFunction extends ListIndexFunction { - - private final Cache cache; - - protected TestListIndexFunction(final Cache cache) { - assert cache != null : "The Cache cannot be null!"; - this.cache = cache; - } - - @Override - protected Cache getCache() { - return this.cache; - } - } - private static class TestResultSender implements ResultSender { private final List<Object> results = new LinkedList<Object>();
