ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shro...@apache.org
Subject ignite git commit: IGNITE-3066: Enforced operations on strings.
Date Wed, 16 Nov 2016 03:39:19 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2788 a10e1b9d1 -> 5d3b6e37b


 IGNITE-3066: Enforced operations on strings.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5d3b6e37
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5d3b6e37
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5d3b6e37

Branch: refs/heads/ignite-2788
Commit: 5d3b6e37b86f6e92d5f8d050c4967c24da75335d
Parents: a10e1b9
Author: shtykh_roman <rshtykh@yahoo.com>
Authored: Wed Nov 16 12:39:03 2016 +0900
Committer: shtykh_roman <rshtykh@yahoo.com>
Committed: Wed Nov 16 12:39:03 2016 +0900

----------------------------------------------------------------------
 .../tcp/redis/RedisProtocolSelfTest.java        | 66 +++++++++++++++++++-
 .../string/GridRedisAppendCommandHandler.java   |  5 +-
 .../string/GridRedisGetCommandHandler.java      |  9 ++-
 .../string/GridRedisGetRangeCommandHandler.java |  5 +-
 .../string/GridRedisGetSetCommandHandler.java   |  9 ++-
 .../string/GridRedisSetRangeCommandHandler.java |  8 ++-
 .../string/GridRedisStrlenCommandHandler.java   |  5 +-
 7 files changed, 96 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5d3b6e37/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolSelfTest.java
index d577efd..bd20b27 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/RedisProtocolSelfTest.java
@@ -18,7 +18,9 @@
 package org.apache.ignite.internal.processors.rest.protocols.tcp.redis;
 
 import java.math.BigInteger;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -157,11 +159,19 @@ public class RedisProtocolSelfTest extends GridCommonAbstractTest {
     public void testGet() throws Exception {
         try (Jedis jedis = pool.getResource()) {
             jcache().put("getKey1", "getVal1");
-            jcache().put("getKey2", 0);
 
             Assert.assertEquals("getVal1", jedis.get("getKey1"));
-            Assert.assertEquals("0", jedis.get("getKey2"));
             Assert.assertNull(jedis.get("wrongKey"));
+
+            jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
+            try {
+                jedis.get("setDataTypeKey");
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("WRONGTYPE"));
+            }
         }
     }
 
@@ -170,10 +180,20 @@ public class RedisProtocolSelfTest extends GridCommonAbstractTest {
      */
     public void testGetSet() throws Exception {
         try (Jedis jedis = pool.getResource()) {
-            jcache().put("getSetKey1", 1);
+            jcache().put("getSetKey1", "1");
 
             Assert.assertEquals("1", jedis.getSet("getSetKey1", "0"));
             Assert.assertNull(jedis.get("getSetNonExistingKey"));
+
+            jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
+            try {
+                jedis.getSet("setDataTypeKey", "0");
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("WRONGTYPE"));
+            }
         }
     }
 
@@ -296,6 +316,16 @@ public class RedisProtocolSelfTest extends GridCommonAbstractTest {
         try (Jedis jedis = pool.getResource()) {
             Assert.assertEquals(5, (long)jedis.append("appendKey1", "Hello"));
             Assert.assertEquals(12, (long)jedis.append("appendKey1", " World!"));
+
+            jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
+            try {
+                jedis.append("setDataTypeKey", "");
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("WRONGTYPE"));
+            }
         }
     }
 
@@ -308,6 +338,16 @@ public class RedisProtocolSelfTest extends GridCommonAbstractTest {
 
             jcache().put("strlenKey", "abc");
             Assert.assertEquals(3, (long)jedis.strlen("strlenKey"));
+
+            jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
+            try {
+                jedis.strlen("setDataTypeKey");
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("WRONGTYPE"));
+            }
         }
     }
 
@@ -343,6 +383,16 @@ public class RedisProtocolSelfTest extends GridCommonAbstractTest {
 
             jcache().put("setRangeKey3", "Hello World");
             Assert.assertEquals(11, (long)jedis.setrange("setRangeKey3", 6, "Redis"));
+
+            jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
+            try {
+                jedis.setrange("setDataTypeKey", 0, "Redis");
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("WRONGTYPE"));
+            }
         }
     }
 
