ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [3/4] incubator-ignite git commit: # IGNITE-153 Fixed test.
Date Sun, 15 Feb 2015 14:11:46 GMT
# IGNITE-153 Fixed test.


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

Branch: refs/heads/IGNITE-160
Commit: 9671e2187279f78c46973b06ee5c3b4e8daee64b
Parents: d85ccfc
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Sun Feb 15 18:39:17 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Sun Feb 15 18:39:17 2015 +0700

----------------------------------------------------------------------
 .../commands/cache/VisorCacheCommandSpec.scala  | 106 +++++++++++++------
 1 file changed, 71 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9671e218/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
----------------------------------------------------------------------
diff --git a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
index d9241e0..4b1f9b8 100644
--- a/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
+++ b/modules/visor-console/src/test/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommandSpec.scala
@@ -18,40 +18,74 @@
 package org.apache.ignite.visor.commands.cache
 
 import org.apache.ignite.Ignition
+import org.apache.ignite.cache.CacheAtomicityMode._
+import org.apache.ignite.cache.CacheMode._
+import org.apache.ignite.cache.query.Query._
 import org.apache.ignite.cache.query.annotations.QuerySqlField
-import org.apache.ignite.visor.visor
-import org.scalatest._
+import org.apache.ignite.configuration._
+import org.apache.ignite.spi.discovery.tcp._
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm._
 
+import org.jetbrains.annotations._
+
+import org.apache.ignite.visor._
 import org.apache.ignite.visor.commands.cache.VisorCacheCommand._
 
 /**
  * Unit test for 'events' command.
  */
-class VisorCacheCommandSpec extends FlatSpec with Matchers with BeforeAndAfterAll {
+class VisorCacheCommandSpec extends VisorRuntimeBaseSpec(1) {
+    behavior of "A 'cache' visor command"
+
+    /** IP finder. */
+    val ipFinder = new TcpDiscoveryVmIpFinder(true)
+
     /**
-     * Open Visor.
+     * @param name Cache name.
+     * @return Cache Configuration.
      */
-    override def beforeAll() {
-        val g = Ignition.start("examples/config/example-cache.xml")
+    def cacheConfig(@Nullable name: String): CacheConfiguration = {
+        val cfg = new CacheConfiguration
+
+        cfg.setCacheMode(REPLICATED)
+        cfg.setAtomicityMode(TRANSACTIONAL)
+        cfg.setName(name)
+        cfg.setQueryIndexEnabled(true)
+
+        val qc = new CacheQueryConfiguration()
 
-        assert(g.caches().size() > 0)
+        qc.setIndexPrimitiveKey(true)
+        qc.setIndexFixedTyping(true)
 
-        visor.open("-d")
+        cfg.setQueryConfiguration(qc)
+
+        cfg
     }
 
     /**
-     * Close Visor.
+     * Creates grid configuration for provided grid host.
+     *
+     * @param name Grid name.
+     * @return Grid configuration.
      */
-    override def afterAll() {
-        visor.close()
+    override def config(name: String): IgniteConfiguration = {
+        val cfg = new IgniteConfiguration
 
-        Ignition.stop(false)
-    }
+        cfg.setGridName(name)
+        cfg.setLocalHost("127.0.0.1")
+        cfg.setCacheConfiguration(cacheConfig("replicated"))
 
-    behavior of "A 'cache' visor command"
+        val discoSpi = new TcpDiscoverySpi()
+
+        discoSpi.setIpFinder(ipFinder)
+
+        cfg.setDiscoverySpi(discoSpi)
+
+        cfg
+    }
 
     it should "put/get some values to/from cache and display information about caches" in
{
-        val c = Ignition.ignite.jcache[String, String]("partitioned")
+        val c = Ignition.ignite("node-1").jcache[String, String]("replicated")
 
         for (i <- 0 to 3) {
             val kv = "" + i
@@ -64,26 +98,28 @@ class VisorCacheCommandSpec extends FlatSpec with Matchers with BeforeAndAfterAl
         visor.cache()
     }
 
-// TODO IGNITE-153 Fix in sprint-2 after new SQL API will implemented.
-//    it should "run query and display information about caches" in {
-//        val g = Ignition.ignite
-//
-//        val c = g.cache[Int, Foo]("replicated")
-//
-//        c.put(0, Foo(20))
-//        c.put(1, Foo(100))
-//        c.put(2, Foo(101))
-//        c.put(3, Foo(150))
-//
-//        // Create two queries
-//        val q1 = c.queries().createSqlQuery(classOf[Foo], "_key > ?")
-//        c.queries().createSqlQuery(classOf[Foo], "_key = ?")
-//
-//        // Execute only one query
-//        q1.execute(100.asInstanceOf[java.lang.Integer]).get
-//
-//        visor cache "-a"
-//    }
+    it should "run query and display information about caches" in {
+        val g = Ignition.ignite("node-1")
+
+        val c = g.jcache[Int, Foo]("replicated")
+
+        c.put(0, Foo(20))
+        c.put(1, Foo(100))
+        c.put(2, Foo(101))
+        c.put(3, Foo(150))
+
+        // Create and execute query that mast return 2 rows.
+        val q1 = c.query(sql(classOf[Foo], "_key > ?").setArgs(java.lang.Integer.valueOf(1))).getAll()
+
+        assert(q1.size() == 2)
+
+        // Create and execute query that mast return 0 rows.
+        val q2 = c.query(sql(classOf[Foo], "_key > ?").setArgs(java.lang.Integer.valueOf(100))).getAll()
+
+        assert(q2.size() == 0)
+
+        visor cache "-a"
+    }
 
     it should "display correct information for 'replicated' cache only" in {
         visor cache "-n=replicated -a"


Mime
View raw message