You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/02/10 15:16:51 UTC
[08/14] 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/16927abb
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/16927abb
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/16927abb
Branch: refs/heads/ignite-1786
Commit: 16927abbb1ed1a6c3b47831562d263dd38f495d1
Parents: fa3706f
Author: sboikov <sb...@gridgain.com>
Authored: Wed Feb 10 15:05:56 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Feb 10 15:06:31 2016 +0300
----------------------------------------------------------------------
.../cache/CacheQueryBuildValueTest.java | 144 +++++++++++++++++++
1 file changed, 144 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/16927abb/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheQueryBuildValueTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheQueryBuildValueTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheQueryBuildValueTest.java
new file mode 100644
index 0000000..cb574bb
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheQueryBuildValueTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import javax.cache.Cache;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.configuration.BinaryConfiguration;
+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;
+
+/**
+ *
+ */
+public class CacheQueryBuildValueTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setMarshaller(null);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>();
+
+ QueryEntity entity = new QueryEntity();
+ entity.setKeyType(Integer.class.getName());
+ entity.setValueType(TestBuilderValue.class.getName());
+
+ ArrayList<QueryIndex> idxs = new ArrayList<>();
+
+ QueryIndex idx = new QueryIndex("iVal");
+ idxs.add(idx);
+
+ LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+ fields.put("iVal", Integer.class.getName());
+
+ entity.setFields(fields);
+
+ entity.setIndexes(idxs);
+
+ ccfg.setQueryEntities(Collections.singleton(entity));
+
+ cfg.setCacheConfiguration(ccfg);
+
+ BinaryConfiguration binaryCfg = new BinaryConfiguration();
+
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+ typeCfg.setTypeName(TestBuilderValue.class.getName());
+
+ binaryCfg.setTypeConfigurations(Collections.singletonList(typeCfg));
+
+ cfg.setBinaryConfiguration(binaryCfg);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGrid(0);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBuilderAndQuery() throws Exception {
+ Ignite node = ignite(0);
+
+ final IgniteCache<Object, Object> cache = node.cache(null);
+
+ IgniteBinary binary = node.binary();
+
+ BinaryObjectBuilder builder = binary.builder(TestBuilderValue.class.getName());
+
+ cache.put(0, builder.build());
+
+ builder.setField("iVal", 1);
+
+ cache.put(1, builder.build());
+
+ List<Cache.Entry<Object, Object>> entries =
+ cache.query(new SqlQuery<>(TestBuilderValue.class, "true")).getAll();
+
+ assertEquals(2, entries.size());
+ }
+
+ /**
+ *
+ */
+ static class TestBuilderValue implements Serializable {
+ /** */
+ private int iVal;
+
+ /**
+ * @param iVal Integer value.
+ */
+ public TestBuilderValue(int iVal) {
+ this.iVal = iVal;
+ }
+ }
+}