Search in sources :

Example 16 with CacheMode

use of org.apache.ignite.cache.CacheMode in project ignite by apache.

the class DynamicEnableIndexingConcurrentSelfTest method params.

/**
 * Test parameters.
 */
@Parameters(name = "cacheMode={0},atomicityMode={1}")
public static Iterable<Object[]> params() {
    CacheMode[] cacheModes = new CacheMode[] { CacheMode.PARTITIONED, CacheMode.REPLICATED };
    CacheAtomicityMode[] atomicityModes = new CacheAtomicityMode[] { CacheAtomicityMode.ATOMIC, CacheAtomicityMode.TRANSACTIONAL, CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT };
    List<Object[]> res = new ArrayList<>();
    for (CacheMode cacheMode : cacheModes) {
        for (CacheAtomicityMode atomicityMode : atomicityModes) res.add(new Object[] { cacheMode, atomicityMode });
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) CacheMode(org.apache.ignite.cache.CacheMode) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) BinaryObject(org.apache.ignite.binary.BinaryObject) Parameters(org.junit.runners.Parameterized.Parameters)

Example 17 with CacheMode

use of org.apache.ignite.cache.CacheMode in project ignite by apache.

the class DynamicEnableIndexingBasicSelfTest method params.

/**
 * Test parameters.
 */
