zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1713309 - in /zookeeper/branches/branch-3.4: ./ src/java/main/org/apache/zookeeper/server/ src/java/test/org/apache/zookeeper/test/
Date Sun, 08 Nov 2015 22:30:06 GMT
Author: rgs
Date: Sun Nov  8 22:30:06 2015
New Revision: 1713309

URL: http://svn.apache.org/viewvc?rev=1713309&view=rev
Log:
ZOOKEEPER-2227: stmk four-letter word fails execution at server while reading
trace mask argument (Chris Nauroth via rgs)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1713309&r1=1713308&r2=1713309&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Sun Nov  8 22:30:06 2015
@@ -144,6 +144,9 @@ BUGFIXES:
   ZOOKEEPER-1853: zkCli.sh can't issue a CREATE command containing
   spaces in the data (Jun Gong via rgs)
 
+  ZOOKEEPER-2227: stmk four-letter word fails execution at server while reading
+  trace mask argument (Chris Nauroth via rgs)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1575. adding .gitattributes to prevent CRLF and LF mismatches for

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=1713309&r1=1713308&r2=1713309&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
Sun Nov  8 22:30:06 2015
@@ -856,6 +856,7 @@ public class NIOServerCnxn extends Serve
             tmask.start();
             return true;
         } else if (len == setTraceMaskCmd) {
+            incomingBuffer = ByteBuffer.allocate(8);
             int rc = sock.read(incomingBuffer);
             if (rc < 0) {
                 throw new IOException("Read error");

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java?rev=1713309&r1=1713308&r2=1713309&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java
Sun Nov  8 22:30:06 2015
@@ -644,10 +644,9 @@ public class NettyServerCnxn extends Ser
             tmask.start();
             return true;
         } else if (len == setTraceMaskCmd) {
-            ByteBuffer mask = ByteBuffer.allocate(4);
+            ByteBuffer mask = ByteBuffer.allocate(8);
             message.readBytes(mask);
-
-            bb.flip();
+            mask.flip();
             long traceMask = mask.getLong();
             ZooTrace.setTextTraceLevel(traceMask);
             SetTraceMaskCommand setMask = new SetTraceMaskCommand(pwriter, traceMask);

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java?rev=1713309&r1=1713308&r2=1713309&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
Sun Nov  8 22:30:06 2015
@@ -19,15 +19,20 @@
 package org.apache.zookeeper.test;
 
 import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.regex.Pattern;
 
 import org.apache.zookeeper.TestableZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.common.IOUtils;
 import static org.apache.zookeeper.client.FourLetterWordMain.send4LetterWord;
 import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.Timeout;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,6 +40,9 @@ public class FourLetterWordsTest extends
     protected static final Logger LOG =
         LoggerFactory.getLogger(FourLetterWordsTest.class);
 
+    @Rule
+    public Timeout timeout = new Timeout(30000);
+
     /** Test the various four letter words */
     @Test
     public void testFourLetterWords() throws Exception {
@@ -187,4 +195,43 @@ public class FourLetterWordsTest extends
         String resp = sendRequest("isro", 2000);
         Assert.assertTrue(resp.contains("rw"));
     }
+
+    @Test
+    public void testSetTraceMask() throws Exception {
+        String gtmkResp = sendRequest("gtmk");
+        Assert.assertNotNull(gtmkResp);
+        gtmkResp = gtmkResp.trim();
+        Assert.assertFalse(gtmkResp.isEmpty());
+        long formerMask = Long.valueOf(gtmkResp);
+        try {
+            verify(buildSetTraceMaskRequest(0), "0");
+            verify("gtmk", "0");
+        } finally {
+            // Restore former value.
+            sendRequest(buildSetTraceMaskRequest(formerMask));
+        }
+    }
+
+    /**
+     * Builds a SetTraceMask request to be sent to the server, consisting of
+     * "stmk" followed by the 8-byte long representation of the trace mask.
+     *
+     * @param mask trace mask to set
+     * @return built request
+     * @throws IOException if there is an I/O error
+     */
+    private String buildSetTraceMaskRequest(long mask) throws IOException {
+        ByteArrayOutputStream baos = null;
+        DataOutputStream dos = null;
+        try {
+            baos = new ByteArrayOutputStream();
+            dos = new DataOutputStream(baos);
+            dos.writeBytes("stmk");
+            dos.writeLong(mask);
+        } finally {
+            IOUtils.closeStream(dos);
+            IOUtils.closeStream(baos);
+        }
+        return new String(baos.toByteArray());
+    }
 }



Mime
View raw message