geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From heyba...@apache.org
Subject [geode] branch develop updated: GEODE-6112: Gfsh should respond to SIGINT (#2964)
Date Mon, 10 Dec 2018 17:31:49 GMT
This is an automated email from the ASF dual-hosted git repository.

heybales pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 9adaffc  GEODE-6112: Gfsh should respond to SIGINT (#2964)
9adaffc is described below

commit 9adaffcfe2d66efe22cc19bb54e15b8568bcc52f
Author: Helena Bales <hbales@pivotal.io>
AuthorDate: Mon Dec 10 09:31:37 2018 -0800

    GEODE-6112: Gfsh should respond to SIGINT (#2964)
    
    Gfsh now responds to SIGINT by clearing the prompt. It does not print a
    new prompt, as that implementation caused issue with the Gfsh History.
    This is the behavior regardless of if there is text entered in the
    prompt.
    
    When a command is running, the command can be sent to the background
    using SIGINT. For example, when running the start server command, if
    the GfshSignalHandler receives a SIGINT, the command will be interrupted
    but the server start will continue in the background.
---
 .../cli/shell/unsafe/GfshSignalHandler.java        | 17 ++++++--
 .../cli/shell/unsafe/GfshSignalHandlerTest.java    | 50 ++++++++++++++++++++++
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java
index 314e5c4..1e08a32 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandler.java
@@ -14,15 +14,18 @@
  */
 package org.apache.geode.management.internal.cli.shell.unsafe;
 
+import java.io.IOException;
 import java.util.Collections;
 import java.util.Hashtable;
 import java.util.Map;
 
+import jline.console.ConsoleReader;
 import sun.misc.SignalHandler;
 
 import org.apache.geode.internal.process.signal.AbstractSignalNotificationHandler;
 import org.apache.geode.internal.process.signal.Signal;
 import org.apache.geode.internal.process.signal.SignalEvent;
+import org.apache.geode.management.internal.cli.shell.Gfsh;
 
 /**
  * This class externalizes signal handling in order to make the GemFire build process a bit
cleaner
@@ -52,14 +55,22 @@ public class GfshSignalHandler extends AbstractSignalNotificationHandler
impleme
   @Override
   public void handle(final sun.misc.Signal sig) {
     notifyListeners(new SignalEvent(sig, Signal.valueOfName(sig.getName())));
-    handleDefault(sig);
+    try {
+      handleDefault(sig, Gfsh.getConsoleReader());
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
   }
 
-  protected void handleDefault(final sun.misc.Signal sig) {
+  protected void handleDefault(final sun.misc.Signal sig, final ConsoleReader consoleReader)
+      throws IOException {
     final Signal signal = Signal.valueOfName(sig.getName());
     switch (signal) {
       case SIGINT:
-        break; // ignore the interrupt signal
+        String prompt = consoleReader.getPrompt();
+        consoleReader.resetPromptLine(prompt, "", -1);
+
+        break;
       default:
         final SignalHandler handler = getOriginalSignalHandler(signal);
         if (handler != null) {
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandlerTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandlerTest.java
new file mode 100644
index 0000000..fb589d6
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/shell/unsafe/GfshSignalHandlerTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.shell.unsafe;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import jline.console.ConsoleReader;
+import org.junit.Test;
+import sun.misc.Signal;
+
+/**
+ * Unit tests for {@link GfshSignalHandler}.
+ *
+ */
+public class GfshSignalHandlerTest {
+  int END_OF_LINE = -1;
+  Signal SIGINT = new Signal("INT");
+  String PROMPT = "somePrompt";
+
+  @Test
+  public void signalHandlerRespondsToSIGINTByClearingPrompt() throws IOException {
+    // Interactive attention (CTRL-C). JVM exits normally
+    GfshSignalHandler signalHandler = new GfshSignalHandler();
+
+    ConsoleReader consoleReader = mock(ConsoleReader.class);
+    when(consoleReader.getPrompt()).thenReturn(PROMPT);
+
+    signalHandler.handleDefault(SIGINT, consoleReader);
+
+    verify(consoleReader, times(1)).resetPromptLine(eq(PROMPT), eq(""), eq(END_OF_LINE));
+  }
+}


Mime
View raw message