Merge branch 'sprint-2' of 
https://git-wip-us.apache.org/repos/asf/incubator-ignite into ignite-sql-tests

Conflicts:
        
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java


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

Branch: refs/heads/ignite-sql-tests
Commit: 4e76acd2e5cd5ee419662f4d4233c128266956b0
Parents: 4df09f2 73dd34d
Author: S.Vladykin <svlady...@gridgain.com>
Authored: Mon Mar 16 13:26:25 2015 +0300
Committer: S.Vladykin <svlady...@gridgain.com>
Committed: Mon Mar 16 13:26:25 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/gridify/AbstractAopTest.java  |   6 +-
 .../rest/AbstractRestProcessorSelfTest.java     |   2 +-
 .../src/main/java/org/apache/ignite/Ignite.java |   2 +-
 .../java/org/apache/ignite/IgniteCache.java     |  38 +--
 .../ignite/cache/CacheEntryProcessor.java       |  28 ++
 .../org/apache/ignite/cache/CacheImmutable.java |  45 ++++
 .../java/org/apache/ignite/cache/GridCache.java | 221 ---------------
 .../ignite/cache/IgniteEntryProcessor.java      |  28 --
 .../apache/ignite/cache/IgniteImmutable.java    |  45 ----
 .../cache/store/CacheLoadOnlyStoreAdapter.java  |   6 +-
 .../configuration/CacheConfiguration.java       |   6 +-
 .../org/apache/ignite/internal/IgniteEx.java    |   3 +-
 .../apache/ignite/internal/IgniteKernal.java    |   1 -
 .../internal/processors/cache/GridCache.java    | 222 +++++++++++++++
 .../processors/cache/GridCacheAdapter.java      |   6 +-
 .../cache/GridCacheConcurrentMap.java           |   2 +-
 .../processors/cache/GridCacheStoreManager.java |  30 ++-
 .../cache/GridCacheWriteBehindStore.java        |  69 +++--
 .../processors/cache/IgniteCacheProxy.java      |   4 +-
 .../cache/query/GridCacheQueryManager.java      |   1 -
 .../continuous/CacheContinuousQueryManager.java |  11 +-
 .../jdbc/GridCacheQueryJdbcMetadataTask.java    |   2 +-
 .../query/jdbc/GridCacheQueryJdbcTask.java      |   2 +-
 .../cacheobject/IgniteCacheObjectProcessor.java |   3 +-
 .../IgniteCacheObjectProcessorImpl.java         |   2 +-
 .../datastreamer/DataStreamerCacheUpdaters.java |  12 +-
 .../datastructures/DataStructuresProcessor.java |   1 -
 .../datastructures/GridCacheSetImpl.java        |   1 -
 .../processors/task/GridTaskProcessor.java      |   2 +-
 .../visor/cache/VisorCacheMetadataTask.java     |   1 +
 .../internal/visor/cache/VisorCacheMetrics.java |   1 +
 .../cache/VisorCacheMetricsCollectorTask.java   |   1 +
 .../visor/cache/VisorCachePreloadTask.java      |   1 +
 .../visor/cache/VisorCacheResetMetricsTask.java |   1 +
 .../visor/cache/VisorCacheSwapBackupsTask.java  |   1 +
 .../visor/node/VisorNodeDataCollectorJob.java   |   1 +
 .../org/apache/ignite/lang/IgnitePredicate.java |   4 +-
 .../ignite/startup/BasicWarmupClosure.java      |   1 +
 .../StreamerCacheAffinityEventRouter.java       |   2 +-
 .../TransactionSynchronization.java             |   2 +-
 .../GridCacheAffinityBackupsSelfTest.java       |   2 +
 .../ignite/igfs/IgfsFragmentizerSelfTest.java   |   1 +
 .../cache/GridCacheAbstractFullApiSelfTest.java |   8 +-
 .../cache/GridCacheClearLocalySelfTest.java     |  19 +-
 ...CacheFullTextQueryMultithreadedSelfTest.java |   1 -
 .../GridCacheOnCopyFlagAbstractSelfTest.java    |   4 +-
 .../GridCacheReturnValueTransferSelfTest.java   |   2 +-
 ...idCacheWriteBehindStoreAbstractSelfTest.java |   2 +-
 .../GridCacheAbstractJobExecutionTest.java      |   9 +-
 .../GridCacheAtomicTimeoutSelfTest.java         |   5 +
 .../GridCacheNodeFailureAbstractTest.java       |   1 +
 ...GridCachePreloadRestartAbstractSelfTest.java |   1 +
 .../IgniteTxTimeoutAbstractTest.java            |   2 +-
 .../dht/GridCacheDhtPreloadSelfTest.java        |   1 +
 .../near/GridCacheNearEvictionSelfTest.java     |   1 +
 .../near/GridCacheNearMultiNodeSelfTest.java    |   1 +
 ...GridCachePartitionedFilteredPutSelfTest.java |   1 +
 ...achePartitionedPreloadLifecycleSelfTest.java |   1 +
 .../GridCacheReplicatedInvalidateSelfTest.java  |   2 +-
 ...CacheReplicatedPreloadLifecycleSelfTest.java |   1 +
 ...eCacheAtomicStoreSessionWriteBehindTest.java |  38 +++
 ...acheStoreSessionWriteBehindAbstractTest.java | 269 +++++++++++++++++++
 ...gniteCacheTxStoreSessionWriteBehindTest.java |  32 +++
 .../GridCacheSwapScanQueryAbstractSelfTest.java |   1 +
 .../processors/igfs/IgfsAbstractSelfTest.java   |   1 +
 .../igfs/IgfsDualAbstractSelfTest.java          |   1 +
 .../processors/igfs/IgfsProcessorSelfTest.java  |   1 +
 .../processors/igfs/IgfsStreamsSelfTest.java    |   1 +
 .../ignite/testsuites/IgniteCacheTestSuite.java |   2 +
 .../query/h2/GridH2IndexingGeoSelfTest.java     |   1 -
 .../igfs/HadoopIgfsDualAbstractSelfTest.java    |   1 +
 .../HadoopDefaultMapReducePlannerSelfTest.java  |   1 -
 .../HibernateAccessStrategyAdapter.java         |   1 -
 .../hibernate/HibernateCollectionRegion.java    |   2 +-
 .../cache/hibernate/HibernateEntityRegion.java  |   2 +-
 .../hibernate/HibernateGeneralDataRegion.java   |   2 +-
 .../hibernate/HibernateNaturalIdRegion.java     |   2 +-
 .../HibernateNonStrictAccessStrategy.java       |   2 +-
 .../hibernate/HibernateQueryResultsRegion.java  |   2 +-
 .../HibernateReadOnlyAccessStrategy.java        |   2 +-
 .../HibernateReadWriteAccessStrategy.java       |  34 +--
 .../ignite/cache/hibernate/HibernateRegion.java |   2 +-
 .../cache/hibernate/HibernateRegionFactory.java |   6 +-
 .../hibernate/HibernateTimestampsRegion.java    |   2 +-
 .../HibernateTransactionalAccessStrategy.java   |   4 +-
 .../HibernateTransactionalDataRegion.java       |   2 +-
 .../HibernateL2CacheConfigurationSelfTest.java  |   2 +-
 .../hibernate/HibernateL2CacheSelfTest.java     |   4 +-
 ...hePartitionedQueryMultiThreadedSelfTest.java |   2 +
 ...dCacheAbstractReduceFieldsQuerySelfTest.java |   1 -
 .../query/h2/sql/GridQueryParsingTest.java      |   1 +
 .../schema-import/src/main/java/media/style.css |   2 +-
 .../ignite/cache/spring/SpringCacheManager.java |   2 +-
 .../commands/cache/VisorCacheCommand.scala      |   8 +-
 94 files changed, 860 insertions(+), 458 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsProcessorSelfTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsStreamsSelfTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/geospatial/src/test/java/org/apache/ignite/internal/processors/query/h2/GridH2IndexingGeoSelfTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/hadoop/src/test/java/org/apache/ignite/igfs/HadoopIgfsDualAbstractSelfTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --cc 
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
index a90281f,0000000..755078a
mode 100644,000000..100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
@@@ -1,309 -1,0 +1,311 @@@
 +/*
 + * 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.*;
 +import org.apache.ignite.cache.*;
 +import org.apache.ignite.cache.query.*;
 +import org.apache.ignite.cache.query.annotations.*;
 +import org.apache.ignite.configuration.*;
 +import org.apache.ignite.internal.*;
++import org.apache.ignite.internal.processors.cache.*;
++import org.apache.ignite.internal.processors.cache.query.*;
 +import org.apache.ignite.internal.util.tostring.*;
 +import org.apache.ignite.internal.util.typedef.*;
 +import org.apache.ignite.internal.util.typedef.internal.*;
 +import org.apache.ignite.spi.discovery.tcp.*;
 +import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 +import org.apache.ignite.testframework.*;
 +import org.apache.ignite.testframework.junits.common.*;
 +
 +import javax.cache.*;
 +import java.io.*;
 +import java.util.*;
 +import java.util.concurrent.atomic.*;
 +
 +import static org.apache.ignite.cache.CacheAtomicityMode.*;
 +import static org.apache.ignite.cache.CacheDistributionMode.*;
 +import static org.apache.ignite.cache.CacheMode.*;
 +
 +/**
 + * Tests for partitioned cache queries.
 + */
 +public class IgniteCachePartitionedQueryMultiThreadedSelfTest extends 
