ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/7] incubator-ignite git commit: ignite-45: wip
Date Tue, 13 Jan 2015 15:21:51 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-1 bb32d468d -> 018a9b0cd


ignite-45: wip


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/ef624c58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ef624c58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ef624c58

Branch: refs/heads/ignite-1
Commit: ef624c58cf434469d58efa8b6e06e576e24c4a55
Parents: 180720f
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Tue Jan 6 15:45:00 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Tue Jan 6 15:45:00 2015 +0300

----------------------------------------------------------------------
 .../services/javax.cache.spi.CachingProvider    |   1 +
 .../org/apache/ignite/IgniteCacheMXBean.java    |  64 ++++
 .../org/apache/ignite/IgniteCacheManager.java   | 311 +++++++++++++++++++
 .../apache/ignite/IgniteCachingProvider.java    | 157 ++++++++++
 .../processors/cache/IgniteCacheProxy.java      |   6 +-
 .../grid/cache/GridCacheConfiguration.java      |  11 +-
 .../org/gridgain/grid/kernal/GridGainEx.java    |   2 +-
 .../cache/IgniteCachingProviderSelfTest.java    | 123 ++++++++
 8 files changed, 670 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/main/java/META-INF/services/javax.cache.spi.CachingProvider
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/META-INF/services/javax.cache.spi.CachingProvider
b/modules/core/src/main/java/META-INF/services/javax.cache.spi.CachingProvider
new file mode 100644
index 0000000..eb232dc
--- /dev/null
+++ b/modules/core/src/main/java/META-INF/services/javax.cache.spi.CachingProvider
@@ -0,0 +1 @@
+org.apache.ignite.IgniteCachingProvider

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/main/java/org/apache/ignite/IgniteCacheMXBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCacheMXBean.java b/modules/core/src/main/java/org/apache/ignite/IgniteCacheMXBean.java
new file mode 100644
index 0000000..0200717
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCacheMXBean.java
@@ -0,0 +1,64 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite;
+
+import javax.cache.*;
+import javax.cache.configuration.*;
+import javax.cache.management.*;
+
+/**
+ *
+ */
+public class IgniteCacheMXBean implements CacheMXBean {
+    /** */
+    private final Cache<?, ?> cache;
+
+    /**
+     * @param cache Cache.
+     */
+    public IgniteCacheMXBean(Cache<?, ?> cache) {
+        this.cache = cache;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getKeyType() {
+        return cache.getConfiguration(CompleteConfiguration.class).getKeyType().getName();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getValueType() {
+        return cache.getConfiguration(CompleteConfiguration.class).getValueType().getName();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isReadThrough() {
+        return cache.getConfiguration(CompleteConfiguration.class).isReadThrough();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isWriteThrough() {
+        return cache.getConfiguration(CompleteConfiguration.class).isWriteThrough();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isStoreByValue() {
+        return cache.getConfiguration(CompleteConfiguration.class).isStoreByValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isStatisticsEnabled() {
+        return cache.getConfiguration(CompleteConfiguration.class).isStatisticsEnabled();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isManagementEnabled() {
+        return cache.getConfiguration(CompleteConfiguration.class).isManagementEnabled();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java b/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java
new file mode 100644
index 0000000..7cfeca1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java
@@ -0,0 +1,311 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite;
+
+import org.apache.ignite.configuration.*;
+import org.gridgain.grid.cache.*;
+
+import javax.cache.*;
+import javax.cache.configuration.*;
+import javax.cache.spi.*;
+import java.net.*;
+import java.util.*;
+import java.util.concurrent.atomic.*;
+
+/**
+ *
+ */
+public class IgniteCacheManager implements CacheManager {
+    /** */
+    private final Map<String, Ignite> igniteMap = new HashMap<>();
+
+    /** */
+    private final URI uri;
+
+    /** */
+    private final CachingProvider cachingProvider;
+
+    /** */
+    private final ClassLoader clsLdr;
+
+    /** */
+    private final AtomicBoolean closed = new AtomicBoolean();
+
+    /**
+     * @param uri Uri.
+     * @param cachingProvider Caching provider.
+     * @param clsLdr Class loader.
+     */
+    public IgniteCacheManager(URI uri, CachingProvider cachingProvider, ClassLoader clsLdr)
{
+        this.uri = uri;
+        this.cachingProvider = cachingProvider;
+        this.clsLdr = clsLdr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CachingProvider getCachingProvider() {
+        return cachingProvider;
+    }
+
+    /** {@inheritDoc} */
+    @Override public URI getURI() {
+        return uri;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClassLoader getClassLoader() {
+        return clsLdr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Properties getProperties() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V, C extends Configuration<K, V>> Cache<K, V>
createCache(String cacheName, C cacheCfg)
+        throws IllegalArgumentException {
+        ensureNotClosed();
+
+        if (cacheCfg == null)
+            throw new NullPointerException();
+
+        if (!(cacheCfg instanceof CompleteConfiguration))
+            throw new UnsupportedOperationException("Configuration is not supported: " +
cacheCfg);
+
+        if (cacheCfg instanceof GridCacheConfiguration) {
+            String cfgCacheName = ((GridCacheConfiguration)cacheCfg).getName();
+
+            if (cfgCacheName != null && !cacheName.equals(cfgCacheName))
+                throw new IllegalArgumentException();
+
+            cacheCfg = (C)new GridCacheConfiguration((GridCacheConfiguration)cacheCfg);
+
+            ((GridCacheConfiguration)cacheCfg).setName(cacheName);
+        }
+
+        Ignite ignite;
+
+        synchronized (igniteMap) {
+            if (igniteMap.containsKey(cacheName))
+                throw new CacheException("Cache already exists [cacheName=" + cacheName +
", manager=" + uri + ']');
+
+            if (uri.equals(cachingProvider.getDefaultURI())) {
+                IgniteConfiguration cfg = new IgniteConfiguration();
+                cfg.setGridName("grid-for-" + cacheName);
+
+                cfg.setCacheConfiguration(new GridCacheConfiguration((CompleteConfiguration)cacheCfg));
+
+                cfg.getCacheConfiguration()[0].setName(cacheName);
+
+                try {
+                    ignite = Ignition.start(cfg);
+                }
+                catch (IgniteCheckedException e) {
+                    throw new CacheException(e);
+                }
+            }
+            else
+                throw new UnsupportedOperationException();
+
+            igniteMap.put(cacheName, ignite);
+        }
+
+        return ignite.jcache(cacheName);
+    }
+
+    /**
+     * @param cacheName Cache name.
+     */
+    private <K, V> IgniteCache<K, V> findCache(String cacheName) {
+        Ignite ignite;
+
+        synchronized (igniteMap) {
+            ignite = igniteMap.get(cacheName);
+        }
+
+        if (ignite == null)
+            return null;
+
+        return ignite.jcache(cacheName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> Cache<K, V> getCache(String cacheName, Class<K>
keyType, Class<V> valType) {
+        ensureNotClosed();
+
+        Cache<K, V> cache = findCache(cacheName);
+
+        if (cache != null) {
+            if(!keyType.isAssignableFrom(cache.getConfiguration(Configuration.class).getKeyType()))
+                throw new ClassCastException();
+
+            if(!valType.isAssignableFrom(cache.getConfiguration(Configuration.class).getValueType()))
+                throw new ClassCastException();
+        }
+
+        return cache;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> Cache<K, V> getCache(String cacheName) {
+        ensureNotClosed();
+
+        IgniteCache<K, V> cache = findCache(cacheName);
+
+        if (cache != null) {
+            if(cache.getConfiguration(Configuration.class).getKeyType() != Object.class)
+                throw new IllegalArgumentException();
+
+            if(cache.getConfiguration(Configuration.class).getValueType() != Object.class)
+                throw new IllegalArgumentException();
+        }
+
+        return cache;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterable<String> getCacheNames() {
+        ensureNotClosed();
+
+        Collection<String> res;
+
+        synchronized (igniteMap) {
+            res = new ArrayList<>(igniteMap.keySet());
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void destroyCache(String cacheName) {
+        ensureNotClosed();
+
+        if (cacheName == null)
+            throw new NullPointerException();
+
+        Ignite ignite;
+
+        synchronized (igniteMap) {
+            ignite = igniteMap.remove(cacheName);
+        }
+
+        if (ignite != null) {
+            try {
+                ignite.close();
+            }
+            catch (Exception ignored) {
+
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void enableManagement(String cacheName, boolean enabled) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void enableStatistics(String cacheName, boolean enabled) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     *
+     */
+    private void ensureNotClosed() throws IllegalStateException {
+        if (closed.get())
+            throw new IllegalStateException("Cache manager are closed [uri=" + uri + ", classLoader="
+ clsLdr + ']');
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() {
+        if (closed.compareAndSet(false, true)) {
+            Ignite[] ignites;
+
+            synchronized (igniteMap) {
+                ignites = igniteMap.values().toArray(new Ignite[igniteMap.values().size()]);
+            }
+
+            for (Ignite ignite : ignites) {
+                try {
+                    ignite.close();
+                }
+                catch (Exception ignored) {
+                    // Ignore any exceptions according to javadoc of javax.cache.CacheManager#close()
+                }
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isClosed() {
+        return closed.get();
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T unwrap(Class<T> clazz) {
+        if(clazz.isAssignableFrom(getClass()))
+            return clazz.cast(this);
+
+//        if(clazz.isAssignableFrom(ignite.getClass()))
+//            return clazz.cast(ignite);
+
+        throw new IllegalArgumentException();
+    }
+
+//    /**
+//     *
+//     */
+//    private static class Future<T> {
+//        /** */
+//        private volatile T res;
+//
+//        /** */
+//        private volatile Throwable e;
+//
+//        public T get() throws CacheException {
+//            if (res == null && e == null) {
+//                synchronized (this) {
+//                    try {
+//                        while (res == null && e == null)
+//                            wait();
+//                    }
+//                    catch (InterruptedException e) {
+//                        Thread.currentThread().interrupt();
+//
+//                        throw new RuntimeException(e);
+//                    }
+//                }
+//            }
+//
+//            if (res != null)
+//                return res;
+//
+//            assert e != null;
+//
+//            throw new CacheException(e);
+//        }
+//
+//        public synchronized void setException(Throwable e) {
+//            this.e = e;
+//
+//            notifyAll();
+//        }
+//
+//        public synchronized void setCacheManager(T res) {
+//            assert res != null;
+//
+//            this.res = res;
+//
+//            notifyAll();
+//        }
+//    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/main/java/org/apache/ignite/IgniteCachingProvider.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCachingProvider.java b/modules/core/src/main/java/org/apache/ignite/IgniteCachingProvider.java
new file mode 100644
index 0000000..eab4cf9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCachingProvider.java
@@ -0,0 +1,157 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite;
+
+import org.gridgain.grid.kernal.*;
+import org.gridgain.grid.util.typedef.internal.*;
+import org.jetbrains.annotations.*;
+
+import javax.cache.*;
+import javax.cache.configuration.*;
+import javax.cache.spi.*;
+import java.net.*;
+import java.util.*;
+
+/**
+ *
+ */
+public class IgniteCachingProvider implements CachingProvider {
+    /** */
+    private static final URI DEFAULT_URI;
+
+    static {
+        URI uri = null;
+
+        try {
+            URL dfltCfgURL = U.resolveGridGainUrl(GridGainEx.DFLT_CFG);
+            if (dfltCfgURL != null)
+                uri = dfltCfgURL.toURI();
+        }
+        catch (URISyntaxException ignored) {
+
+        }
+
+        if (uri == null)
+            uri = URI.create("ignite://default");
+
+        DEFAULT_URI = uri;
+    }
+
+    /** */
+    private final Map<ClassLoader, Map<URI, IgniteCacheManager>> cacheManagers
= new WeakHashMap<>();
+
+    /** {@inheritDoc} */
+    @Override public CacheManager getCacheManager(@Nullable URI uri, ClassLoader clsLdr,
Properties props) {
+        if (uri == null)
+            uri = getDefaultURI();
+
+        if (clsLdr == null)
+            clsLdr = getDefaultClassLoader();
+
+        synchronized (cacheManagers) {
+            Map<URI, IgniteCacheManager> uriMap = cacheManagers.get(clsLdr);
+
+            if (uriMap == null) {
+                uriMap = new HashMap<>();
+
+                cacheManagers.put(clsLdr, uriMap);
+            }
+
+            IgniteCacheManager mgr = uriMap.get(uri);
+
+            if (mgr == null) {
+                mgr = new IgniteCacheManager(uri, this, clsLdr);
+
+                uriMap.put(uri, mgr);
+            }
+
+            return mgr;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public ClassLoader getDefaultClassLoader() {
+        return getClass().getClassLoader();
+    }
+
+    /** {@inheritDoc} */
+    @Override public URI getDefaultURI() {
+        return DEFAULT_URI;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Properties getDefaultProperties() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheManager getCacheManager(URI uri, ClassLoader clsLdr) {
+        return getCacheManager(uri, clsLdr, getDefaultProperties());
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheManager getCacheManager() {
+        return getCacheManager(getDefaultURI(), getDefaultClassLoader());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() {
+        Collection<IgniteCacheManager> mgrs = new ArrayList<>();
+
+        synchronized (cacheManagers) {
+            for (Map<URI, IgniteCacheManager> uriMap : cacheManagers.values())
+                mgrs.addAll(uriMap.values());
+
+            cacheManagers.clear();
+        }
+
+        for (IgniteCacheManager mgr : mgrs)
+            mgr.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close(ClassLoader clsLdr) {
+        Collection<IgniteCacheManager> mgrs;
+
+        synchronized (cacheManagers) {
+            Map<URI, IgniteCacheManager> uriMap = cacheManagers.remove(clsLdr);
+
+            if (uriMap == null)
+                return;
+
+            mgrs = uriMap.values();
+        }
+
+        for (IgniteCacheManager mgr : mgrs)
+            mgr.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close(URI uri, ClassLoader clsLdr) {
+        IgniteCacheManager mgr;
+
+        synchronized (cacheManagers) {
+            Map<URI, IgniteCacheManager> uriMap = cacheManagers.get(clsLdr);
+
+            if (uriMap == null)
+                return;
+
+            mgr = uriMap.remove(uri);
+        }
+
+        if (mgr != null)
+            mgr.close();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isSupported(OptionalFeature optionalFeature) {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index a985fde..df9bc41 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -88,10 +88,12 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
 
     /** {@inheritDoc} */
     @Override public <C extends Configuration<K, V>> C getConfiguration(Class<C>
clazz) {
-        if (!clazz.equals(GridCacheConfiguration.class))
+        GridCacheConfiguration cfg = ctx.config();
+
+        if (!clazz.isAssignableFrom(cfg.getClass()))
             throw new IllegalArgumentException();
 
-        return (C)ctx.config();
+        return clazz.cast(cfg);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
index 5a9a675..f92c10a 100644
--- a/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
+++ b/modules/core/src/main/java/org/gridgain/grid/cache/GridCacheConfiguration.java
@@ -331,9 +331,16 @@ public class GridCacheConfiguration extends MutableConfiguration {
     /**
      * Copy constructor.
      *
-     * @param cc Configuration to copy.
+     * @param cfg Configuration to copy.
      */
-    public GridCacheConfiguration(GridCacheConfiguration cc) {
+    public GridCacheConfiguration(CompleteConfiguration cfg) {
+        super(cfg);
+
+        if (!(cfg instanceof GridCacheConfiguration))
+            return;
+
+        GridCacheConfiguration cc = (GridCacheConfiguration)cfg;
+
         /*
          * NOTE: MAKE SURE TO PRESERVE ALPHABETIC ORDER!
          * ==============================================

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/main/java/org/gridgain/grid/kernal/GridGainEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/GridGainEx.java b/modules/core/src/main/java/org/gridgain/grid/kernal/GridGainEx.java
index 555ab55..24b92dd 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/GridGainEx.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/GridGainEx.java
@@ -103,7 +103,7 @@ import static org.apache.ignite.plugin.segmentation.GridSegmentationPolicy.*;
  */
 public class GridGainEx {
     /** Default configuration path relative to GridGain home. */
-    private static final String DFLT_CFG = "config/default-config.xml";
+    public static final String DFLT_CFG = "config/default-config.xml";
 
     /** Map of named grids. */
     private static final ConcurrentMap<Object, GridNamedInstance> grids = new ConcurrentHashMap8<>();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ef624c58/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachingProviderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachingProviderSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachingProviderSelfTest.java
new file mode 100644
index 0000000..c224ec2
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachingProviderSelfTest.java
@@ -0,0 +1,123 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import com.google.common.collect.*;
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.gridgain.grid.cache.*;
+
+import javax.cache.*;
+import javax.cache.spi.*;
+import java.util.*;
+
+/**
+ *
+ */
+public class IgniteCachingProviderSelfTest extends IgniteCacheAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected GridCacheMode cacheMode() {
+        return GridCacheMode.REPLICATED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected GridCacheAtomicityMode atomicityMode() {
+        return GridCacheAtomicityMode.TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected GridCacheDistributionMode distributionMode() {
+        return GridCacheDistributionMode.PARTITIONED_ONLY;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getTestGridName(int idx) {
+        assert idx == 0;
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        assert gridName == null;
+
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        GridCacheConfiguration cache1 = cacheConfiguration(null);
+        cache1.setName("cache1");
+
+        GridCacheConfiguration cache2 = cacheConfiguration(null);
+        cache2.setName("cache2");
+
+        cfg.setCacheConfiguration(cacheConfiguration(null), cache1, cache2);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        // No-op. Disabling start of ignite.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     *
+     */
+    public void testStartIgnite() {
+        CachingProvider cachingProvider = Caching.getCachingProvider();
+
+        assert cachingProvider instanceof IgniteCachingProvider;
+
+        CacheManager cacheMgr = cachingProvider.getCacheManager();
+
+        assertEquals(Collections.<String>emptySet(), Sets.newHashSet(cacheMgr.getCacheNames()));
+
+        Cache<Integer, String> cacheA = cacheMgr.createCache("a", new GridCacheConfiguration());
+
+        cacheA.put(1, "1");
+
+        assertEquals("1", cacheA.get(1));
+
+        cacheMgr.createCache("b", new GridCacheConfiguration());
+
+        assertEquals(Sets.newHashSet("a", "b"), Sets.newHashSet(cacheMgr.getCacheNames()));
+
+        cacheMgr.destroyCache("a");
+        cacheMgr.destroyCache("b");
+
+        assertEquals(Collections.<String>emptySet(), Sets.newHashSet(cacheMgr.getCacheNames()));
+    }
+
+    /**
+     *
+     */
+    public void testCloseManager() throws Exception {
+        startGridsMultiThreaded(1);
+
+        CachingProvider cachingProvider = Caching.getCachingProvider();
+
+        assert cachingProvider instanceof IgniteCachingProvider;
+
+        CacheManager cacheMgr = cachingProvider.getCacheManager();
+
+        cachingProvider.close();
+
+        assertNotSame(cacheMgr, cachingProvider.getCacheManager());
+    }
+}


Mime
View raw message