Repository: incubator-ignite Updated Branches: refs/heads/ignite-63 b89b472d3 -> bda1cbfd2
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala new file mode 100644 index 0000000..596e218 --- /dev/null +++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarConversionsSpec.scala @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gridgain.scalar.tests + +import org.apache.ignite.lang._ +import org.scalatest.FlatSpec +import org.scalatest.matchers.ShouldMatchers +import org.gridgain.scalar._ +import scalar._ +import java.util.concurrent.atomic._ +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner +import org.apache.ignite.internal.util.lang._ + +/** + * + */ +@RunWith(classOf[JUnitRunner]) +class ScalarConversionsSpec extends FlatSpec with ShouldMatchers { + behavior of "Scalar mixin" + + it should "convert reducer" in { + val r = new IgniteReducer[Int, Int] { + var sum = 0 + + override def collect(e: Int): Boolean = { + sum += e + + true + } + + override def reduce(): Int = { + sum + } + } + + assert(r.scala.apply(Seq(1, 2, 3)) == 6) + } + + it should "convert reducer 2" in { + val r = new IgniteReducer2[Int, Int, Int] { + var sum = 0 + + override def collect(e1: Int, e2: Int): Boolean = { + sum += e1 * e2 + + true + } + + override def apply(): Int = { + sum + } + } + + assert(r.scala.apply(Seq(1, 2), Seq(3, 4)) == 21) + } + + it should "convert reducer 3" in { + val r = new IgniteReducer3[Int, Int, Int, Int] { + var sum = 0 + + override def collect(e1: Int, e2: Int, e3: Int): Boolean = { + sum += e1 * e2 * e3 + + true + } + + override def apply(): Int = { + sum + } + } + + assert(r.scala.apply(Seq(1, 2), Seq(1, 2), Seq(1, 2)) == 27) + } + + it should "convert tuple 2" in { + val t = new IgniteBiTuple[Int, Int](1, 2) + + assert(t.scala._1 == 1) + assert(t.scala._2 == 2) + } + + it should "convert tuple 3" in { + val t = new GridTuple3[Int, Int, Int](1, 2, 3) + + assert(t.scala._1 == 1) + assert(t.scala._2 == 2) + assert(t.scala._3 == 3) + } + + it should "convert tuple 4" in { + val t = new GridTuple4[Int, Int, Int, Int](1, 2, 3, 4) + + assert(t.scala._1 == 1) + assert(t.scala._2 == 2) + assert(t.scala._3 == 3) + assert(t.scala._4 == 4) + } + + it should "convert tuple 5" in { + val t = new GridTuple5[Int, Int, Int, Int, Int](1, 2, 3, 4, 5) + + assert(t.scala._1 == 1) + assert(t.scala._2 == 2) + assert(t.scala._3 == 3) + assert(t.scala._4 == 4) + assert(t.scala._5 == 5) + } + + it should "convert in closure" in { + val i = new AtomicInteger() + + val f = new IgniteInClosure[Int] { + override def apply(e: Int) { + i.set(e * 3) + } + } + + f.scala.apply(3) + + assert(i.get == 9) + } + + it should "convert in closure 2" in { + val i = new AtomicInteger() + + val f = new IgniteBiInClosure[Int, Int] { + override def apply(e1: Int, e2: Int) { + i.set(e1 + e2) + } + } + + f.scala.apply(3, 3) + + assert(i.get == 6) + } + + it should "convert in closure 3" in { + val i = new AtomicInteger() + + val f = new GridInClosure3[Int, Int, Int] { + override def apply(e1: Int, e2: Int, e3: Int) { + i.set(e1 + e2 + e3) + } + } + + f.scala.apply(3, 3, 3) + + assert(i.get == 9) + } + + it should "convert absolute closure" in { + val i = new AtomicInteger() + + val f = new GridAbsClosure { + override def apply() { + i.set(3) + } + } + + f.scala.apply() + + assert(i.get == 3) + } + + it should "convert absolute predicate" in { + val i = new AtomicInteger() + + val p = new GridAbsPredicate { + override def apply(): Boolean = + i.get > 5 + } + + i.set(5) + + assert(!p.scala.apply()) + + i.set(6) + + assert(p.scala.apply()) + } + + it should "convert predicate" in { + val p = new IgnitePredicate[Int] { + override def apply(e: Int): Boolean = + e > 5 + } + + assert(!p.scala.apply(5)) + assert(p.scala.apply(6)) + } + + it should "convert predicate 2" in { + val p = new IgniteBiPredicate[Int, Int] { + override def apply(e1: Int, e2: Int): Boolean = + e1 + e2 > 5 + } + + assert(!p.scala.apply(2, 3)) + assert(p.scala.apply(3, 3)) + } + + it should "convert predicate 3" in { + val p = new GridPredicate3[Int, Int, Int] { + override def apply(e1: Int, e2: Int, e3: Int): Boolean = + e1 + e2 + e3 > 5 + } + + assert(!p.scala.apply(1, 2, 2)) + assert(p.scala.apply(2, 2, 2)) + } + + it should "convert closure" in { + val f = new IgniteClosure[Int, Int] { + override def apply(e: Int): Int = + e * 3 + } + + assert(f.scala.apply(3) == 9) + } + + it should "convert closure 2" in { + val f = new IgniteBiClosure[Int, Int, Int] { + override def apply(e1: Int, e2: Int): Int = + e1 + e2 + } + + assert(f.scala.apply(3, 3) == 6) + } + + it should "convert closure 3" in { + val f = new GridClosure3[Int, Int, Int, Int] { + override def apply(e1: Int, e2: Int, e3: Int): Int = + e1 + e2 + e3 + } + + assert(f.scala.apply(3, 3, 3) == 9) + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala new file mode 100644 index 0000000..df85c08 --- /dev/null +++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarProjectionSpec.scala @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gridgain.scalar.tests + +import org.apache.ignite.Ignition +import org.apache.ignite.cluster.ClusterNode +import org.apache.ignite.configuration.IgniteConfiguration +import org.apache.ignite.messaging.MessagingListenActor +import org.gridgain.scalar._ +import scalar._ +import org.scalatest.matchers._ +import org.scalatest._ +import junit.JUnitRunner +import org.apache.ignite._ +import org.gridgain.grid._ +import collection.JavaConversions._ +import java.util.UUID +import org.junit.runner.RunWith + +/** + * Scalar cache test. + */ +@RunWith(classOf[JUnitRunner]) +class ScalarProjectionSpec extends FlatSpec with ShouldMatchers with BeforeAndAfterAll { + /** + * + */ + override def beforeAll() { + Ignition.start(gridConfig("node-1", false)) + Ignition.start(gridConfig("node-2", true)) + } + + /** + * + */ + override def afterAll() { + Ignition.stop("node-1", true) + Ignition.stop("node-2", true) + } + + /** + * + * @param name Grid name. + * @param shown Shown flag. + */ + private def gridConfig(name: String, shown: Boolean): IgniteConfiguration = { + val attrs: java.util.Map[String, Boolean] = Map[String, Boolean]("shown" -> shown) + + val cfg = new IgniteConfiguration + + cfg.setGridName(name) + cfg.setUserAttributes(attrs) + + cfg + } + + behavior of "ScalarProjectionPimp class" + + it should "return all nodes" in scalar(gridConfig("node-scalar", true)) { + assertResult(3) { + grid$("node-scalar").get.cluster().nodes().size + } + } + + it should "return shown nodes" in scalar(gridConfig("node-scalar", true)) { + assert(grid$("node-scalar").get.nodes$((node: ClusterNode) => node.attribute[Boolean]("shown")).size == 2) + } + + it should "return all remote nodes" in scalar(gridConfig("node-scalar", true)) { + assertResult(2) { + grid$("node-scalar").get.remoteNodes$().size + } + } + + it should "return shown remote nodes" in scalar(gridConfig("node-scalar", true)) { + assert(grid$("node-scalar").get.remoteNodes$((node: ClusterNode) => + node.attribute[Boolean]("shown")).size == 1) + } + + it should "correctly send messages" in scalar(gridConfig("node-scalar", true)) { + + grid$("node-1").get.message().remoteListen(null, new MessagingListenActor[Any]() { + def receive(nodeId: UUID, msg: Any) { + println("node-1 received " + msg) + } + }) + + grid$("node-2").get.message().remoteListen(null, new MessagingListenActor[Any]() { + def receive(nodeId: UUID, msg: Any) { + println("node-2 received " + msg) + } + }) + + grid$("node-scalar").get !< ("Message", null) + grid$("node-scalar").get !< (Seq("Message1", "Message2"), null) + } + + it should "correctly make calls" in scalar(gridConfig("node-scalar", true)) { + println("CALL RESULT: " + grid$("node-scalar").get #< (() => "Message", null)) + + println("ASYNC CALL RESULT: " + grid$("node-scalar").get.callAsync$[String](() => "Message", null).get) + + val call1: () => String = () => "Message1" + val call2: () => String = () => "Message2" + + println("MULTIPLE CALL RESULT: " + grid$("node-scalar").get #< (Seq(call1, call2), null)) + + println("MULTIPLE ASYNC CALL RESULT: " + + (grid$("node-scalar").get #? (Seq(call1, call2), null)).get) + } + + it should "correctly make runs" in scalar(gridConfig("node-scalar", true)) { + grid$("node-scalar").get *< (() => println("RUN RESULT: Message"), null) + + (grid$("node-scalar").get *? (() => println("ASYNC RUN RESULT: Message"), null)).get + + val run1: () => Unit = () => println("RUN 1 RESULT: Message1") + val run2: () => Unit = () => println("RUN 2 RESULT: Message2") + + grid$("node-scalar").get *< (Seq(run1, run2), null) + + val runAsync1: () => Unit = () => println("ASYNC RUN 1 RESULT: Message1") + val runAsync2: () => Unit = () => println("ASYNC RUN 2 RESULT: Message2") + + (grid$("node-scalar").get *? (Seq(runAsync1, runAsync2), null)).get + } + + it should "correctly reduce" in scalar(gridConfig("node-scalar", true)) { + val call1: () => Int = () => 15 + val call2: () => Int = () => 82 + + assert(grid$("node-scalar").get @< (Seq(call1, call2), (n: Seq[Int]) => n.sum, null) == 97) + assert(grid$("node-scalar").get.reduceAsync$(Seq(call1, call2), (n: Seq[Int]) => n.sum, null).get == 97) + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala new file mode 100644 index 0000000..607db68 --- /dev/null +++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarReturnableSpec.scala @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gridgain.scalar.tests + +import org.scalatest.matchers._ +import org.gridgain.scalar._ +import scalar._ +import org.scalatest._ +import junit.JUnitRunner +import scala.util.control.Breaks._ +import org.junit.runner.RunWith + +/** + * + */ +@RunWith(classOf[JUnitRunner]) +class ScalarReturnableSpec extends FlatSpec with ShouldMatchers { + "Scalar '^^'" should "work" in { + var i = 0 + + breakable { + while (true) { + if (i == 0) + println("Only once!") ^^ + + i += 1 + } + } + + assert(i == 0) + } + + "Scalar '^^'" should "also work" in { + test() + } + + // Ignore exception below. + def test() = breakable { + while (true) { + println("Only once!") ^^ + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarSpec.scala new file mode 100644 index 0000000..0dcad14 --- /dev/null +++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarSpec.scala @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gridgain.scalar.tests + +import org.gridgain.scalar._ +import org.scalatest._ +import junit.JUnitRunner +import org.junit.runner.RunWith + +/** + * + */ +@RunWith(classOf[JUnitRunner]) +class ScalarSpec extends FunSpec { + describe("Scalar") { + it("should start and stop") { + scalar start() + scalar.logo() + scalar stop() + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/apache/ignite/scalar/testsuites/ScalarSelfTestSuite.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/testsuites/ScalarSelfTestSuite.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/testsuites/ScalarSelfTestSuite.scala new file mode 100644 index 0000000..12b0bd4 --- /dev/null +++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/testsuites/ScalarSelfTestSuite.scala @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.gridgain.scalar.testsuites + +import org.scalatest._ +import org.gridgain.scalar.tests._ +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +/** + * + */ +@RunWith(classOf[JUnitRunner]) +class ScalarSelfTestSuite extends Suites( + new ScalarAffinityRoutingSpec, + new ScalarCacheQueriesSpec, + new ScalarCacheSpec, + new ScalarConversionsSpec, + new ScalarProjectionSpec, + new ScalarReturnableSpec, + new ScalarSpec +) { +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarAffinityRoutingSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarAffinityRoutingSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarAffinityRoutingSpec.scala deleted file mode 100644 index 989e72d..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarAffinityRoutingSpec.scala +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.scalatest.matchers._ -import org.scalatest._ -import junit.JUnitRunner -import org.gridgain.scalar.scalar -import scalar._ -import collection.JavaConversions._ -import java.util.concurrent.atomic.AtomicInteger -import org.junit.runner.RunWith - -/** - * Tests for `affinityRun..` and `affinityCall..` methods. - */ -@RunWith(classOf[JUnitRunner]) -class ScalarAffinityRoutingSpec extends FlatSpec with ShouldMatchers with BeforeAndAfterAll { - /** Cache name. */ - private val CACHE_NAME = "partitioned_tx" - - "affinityRun$ method" should "run correctly" in scalar("examples/config/example-cache.xml") { - val c = cache$[Int, Int](CACHE_NAME).get - - c += (0 -> 0) - c += (1 -> 1) - c += (2 -> 2) - - val cnt = c.dataStructures().atomicLong("affinityRun", 0, true) - - grid$.affinityRun$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null) - grid$.affinityRun$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null) - grid$.affinityRun$(CACHE_NAME, 2, () => { cnt.incrementAndGet() }, null) - - assert(cnt.get === 3) - } - - "affinityRunAsync$ method" should "run correctly" in scalar("examples/config/example-cache.xml") { - val c = cache$[Int, Int](CACHE_NAME).get - - c += (0 -> 0) - c += (1 -> 1) - c += (2 -> 2) - - val cnt = c.dataStructures().atomicLong("affinityRunAsync", 0, true) - - grid$.affinityRunAsync$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null).get - grid$.affinityRunAsync$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null).get - grid$.affinityRunAsync$(CACHE_NAME, 2, () => { cnt.incrementAndGet() }, null).get - - assert(cnt.get === 3) - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheProjectionSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheProjectionSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheProjectionSpec.scala deleted file mode 100644 index 0714f16..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheProjectionSpec.scala +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.gridgain.scalar._ -import scalar._ -import org.scalatest.FlatSpec -import org.scalatest.junit.JUnitRunner -import org.junit.runner.RunWith - -/** - * Test for using grid.cache(..).projection(...) from scala code. - */ -@RunWith(classOf[JUnitRunner]) -class ScalarCacheProjectionSpec extends FlatSpec { - behavior of "Cache projection" - - it should "work properly via grid.cache(...).viewByType(...)" in scalar("examples/config/example-cache.xml") { - val cache = grid$.cache("local").viewByType(classOf[String], classOf[Int]) - - assert(cache.putx("1", 1)) - assert(cache.get("1") == 1) - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheQueriesSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheQueriesSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheQueriesSpec.scala deleted file mode 100644 index 08d3b7d..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheQueriesSpec.scala +++ /dev/null @@ -1,601 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.apache.ignite.cache.GridCache -import org.apache.ignite.cluster.ClusterNode -import org.gridgain.scalar._ -import scalar._ -import org.scalatest.matchers._ -import org.scalatest._ -import junit.JUnitRunner -import org.gridgain.grid.cache._ -import org.apache.ignite._ -import org.gridgain.grid._ -import org.junit.runner.RunWith - -/** - * Tests for Scalar cache queries API. - */ -@RunWith(classOf[JUnitRunner]) -class ScalarCacheQueriesSpec extends FlatSpec with ShouldMatchers with BeforeAndAfterAll { - /** Entries count. */ - private val ENTRY_CNT = 10 - - /** Words. */ - private val WORDS = List("", "one", "two", "three", "four", "five", - "six", "seven", "eight", "nine", "ten") - - /** Node. */ - private var n: ClusterNode = null - - /** Cache. */ - private var c: GridCache[Int, ObjectValue] = null - - /** - * Start node and put data to cache. - */ - override def beforeAll() { - n = start("modules/scalar/src/test/resources/spring-cache.xml").cluster().localNode - - c = cache$[Int, ObjectValue].get - - (1 to ENTRY_CNT).foreach(i => c.putx(i, ObjectValue(i, "str " + WORDS(i)))) - - assert(c.size == ENTRY_CNT) - - c.foreach(e => println(e.getKey + " -> " + e.getValue)) - } - - /** - * Stop node. - */ - override def afterAll() { - stop() - } - - behavior of "Scalar cache queries API" - - it should "correctly execute SCAN queries" in { - var res = c.scan(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 == t._2.intVal)) - - res = c.scan((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 == t._2.intVal)) - - res = c.scan(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 == t._2.intVal)) - - res = c.scan((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 == t._2.intVal)) - } - - it should "correctly execute SQL queries" in { - var res = c.sql(classOf[ObjectValue], "intVal > 5") - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res = c.sql(classOf[ObjectValue], "intVal > ?", 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res = c.sql("intVal > 5") - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res = c.sql("intVal > ?", 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res = c.sql(classOf[ObjectValue], "intVal > 5") - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res = c.sql(classOf[ObjectValue], "intVal > ?", 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res = c.sql("intVal > 5") - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - - res = c.sql("intVal > ?", 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 == t._2.intVal)) - } - - it should "correctly execute TEXT queries" in { - var res = c.text(classOf[ObjectValue], "str") - - assert(res.size == ENTRY_CNT) - - res = c.text(classOf[ObjectValue], "five") - - assert(res.size == 1) - assert(res.head._1 == 5) - - res = c.text("str") - - assert(res.size == ENTRY_CNT) - - res = c.text("five") - - assert(res.size == 1) - assert(res.head._1 == 5) - - res = c.text(classOf[ObjectValue], "str") - - assert(res.size == ENTRY_CNT) - - res = c.text(classOf[ObjectValue], "five") - - assert(res.size == 1) - assert(res.head._1 == 5) - - res = c.text("str") - - assert(res.size == ENTRY_CNT) - - res = c.text("five") - - assert(res.size == 1) - assert(res.head._1 == 5) - } - - it should "correctly execute SCAN transform queries" in { - var res = c.scanTransform(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 + 1 == t._2)) - - res = c.scanTransform((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 + 1 == t._2)) - - res = c.scanTransform(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 + 1 == t._2)) - - res = c.scanTransform((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 2) - - res.foreach(t => assert(t._1 > 5 && t._1 < 8 && t._1 + 1 == t._2)) - } - - it should "correctly execute SQL transform queries" in { - var res = c.sqlTransform(classOf[ObjectValue], "intVal > 5", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - - res = c.sqlTransform(classOf[ObjectValue], "intVal > ?", (v: ObjectValue) => v.intVal + 1, 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - - res = c.sqlTransform("intVal > 5", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - - res = c.sqlTransform("intVal > ?", (v: ObjectValue) => v.intVal + 1, 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - - res = c.sqlTransform(classOf[ObjectValue], "intVal > 5", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - - res = c.sqlTransform(classOf[ObjectValue], "intVal > ?", (v: ObjectValue) => v.intVal + 1, 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - - res = c.sqlTransform("intVal > 5", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - - res = c.sqlTransform("intVal > ?", (v: ObjectValue) => v.intVal + 1, 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t._1 > 5 && t._1 + 1 == t._2)) - } - - it should "correctly execute TEXT transform queries" in { - var res = c.textTransform(classOf[ObjectValue], "str", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT) - - res.foreach(t => assert(t._1 + 1 == t._2)) - - res = c.textTransform(classOf[ObjectValue], "five", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 1) - assert(res.head._1 == 5 && res.head._2 == 6) - - res = c.textTransform("str", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT) - - res.foreach(t => assert(t._1 + 1 == t._2)) - - res = c.textTransform("five", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 1) - assert(res.head._1 == 5 && res.head._2 == 6) - - res = c.textTransform(classOf[ObjectValue], "str", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT) - - res.foreach(t => assert(t._1 + 1 == t._2)) - - res = c.textTransform(classOf[ObjectValue], "five", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 1) - assert(res.head._1 == 5 && res.head._2 == 6) - - res = c.textTransform("str", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == ENTRY_CNT) - - res.foreach(t => assert(t._1 + 1 == t._2)) - - res = c.textTransform("five", (v: ObjectValue) => v.intVal + 1) - - assert(res.size == 1) - assert(res.head._1 == 5 && res.head._2 == 6) - } - - it should "correctly execute SCAN reduce queries with two reducers" in { - var res = c.scanReduce(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 13) - - res = c.scanReduce((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 13) - - res = c.scanReduce(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 13) - - res = c.scanReduce((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 13) - } - - it should "correctly execute SQL reduce queries with two reducers" in { - var res = c.sqlReduce(classOf[ObjectValue], "intVal > 5", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 40) - - res = c.sqlReduce(classOf[ObjectValue], "intVal > ?", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum, 3) - - assert(res == 49) - - res = c.sqlReduce("intVal > 5", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 40) - - res = c.sqlReduce("intVal > ?", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum, 3) - - assert(res == 49) - - res = c.sqlReduce(classOf[ObjectValue], "intVal > 5", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 40) - - res = c.sqlReduce(classOf[ObjectValue], "intVal > ?", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum, 3) - - assert(res == 49) - - res = c.sqlReduce("intVal > 5", (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, - (i: Iterable[Int]) => i.sum) - - assert(res == 40) - - res = c.sqlReduce("intVal > ?", (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, - (i: Iterable[Int]) => i.sum, 3) - - assert(res == 49) - } - - it should "correctly execute TEXT reduce queries with two reducers" in { - var res = c.textReduce(classOf[ObjectValue], "str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce(classOf[ObjectValue], "three five seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 15) - - res = c.textReduce("str", (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, - (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce("three five seven", (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, - (i: Iterable[Int]) => i.sum) - - assert(res == 15) - - res = c.textReduce(classOf[ObjectValue], "str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce(classOf[ObjectValue], "three five seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 15) - - res = c.textReduce("str", (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, - (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce("three five seven", (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, - (i: Iterable[Int]) => i.sum) - - assert(res == 15) - - res = c.textReduce(classOf[ObjectValue], "str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce(classOf[ObjectValue], "seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 7) - - res = c.textReduce("str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce("seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 7) - - res = c.textReduce(classOf[ObjectValue], "str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce(classOf[ObjectValue], "seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 7) - - res = c.textReduce("str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 55) - - res = c.textReduce("seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, (i: Iterable[Int]) => i.sum) - - assert(res == 7) - } - - it should "correctly execute SCAN reduce queries with one reducer" in { - var res = c.scanReduceRemote(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 13) - - res = c.scanReduceRemote((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 13) - - res = c.scanReduceRemote(classOf[ObjectValue], (k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 13) - - res = c.scanReduceRemote((k: Int, v: ObjectValue) => k > 5 && v.intVal < 8, - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 13) - } - - it should "correctly execute SQL reduce queries with one reducer" in { - var res = c.sqlReduceRemote(classOf[ObjectValue], "intVal > 5", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 40) - - res = c.sqlReduceRemote(classOf[ObjectValue], "intVal > ?", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, 3) - - assert(res.sum == 49) - - res = c.sqlReduceRemote("intVal > 5", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 40) - - res = c.sqlReduceRemote("intVal > ?", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, 3) - - assert(res.sum == 49) - - res = c.sqlReduceRemote(classOf[ObjectValue], "intVal > 5", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 40) - - res = c.sqlReduceRemote(classOf[ObjectValue], "intVal > ?", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, 3) - - assert(res.sum == 49) - - res = c.sqlReduceRemote("intVal > 5", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 40) - - res = c.sqlReduceRemote("intVal > ?", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum, 3) - - assert(res.sum == 49) - } - - it should "correctly execute TEXT reduce queries with one reducer" in { - var res = c.textReduceRemote(classOf[ObjectValue], "str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 55) - - res = c.textReduceRemote(classOf[ObjectValue], "seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 7) - - res = c.textReduceRemote("str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 55) - - res = c.textReduceRemote("seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 7) - - res = c.textReduceRemote(classOf[ObjectValue], "str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 55) - - res = c.textReduceRemote(classOf[ObjectValue], "seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 7) - - res = c.textReduceRemote("str", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 55) - - res = c.textReduceRemote("seven", - (i: Iterable[(Int, ObjectValue)]) => i.map(_._2.intVal).sum) - - assert(res.sum == 7) - } - - it should "correctly execute fields queries" in { - var res = c.sqlFields(null, "select intVal from ObjectValue where intVal > 5") - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t.size == 1 && t.head.asInstanceOf[Int] > 5)) - - res = c.sqlFields(null, "select intVal from ObjectValue where intVal > ?", 5) - - assert(res.size == ENTRY_CNT - 5) - - res.foreach(t => assert(t.size == 1 && t.head.asInstanceOf[Int] > 5)) - } - - it should "correctly execute queries with multiple arguments" in { - val res = c.sql("from ObjectValue where intVal in (?, ?, ?)", 1, 2, 3) - - assert(res.size == 3) - } -} - -/** - * Object for queries. - */ -private case class ObjectValue( - /** Integer value. */ - @ScalarCacheQuerySqlField - intVal: Int, - - /** String value. */ - @ScalarCacheQueryTextField - strVal: String -) { - override def toString: String = { - "ObjectValue [" + intVal + ", " + strVal + "]" - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheSpec.scala deleted file mode 100644 index 03432e6..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarCacheSpec.scala +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.apache.ignite.events.{IgniteEventType, IgniteEvent} -import org.apache.ignite.lang.IgnitePredicate -import org.gridgain.scalar._ -import scalar._ -import org.scalatest.matchers._ -import org.scalatest._ -import junit.JUnitRunner -import IgniteEventType._ -import collection.JavaConversions._ -import org.junit.runner.RunWith - -/** - * Scalar cache test. - */ -@RunWith(classOf[JUnitRunner]) -class ScalarCacheSpec extends FlatSpec with ShouldMatchers { - behavior of "Scalar cache" - - it should "work properly via Java APIs" in { - scalar("examples/config/example-cache.xml") { - registerListener() - - val c = cache$("partitioned").get.viewByType(classOf[Int], classOf[Int]) - - c.putx(1, 1) - c.putx(2, 2) - - c.values foreach println - - println("Size is: " + c.size) - } - } - - /** - * This method will register listener for cache events on all nodes, - * so we can actually see what happens underneath locally and remotely. - */ - def registerListener() { - val g = grid$ - - g *< (() => { - val lsnr = new IgnitePredicate[IgniteEvent]() { - override def apply(e: IgniteEvent): Boolean = { - println(e.shortDisplay) - - true - } - } - - if (g.cluster().nodeLocalMap[String, AnyRef].putIfAbsent("lsnr", lsnr) == null) { - g.events.localListen(lsnr, - EVT_CACHE_OBJECT_PUT, - EVT_CACHE_OBJECT_READ, - EVT_CACHE_OBJECT_REMOVED) - - println("Listener is registered.") - } - }, null) - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarConversionsSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarConversionsSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarConversionsSpec.scala deleted file mode 100644 index 596e218..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarConversionsSpec.scala +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.apache.ignite.lang._ -import org.scalatest.FlatSpec -import org.scalatest.matchers.ShouldMatchers -import org.gridgain.scalar._ -import scalar._ -import java.util.concurrent.atomic._ -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner -import org.apache.ignite.internal.util.lang._ - -/** - * - */ -@RunWith(classOf[JUnitRunner]) -class ScalarConversionsSpec extends FlatSpec with ShouldMatchers { - behavior of "Scalar mixin" - - it should "convert reducer" in { - val r = new IgniteReducer[Int, Int] { - var sum = 0 - - override def collect(e: Int): Boolean = { - sum += e - - true - } - - override def reduce(): Int = { - sum - } - } - - assert(r.scala.apply(Seq(1, 2, 3)) == 6) - } - - it should "convert reducer 2" in { - val r = new IgniteReducer2[Int, Int, Int] { - var sum = 0 - - override def collect(e1: Int, e2: Int): Boolean = { - sum += e1 * e2 - - true - } - - override def apply(): Int = { - sum - } - } - - assert(r.scala.apply(Seq(1, 2), Seq(3, 4)) == 21) - } - - it should "convert reducer 3" in { - val r = new IgniteReducer3[Int, Int, Int, Int] { - var sum = 0 - - override def collect(e1: Int, e2: Int, e3: Int): Boolean = { - sum += e1 * e2 * e3 - - true - } - - override def apply(): Int = { - sum - } - } - - assert(r.scala.apply(Seq(1, 2), Seq(1, 2), Seq(1, 2)) == 27) - } - - it should "convert tuple 2" in { - val t = new IgniteBiTuple[Int, Int](1, 2) - - assert(t.scala._1 == 1) - assert(t.scala._2 == 2) - } - - it should "convert tuple 3" in { - val t = new GridTuple3[Int, Int, Int](1, 2, 3) - - assert(t.scala._1 == 1) - assert(t.scala._2 == 2) - assert(t.scala._3 == 3) - } - - it should "convert tuple 4" in { - val t = new GridTuple4[Int, Int, Int, Int](1, 2, 3, 4) - - assert(t.scala._1 == 1) - assert(t.scala._2 == 2) - assert(t.scala._3 == 3) - assert(t.scala._4 == 4) - } - - it should "convert tuple 5" in { - val t = new GridTuple5[Int, Int, Int, Int, Int](1, 2, 3, 4, 5) - - assert(t.scala._1 == 1) - assert(t.scala._2 == 2) - assert(t.scala._3 == 3) - assert(t.scala._4 == 4) - assert(t.scala._5 == 5) - } - - it should "convert in closure" in { - val i = new AtomicInteger() - - val f = new IgniteInClosure[Int] { - override def apply(e: Int) { - i.set(e * 3) - } - } - - f.scala.apply(3) - - assert(i.get == 9) - } - - it should "convert in closure 2" in { - val i = new AtomicInteger() - - val f = new IgniteBiInClosure[Int, Int] { - override def apply(e1: Int, e2: Int) { - i.set(e1 + e2) - } - } - - f.scala.apply(3, 3) - - assert(i.get == 6) - } - - it should "convert in closure 3" in { - val i = new AtomicInteger() - - val f = new GridInClosure3[Int, Int, Int] { - override def apply(e1: Int, e2: Int, e3: Int) { - i.set(e1 + e2 + e3) - } - } - - f.scala.apply(3, 3, 3) - - assert(i.get == 9) - } - - it should "convert absolute closure" in { - val i = new AtomicInteger() - - val f = new GridAbsClosure { - override def apply() { - i.set(3) - } - } - - f.scala.apply() - - assert(i.get == 3) - } - - it should "convert absolute predicate" in { - val i = new AtomicInteger() - - val p = new GridAbsPredicate { - override def apply(): Boolean = - i.get > 5 - } - - i.set(5) - - assert(!p.scala.apply()) - - i.set(6) - - assert(p.scala.apply()) - } - - it should "convert predicate" in { - val p = new IgnitePredicate[Int] { - override def apply(e: Int): Boolean = - e > 5 - } - - assert(!p.scala.apply(5)) - assert(p.scala.apply(6)) - } - - it should "convert predicate 2" in { - val p = new IgniteBiPredicate[Int, Int] { - override def apply(e1: Int, e2: Int): Boolean = - e1 + e2 > 5 - } - - assert(!p.scala.apply(2, 3)) - assert(p.scala.apply(3, 3)) - } - - it should "convert predicate 3" in { - val p = new GridPredicate3[Int, Int, Int] { - override def apply(e1: Int, e2: Int, e3: Int): Boolean = - e1 + e2 + e3 > 5 - } - - assert(!p.scala.apply(1, 2, 2)) - assert(p.scala.apply(2, 2, 2)) - } - - it should "convert closure" in { - val f = new IgniteClosure[Int, Int] { - override def apply(e: Int): Int = - e * 3 - } - - assert(f.scala.apply(3) == 9) - } - - it should "convert closure 2" in { - val f = new IgniteBiClosure[Int, Int, Int] { - override def apply(e1: Int, e2: Int): Int = - e1 + e2 - } - - assert(f.scala.apply(3, 3) == 6) - } - - it should "convert closure 3" in { - val f = new GridClosure3[Int, Int, Int, Int] { - override def apply(e1: Int, e2: Int, e3: Int): Int = - e1 + e2 + e3 - } - - assert(f.scala.apply(3, 3, 3) == 9) - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarProjectionSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarProjectionSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarProjectionSpec.scala deleted file mode 100644 index df85c08..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarProjectionSpec.scala +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.apache.ignite.Ignition -import org.apache.ignite.cluster.ClusterNode -import org.apache.ignite.configuration.IgniteConfiguration -import org.apache.ignite.messaging.MessagingListenActor -import org.gridgain.scalar._ -import scalar._ -import org.scalatest.matchers._ -import org.scalatest._ -import junit.JUnitRunner -import org.apache.ignite._ -import org.gridgain.grid._ -import collection.JavaConversions._ -import java.util.UUID -import org.junit.runner.RunWith - -/** - * Scalar cache test. - */ -@RunWith(classOf[JUnitRunner]) -class ScalarProjectionSpec extends FlatSpec with ShouldMatchers with BeforeAndAfterAll { - /** - * - */ - override def beforeAll() { - Ignition.start(gridConfig("node-1", false)) - Ignition.start(gridConfig("node-2", true)) - } - - /** - * - */ - override def afterAll() { - Ignition.stop("node-1", true) - Ignition.stop("node-2", true) - } - - /** - * - * @param name Grid name. - * @param shown Shown flag. - */ - private def gridConfig(name: String, shown: Boolean): IgniteConfiguration = { - val attrs: java.util.Map[String, Boolean] = Map[String, Boolean]("shown" -> shown) - - val cfg = new IgniteConfiguration - - cfg.setGridName(name) - cfg.setUserAttributes(attrs) - - cfg - } - - behavior of "ScalarProjectionPimp class" - - it should "return all nodes" in scalar(gridConfig("node-scalar", true)) { - assertResult(3) { - grid$("node-scalar").get.cluster().nodes().size - } - } - - it should "return shown nodes" in scalar(gridConfig("node-scalar", true)) { - assert(grid$("node-scalar").get.nodes$((node: ClusterNode) => node.attribute[Boolean]("shown")).size == 2) - } - - it should "return all remote nodes" in scalar(gridConfig("node-scalar", true)) { - assertResult(2) { - grid$("node-scalar").get.remoteNodes$().size - } - } - - it should "return shown remote nodes" in scalar(gridConfig("node-scalar", true)) { - assert(grid$("node-scalar").get.remoteNodes$((node: ClusterNode) => - node.attribute[Boolean]("shown")).size == 1) - } - - it should "correctly send messages" in scalar(gridConfig("node-scalar", true)) { - - grid$("node-1").get.message().remoteListen(null, new MessagingListenActor[Any]() { - def receive(nodeId: UUID, msg: Any) { - println("node-1 received " + msg) - } - }) - - grid$("node-2").get.message().remoteListen(null, new MessagingListenActor[Any]() { - def receive(nodeId: UUID, msg: Any) { - println("node-2 received " + msg) - } - }) - - grid$("node-scalar").get !< ("Message", null) - grid$("node-scalar").get !< (Seq("Message1", "Message2"), null) - } - - it should "correctly make calls" in scalar(gridConfig("node-scalar", true)) { - println("CALL RESULT: " + grid$("node-scalar").get #< (() => "Message", null)) - - println("ASYNC CALL RESULT: " + grid$("node-scalar").get.callAsync$[String](() => "Message", null).get) - - val call1: () => String = () => "Message1" - val call2: () => String = () => "Message2" - - println("MULTIPLE CALL RESULT: " + grid$("node-scalar").get #< (Seq(call1, call2), null)) - - println("MULTIPLE ASYNC CALL RESULT: " + - (grid$("node-scalar").get #? (Seq(call1, call2), null)).get) - } - - it should "correctly make runs" in scalar(gridConfig("node-scalar", true)) { - grid$("node-scalar").get *< (() => println("RUN RESULT: Message"), null) - - (grid$("node-scalar").get *? (() => println("ASYNC RUN RESULT: Message"), null)).get - - val run1: () => Unit = () => println("RUN 1 RESULT: Message1") - val run2: () => Unit = () => println("RUN 2 RESULT: Message2") - - grid$("node-scalar").get *< (Seq(run1, run2), null) - - val runAsync1: () => Unit = () => println("ASYNC RUN 1 RESULT: Message1") - val runAsync2: () => Unit = () => println("ASYNC RUN 2 RESULT: Message2") - - (grid$("node-scalar").get *? (Seq(runAsync1, runAsync2), null)).get - } - - it should "correctly reduce" in scalar(gridConfig("node-scalar", true)) { - val call1: () => Int = () => 15 - val call2: () => Int = () => 82 - - assert(grid$("node-scalar").get @< (Seq(call1, call2), (n: Seq[Int]) => n.sum, null) == 97) - assert(grid$("node-scalar").get.reduceAsync$(Seq(call1, call2), (n: Seq[Int]) => n.sum, null).get == 97) - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarReturnableSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarReturnableSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarReturnableSpec.scala deleted file mode 100644 index 607db68..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarReturnableSpec.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.scalatest.matchers._ -import org.gridgain.scalar._ -import scalar._ -import org.scalatest._ -import junit.JUnitRunner -import scala.util.control.Breaks._ -import org.junit.runner.RunWith - -/** - * - */ -@RunWith(classOf[JUnitRunner]) -class ScalarReturnableSpec extends FlatSpec with ShouldMatchers { - "Scalar '^^'" should "work" in { - var i = 0 - - breakable { - while (true) { - if (i == 0) - println("Only once!") ^^ - - i += 1 - } - } - - assert(i == 0) - } - - "Scalar '^^'" should "also work" in { - test() - } - - // Ignore exception below. - def test() = breakable { - while (true) { - println("Only once!") ^^ - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarSpec.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarSpec.scala deleted file mode 100644 index 0dcad14..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/tests/ScalarSpec.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.tests - -import org.gridgain.scalar._ -import org.scalatest._ -import junit.JUnitRunner -import org.junit.runner.RunWith - -/** - * - */ -@RunWith(classOf[JUnitRunner]) -class ScalarSpec extends FunSpec { - describe("Scalar") { - it("should start and stop") { - scalar start() - scalar.logo() - scalar stop() - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6f9c9e6/modules/scalar/src/test/scala/org/gridgain/scalar/testsuites/ScalarSelfTestSuite.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/gridgain/scalar/testsuites/ScalarSelfTestSuite.scala b/modules/scalar/src/test/scala/org/gridgain/scalar/testsuites/ScalarSelfTestSuite.scala deleted file mode 100644 index 12b0bd4..0000000 --- a/modules/scalar/src/test/scala/org/gridgain/scalar/testsuites/ScalarSelfTestSuite.scala +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.gridgain.scalar.testsuites - -import org.scalatest._ -import org.gridgain.scalar.tests._ -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner - -/** - * - */ -@RunWith(classOf[JUnitRunner]) -class ScalarSelfTestSuite extends Suites( - new ScalarAffinityRoutingSpec, - new ScalarCacheQueriesSpec, - new ScalarCacheSpec, - new ScalarConversionsSpec, - new ScalarProjectionSpec, - new ScalarReturnableSpec, - new ScalarSpec -) { -}