Index: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartOnClientNodesTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartOnClientNodesTest.java (revision ) +++ modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStartOnClientNodesTest.java (revision ) @@ -0,0 +1,130 @@ +/* + * 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.cache.CacheMemoryMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.offheap.GridOffHeapProcessor; +import org.apache.ignite.internal.util.offheap.GridOffHeapPartitionedMap; +import org.apache.ignite.lang.IgnitePredicate; +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.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.jsr166.ConcurrentHashMap8; + +/** + * Test for dynamic cache start. + */ +@SuppressWarnings("unchecked") +public class CacheStartOnClientNodesTest extends GridCommonAbstractTest { + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final String CACHE_NAME = "CACHE_NAME"; + + /** Client index. */ + private static int CLIENT_INDEX = 2; + + /** Client index. */ + private static int FORCE_CLIENT_INDEX = 3; + + /** */ + private static final IgnitePredicate NODE_FILTER = new IgnitePredicate() { + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode n) { + return false; + } + }; + + /** */ + private boolean client; + + /** */ + private boolean forceServerMode; + + /** */ + private IgnitePredicate nodeFilter; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGridsMultiThreaded(2); + + client = true; + + startGrid(CLIENT_INDEX); + + forceServerMode = true; + + startGrid(FORCE_CLIENT_INDEX); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder); + + if (client) { + cfg.setClientMode(true); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(forceServerMode); + } + + return cfg; + } + /** + * @throws Exception If failed. + */ + public void testOffHeapClient() throws Exception { + try { + Ignite client = grid(CLIENT_INDEX); + + client.createCache(new CacheConfiguration(CACHE_NAME) + .setCacheMode(CacheMode.REPLICATED) + .setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED)); + + assertNotNull(client.cache(CACHE_NAME)); + + GridOffHeapProcessor offheap = ((IgniteKernal)client).cachex(CACHE_NAME).context().offheap(); + + assertNotNull(offheap); + assertEquals(0, + ((ConcurrentHashMap8)GridTestUtils + .getFieldValue(offheap, "offheap")).get("gg-swap-cache-" + CACHE_NAME) + .systemAllocatedSize()); + } + finally { + grid(0).destroyCache(CACHE_NAME); + } + } +}