Search in sources :

Example 6 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class IgniteServiceDynamicCachesSelfTest method testDeployCalledBeforeCacheStart.

/**
     * @throws Exception If failed.
     */
public void testDeployCalledBeforeCacheStart() throws Exception {
    String cacheName = "cache";
    CacheConfiguration ccfg = new CacheConfiguration(cacheName);
    ccfg.setBackups(1);
    Ignite ig = ignite(0);
    final IgniteServices svcs = ig.services();
    final String svcName = "myService";
    ig.createCache(ccfg);
    Object key = primaryKey(ig.cache(cacheName));
    ig.destroyCache(cacheName);
    awaitPartitionMapExchange();
    svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);
    assert svcs.service(svcName) == null;
    ig.createCache(ccfg);
    try {
        boolean res = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return svcs.service(svcName) != null;
            }
        }, 10 * 1000);
        assertTrue("Service was not deployed", res);
        info("stopping cache: " + cacheName);
        ig.destroyCache(cacheName);
        res = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return svcs.service(svcName) == null;
            }
        }, 10 * 1000);
        assertTrue("Service was not undeployed", res);
    } finally {
        ig.services().cancelAll();
        ig.destroyCache(cacheName);
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) IgniteServices(org.apache.ignite.IgniteServices) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 7 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridCacheAbstractFullApiSelfTest method checkGetOutTx.

/**
     * @throws Exception If failed.
     */
private void checkGetOutTx(boolean async) throws Exception {
    final AtomicInteger lockEvtCnt = new AtomicInteger();
    IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            lockEvtCnt.incrementAndGet();
            return true;
        }
    };
    try {
        IgniteCache<String, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
        List<String> keys = primaryKeysForCache(cache, 2);
        assertEquals(2, keys.size());
        cache.put(keys.get(0), 0);
        cache.put(keys.get(1), 1);
        grid(0).events().localListen(lsnr, EVT_CACHE_OBJECT_LOCKED, EVT_CACHE_OBJECT_UNLOCKED);
        try (Transaction tx = transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
            Integer val0;
            if (async)
                val0 = cache.getAsync(keys.get(0)).get();
            else
                val0 = cache.get(keys.get(0));
            assertEquals(0, val0.intValue());
            Map<String, Integer> allOutTx;
            if (async)
                allOutTx = cache.getAllOutTxAsync(F.asSet(keys.get(1))).get();
            else
                allOutTx = cache.getAllOutTx(F.asSet(keys.get(1)));
            assertEquals(1, allOutTx.size());
            assertTrue(allOutTx.containsKey(keys.get(1)));
            assertEquals(1, allOutTx.get(keys.get(1)).intValue());
        }
        assertTrue(GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                info("Lock event count: " + lockEvtCnt.get());
                if (atomicityMode() == ATOMIC)
                    return lockEvtCnt.get() == 0;
                if (cacheMode() == PARTITIONED && nearEnabled()) {
                    if (!grid(0).configuration().isClientMode())
                        return lockEvtCnt.get() == 4;
                }
                return lockEvtCnt.get() == 2;
            }
        }, 15000));
    } finally {
        grid(0).events().stopLocalListen(lsnr, EVT_CACHE_OBJECT_LOCKED, EVT_CACHE_OBJECT_UNLOCKED);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PA(org.apache.ignite.internal.util.typedef.PA) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Event(org.apache.ignite.events.Event) CacheEvent(org.apache.ignite.events.CacheEvent)

Example 8 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class IgniteCacheClientNodeChangingTopologyTest method checkData.

/**
     * @param map Expected data.
     * @param keys Expected keys (if expected data is not specified).
     * @param clientCache Client cache.
     * @param expNodes Expected nodes number.
     * @throws Exception If failed.
     */
private void checkData(final Map<Integer, Integer> map, final Set<Integer> keys, IgniteCache<?, ?> clientCache, final int expNodes) throws Exception {
    final List<Ignite> nodes = G.allGrids();
    final Affinity<Integer> aff = nodes.get(0).affinity(DEFAULT_CACHE_NAME);
    assertEquals(expNodes, nodes.size());
    boolean hasNearCache = clientCache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null;
    final Ignite nearCacheNode = hasNearCache ? clientCache.unwrap(Ignite.class) : null;
    boolean wait = GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            try {
                Set<Integer> keys0 = map != null ? map.keySet() : keys;
                assertNotNull(keys0);
                for (Integer key : keys0) {
                    GridCacheVersion ver = null;
                    Object val = null;
                    for (Ignite node : nodes) {
                        IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
                        boolean affNode = aff.isPrimaryOrBackup(node.cluster().localNode(), key);
                        Object val0 = cache.localPeek(key);
                        if (affNode || node == nearCacheNode) {
                            if (map != null)
                                assertEquals("Unexpected value for " + node.name(), map.get(key), val0);
                            else
                                assertNotNull("Unexpected value for " + node.name(), val0);
                            GridCacheAdapter cache0 = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
                            if (affNode && cache0.isNear())
                                cache0 = ((GridNearCacheAdapter) cache0).dht();
                            GridCacheEntryEx entry = cache0.entryEx(key);
                            try {
                                entry.unswap(true);
                                assertNotNull("No entry [node=" + node.name() + ", key=" + key + ']', entry);
                                GridCacheVersion ver0 = entry instanceof GridNearCacheEntry ? ((GridNearCacheEntry) entry).dhtVersion() : entry.version();
                                assertNotNull("Null version [node=" + node.name() + ", key=" + key + ']', ver0);
                                if (ver == null) {
                                    ver = ver0;
                                    val = val0;
                                } else {
                                    assertEquals("Version check failed [node=" + node.name() + ", key=" + key + ", affNode=" + affNode + ", primary=" + aff.isPrimary(node.cluster().localNode(), key) + ']', ver0, ver);
                                    assertEquals("Value check failed [node=" + node.name() + ", key=" + key + ", affNode=" + affNode + ", primary=" + aff.isPrimary(node.cluster().localNode(), key) + ']', val0, val);
                                }
                            } finally {
                                cache0.context().evicts().touch(entry, cache0.context().affinity().affinityTopologyVersion());
                            }
                        } else
                            assertNull("Unexpected non-null value for " + node.name(), val0);
                    }
                }
            } catch (AssertionError e) {
                log.info("Check failed, will retry: " + e);
                return false;
            } catch (Exception e) {
                fail("Unexpected exception: " + e);
            }
            return true;
        }
    }, 10_000);
    assertTrue("Data check failed.", wait);
}
Also used : ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) Set(java.util.Set) HashSet(java.util.HashSet) IgniteCache(org.apache.ignite.IgniteCache) TimeoutException(java.util.concurrent.TimeoutException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PA(org.apache.ignite.internal.util.typedef.PA) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Ignite(org.apache.ignite.Ignite)

Example 9 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class CacheLateAffinityAssignmentTest method checkServicesDeploy.

/**
     * @param ignite Node.
     * @param affinity Affinity.
     * @throws Exception If failed.
     */
private void checkServicesDeploy(Ignite ignite, final List<List<ClusterNode>> affinity) throws Exception {
    Affinity<Object> aff = ignite.affinity(CACHE_NAME1);
    for (int i = 0; i < 10; i++) {
        final int part = aff.partition(i);
        final String srvcName = "service-" + i;
        final ClusterNode srvcNode = affinity.get(part).get(0);
        boolean wait = GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                TestService srvc = grid(srvcNode).services().service(srvcName);
                if (srvc == null)
                    return false;
                assertEquals(srvcNode, srvc.serviceNode());
                return true;
            }
        }, 5000);
        assertTrue(wait);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) PA(org.apache.ignite.internal.util.typedef.PA)

