You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/02/20 12:46:54 UTC
[35/38] ignite git commit: Added test.
Added test.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b99714d5
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b99714d5
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b99714d5
Branch: refs/heads/ignite-961
Commit: b99714d5b888453e0f5b4b08230fa35cc07690a8
Parents: 883436c
Author: sboikov <sb...@gridgain.com>
Authored: Sat Feb 20 10:15:07 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Sat Feb 20 10:15:34 2016 +0300
----------------------------------------------------------------------
.../IgniteBinaryObjectQueryArgumentsTest.java | 161 +++++++++++++++++++
1 file changed, 161 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/b99714d5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectQueryArgumentsTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectQueryArgumentsTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectQueryArgumentsTest.java
new file mode 100644
index 0000000..5676ddd
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectQueryArgumentsTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.apache.ignite.internal.processors.cache;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.cache.Cache;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class IgniteBinaryObjectQueryArgumentsTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final int NODES = 3;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ QueryEntity person = new QueryEntity();
+ person.setKeyType(TestKey.class.getName());
+ person.setValueType(Person.class.getName());
+ person.addQueryField("name", String.class.getName(), null);
+
+ ccfg.setQueryEntities(Arrays.asList(person));
+
+ cfg.setCacheConfiguration(ccfg);
+
+ cfg.setMarshaller(null);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGridsMultiThreaded(NODES);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectArgument() throws Exception {
+ IgniteCache<TestKey, Person> cache = ignite(0).cache(null);
+
+ for (int i = 0; i < 100; i++)
+ cache.put(new TestKey(i), new Person("name-" + i));
+
+ SqlQuery<TestKey, Person> qry = new SqlQuery<>(Person.class, "where _key=?");
+
+ IgniteBinary binary = ignite(0).binary();
+
+ for (int i = 0; i < 100; i++) {
+ Object key = new TestKey(i);
+
+ if (i % 2 == 0)
+ key = binary.toBinary(key);
+
+ qry.setArgs(key);
+
+ List<Cache.Entry<TestKey, Person>> res = cache.query(qry).getAll();
+
+ assertEquals(1, res.size());
+
+ Person p = res.get(0).getValue();
+
+ assertEquals("name-" + i, p.name);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class Person {
+ /** */
+ String name;
+
+ /**
+ * @param name Name.
+ */
+ public Person(String name) {
+ this.name = name;
+ }
+ }
+
+ /**
+ *
+ */
+ public static class TestKey {
+ /** */
+ private int id;
+
+ /**
+ * @param id Key.
+ */
+ public TestKey(int id) {
+ this.id = id;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestKey other = (TestKey)o;
+
+ return id == other.id;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return id;
+ }
+ }
+}