[
https://issues.apache.org/jira/browse/IGNITE-2216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15066363#comment-15066363
]
Vladimir Ozerov commented on IGNITE-2216:
-
Sample test reproducing the issue. It fails with both OptimziedMarshaller and
BinaryMarshaller.
{code}
/*
* 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 org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CacheRebalanceMode;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import javax.cache.Cache;
import java.util.Iterator;
import java.util.List;
/**
* Tests for class with duplicate field names and aliases on them.
*/
public class BinaryDuplicateFieldsWithAliasQuerySelfTest extends
GridCommonAbstractTest {
/** Field 1. */
private static final String FIELD_1 = "x1";
/** Field 2. */
private static final String FIELD_2 = "x2";
/** Ignite instance. */
private Ignite ignite;
/** Cache. */
private IgniteCache cache;
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override protected void beforeTest() throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setLocalHost("127.0.0.1");
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true));
cfg.setDiscoverySpi(discoSpi);
//cfg.setMarshaller(new BinaryMarshaller());
cfg.setMarshaller(new OptimizedMarshaller());
CacheConfiguration cacheCfg = new CacheConfiguration();
cacheCfg.setName(null);
cacheCfg.setCacheMode(CacheMode.PARTITIONED);
cacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cacheCfg.setRebalanceMode(CacheRebalanceMode.SYNC);
cacheCfg.setIndexedTypes(Integer.class, Entity2.class);
cfg.setCacheConfiguration(cacheCfg);
ignite = Ignition.start(cfg);
cache = ignite.cache(null);
}
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
G.stopAll(true);
ignite = null;
cache = null;
}
/**
* Test duplicate fields querying.
*
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
public void testDuplicateFields() throws Exception {
cache.put(1, new Entity2(10, 11));
cache.put(2, new Entity2(20, 21));
cache.put(3, new Entity2(30, 31));
// Test first field.
Iterator iter = cache.query(new SqlQuery(Entity2.class, FIELD_1 +
"=20")).iterator();
assert iter.hasNext();
Cache.Entry res = (Cache.Entry)iter.next();
assertEquals(2, (int)res.getKey());
assertEquals(20, res.getValue().get1());
assertEquals(21, res.getValue().get2());
assert !iter.hasNext();
// Test second field.
iter = cache.query(new SqlQuery(Entity2.class, FIELD_2 +
"=21")).iterator();
assert iter.hasNext();
res = (Cache.Entry)iter.next();
assertEquals(2, (int)res.getKey());
assertEquals(20, res.getValue().get1());
assertEquals(21, res.getValue().get2());
assert !iter.hasNext();
iter = ca