Example 10 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class CacheContinuousBatchAckTest method checkBackupAcknowledgeMessage.

/**
     * @param ccfg Cache configuration.
     * @throws Exception If failed.
     */
private void checkBackupAcknowledgeMessage(CacheConfiguration<Object, Object> ccfg) throws Exception {
    QueryCursor qry = null;
    IgniteCache<Object, Object> cache = null;
    try {
        ContinuousQuery q = new ContinuousQuery();
        q.setLocalListener(new CacheEntryUpdatedListener() {

            @Override
            public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
            // No-op.
            }
        });
        cache = grid(SERVER).getOrCreateCache(ccfg);
        qry = cache.query(q);
        for (int i = 0; i < 10000; i++) cache.put(i, i);
        assert !GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return fail.get();
            }
        }, 1300L);
    } finally {
        if (qry != null)
            qry.close();
        if (cache != null)
            grid(SERVER).destroyCache(cache.getName());
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) QueryCursor(org.apache.ignite.cache.query.QueryCursor)

Aggregations

PA (org.apache.ignite.internal.util.typedef.PA)48 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 Ignite (org.apache.ignite.Ignite)17 ArrayList (java.util.ArrayList)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 UUID (java.util.UUID)9 CacheEntryEvent (javax.cache.event.CacheEntryEvent)9 IgniteException (org.apache.ignite.IgniteException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IgniteCache (org.apache.ignite.IgniteCache)5 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 T2 (org.apache.ignite.internal.util.typedef.T2)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Transaction (org.apache.ignite.transactions.Transaction)4