geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kh...@apache.org
Subject [32/49] geode git commit: GEODE-2612: Added gfsh support for invoking callbacks during snapshot load
Date Fri, 17 Mar 2017 20:11:07 GMT
GEODE-2612: Added gfsh support for invoking callbacks during snapshot load


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/6cc8a113
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/6cc8a113
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/6cc8a113

Branch: refs/heads/feature/GEODE-2420
Commit: 6cc8a1139768eaae41cddf8ec0e392583c26ad92
Parents: f7aad2e
Author: Barry Oglesby <boglesby@pivotal.io>
Authored: Thu Mar 9 15:49:14 2017 -0800
Committer: Ken Howe <khowe@pivotal.io>
Committed: Fri Mar 17 13:09:45 2017 -0700

----------------------------------------------------------------------
 .../internal/cli/commands/DataCommands.java     |   7 +-
 .../cli/functions/ImportDataFunction.java       |  15 ++-
 .../internal/cli/i18n/CliStrings.java           |   3 +
 .../commands/GemfireDataCommandsDUnitTest.java  | 117 +++++++++++++++++--
 .../cli/commands/golden-help-offline.properties |   6 +-
 5 files changed, 129 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/6cc8a113/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
index a938987..484bbf2 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DataCommands.java
@@ -841,7 +841,10 @@ public class DataCommands implements CommandMarker {
       @CliOption(key = CliStrings.IMPORT_DATA__MEMBER, mandatory = true,
           unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
           optionContext = ConverterHint.MEMBERIDNAME,
-          help = CliStrings.IMPORT_DATA__MEMBER__HELP) String memberNameOrId) {
+          help = CliStrings.IMPORT_DATA__MEMBER__HELP) String memberNameOrId,
+      @CliOption(key = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS, mandatory = false,
+          unspecifiedDefaultValue = "false",
+          help = CliStrings.IMPORT_DATA__INVOKE_CALLBACKS__HELP) boolean invokeCallbacks)
{
 
     this.securityService.authorizeRegionWrite(regionName);
 
@@ -856,7 +859,7 @@ public class DataCommands implements CommandMarker {
             .format(CliStrings.INVALID_FILE_EXTENSION, CliStrings.GEODE_DATA_FILE_EXTENSION));
       }
       if (targetMember != null) {
-        final String args[] = {regionName, filePath};
+        final Object args[] = {regionName, filePath, invokeCallbacks};
         ResultCollector<?, ?> rc = CliUtil.executeFunction(importDataFunction, args,
targetMember);
         List<Object> results = (List<Object>) rc.getResult();
 

http://git-wip-us.apache.org/repos/asf/geode/blob/6cc8a113/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportDataFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportDataFunction.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportDataFunction.java
index 6444662..13949c8 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportDataFunction.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ImportDataFunction.java
@@ -22,6 +22,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.cache.execute.FunctionAdapter;
 import org.apache.geode.cache.execute.FunctionContext;
 import org.apache.geode.cache.snapshot.RegionSnapshotService;
+import org.apache.geode.cache.snapshot.SnapshotOptions;
 import org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat;
 import org.apache.geode.internal.InternalEntity;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
@@ -36,9 +37,13 @@ public class ImportDataFunction extends FunctionAdapter implements InternalEntit
   private static final long serialVersionUID = 1L;
 
   public void execute(FunctionContext context) {
-    final String[] args = (String[]) context.getArguments();
-    final String regionName = args[0];
-    final String importFileName = args[1];
+    final Object[] args = (Object[]) context.getArguments();
+    final String regionName = (String) args[0];
+    final String importFileName = (String) args[1];
+    boolean invokeCallbacks = false;
+    if (args.length > 2) {
+      invokeCallbacks = (boolean) args[2];
+    }
 
     try {
       final Cache cache = CacheFactory.getAnyInstance();
@@ -46,8 +51,10 @@ public class ImportDataFunction extends FunctionAdapter implements InternalEntit
       final String hostName = cache.getDistributedSystem().getDistributedMember().getHost();
       if (region != null) {
         RegionSnapshotService<?, ?> snapshotService = region.getSnapshotService();
+        SnapshotOptions options = snapshotService.createOptions();
+        options.invokeCallbacks(invokeCallbacks);
         File importFile = new File(importFileName);
-        snapshotService.load(new File(importFileName), SnapshotFormat.GEMFIRE);
+        snapshotService.load(new File(importFileName), SnapshotFormat.GEMFIRE, options);
         String successMessage = CliStrings.format(CliStrings.IMPORT_DATA__SUCCESS__MESSAGE,
             importFile.getCanonicalPath(), hostName, regionName);
         context.getResultSender().lastResult(successMessage);

http://git-wip-us.apache.org/repos/asf/geode/blob/6cc8a113/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
index 51d39d6..b835e8b 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
@@ -1566,6 +1566,9 @@ public class CliStrings {
   public static final String IMPORT_DATA__REGION__NOT__FOUND = "Region {0} not found.";
   public static final String IMPORT_DATA__SUCCESS__MESSAGE =
       "Data imported from file : {0} on host : {1} to region : {2}";
+  public static final String IMPORT_DATA__INVOKE_CALLBACKS = "invoke-callbacks";
+  public static final String IMPORT_DATA__INVOKE_CALLBACKS__HELP =
+      "Whether callbacks should be invoked";
 
   /* 'list async-event-queues' command */
   public static final String LIST_ASYNC_EVENT_QUEUES = "list async-event-queues";

http://git-wip-us.apache.org/repos/asf/geode/blob/6cc8a113/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
index 8a20631..e99a7fb 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GemfireDataCommandsDUnitTest.java
@@ -31,8 +31,11 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Random;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
-import org.junit.Ignore;
+import org.apache.geode.cache.CacheListener;
+import org.apache.geode.cache.EntryEvent;
+import org.apache.geode.cache.util.CacheListenerAdapter;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -1730,18 +1733,19 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase
{
 
       setUpJmxManagerOnVm0ThenConnect(null);
 
-      manager.invoke(new SerializableCallable() {
-        public Object call() {
-          Region region = createParReg(regionName, getCache());
-          return region.put("Manager", "ASD");
+      manager.invoke(new SerializableRunnable() {
+        public void run() {
+          createParReg(regionName, getCache());
         }
       });
 
-      vm1.invoke(new SerializableCallable() {
+      vm1.invoke(new SerializableRunnable() {
         @Override
-        public Object call() throws Exception {
+        public void run() throws Exception {
           Region region = createParReg(regionName, getCache());
-          return region.put("VM1", "QWE");
+          for (int i = 0; i < 100; i++) {
+            region.put(i, i);
+          }
         }
       });
 
@@ -1760,12 +1764,20 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase
{
       vm1.invoke(new SerializableRunnable() {
         public void run() {
           Region region = getCache().getRegion(regionName);
-          region.destroy("Manager");
-          region.destroy("VM1");
+          for (int i = 0; i < 100; i++) {
+            region.destroy(i);
+          }
         }
       });
 
       /**
+       * Add CacheListener
+       */
+
+      manager.invoke(addCacheListenerInvocations(regionName));
+      vm1.invoke(addCacheListenerInvocations(regionName));
+
+      /**
        * Import the data
        */
 
@@ -1789,11 +1801,49 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase
{
       manager.invoke(new SerializableRunnable() {
         public void run() {
           Region region = getCache().getRegion(regionName);
-          assertEquals(region.get("Manager"), "ASD");
-          assertEquals(region.get("VM1"), "QWE");
+          for (int i = 0; i < 100; i++) {
+            assertEquals(i, region.get(i));
+          }
+        }
+      });
+
+      /**
+       * Verify callbacks were not invoked
+       */
+
+      manager.invoke(verifyCacheListenerInvocations(regionName, false));
+      vm1.invoke(verifyCacheListenerInvocations(regionName, false));
+
+      /**
+       * Import the data with invokeCallbacks=true
+       */
+
+      vm1.invoke(new SerializableRunnable() {
+        public void run() {
+          Region region = getCache().getRegion(regionName);
+          for (int i = 0; i < 100; i++) {
+            region.destroy(i);
+          }
         }
       });
 
+      csb = new CommandStringBuilder(CliStrings.IMPORT_DATA);
+      csb.addOption(CliStrings.IMPORT_DATA__REGION, regionName);
+      csb.addOption(CliStrings.IMPORT_DATA__FILE, filePath);
+      csb.addOption(CliStrings.IMPORT_DATA__MEMBER, "Manager");
+      csb.addOption(CliStrings.IMPORT_DATA__INVOKE_CALLBACKS, "true");
+      commandString = csb.toString();
+      cmdResult = executeCommand(commandString);
+      commandResultToString(cmdResult);
+      assertEquals(Result.Status.OK, cmdResult.getStatus());
+
+      /**
+       * Verify callbacks were invoked
+       */
+
+      manager.invoke(verifyCacheListenerInvocations(regionName, true));
+      vm1.invoke(verifyCacheListenerInvocations(regionName, true));
+
       // Test for bad input
       csb = new CommandStringBuilder(CliStrings.EXPORT_DATA);
       csb.addOption(CliStrings.EXPORT_DATA__REGION, "FDSERW");
@@ -1824,6 +1874,35 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase
{
     }
   }
 
+  private SerializableRunnable addCacheListenerInvocations(final String regionName) {
+    return new SerializableRunnable() {
+      public void run() {
+        Region region = getCache().getRegion(regionName);
+        region.getAttributesMutator().addCacheListener(new CountingCacheListener());
+      }
+    };
+  }
+
+  private SerializableRunnable verifyCacheListenerInvocations(final String regionName,
+      boolean callbacksShouldHaveBeenInvoked) {
+    return new SerializableRunnable() {
+      public void run() {
+        Region region = getCache().getRegion(regionName);
+        CacheListener<?, ?>[] listeners = region.getAttributes().getCacheListeners();
+        for (CacheListener<?, ?> listener : listeners) {
+          if (listener instanceof CountingCacheListener) {
+            CountingCacheListener ccl = (CountingCacheListener) listener;
+            if (callbacksShouldHaveBeenInvoked) {
+              assertNotEquals(0, ccl.getEvents());
+            } else {
+              assertEquals(0, ccl.getEvents());
+            }
+          }
+        }
+      }
+    };
+  }
+
   void setupWith2Regions() {
     final VM vm1 = Host.getHost(0).getVM(1);
     final VM vm2 = Host.getHost(0).getVM(2);
@@ -2329,4 +2408,18 @@ public class GemfireDataCommandsDUnitTest extends CliCommandTestBase
{
         + memSizeFromFunctionCall);
     assertTrue(memSizeFromFunctionCall.equals(memSizeFromMbean));
   }
+
+  private static class CountingCacheListener extends CacheListenerAdapter {
+
+    private final AtomicInteger events = new AtomicInteger();
+
+    @Override
+    public void afterCreate(EntryEvent event) {
+      events.incrementAndGet();
+    }
+
+    private int getEvents() {
+      return events.get();
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/6cc8a113/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
index 17b7515..8cc8aba 100644
--- a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
+++ b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
@@ -1682,7 +1682,7 @@ IS AVAILABLE\n\
 SYNOPSIS\n\
 \ \ \ \ Import user data from a file to a region.\n\
 SYNTAX\n\
-\ \ \ \ import data --region=value --file=value --member=value\n\
+\ \ \ \ import data --region=value --file=value --member=value [--invoke-callbacks=value]\n\
 PARAMETERS\n\
 \ \ \ \ region\n\
 \ \ \ \ \ \ \ \ Region into which data will be imported.\n\
@@ -1694,6 +1694,10 @@ PARAMETERS\n\
 \ \ \ \ \ \ \ \ Name/Id of a member which hosts the region. The data will be imported from
the specified\n\
 \ \ \ \ \ \ \ \ file on the host where the member is running.\n\
 \ \ \ \ \ \ \ \ Required: true\n\
+\ \ \ \ invoke-callbacks\n\
+\ \ \ \ \ \ \ \ Whether callbacks should be invoked\n\
+\ \ \ \ \ \ \ \ Required: false\n\
+\ \ \ \ \ \ \ \ Default (if the parameter is not specified): false\n\
 
 list-async-event-queues.help=\
 NAME\n\


Mime
View raw message