Author: tolusha
Date: 2010-07-13 07:48:53 -0400 (Tue, 13 Jul 2010)
New Revision: 2776
Added:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/infinispan/
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/infinispan/TestISPNCache.java
Removed:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/ispn/
Log:
EXOJCR-837: move test to another packet
Added:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/infinispan/TestISPNCache.java
===================================================================
---
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/infinispan/TestISPNCache.java
(rev 0)
+++
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/infinispan/TestISPNCache.java 2010-07-13
11:48:53 UTC (rev 2776)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.infinispan;
+
+import junit.framework.TestCase;
+
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy
Bazko</a>
+ * @version $Id: TestINSPCache.java 111 2010-11-11 11:11:11Z tolusha $
+ *
+ */
+public class TestISPNCache extends TestCase
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ /**
+ * Test default cache and base operation.
+ *
+ * @throws Exception
+ */
+ public void testGetCache() throws Exception
+ {
+ // Create cache manager
+ GlobalConfiguration myGlobalConfig = new GlobalConfiguration();
+ EmbeddedCacheManager manager = new DefaultCacheManager(myGlobalConfig);
+
+ // Create a cache
+ Configuration config = new Configuration();
+ manager.defineConfiguration("cache", config);
+ Cache cache = manager.getCache("cache");
+
+ cache.put("key", "value");
+ assertTrue(cache.size() == 1);
+ assertTrue(cache.containsKey("key"));
+
+ String value = (String)cache.remove("key");
+ assertTrue(value.equals("value"));
+ assertTrue(cache.isEmpty());
+
+ cache.put("key", "value");
+ cache.putIfAbsent("key", "newValue");
+ assertTrue("value".equals(cache.get("key")));
+
+ cache.clear();
+ assertTrue(cache.isEmpty());
+
+ cache.put("key", "value", 2, TimeUnit.SECONDS);
+ assertTrue(cache.containsKey("key"));
+ Thread.sleep(2000);
+ assertFalse(cache.containsKey("key"));
+ }
+
+ /**
+ * Test cluster cache and base operation.
+ *
+ * @throws Exception
+ */
+ public void testGetClusterCache() throws Exception
+ {
+ // Create cache manager
+ EmbeddedCacheManager manager = new
DefaultCacheManager(GlobalConfiguration.getClusteredDefault());
+
+ // Create a cache
+ Cache cache = manager.getCache();
+
+ cache.put("key", "value");
+ assertTrue(cache.size() == 1);
+ assertTrue(cache.containsKey("key"));
+
+ String value = (String)cache.remove("key");
+ assertTrue(value.equals("value"));
+ assertTrue(cache.isEmpty());
+
+ cache.put("key", "value");
+ cache.putIfAbsent("key", "newValue");
+ assertTrue("value".equals(cache.get("key")));
+
+ cache.clear();
+ assertTrue(cache.isEmpty());
+
+ cache.put("key", "value", 2, TimeUnit.SECONDS);
+ assertTrue(cache.containsKey("key"));
+ Thread.sleep(2000);
+ assertFalse(cache.containsKey("key"));
+ }
+}