GridCommonAbstractTest {
 +    /** */
 +    private static final boolean TEST_INFO = true;
 +
 +    /** Number of test grids (nodes). Should not be less than 2. */
 +    private static final int GRID_CNT = 3;
 +
 +    /** */
 +    private static TcpDiscoveryIpFinder ipFinder = new 
TcpDiscoveryVmIpFinder(true);
 +
 +    /** Don't start grid by default. */
 +    public IgniteCachePartitionedQueryMultiThreadedSelfTest() {
 +        super(false);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
 +        IgniteConfiguration c = super.getConfiguration(gridName);
 +
 +        TcpDiscoverySpi disco = new TcpDiscoverySpi();
 +
 +        disco.setIpFinder(ipFinder);
 +
 +        c.setDiscoverySpi(disco);
 +
 +        CacheConfiguration cc = defaultCacheConfiguration();
 +
 +        cc.setCacheMode(PARTITIONED);
 +
 +        // Query should be executed without ongoing transactions.
 +        
cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
 +        cc.setBackups(0);
 +        cc.setRebalanceMode(CacheRebalanceMode.SYNC);
 +        cc.setAtomicityMode(TRANSACTIONAL);
 +        cc.setDistributionMode(NEAR_PARTITIONED);
 +        cc.setIndexedTypes(
 +            UUID.class, Person.class
 +        );
 +
 +        c.setCacheConfiguration(cc);
 +
 +        return c;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected void beforeTestsStarted() throws Exception {
 +        assert GRID_CNT >= 2 : "Constant GRID_CNT must be greater than or 
equal to 2.";
 +
 +        startGridsMultiThreaded(GRID_CNT);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected void afterTestsStopped() throws Exception {
 +        stopAllGrids();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected void afterTest() throws Exception {
 +        super.afterTest();
 +
 +        // Clean up all caches.
 +        for (int i = 0; i < GRID_CNT; i++)
 +            grid(i).jcache(null).removeAll();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected void info(String msg) {
 +        if (TEST_INFO)
 +            super.info(msg);
 +    }
 +
 +    /**
 +     * JUnit.
 +     *
 +     * @throws Exception If failed.
 +     */
 +    @SuppressWarnings({"TooBroadScope"})
 +    public void testLuceneAndSqlMultithreaded() throws Exception {
 +        // ---------- Test parameters ---------- //
 +        int luceneThreads = 10;
 +        int sqlThreads = 10;
 +        long duration = 10 * 1000;
 +        final int logMod = 100;
 +
 +        final Person p1 = new Person("Jon", 1500, "Master");
 +        final Person p2 = new Person("Jane", 2000, "Master");
 +        final Person p3 = new Person("Mike", 1800, "Bachelor");
 +        final Person p4 = new Person("Bob", 1900, "Bachelor");
 +
 +        final IgniteCache<UUID, Person> cache0 = grid(0).jcache(null);
 +
 +        cache0.put(p1.id(), p1);
 +        cache0.put(p2.id(), p2);
 +        cache0.put(p3.id(), p3);
 +        cache0.put(p4.id(), p4);
 +
 +        assertEquals(4, cache0.localSize());
 +
 +        assert grid(0).cluster().nodes().size() == GRID_CNT;
 +
 +        final AtomicBoolean done = new AtomicBoolean();
 +
 +        final AtomicLong luceneCnt = new AtomicLong();
 +
 +        // Start lucene query threads.
 +        IgniteInternalFuture<?> futLucene = 
GridTestUtils.runMultiThreadedAsync(new CAX() {
 +            @Override public void applyx() throws IgniteCheckedException {
 +                while (!done.get()) {
 +                    QueryCursor<Cache.Entry<UUID, Person>> master =
 +                        cache0.query(new TextQuery(Person.class, "Master"));
 +
 +                    Collection<Cache.Entry<UUID, Person>> entries = 
master.getAll();
 +
 +                    checkResult(entries, p1, p2);
 +
 +                    long cnt = luceneCnt.incrementAndGet();
 +
 +                    if (cnt % logMod == 0)
 +                        info("Executed LUCENE queries: " + cnt);
 +                }
 +            }
 +        }, luceneThreads, "LUCENE-THREAD");
 +
 +        final AtomicLong sqlCnt = new AtomicLong();
 +
 +        // Start sql query threads.
 +        IgniteInternalFuture<?> futSql = 
GridTestUtils.runMultiThreadedAsync(new CAX() {
 +            @Override public void applyx() throws IgniteCheckedException {
 +                while (!done.get()) {
 +                    QueryCursor<Cache.Entry<UUID, Person>> bachelors =
 +                            cache0.query(new SqlQuery(Person.class, "degree = 
'Bachelor'"));
 +
 +                    Collection<Cache.Entry<UUID, Person>> entries = 
bachelors.getAll();
 +
 +                    checkResult(entries, p3, p4);
 +
 +                    long cnt = sqlCnt.incrementAndGet();
 +
 +                    if (cnt % logMod == 0)
 +                        info("Executed SQL queries: " + cnt);
 +                }
 +            }
 +        }, sqlThreads, "SQL-THREAD");
 +
 +        Thread.sleep(duration);
 +
 +        done.set(true);
 +
 +        futLucene.get();
 +        futSql.get();
 +    }
 +
 +    /**
 +     * @param entries Queried result.
 +     * @param persons Persons that should be in the result.
 +     */
 +    private void checkResult(Iterable<Cache.Entry<UUID, Person>> entries, 
Person... persons) {
 +        for (Cache.Entry<UUID, Person> entry : entries) {
 +            assertEquals(entry.getKey(), entry.getValue().id());
 +
 +            assert F.asList(persons).contains(entry.getValue());
 +        }
 +    }
 +
 +    /** Test class. */
 +    private static class Person implements Externalizable {
 +        /** */
 +        @GridToStringExclude
 +        private UUID id = UUID.randomUUID();
 +
 +        /** */
 +        @QuerySqlField
 +        private String name;
 +
 +        /** */
 +        @QuerySqlField
 +        private int salary;
 +
 +        /** */
 +        @QuerySqlField
 +        @QueryTextField
 +        private String degree;
 +
 +        /** Required by {@link Externalizable}. */
 +        public Person() {
 +            // No-op.
 +        }
 +
 +        /**
 +         * @param name Name.
 +         * @param salary Salary.
 +         * @param degree Degree.
 +         */
 +        Person(String name, int salary, String degree) {
 +            assert name != null;
 +            assert salary > 0;
 +            assert degree != null;
 +
 +            this.name = name;
 +            this.salary = salary;
 +            this.degree = degree;
 +        }
 +
 +        /** @return Id. */
 +        UUID id() {
 +            return id;
 +        }
 +
 +        /** @return Name. */
 +        String name() {
 +            return name;
 +        }
 +
 +        /** @return Salary. */
 +        double salary() {
 +            return salary;
 +        }
 +
 +        /** @return Degree. */
 +        String degree() {
 +            return degree;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void writeExternal(ObjectOutput out) throws 
IOException {
 +            U.writeUuid(out, id);
 +            U.writeString(out, name);
 +            out.writeInt(salary);
 +            U.writeString(out, degree);
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void readExternal(ObjectInput in) throws 
IOException, ClassNotFoundException {
 +            id = U.readUuid(in);
 +            name = U.readString(in);
 +            salary = in.readInt();
 +            degree = U.readString(in);
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public int hashCode() {
 +            return id.hashCode() + 31 * name.hashCode() + 31 * 31 * salary;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public boolean equals(Object obj) {
 +            if (obj == this)
 +                return true;
 +
 +            if (!(obj instanceof Person))
 +                return false;
 +
 +            Person that = (Person)obj;
 +
 +            return that.id.equals(id) && that.name.equals(name) && 
that.salary == salary && that.degree.equals(degree);
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public String toString() {
 +            return S.toString(Person.class, this);
 +        }
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/reducefields/GridCacheAbstractReduceFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --cc 
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/reducefields/GridCacheAbstractReduceFieldsQuerySelfTest.java
index e7fdb3c,0000000..43f596f
mode 100644,000000..100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/reducefields/GridCacheAbstractReduceFieldsQuerySelfTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/reducefields/GridCacheAbstractReduceFieldsQuerySelfTest.java
@@@ -1,414 -1,0 +1,413 @@@
 +/*
 + * 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.reducefields;
 +
 +import org.apache.ignite.cache.*;
 +import org.apache.ignite.cache.affinity.*;
 +import org.apache.ignite.cache.query.annotations.*;
 +import org.apache.ignite.configuration.*;
 +import org.apache.ignite.internal.*;
 +import org.apache.ignite.internal.processors.cache.*;
 +import org.apache.ignite.internal.processors.cache.query.*;
 +import org.apache.ignite.internal.util.typedef.*;
- import org.apache.ignite.internal.util.typedef.internal.*;
 +import org.apache.ignite.lang.*;
 +import org.apache.ignite.marshaller.optimized.*;
 +import org.apache.ignite.spi.discovery.*;
 +import org.apache.ignite.spi.discovery.tcp.*;
 +import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 +import org.apache.ignite.testframework.junits.common.*;
 +import org.jetbrains.annotations.*;
 +
 +import java.io.*;
 +import java.util.*;
 +
 +import static org.apache.ignite.cache.CacheAtomicityMode.*;
 +import static org.apache.ignite.cache.CacheDistributionMode.*;
 +import static org.apache.ignite.cache.CacheMode.*;
 +import static org.apache.ignite.cache.CacheRebalanceMode.*;
 +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
 +
 +/**
 + * Tests for reduce fields queries.
 + */
 +public abstract class GridCacheAbstractReduceFieldsQuerySelfTest extends 
GridCommonAbstractTest {
 +    /** IP finder. */
 +    private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
 +
 +    /** Flag indicating if starting node should have cache. */
 +    protected boolean hasCache;
 +
 +    /** {@inheritDoc} */
 +    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
 +        IgniteConfiguration cfg = super.getConfiguration(gridName);
 +
 +        if (hasCache)
 +            cfg.setCacheConfiguration(cache(null));
 +        else
 +            cfg.setCacheConfiguration();
 +
 +        cfg.setDiscoverySpi(discovery());
 +        cfg.setMarshaller(new OptimizedMarshaller(false));
 +
 +        return cfg;
 +    }
 +
 +    /**
 +     * @return Distribution.
 +     */
 +    protected CacheDistributionMode distributionMode() {
 +        return NEAR_PARTITIONED;
 +    }
 +
 +    /**
 +     * @param name Cache name.
 +     * @return Cache.
 +     */
 +    private CacheConfiguration cache(@Nullable String name) {
 +        CacheConfiguration<?,?> cache = defaultCacheConfiguration();
 +
 +        cache.setName(name);
 +        cache.setCacheMode(cacheMode());
 +        cache.setAtomicityMode(atomicityMode());
 +        cache.setDistributionMode(distributionMode());
 +        cache.setWriteSynchronizationMode(FULL_SYNC);
 +        cache.setRebalanceMode(SYNC);
 +        cache.setIndexedTypes(
 +            String.class, Organization.class,
 +            CacheAffinityKey.class, Person.class
 +        );
 +
 +        if (cacheMode() == PARTITIONED)
 +            cache.setBackups(1);
 +
 +        return cache;
 +    }
 +
 +    /**
 +     * @return Discovery SPI.
 +     */
 +    private static DiscoverySpi discovery() {
 +        TcpDiscoverySpi spi = new TcpDiscoverySpi();
 +
 +        spi.setIpFinder(IP_FINDER);
 +
 +        return spi;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected void beforeTestsStarted() throws Exception {
 +        hasCache = true;
 +
 +        startGridsMultiThreaded(gridCount());
 +
 +        hasCache = false;
 +
 +        startGrid(gridCount());
 +
 +        GridCache<String, Organization> orgCache = 
((IgniteKernal)grid(0)).cache(null);
 +
 +        assert orgCache != null;
 +
 +        assert orgCache.putx("o1", new Organization(1, "A"));
 +        assert orgCache.putx("o2", new Organization(2, "B"));
 +
 +        GridCache<CacheAffinityKey<String>, Person> personCache = 
((IgniteKernal)grid(0)).cache(null);
 +
 +        assert personCache != null;
 +
 +        assert personCache.putx(new CacheAffinityKey<>("p1", "o1"), new 
Person("John White", 25, 1));
 +        assert personCache.putx(new CacheAffinityKey<>("p2", "o1"), new 
Person("Joe Black", 35, 1));
 +        assert personCache.putx(new CacheAffinityKey<>("p3", "o2"), new 
Person("Mike Green", 40, 2));
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected void afterTestsStopped() throws Exception {
 +        stopAllGrids();
 +    }
 +
 +    /**
 +     * @return cache mode.
 +     */
 +    protected abstract CacheMode cacheMode();
 +
 +    /**
 +     * @return Number of grids to start.
 +     */
 +    protected abstract int gridCount();
 +
 +    /**
 +     * @return Cache atomicity mode.
 +     */
 +    protected CacheAtomicityMode atomicityMode() {
 +        return TRANSACTIONAL;
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testNoDataInCache() throws Exception {
 +        CacheQuery<List<?>> qry = ((IgniteKernal)grid(0))
 +            .cache(null).queries().createSqlFieldsQuery("select age from 
Person where orgId = 999");
 +
 +        Collection<IgniteBiTuple<Integer, Integer>> res = qry.execute(new 
AverageRemoteReducer()).get();
 +
 +        assertEquals("Result", 0, F.reduce(res, new 
AverageLocalReducer()).intValue());
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testAverageQuery() throws Exception {
 +        CacheQuery<List<?>> qry = 
((IgniteKernal)grid(0)).cache(null).queries().createSqlFieldsQuery("select age 
from Person");
 +
 +        Collection<IgniteBiTuple<Integer, Integer>> res = qry.execute(new 
AverageRemoteReducer()).get();
 +
 +        assertEquals("Average", 33, F.reduce(res, new 
AverageLocalReducer()).intValue());
 +    }
 +
 +    /**
 +     * @throws Exception If failed.
 +     */
 +    public void testAverageQueryWithArguments() throws Exception {
 +        CacheQuery<List<?>> qry = 
((IgniteKernal)grid(0)).cache(null).queries().createSqlFieldsQuery(
 +            "select age from Person where orgId = ?");
 +
 +        Collection<IgniteBiTuple<Integer, Integer>> res = qry.execute(new 
AverageRemoteReducer(), 1).get();
 +
 +        assertEquals("Average", 30, F.reduce(res, new 
AverageLocalReducer()).intValue());
 +    }
 +
 +//    /**
 +//     * @throws Exception If failed.
 +//     */
 +//    public void testFilters() throws Exception {
 +//        GridCacheReduceFieldsQuery<Object, Object, GridBiTuple<Integer, 
Integer>, Integer> qry = ((IgniteKernal)grid(0)).cache(null)
 +//            .queries().createReduceFieldsQuery("select age from Person");
 +//
 +//        qry = qry.remoteKeyFilter(
 +//            new GridPredicate<Object>() {
 +//                @Override public boolean apply(Object e) {
 +//                    return !"p2".equals(((CacheAffinityKey)e).key());
 +//                }
 +//            }
 +//        ).remoteValueFilter(
 +//            new P1<Object>() {
 +//                @Override public boolean apply(Object e) {
 +//                    return !"Mike Green".equals(((Person)e).name);
 +//                }
 +//            }
 +//        );
 +//
 +//        qry = qry.remoteReducer(new 
AverageRemoteReducer()).localReducer(new AverageLocalReducer());
 +//
 +//        Integer avg = qry.reduce().get();
 +//
 +//        assertNotNull("Average", avg);
 +//        assertEquals("Average", 25, avg.intValue());
 +//    }
 +
 +//    /**
 +//     * @throws Exception If failed.
 +//     */
 +//    public void testOnProjectionWithFilter() throws Exception {
 +//        P2<CacheAffinityKey<String>, Person> p = new 
P2<CacheAffinityKey<String>, Person>() {
 +//            @Override public boolean apply(CacheAffinityKey<String> key, 
Person val) {
 +//                return val.orgId == 1;
 +//            }
 +//        };
 +//
 +//        CacheProjection<CacheAffinityKey<String>, Person> cachePrj =
 +//            grid(0).<CacheAffinityKey<String>, 
Person>cache(null).projection(p);
 +//
 +//        GridCacheReduceFieldsQuery<CacheAffinityKey<String>, Person, 
GridBiTuple<Integer, Integer>, Integer> qry =
 +//            cachePrj.queries().createReduceFieldsQuery("select age from 
Person");
 +//
 +//        qry = qry.remoteValueFilter(
 +//            new P1<Person>() {
 +//                @Override public boolean apply(Person e) {
 +//                    return !"Joe Black".equals(e.name);
 +//                }
 +//            });
 +//
 +//        qry = qry.remoteReducer(new 
AverageRemoteReducer()).localReducer(new AverageLocalReducer());
 +//
 +//        Integer avg = qry.reduce().get();
 +//
 +//        assertNotNull("Average", avg);
 +//        assertEquals("Average", 25, avg.intValue());
 +//    }
 +
 +    /**
 +     * @return true if cache mode is replicated, false otherwise.
 +     */
 +    private boolean isReplicatedMode() {
 +        return cacheMode() == REPLICATED;
 +    }
 +
 +    /**
 +     * Person.
 +     */
 +    @SuppressWarnings("UnusedDeclaration")
 +    private static class Person implements Serializable {
 +        /** Name. */
 +        @QuerySqlField(index = false)
 +        private final String name;
 +
 +        /** Age. */
 +        @QuerySqlField(index = true)
 +        private final int age;
 +
 +        /** Organization ID. */
 +        @QuerySqlField(index = true)
 +        private final int orgId;
 +
 +        /**
 +         * @param name Name.
 +         * @param age Age.
 +         * @param orgId Organization ID.
 +         */
 +        private Person(String name, int age, int orgId) {
 +            assert !F.isEmpty(name);
 +            assert age > 0;
 +            assert orgId > 0;
 +
 +            this.name = name;
 +            this.age = age;
 +            this.orgId = orgId;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public boolean equals(Object o) {
 +            if (this == o)
 +                return true;
 +
 +            if (o == null || getClass() != o.getClass())
 +                return false;
 +
 +            Person person = (Person)o;
 +
 +            return age == person.age && orgId == person.orgId && 
name.equals(person.name);
 +
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public int hashCode() {
 +            int res = name.hashCode();
 +
 +            res = 31 * res + age;
 +            res = 31 * res + orgId;
 +
 +            return res;
 +        }
 +    }
 +
 +    /**
 +     * Organization.
 +     */
 +    @SuppressWarnings("UnusedDeclaration")
 +    private static class Organization implements Serializable {
 +        /** ID. */
 +        @QuerySqlField
 +        private final int id;
 +
 +        /** Name. */
 +        @QuerySqlField(index = false)
 +        private final String name;
 +
 +        /**
 +         * @param id ID.
 +         * @param name Name.
 +         */
 +        private Organization(int id, String name) {
 +            assert id > 0;
 +            assert !F.isEmpty(name);
 +
 +            this.id = id;
 +            this.name = name;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public boolean equals(Object o) {
 +            if (this == o)
 +                return true;
 +
 +            if (o == null || getClass() != o.getClass())
 +                return false;
 +
 +            Organization that = (Organization)o;
 +
 +            return id == that.id && name.equals(that.name);
 +
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public int hashCode() {
 +            int res = id;
 +
 +            res = 31 * res + name.hashCode();
 +
 +            return res;
 +        }
 +    }
 +
 +    /**
 +     * Average remote reducer factory.
 +     */
 +    protected static class AverageRemoteReducer implements 
IgniteReducer<List<?>, IgniteBiTuple<Integer, Integer>> {
 +        /** */
 +        private int sum;
 +
 +        /** */
 +        private int cnt;
 +
 +        @Override public boolean collect(List<?> e) {
 +            sum += (Integer)e.get(0);
 +
 +            cnt++;
 +
 +            return true;
 +        }
 +
 +        @Override public IgniteBiTuple<Integer, Integer> reduce() {
 +            return F.t(sum, cnt);
 +        }
 +    }
 +
 +    /**
 +     * Average local reducer factory.
 +     */
 +    protected static class AverageLocalReducer implements 
IgniteReducer<IgniteBiTuple<Integer, Integer>, Integer> {
 +        /** */
 +        private int sum;
 +
 +        /** */
 +        private int cnt;
 +
 +        @Override public boolean collect(IgniteBiTuple<Integer, Integer> t) {
 +            sum += t.get1();
 +            cnt += t.get2();
 +
 +            return true;
 +        }
 +
 +        @Override public Integer reduce() {
 +            return cnt == 0 ? 0 : sum / cnt;
 +        }
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e76acd2/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/cache/VisorCacheCommand.scala
----------------------------------------------------------------------

Reply via email to