@@ -358,6 +408,16 @@ public class RedisProtocolSelfTest extends GridCommonAbstractTest {
             Assert.assertEquals("ing", jedis.getrange("getRangeKey", -3, -1));
             Assert.assertEquals("This is a string", jedis.getrange("getRangeKey", 0, -1));
             Assert.assertEquals("string", jedis.getrange("getRangeKey", 10, 100));
+
+            jcache().put("setDataTypeKey", new HashSet<String>(Arrays.asList("1", "2")));
+            try {
+                jedis.getrange("setDataTypeKey", 0, 1);
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("WRONGTYPE"));
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/5d3b6e37/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
index a46f0f6..60d25fd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
@@ -101,9 +101,12 @@ public class GridRedisAppendCommandHandler extends GridRedisRestCommandHandler
{
     @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         if (restRes.getResponse() == null)
             return GridRedisProtocolParser.nil();
-        else {
+
+        if (restRes.getResponse() instanceof String) {
             int resLen = ((String)restRes.getResponse()).length();
             return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
         }
+        else
+            return GridRedisProtocolParser.toTypeError("Operation against a key holding the
wrong kind of value");
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5d3b6e37/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
index 0295876..7be53b2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
@@ -70,7 +70,12 @@ public class GridRedisGetCommandHandler extends GridRedisRestCommandHandler
{
 
     /** {@inheritDoc} */
     @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
-            : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.nil();
+
+        if (restRes.getResponse() instanceof String)
+            return GridRedisProtocolParser.toBulkString(restRes.getResponse());
+        else
+            return GridRedisProtocolParser.toTypeError("Operation against a key holding the
wrong kind of value");
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5d3b6e37/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
index a0aaf37..41b1eac 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
@@ -81,7 +81,8 @@ public class GridRedisGetRangeCommandHandler extends GridRedisRestCommandHandler
     @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         if (restRes.getResponse() == null)
             return GridRedisProtocolParser.toBulkString("");
-        else {
+
+        if (restRes.getResponse() instanceof String) {
             String res = String.valueOf(restRes.getResponse());
             int startOffset;
             int endOffset;
@@ -97,6 +98,8 @@ public class GridRedisGetRangeCommandHandler extends GridRedisRestCommandHandler
 
             return GridRedisProtocolParser.toBulkString(res.substring(startOffset, endOffset));
         }
+        else
+            return GridRedisProtocolParser.toTypeError("Operation against a key holding the
wrong kind of value");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/5d3b6e37/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
index 9e70516..781b8ab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
@@ -78,7 +78,12 @@ public class GridRedisGetSetCommandHandler extends GridRedisRestCommandHandler
{
 
     /** {@inheritDoc} */
     @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
-        return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
-            : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.nil();
+
+        if (restRes.getResponse() instanceof String)
+            return GridRedisProtocolParser.toBulkString(restRes.getResponse());
+        else
+            return GridRedisProtocolParser.toTypeError("Operation against a key holding the
wrong kind of value");
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5d3b6e37/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
index 40244c8..dfd24a5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
@@ -111,6 +111,9 @@ public class GridRedisSetRangeCommandHandler extends GridRedisRestCommandHandler
             putReq.value(new String(dst));
         }
         else {
+            if (!(resp instanceof String))
+                return getReq;
+
             String cacheVal = String.valueOf(resp);
 
             cacheVal = cacheVal.substring(0, off) + val;
@@ -127,9 +130,12 @@ public class GridRedisSetRangeCommandHandler extends GridRedisRestCommandHandler
     @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         if (restRes.getResponse() == null)
             return GridRedisProtocolParser.toInteger("0");
-        else {
+
+        if (restRes.getResponse() instanceof String) {
             int resLen = ((String)restRes.getResponse()).length();
             return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
         }
+        else
+            return GridRedisProtocolParser.toTypeError("Operation against a key holding the
wrong kind of value");
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/5d3b6e37/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
index 876c798..b4a88c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
@@ -72,9 +72,12 @@ public class GridRedisStrlenCommandHandler extends GridRedisRestCommandHandler
{
     @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         if (restRes.getResponse() == null)
             return GridRedisProtocolParser.toInteger("0");
-        else {
+
+        if (restRes.getResponse() instanceof String) {
             int len = String.valueOf(restRes.getResponse()).length();
             return GridRedisProtocolParser.toInteger(String.valueOf(len));
         }
+        else
+            return GridRedisProtocolParser.toTypeError("Operation against a key holding the
wrong kind of value");
     }
 }


Mime
View raw message