@Parameters(name = "hasNear={0},nodeIdx={1},cacheMode={2},atomicityMode={3}")
public static Iterable<Object[]> params() {
    int[] opNodes = new int[] { IDX_CLI, IDX_SRV_CRD, IDX_SRV_NON_CRD, IDX_SRV_FILTERED };
    CacheMode[] cacheModes = new CacheMode[] { CacheMode.PARTITIONED, CacheMode.REPLICATED };
    CacheAtomicityMode[] atomicityModes = new CacheAtomicityMode[] { CacheAtomicityMode.ATOMIC, CacheAtomicityMode.TRANSACTIONAL, CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT };
    List<Object[]> res = new ArrayList<>();
    for (int node : opNodes) {
        for (CacheMode cacheMode : cacheModes) {
            for (CacheAtomicityMode atomicityMode : atomicityModes) {
                res.add(new Object[] { true, node, cacheMode, atomicityMode });
                // For TRANSACTIONAL_SNAPSHOT near caches is forbidden.
                if (atomicityMode != CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)
                    res.add(new Object[] { false, node, cacheMode, atomicityMode });
            }
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) CacheMode(org.apache.ignite.cache.CacheMode) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) Parameters(org.junit.runners.Parameterized.Parameters)

Example 18 with CacheMode

use of org.apache.ignite.cache.CacheMode in project ignite by apache.

the class ParametersTest method testEnumVariationsWithNull.

/**
 * @throws Exception If failed.
 */
@Test
public void testEnumVariationsWithNull() throws Exception {
    ConfigParameter<CacheConfiguration>[] cfgParam = Parameters.enumParameters(true, "setCacheMode", CacheMode.class);
    assertEquals(CacheMode.values().length + 1, cfgParam.length);
    cfgParam[0] = null;
    Set<CacheMode> set = new HashSet<>();
    for (int i = 1; i < cfgParam.length; i++) {
        ConfigParameter<CacheConfiguration> modeApplier = cfgParam[i];
        CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        modeApplier.apply(cfg);
        CacheMode mode = cfg.getCacheMode();
        set.add(mode);
        System.out.println(">>> " + mode);
    }
    assertEquals(CacheMode.values().length, set.size());
}
Also used : ConfigParameter(org.apache.ignite.testframework.configvariations.ConfigParameter) CacheMode(org.apache.ignite.cache.CacheMode) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with CacheMode

use of org.apache.ignite.cache.CacheMode in project ignite by apache.

the class ParametersTest method testEnumVariations.

/**
 * @throws Exception If failed.
 */
@Test
public void testEnumVariations() throws Exception {
    ConfigParameter<CacheConfiguration>[] modes = Parameters.enumParameters("setCacheMode", CacheMode.class);
    assertEquals(CacheMode.values().length, modes.length);
    Set<CacheMode> res = new HashSet<>();
    for (ConfigParameter<CacheConfiguration> modeApplier : modes) {
        CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        modeApplier.apply(cfg);
        CacheMode mode = cfg.getCacheMode();
        res.add(mode);
        System.out.println(">>> " + mode);
    }
    assertEquals(modes.length, res.size());
}
Also used : ConfigParameter(org.apache.ignite.testframework.configvariations.ConfigParameter) CacheMode(org.apache.ignite.cache.CacheMode) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with CacheMode

use of org.apache.ignite.cache.CacheMode in project ignite by apache.

the class CacheMvccBasicContinuousQueryTest method checkUpdateCountersGapIsProcessedSimple.

/**
 * @throws Exception if failed.
 */
private void checkUpdateCountersGapIsProcessedSimple(CacheMode cacheMode) throws Exception {
    testSpi = true;
    final int srvCnt = 4;
    final int backups = srvCnt - 1;
    startGridsMultiThreaded(srvCnt);
    client = true;
    IgniteEx nearNode = startGrid(srvCnt);
    IgniteCache<Object, Object> cache = nearNode.createCache(cacheConfiguration(cacheMode, FULL_SYNC, backups, srvCnt).setIndexedTypes(Integer.class, Integer.class));
    IgniteEx primary = grid(0);
    List<Integer> keys = primaryKeys(primary.cache(DEFAULT_CACHE_NAME), 3);
    ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
    List<CacheEntryEvent> arrivedEvts = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(2);
    qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {

        @Override
        public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
            for (CacheEntryEvent e : evts) {
                arrivedEvts.add(e);
                latch.countDown();
            }
        }
    });
    QueryCursor<Cache.Entry<Integer, Integer>> cur = nearNode.cache(DEFAULT_CACHE_NAME).query(qry);
    // Initial value.
    cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(keys.get(0))).getAll();
    // prevent first transaction prepare on backups
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(primary);
    final AtomicInteger dhtPrepMsgLimiter = new AtomicInteger();
    spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtTxPrepareRequest)
                return dhtPrepMsgLimiter.getAndIncrement() < backups;
            if (msg instanceof GridContinuousMessage)
                return true;
            return false;
        }
    });
    // First tx. Expect it will be prepared only on the primary node and GridDhtTxPrepareRequests to remotes
    // will be swallowed.
    Transaction txA = nearNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
    cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(keys.get(1))).getAll();
    txA.commitAsync();
    // Wait until first tx changes it's status to PREPARING.
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            boolean preparing = nearNode.context().cache().context().tm().activeTransactions().stream().allMatch(tx -> tx.state() == PREPARING);
            boolean allPrepsSwallowed = dhtPrepMsgLimiter.get() == backups;
            return preparing && allPrepsSwallowed;
        }
    }, 3_000);
    // Second tx.
    GridTestUtils.runAsync(() -> {
        try (Transaction txB = nearNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(keys.get(2)));
            txB.commit();
        }
    }).get();
    long primaryUpdCntr = getUpdateCounter(primary, keys.get(0));
    // There were three updates: init, first and second.
    assertEquals(3, primaryUpdCntr);
    // drop primary
    stopGrid(primary.name());
    // Wait all txs are rolled back.
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            boolean allRolledBack = true;
            for (int i = 1; i < srvCnt; i++) {
                boolean rolledBack = grid(i).context().cache().context().tm().activeTransactions().stream().allMatch(tx -> tx.state() == ROLLED_BACK);
                allRolledBack &= rolledBack;
            }
            return allRolledBack;
        }
    }, 3_000);
    for (int i = 1; i < srvCnt; i++) {
        IgniteCache backupCache = grid(i).cache(DEFAULT_CACHE_NAME);
        int size = backupCache.query(new SqlFieldsQuery("select * from Integer")).getAll().size();
        long backupCntr = getUpdateCounter(grid(i), keys.get(0));
        assertEquals(2, size);
        assertEquals(primaryUpdCntr, backupCntr);
    }
    assertTrue(latch.await(3, SECONDS));
    assertEquals(2, arrivedEvts.size());
    assertEquals(keys.get(0), arrivedEvts.get(0).getKey());
    assertEquals(keys.get(2), arrivedEvts.get(1).getKey());
    cur.close();
    nearNode.close();
}
Also used : GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Affinity(org.apache.ignite.cache.affinity.Affinity) CacheContinuousQueryManager(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager) Transaction(org.apache.ignite.transactions.Transaction) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) IgniteEx(org.apache.ignite.internal.IgniteEx) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Cache(javax.cache.Cache) CacheException(javax.cache.CacheException) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) G(org.apache.ignite.internal.util.typedef.G) Collection(java.util.Collection) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) PREPARING(org.apache.ignite.transactions.TransactionState.PREPARING) GridContinuousMessage(org.apache.ignite.internal.processors.continuous.GridContinuousMessage) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) List(java.util.List) CacheEntryEvent(javax.cache.event.CacheEntryEvent) QueryCursor(org.apache.ignite.cache.query.QueryCursor) TX_SIZE_THRESHOLD(org.apache.ignite.internal.processors.cache.mvcc.MvccCachingManager.TX_SIZE_THRESHOLD) PA(org.apache.ignite.internal.util.typedef.PA) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Message(org.apache.ignite.plugin.extensions.communication.Message) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridContinuousProcessor(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor) SECONDS(java.util.concurrent.TimeUnit.SECONDS) CacheMode(org.apache.ignite.cache.CacheMode) GridContinuousMessage(org.apache.ignite.internal.processors.continuous.GridContinuousMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ArrayList(java.util.ArrayList) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) GridContinuousMessage(org.apache.ignite.internal.processors.continuous.GridContinuousMessage) CountDownLatch(java.util.concurrent.CountDownLatch) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx)

Aggregations

CacheMode (org.apache.ignite.cache.CacheMode)20 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)9 HashSet (java.util.HashSet)8 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 List (java.util.List)6 IgniteCache (org.apache.ignite.IgniteCache)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)6 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)6 Message (org.apache.ignite.plugin.extensions.communication.Message)6 Collection (java.util.Collection)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 U (org.apache.ignite.internal.util.typedef.internal.U)5 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)5 HashMap (java.util.HashMap)4