Search in sources :

Example 66 with CacheConfiguration

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

the class IgniteClientAffinityAssignmentSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    if (cache) {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        ccfg.setBackups(1);
        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
        ccfg.setNearConfiguration(null);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, PARTS));
        cfg.setCacheConfiguration(ccfg);
    } else
        cfg.setClientMode(true);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 67 with CacheConfiguration

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

the class IgniteCacheTopologySafeGetSelfTest method cacheCfg.

/**
     * @param name Cache name.
     * @param cacheMode Cache mode.
     * @param near Near enabled flag.
     * @return Cache configuration.
     */
@SuppressWarnings("unchecked")
private CacheConfiguration cacheCfg(String name, CacheAtomicityMode cacheMode, boolean near) {
    CacheConfiguration cfg = new CacheConfiguration(name);
    cfg.setAtomicityMode(cacheMode);
    cfg.setBackups(1);
    if (near)
        cfg.setNearConfiguration(new NearCacheConfiguration());
    else
        cfg.setNearConfiguration(null);
    return cfg;
}
Also used : NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 68 with CacheConfiguration

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

the class GridCacheAbstractDataStructuresFailoverSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
    AtomicConfiguration atomicCfg = new AtomicConfiguration();
    atomicCfg.setCacheMode(collectionCacheMode());
    atomicCfg.setBackups(collectionConfiguration().getBackups());
    cfg.setAtomicConfiguration(atomicCfg);
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setName(TRANSACTIONAL_CACHE_NAME);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setCacheConfiguration(ccfg);
    if (client) {
        cfg.setClientMode(client);
        ((TcpDiscoverySpi) (cfg.getDiscoverySpi())).setForceServerMode(true);
    }
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 69 with CacheConfiguration

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

the class GridCacheAtomicReferenceApiSelfAbstractTest method testIsolation.

/**
     * Implementation of ignite data structures internally uses special system caches, need make sure
     * that transaction on these system caches do not intersect with transactions started by user.
     *
     * @throws Exception If failed.
     */
public void testIsolation() throws Exception {
    Ignite ignite = grid(0);
    CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    cfg.setName("myCache");
    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setWriteSynchronizationMode(FULL_SYNC);
    IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(cfg);
    try {
        String atomicName = UUID.randomUUID().toString();
        String initValue = "qazwsx";
        IgniteAtomicReference<String> atomicReference = ignite.atomicReference(atomicName, initValue, true);
        try (Transaction tx = ignite.transactions().txStart()) {
            cache.put(1, 1);
            assertEquals(initValue, atomicReference.get());
            assertTrue(atomicReference.compareAndSet(initValue, "aaa"));
            assertEquals("aaa", atomicReference.get());
            tx.rollback();
            assertEquals(0, cache.size());
        }
        assertTrue(atomicReference.compareAndSet("aaa", null));
        assertNull(atomicReference.get());
        atomicReference.close();
        assertTrue(atomicReference.removed());
    } finally {
        ignite.destroyCache(cfg.getName());
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 70 with CacheConfiguration

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

the class GridCacheAtomicStampedApiSelfAbstractTest method testIsolation.

/**
     * @throws Exception If failed.
     */
public void testIsolation() throws Exception {
    Ignite ignite = grid(0);
    CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    cfg.setName("MyCache");
    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setWriteSynchronizationMode(FULL_SYNC);
    IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(cfg);
    try {
        String atomicName = UUID.randomUUID().toString();
        String initVal = "qwerty";
        String initStamp = "asdf";
        IgniteAtomicStamped<String, String> atomicStamped = ignite.atomicStamped(atomicName, initVal, initStamp, true);
        try (Transaction tx = ignite.transactions().txStart()) {
            cache.put(1, 1);
            assertEquals(initVal, atomicStamped.value());
            assertEquals(initStamp, atomicStamped.stamp());
            assertEquals(initVal, atomicStamped.get().get1());
            assertEquals(initStamp, atomicStamped.get().get2());
            assertTrue(atomicStamped.compareAndSet(initVal, "b", initStamp, "d"));
            tx.rollback();
        }
        assertEquals(0, cache.size());
        assertEquals("b", atomicStamped.value());
        assertEquals("d", atomicStamped.stamp());
        atomicStamped.close();
        assertTrue(atomicStamped.removed());
    } finally {
        ignite.destroyCache(cfg.getName());
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)980 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)392 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)287 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)250 Ignite (org.apache.ignite.Ignite)148 ArrayList (java.util.ArrayList)69 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)64 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)59 QueryEntity (org.apache.ignite.cache.QueryEntity)44 IgniteException (org.apache.ignite.IgniteException)43 CacheException (javax.cache.CacheException)42 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)40 IgniteEx (org.apache.ignite.internal.IgniteEx)40 IgniteCache (org.apache.ignite.IgniteCache)39 LinkedHashMap (java.util.LinkedHashMap)35 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)34 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)32 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)30 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)30 Transaction (org.apache.ignite.transactions.Transaction)28