/*
* 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.distributed.near;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
import org.apache.ignite.spi.discovery.DiscoverySpi;
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 org.apache.ignite.transactions.Transaction;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
/**
* Test filtered put.
*/
public class GridCachePartitionedFilteredPutSelfTest extends GridCommonAbstractTest {
/** */
private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setDiscoverySpi(discoverySpi());
cfg.setCacheConfiguration(cacheConfiguration());
return cfg;
}
/**
* @return Discovery SPI;
*/
private DiscoverySpi discoverySpi() {
TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setIpFinder(IP_FINDER);
return spi;
}
/**
* @return Cache configuration.
*/
private CacheConfiguration cacheConfiguration() {
CacheConfiguration cfg = defaultCacheConfiguration();
cfg.setCacheMode(PARTITIONED);
cfg.setBackups(1);
cfg.setAtomicityMode(TRANSACTIONAL);
cfg.setNearConfiguration(new NearCacheConfiguration());
return cfg;
}
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
startGrid();
}
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
stopGrid();
}
/**
* @throws Exception If failed.
*/
public void testPutAndRollbackCheckNear() throws Exception {
doPutAndRollback();
IgniteCache<Object, Object> c = jcache();
assert c.size() == 0 : "Actual size: " + c.size();
}
/**
* @throws Exception If failed.
*/
public void testPutAndRollbackCheckDht() throws Exception {
doPutAndRollback();
GridCacheAdapter<Integer, Integer> c =
((GridNearCacheAdapter<Integer, Integer>)((IgniteKernal)grid()).internalCache(DEFAULT_CACHE_NAME).<Integer, Integer>cache()).dht();
assert c.entrySet().isEmpty() : "Actual size: " + c.entrySet().size();
}
/**
* @throws Exception If failed.
*/
private void doPutAndRollback() throws Exception {
IgniteCache<Object, Object> c = jcache();
try (Transaction tx = grid().transactions().txStart()) {
c.put(1, 1);
tx.rollback();
}
assert c.localSize() == 0;
assert c.localPeek(1, CachePeekMode.ONHEAP) == null;
assert c.get(1) == null;
}
}