Repository: ignite Updated Branches: refs/heads/ignite-3345 970b01a66 -> 300a93a24
IGNITE-3345 WIP Added tests. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1d22e79f Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1d22e79f Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1d22e79f Branch: refs/heads/ignite-3345 Commit: 1d22e79fd33bfbb69687999b1ab12dab5b0e6e93 Parents: 970b01a Author: Alexey Kuznetsov <[email protected]> Authored: Sun Feb 18 16:35:31 2018 +0700 Committer: Alexey Kuznetsov <[email protected]> Committed: Sun Feb 18 16:35:31 2018 +0700 ---------------------------------------------------------------------- .../JettyRestProcessorAbstractSelfTest.java | 127 +++++++++++++++++++ .../http/jetty/GridJettyRestHandler.java | 6 +- 2 files changed, 132 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/1d22e79f/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java index 13613ef..fda7ebc 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java @@ -27,10 +27,14 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; import java.text.DateFormat; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -229,6 +233,31 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro } /** + * @param cacheName Optional cache name. + * @param cmd REST command. + * @param params Command parameters. + * @return Returned content. + * @throws Exception If failed. + */ + protected String content(String cacheName, GridRestCommand cmd, String... params) throws Exception { + Map<String, String> paramsMap = new LinkedHashMap<>(); + + if (cacheName != null) + paramsMap.put("cacheName", cacheName); + + paramsMap.put("cmd", cmd.key()); + + if (params != null) { + assertEquals(0, params.length % 2); + + for (int i = 0; i < params.length; i += 2) + paramsMap.put(params[i], params[i + 1]); + } + + return content(paramsMap); + } + + /** * @param content Content to check. */ private void assertResponseContainsError(String content) throws IOException { @@ -1983,6 +2012,104 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertFalse(queryCursorFound()); } + private void putTypedValue(String type, String k, String v) throws Exception { + String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_PUT, + "keyType", type, + "valueType", type, + "key", k, + "val", v + ); + + info("Command result: " + ret); + } + + /** + * @throws Exception If failed. + */ + public void testTypedPutGet() throws Exception { + // Test boolean type. + putTypedValue("boolean", "true", "false"); + + IgniteCache<Boolean, Boolean> cBool = jcache(); + + assertEquals(cBool.get(true), Boolean.FALSE); + + // Test byte type. + putTypedValue("byte", "64", "100"); + + IgniteCache<Byte, Byte> cByte = jcache(); + + assertEquals(cByte.get(Byte.valueOf("64")), Byte.valueOf("100")); + + // Test short type. + putTypedValue("short", "1024", "4096"); + + IgniteCache<Short, Short> cShort = jcache(); + + assertEquals(cShort.get(Short.valueOf("1024")), Short.valueOf("4096")); + + // Test integer type. + putTypedValue("int", "65555", "128256"); + putTypedValue("integer", "74555", "200000"); + + IgniteCache<Integer, Integer> cInt = jcache(); + + assertEquals(cInt.get(65555), Integer.valueOf(128256)); + assertEquals(cInt.get(74555), Integer.valueOf(200000)); + + // Test long type. + putTypedValue("long", "3000000", "400000"); + + IgniteCache<Long, Long> cLong = jcache(); + + assertEquals(cLong.get(3000000L), Long.valueOf(400000)); + + // Test float type. + putTypedValue("float", "1.5", "2.5"); + + IgniteCache<Float, Float> cFloat = jcache(); + + assertEquals(cFloat.get(1.5f), 2.5f); + + // Test double type. + putTypedValue("double", "5.5", "75.5"); + + IgniteCache<Double, Double> cDouble = jcache(); + + assertEquals(cDouble.get(5.5d), 75.5d); + + // Test date type. + putTypedValue("date", "2018-02-18", "2017-01-01"); + + IgniteCache<Date, Date> cDate = jcache(); + + assertEquals(cDate.get(Date.valueOf("2018-02-18")), Date.valueOf("2017-01-01")); + + // Test time type. + putTypedValue("time", "01:01:01", "02:02:02"); + + IgniteCache<Time, Time> cTime = jcache(); + + assertEquals(cTime.get(Time.valueOf("01:01:01")), Time.valueOf("02:02:02")); + + // Test timestamp type. + putTypedValue("timestamp", "2018-02-18%2001:01:01", "2017-01-01%2002:02:02"); + + IgniteCache<Timestamp, Timestamp> cTimestamp = jcache(); + + assertEquals(cTimestamp.get(Timestamp.valueOf("2018-02-18 01:01:01")), Timestamp.valueOf("2017-01-01 02:02:02")); + + // Test UUID type. + UUID k = UUID.fromString("121f5ae8-148d-11e8-b642-0ed5f89f718b"); + UUID v = UUID.fromString("64c6c225-b31c-4000-b136-ef14562ac785"); + + putTypedValue("UUID", k.toString(), v.toString()); + + IgniteCache<UUID, UUID> cUUID = jcache(); + + assertEquals(cUUID.get(k), v); + } + /** * @return Signature. * @throws Exception If failed. http://git-wip-us.apache.org/repos/asf/ignite/blob/1d22e79f/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java ---------------------------------------------------------------------- diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java index f13a196..4c04ccb 100644 --- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java +++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java @@ -28,6 +28,7 @@ import java.io.LineNumberReader; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; import java.sql.Date; +import java.sql.Time; import java.sql.Timestamp; import java.util.Collections; import java.util.Iterator; @@ -420,10 +421,13 @@ public class GridJettyRestHandler extends AbstractHandler { case "date": return Date.valueOf(s); + case "time": + return Time.valueOf(s); + case "timestamp": return Timestamp.valueOf(s); - case "UUID": + case "uuid": return UUID.fromString(s); default:
