Search in sources :

Example 61 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class GridCacheNearOnlyMultiNodeFullApiSelfTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    cnt = new AtomicInteger();
    super.beforeTestsStarted();
    for (int i = 0; i < gridCount(); i++) {
        if (ignite(i).configuration().isClientMode()) {
            if (clientHasNearCache())
                ignite(i).getOrCreateCache(defaultCacheConfiguration(), new NearCacheConfiguration<>());
            else
                ignite(i).getOrCreateCache(DEFAULT_CACHE_NAME);
            break;
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 62 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class GridCacheNearOnlyTopologySelfTest method checkStartupNearNode.

/**
 * @throws Exception If failed.
 */
private void checkStartupNearNode(int nearNodeIdx, int totalNodeCnt) throws Exception {
    try {
        cache = true;
        for (int i = 0; i < totalNodeCnt; i++) {
            cilent = nearNodeIdx == i;
            Ignite ignite = startGrid(i);
            if (cilent)
                ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
        }
    } finally {
        stopAllGrids();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 63 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class GridCacheNearOnlyTopologySelfTest method testKeyMappingOnComputeNode.

/**
 * @throws Exception If failed.
 */
public void testKeyMappingOnComputeNode() throws Exception {
    try {
        cache = true;
        for (int i = 0; i < 4; i++) {
            cilent = i == 0;
            Ignite ignite = startGrid(i);
            if (cilent)
                ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
        }
        cache = false;
        cilent = true;
        Ignite compute = startGrid(4);
        for (int i = 0; i < 100; i++) {
            ClusterNode node = compute.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i);
            assertFalse("For key: " + i, node.id().equals(compute.cluster().localNode().id()));
            assertFalse("For key: " + i, node.id().equals(grid(0).localNode().id()));
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 64 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class GridCacheNearOnlyTopologySelfTest method testKeyMapping.

/**
 * @throws Exception If failed.
 */
public void testKeyMapping() throws Exception {
    try {
        cache = true;
        for (int i = 0; i < 4; i++) {
            cilent = i == 0;
            Ignite ignite = startGrid(i);
            if (cilent)
                ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
        }
        for (int i = 0; i < 100; i++) assertFalse("For key: " + i, grid(0).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(0).localNode(), i));
    } finally {
        stopAllGrids();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 65 with NearCacheConfiguration

use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.

the class GridCacheNearOnlyTopologySelfTest method testNodeLeave.

/**
 * @throws Exception If failed.
 */
public void testNodeLeave() throws Exception {
    try {
        cache = true;
        for (int i = 0; i < 2; i++) {
            cilent = i == 0;
            Ignite ignite = startGrid(i);
            if (cilent)
                ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
        }
        for (int i = 0; i < 10; i++) grid(1).cache(DEFAULT_CACHE_NAME).put(i, i);
        final Ignite igniteNearOnly = grid(0);
        final IgniteCache<Object, Object> nearOnly = igniteNearOnly.cache(DEFAULT_CACHE_NAME);
        // Populate near cache.
        for (int i = 0; i < 10; i++) {
            assertEquals(i, nearOnly.get(i));
            assertEquals(i, nearOnly.localPeek(i, CachePeekMode.ONHEAP));
        }
        // Stop the only dht node.
        stopGrid(1);
        for (int i = 0; i < 10; i++) {
            assertNull(nearOnly.localPeek(i, CachePeekMode.ONHEAP));
            final int key = i;
            GridTestUtils.assertThrowsWithCause(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    return nearOnly.get(key);
                }
            }, ClusterTopologyCheckedException.class);
        }
        // Test optimistic transaction.
        GridTestUtils.assertThrowsWithCause(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                try (Transaction tx = igniteNearOnly.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
                    nearOnly.put("key", "val");
                    tx.commit();
                }
                return null;
            }
        }, ClusterTopologyCheckedException.class);
        // Test pessimistic transaction.
        GridTestUtils.assertThrowsWithCause(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                try (Transaction tx = igniteNearOnly.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                    nearOnly.put("key", "val");
                    tx.commit();
                }
                return null;
            }
        }, ClusterTopologyCheckedException.class);
    } finally {
        stopAllGrids();
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Aggregations

NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)158 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)121 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)50 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)41 Ignite (org.apache.ignite.Ignite)37 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 IgniteCache (org.apache.ignite.IgniteCache)12 CacheException (javax.cache.CacheException)11 IgniteEx (org.apache.ignite.internal.IgniteEx)9 Transaction (org.apache.ignite.transactions.Transaction)9 ArrayList (java.util.ArrayList)8 IgniteException (org.apache.ignite.IgniteException)8 HashMap (java.util.HashMap)7 FifoEvictionPolicy (org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy)7 LinkedHashMap (java.util.LinkedHashMap)6 Callable (java.util.concurrent.Callable)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 LruEvictionPolicy (org.apache.ignite.cache.eviction.lru.LruEvictionPolicy)6 QuerySchema (org.apache.ignite.internal.processors.query.QuerySchema)6 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)6