ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: IGNITE-3345 Added tests.
Date Mon, 19 Feb 2018 04:27:41 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3345 044c522f4 -> 22f85e3b1


IGNITE-3345 Added tests.


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

Branch: refs/heads/ignite-3345
Commit: 22f85e3b1b53b3bb65cfd15e265cebeea7707065
Parents: 044c522
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Mon Feb 19 11:27:37 2018 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Mon Feb 19 11:27:37 2018 +0700

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 241 ++++++++++---------
 1 file changed, 130 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/22f85e3b/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 d59d489..65d8a67 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
@@ -2012,8 +2012,21 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         assertFalse(queryCursorFound());
     }
 
+    /**
+     * @return Cache.
+     */
+    protected <K, V> IgniteCache<K, V> typedCache() {
+        return grid(0).cache("test_typed_access");
+    }
+
+    /**
+     * @param type Key and value type.
+     * @param k Key to put.
+     * @param v Value to put.
+     * @throws Exception If failed.
+     */
     private void putTypedValue(String type, String k, String v) throws Exception {
-        String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_PUT,
+        String ret = content("test_typed_access", GridRestCommand.CACHE_PUT,
             "keyType", type,
             "valueType", type,
             "key", k,
@@ -2031,7 +2044,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("boolean", "true", "false");
         putTypedValue("java.lang.Boolean", "false", "true");
 
-        IgniteCache<Boolean, Boolean> cBool = jcache();
+        IgniteCache<Boolean, Boolean> cBool = typedCache();
 
         assertEquals(cBool.get(true), Boolean.FALSE);
         assertEquals(cBool.get(false), Boolean.TRUE);
@@ -2040,7 +2053,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("byte", "64", "100");
         putTypedValue("java.lang.Byte", "-25", "-127");
 
-        IgniteCache<Byte, Byte> cByte = jcache();
+        IgniteCache<Byte, Byte> cByte = typedCache();
 
         assertEquals(cByte.get(Byte.valueOf("64")), Byte.valueOf("100"));
         assertEquals(cByte.get(Byte.valueOf("-25")), Byte.valueOf("-127"));
@@ -2049,7 +2062,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("short", "1024", "4096");
         putTypedValue("java.lang.Short", "-15000", "-16000");
 
-        IgniteCache<Short, Short> cShort = jcache();
+        IgniteCache<Short, Short> cShort = typedCache();
 
         assertEquals(cShort.get(Short.valueOf("1024")), Short.valueOf("4096"));
         assertEquals(cShort.get(Short.valueOf("-15000")), Short.valueOf("-16000"));
@@ -2059,7 +2072,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("Integer", "74555", "200000");
         putTypedValue("java.lang.Integer", "-200", "-100000");
 
-        IgniteCache<Integer, Integer> cInt = jcache();
+        IgniteCache<Integer, Integer> cInt = typedCache();
 
         assertEquals(cInt.get(65555), Integer.valueOf(128256));
         assertEquals(cInt.get(74555), Integer.valueOf(200000));
@@ -2069,7 +2082,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("long", "3000000", "400000");
         putTypedValue("java.lang.Long", "-3000000", "-400000");
 
-        IgniteCache<Long, Long> cLong = jcache();
+        IgniteCache<Long, Long> cLong = typedCache();
 
         assertEquals(cLong.get(3000000L), Long.valueOf(400000));
         assertEquals(cLong.get(-3000000L), Long.valueOf(-400000));
@@ -2078,7 +2091,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("float", "1.5", "2.5");
         putTypedValue("java.lang.Float", "-7.5", "-8.5");
 
-        IgniteCache<Float, Float> cFloat = jcache();
+        IgniteCache<Float, Float> cFloat = typedCache();
 
         assertEquals(cFloat.get(1.5f), 2.5f);
         assertEquals(cFloat.get(-7.5f), -8.5f);
@@ -2087,7 +2100,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("double", "5.5", "75.5");
         putTypedValue("java.lang.Double", "-155.5", "-255.5");
 
-        IgniteCache<Double, Double> cDouble = jcache();
+        IgniteCache<Double, Double> cDouble = typedCache();
 
         assertEquals(cDouble.get(5.5d), 75.5d);
         assertEquals(cDouble.get(-155.5d), -255.5d);
@@ -2096,7 +2109,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("Date", "2018-02-18", "2017-01-01");
         putTypedValue("java.sql.Date", "2018-01-01", "2017-02-02");
 
-        IgniteCache<Date, Date> cDate = jcache();
+        IgniteCache<Date, Date> cDate = typedCache();
 
         assertEquals(cDate.get(Date.valueOf("2018-02-18")), Date.valueOf("2017-01-01"));
         assertEquals(cDate.get(Date.valueOf("2018-01-01")), Date.valueOf("2017-02-02"));
@@ -2105,7 +2118,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("Time", "01:01:01", "02:02:02");
         putTypedValue("java.sql.Time", "03:03:03", "04:04:04");
 
-        IgniteCache<Time, Time> cTime = jcache();
+        IgniteCache<Time, Time> cTime = typedCache();
 
         assertEquals(cTime.get(Time.valueOf("01:01:01")), Time.valueOf("02:02:02"));
         assertEquals(cTime.get(Time.valueOf("03:03:03")), Time.valueOf("04:04:04"));
@@ -2114,7 +2127,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("Timestamp", "2018-02-18%2001:01:01", "2017-01-01%2002:02:02");
         putTypedValue("java.sql.timestamp", "2018-01-01%2001:01:01", "2018-05-05%2005:05:05");
 
-        IgniteCache<Timestamp, Timestamp> cTimestamp = jcache();
+        IgniteCache<Timestamp, Timestamp> cTimestamp = typedCache();
 
         assertEquals(cTimestamp.get(Timestamp.valueOf("2018-02-18 01:01:01")), Timestamp.valueOf("2017-01-01
02:02:02"));
         assertEquals(cTimestamp.get(Timestamp.valueOf("2018-01-01 01:01:01")), Timestamp.valueOf("2018-05-05
05:05:05"));
@@ -2128,7 +2141,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         UUID v2 = UUID.randomUUID();
         putTypedValue("java.util.UUID", k2.toString(), v2.toString());
 
-        IgniteCache<UUID, UUID> cUUID = jcache();
+        IgniteCache<UUID, UUID> cUUID = typedCache();
 
         assertEquals(cUUID.get(k1), v1);
         assertEquals(cUUID.get(k2), v2);
@@ -2142,30 +2155,35 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         putTypedValue("IgniteUuid", ik1.toString(), iv1.toString());
         putTypedValue("org.apache.ignite.lang.IgniteUuid", ik2.toString(), iv2.toString());
 
-        IgniteCache<IgniteUuid, IgniteUuid> cIgniteUUID = jcache();
+        IgniteCache<IgniteUuid, IgniteUuid> cIgniteUUID = typedCache();
 
         assertEquals(cIgniteUUID.get(ik1), iv1);
         assertEquals(cIgniteUUID.get(ik2), iv2);
     }
 
-    private void getTypedValue(String type, String k, String v) throws Exception {
-        String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_GET,
-            "keyType", type,
+    /**
+     * @param keyType Key type.
+     * @param k Key value.
+     * @param exp Expected value to test.
+     * @throws Exception If failed.
+     */
+    private void getTypedValue(String keyType, String k, String exp) throws Exception {
+        String ret = content("test_typed_access", GridRestCommand.CACHE_GET,
+            "keyType", keyType,
             "key", k
         );
 
         info("Command result: " + ret);
 
-        assertEquals(v, jsonResponse(ret).asText());
+        assertEquals(exp, jsonResponse(ret).asText());
     }
 
-
     /**
      * @throws Exception If failed.
      */
     public void testTypedGet() throws Exception {
         // Test boolean type.
-        IgniteCache<Boolean, Boolean> cBool = jcache();
+        IgniteCache<Boolean, Boolean> cBool = typedCache();
 
         cBool.put(true, false);
         cBool.put(false, true);
@@ -2174,7 +2192,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         getTypedValue("java.lang.Boolean", "false", "true");
 
         // Test byte type.
-        IgniteCache<Byte, Byte> cByte = jcache();
+        IgniteCache<Byte, Byte> cByte = typedCache();
 
         cByte.put((byte)77, (byte)55);
         cByte.put((byte)-88, (byte)-10);
@@ -2182,18 +2200,17 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         getTypedValue("byte", "77", "55");
         getTypedValue("java.lang.Byte", "-88", "-10");
 
+        // Test short type.
+        IgniteCache<Short, Short> cShort = typedCache();
+
+        cShort.put((short)2222, (short)3333);
+        cShort.put((short)-11111, (short)-12222);
+
+        getTypedValue("short", "2222", "3333");
+        getTypedValue("java.lang.Short", "-11111", "-12222");
 
-//        // Test short type.
-//        putTypedValue("short", "1024", "4096");
-//        putTypedValue("java.lang.Short", "-15000", "-16000");
-//
-//        IgniteCache<Short, Short> cShort = jcache();
-//
-//        assertEquals(cShort.get(Short.valueOf("1024")), Short.valueOf("4096"));
-//        assertEquals(cShort.get(Short.valueOf("-15000")), Short.valueOf("-16000"));
-//
         // Test integer type.
-        IgniteCache<Integer, Integer> cInt = jcache();
+        IgniteCache<Integer, Integer> cInt = typedCache();
         cInt.put(65555, 128256);
         cInt.put(74555, 200000);
         cInt.put(-200, -100000);
@@ -2202,89 +2219,88 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         getTypedValue("Integer", "74555", "200000");
         getTypedValue("java.lang.Integer", "-200", "-100000");
 
+        // Test long type.
+        IgniteCache<Long, Long> cLong = typedCache();
+
+        cLong.put(3333333L, 4444444L);
+        cLong.put(-3333333L, -4444444L);
+
+        getTypedValue("long", "3333333", "4444444");
+        getTypedValue("java.lang.Long", "-3333333", "-4444444");
+
+        // Test float type.
+        IgniteCache<Float, Float> cFloat = typedCache();
+
+        cFloat.put(11.5f, 21.5f);
+        cFloat.put(-71.5f, -81.5f);
+
+        getTypedValue("float", "11.5", "21.5");
+        getTypedValue("java.lang.Float", "-71.5", "-81.5");
+
+        // Test double type.
+        IgniteCache<Double, Double> cDouble = typedCache();
+
+        cDouble.put(58.5d, 758.5d);
+        cDouble.put(-1558.5d, -2558.5d);
+
+        getTypedValue("double", "58.5", "758.5");
+        getTypedValue("java.lang.Double", "-1558.5", "-2558.5");
+
+        // Test date type.
+        IgniteCache<Date, Date> cDate = typedCache();
+
+        cDate.put(Date.valueOf("2018-02-18"), Date.valueOf("2017-01-01"));
+        cDate.put(Date.valueOf("2018-01-01"), Date.valueOf("2017-02-02"));
+
+        getTypedValue("Date", "2018-02-18", "2017-01-01");
+        getTypedValue("java.sql.Date", "2018-01-01", "2017-02-02");
+
+        // Test time type.
+        IgniteCache<Time, Time> cTime = typedCache();
+
+        cTime.put(Time.valueOf("01:01:01"), Time.valueOf("02:02:02"));
+        cTime.put(Time.valueOf("03:03:03"), Time.valueOf("04:04:04"));
+
+        getTypedValue("Time", "01:01:01", "02:02:02");
+        getTypedValue("java.sql.Time", "03:03:03", "04:04:04");
+
+        // Test timestamp type.
+        IgniteCache<Timestamp, String> cTimestamp = typedCache();
+
+        cTimestamp.put(Timestamp.valueOf("2018-02-18 01:01:01"), "test1");
+        cTimestamp.put(Timestamp.valueOf("2018-01-01 01:01:01"), "test2");
+
+        getTypedValue("Timestamp", "2018-02-18%2001:01:01", "test1");
+        getTypedValue("java.sql.timestamp", "2018-01-01%2001:01:01", "test2");
+
+        // Test UUID type.
+        IgniteCache<UUID, UUID> cUUID = typedCache();
+
+        UUID k1 = UUID.fromString("121f5ae8-148d-11e8-b642-0ed5f89f718b");
+        UUID v1 = UUID.fromString("64c6c225-b31c-4000-b136-ef14562ac785");
+        cUUID.put(k1, v1);
+
+        UUID k2 = UUID.randomUUID();
+        UUID v2 = UUID.randomUUID();
+        cUUID.put(k2, v2);
+
+        getTypedValue("UUID", k1.toString(), v1.toString());
+        getTypedValue("java.util.UUID", k2.toString(), v2.toString());
+
+
+        // Test IgniteUuid type.
+        IgniteCache<IgniteUuid, IgniteUuid> cIgniteUUID = typedCache();
 
+        IgniteUuid ik1 = IgniteUuid.randomUuid();
+        IgniteUuid iv1 = IgniteUuid.randomUuid();
+        cIgniteUUID.put(ik1, iv1);
 
-//        // Test long type.
-//        putTypedValue("long", "3000000", "400000");
-//        putTypedValue("java.lang.Long", "-3000000", "-400000");
-//
-//        IgniteCache<Long, Long> cLong = jcache();
-//
-//        assertEquals(cLong.get(3000000L), Long.valueOf(400000));
-//        assertEquals(cLong.get(-3000000L), Long.valueOf(-400000));
-//
-//        // Test float type.
-//        putTypedValue("float", "1.5", "2.5");
-//        putTypedValue("java.lang.Float", "-7.5", "-8.5");
-//
-//        IgniteCache<Float, Float> cFloat = jcache();
-//
-//        assertEquals(cFloat.get(1.5f), 2.5f);
-//        assertEquals(cFloat.get(-7.5f), -8.5f);
-//
-//        // Test double type.
-//        putTypedValue("double", "5.5", "75.5");
-//        putTypedValue("java.lang.Double", "-155.5", "-255.5");
-//
-//        IgniteCache<Double, Double> cDouble = jcache();
-//
-//        assertEquals(cDouble.get(5.5d), 75.5d);
-//        assertEquals(cDouble.get(-155.5d), -255.5d);
-//
-//        // Test date type.
-//        putTypedValue("Date", "2018-02-18", "2017-01-01");
-//        putTypedValue("java.sql.Date", "2018-01-01", "2017-02-02");
-//
-//        IgniteCache<Date, Date> cDate = jcache();
-//
-//        assertEquals(cDate.get(Date.valueOf("2018-02-18")), Date.valueOf("2017-01-01"));
-//        assertEquals(cDate.get(Date.valueOf("2018-01-01")), Date.valueOf("2017-02-02"));
-//
-//        // Test time type.
-//        putTypedValue("Time", "01:01:01", "02:02:02");
-//        putTypedValue("java.sql.Time", "03:03:03", "04:04:04");
-//
-//        IgniteCache<Time, Time> cTime = jcache();
-//
-//        assertEquals(cTime.get(Time.valueOf("01:01:01")), Time.valueOf("02:02:02"));
-//        assertEquals(cTime.get(Time.valueOf("03:03:03")), Time.valueOf("04:04:04"));
-//
-//        // Test timestamp type.
-//        putTypedValue("Timestamp", "2018-02-18%2001:01:01", "2017-01-01%2002:02:02");
-//        putTypedValue("java.sql.timestamp", "2018-01-01%2001:01:01", "2018-05-05%2005:05:05");
-//
-//        IgniteCache<Timestamp, Timestamp> cTimestamp = jcache();
-//
-//        assertEquals(cTimestamp.get(Timestamp.valueOf("2018-02-18 01:01:01")), Timestamp.valueOf("2017-01-01
02:02:02"));
-//        assertEquals(cTimestamp.get(Timestamp.valueOf("2018-01-01 01:01:01")), Timestamp.valueOf("2018-05-05
05:05:05"));
-//
-//        // Test UUID type.
-//        UUID k1 = UUID.fromString("121f5ae8-148d-11e8-b642-0ed5f89f718b");
-//        UUID v1 = UUID.fromString("64c6c225-b31c-4000-b136-ef14562ac785");
-//        putTypedValue("UUID", k1.toString(), v1.toString());
-//
-//        UUID k2 = UUID.randomUUID();
-//        UUID v2 = UUID.randomUUID();
-//        putTypedValue("java.util.UUID", k2.toString(), v2.toString());
-//
-//        IgniteCache<UUID, UUID> cUUID = jcache();
-//
-//        assertEquals(cUUID.get(k1), v1);
-//        assertEquals(cUUID.get(k2), v2);
-//
-//        // Test IgniteUuid type.
-//        IgniteUuid ik1 = IgniteUuid.randomUuid();
-//        IgniteUuid iv1 = IgniteUuid.randomUuid();
-//        IgniteUuid ik2 = IgniteUuid.randomUuid();
-//        IgniteUuid iv2 = IgniteUuid.randomUuid();
-//
-//        putTypedValue("IgniteUuid", ik1.toString(), iv1.toString());
-//        putTypedValue("org.apache.ignite.lang.IgniteUuid", ik2.toString(), iv2.toString());
-//
-//        IgniteCache<IgniteUuid, IgniteUuid> cIgniteUUID = jcache();
-//
-//        assertEquals(cIgniteUUID.get(ik1), iv1);
-//        assertEquals(cIgniteUUID.get(ik2), iv2);
+        IgniteUuid ik2 = IgniteUuid.randomUuid();
+        IgniteUuid iv2 = IgniteUuid.randomUuid();
+        cIgniteUUID.put(ik2, iv2);
+
+        getTypedValue("IgniteUuid", ik1.toString(), iv1.toString());
+        getTypedValue("org.apache.ignite.lang.IgniteUuid", ik2.toString(), iv2.toString());
     }
 
     /**
@@ -2317,6 +2333,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
      * Init cache.
      */
     protected void initCache() {
+        CacheConfiguration typedCache = new CacheConfiguration<>("test_typed_access");
+        ignite(0).getOrCreateCache(typedCache);
+
         CacheConfiguration<Integer, Organization> orgCacheCfg = new CacheConfiguration<>("organization");
 
         orgCacheCfg.setIndexedTypes(Integer.class, Organization.class);


Mime
View raw message