Search in sources :

Example 16 with IgniteCacheProxy

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.

the class TxDeadlockDetectionMessageMarshallingTest method testMessageUnmarshallWithoutCacheContext.

/**
     * @throws Exception If failed.
     */
public void testMessageUnmarshallWithoutCacheContext() throws Exception {
    try {
        Ignite ignite = startGrid(0);
        CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
        IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(ccfg);
        clientMode = true;
        Ignite client = startGrid(1);
        final GridCacheSharedContext<Object, Object> clientCtx = ((IgniteKernal) client).context().cache().context();
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicBoolean res = new AtomicBoolean();
        clientCtx.gridIO().addMessageListener(TOPIC, new GridMessageListener() {

            @Override
            public void onMessage(UUID nodeId, Object msg) {
                if (msg instanceof TxLocksResponse) {
                    try {
                        ((TxLocksResponse) msg).finishUnmarshal(clientCtx, clientCtx.deploy().globalLoader());
                        res.set(true);
                    } catch (Exception e) {
                        log.error("Message unmarshal failed", e);
                    } finally {
                        latch.countDown();
                    }
                }
            }
        });
        GridCacheContext cctx = ((IgniteCacheProxy) cache).context();
        KeyCacheObject key = cctx.toCacheKeyObject(1);
        TxLocksResponse msg = new TxLocksResponse();
        msg.addKey(cctx.txKey(key));
        msg.prepareMarshal(cctx.shared());
        ((IgniteKernal) ignite).context().cache().context().gridIO().sendToCustomTopic(((IgniteKernal) client).localNode(), TOPIC, msg, GridIoPolicy.PUBLIC_POOL);
        boolean await = latch.await(1, TimeUnit.SECONDS);
        assertTrue(await && res.get());
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Ignite(org.apache.ignite.Ignite) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) UUID(java.util.UUID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 17 with IgniteCacheProxy

use of org.apache.ignite.internal.processors.cache.IgniteCacheProxy in project ignite by apache.

the class IgfsCacheSelfTest method testCache.

/**
     * Test cache.
     *
     * @throws Exception If failed.
     */
public void testCache() throws Exception {
    final Ignite g = grid();
    Collection<IgniteCacheProxy<?, ?>> caches = ((IgniteKernal) g).caches();
    info("Caches: " + F.viewReadOnly(caches, new C1<IgniteCacheProxy<?, ?>, Object>() {

        @Override
        public Object apply(IgniteCacheProxy<?, ?> c) {
            return c.getName();
        }
    }));
    assertEquals(1, caches.size());
    assert CACHE_NAME.equals(caches.iterator().next().getName());
    GridTestUtils.assertThrows(log(), new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            g.cache(((IgniteKernal) g).igfsx("igfs").configuration().getMetaCacheConfiguration().getName());
            return null;
        }
    }, IllegalStateException.class, null);
    GridTestUtils.assertThrows(log(), new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            g.cache(((IgniteKernal) g).igfsx("igfs").configuration().getDataCacheConfiguration().getName());
            return null;
        }
    }, IllegalStateException.class, null);
    assert g.cache(CACHE_NAME) != null;
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) Ignite(org.apache.ignite.Ignite) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy)

Aggregations

IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)17 Ignite (org.apache.ignite.Ignite)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)4 IgniteKernal (org.apache.ignite.internal.IgniteKernal)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)2 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1