From do-not-reply at jboss.org Tue Jul 13 07:37:51 2010 Content-Type: multipart/mixed; boundary="===============7463470991895183268==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: exo-jcr-commits at lists.jboss.org Subject: [exo-jcr-commits] exo-jcr SVN: r2775 - in jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl: ispn and 1 other directory. Date: Tue, 13 Jul 2010 07:37:51 -0400 Message-ID: <201007131137.o6DBbpOF025318@svn01.web.mwc.hst.phx2.redhat.com> --===============7463470991895183268== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: tolusha Date: 2010-07-13 07:37:50 -0400 (Tue, 13 Jul 2010) New Revision: 2775 Added: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatf= orm/services/jcr/impl/ispn/ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatf= orm/services/jcr/impl/ispn/TestISPNCache.java Log: EXOJCR-837: simple test Added: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exop= latform/services/jcr/impl/ispn/TestISPNCache.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplat= form/services/jcr/impl/ispn/TestISPNCache.java (rev= 0) +++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplat= form/services/jcr/impl/ispn/TestISPNCache.java 2010-07-13 11:37:50 UTC (rev= 2775) @@ -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.impl.ispn; + +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 Anatoliy Bazko + * @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 =3D new GlobalConfiguration(); + EmbeddedCacheManager manager =3D new DefaultCacheManager(myGlobalCon= fig); + + // Create a cache + Configuration config =3D new Configuration(); + manager.defineConfiguration("cache", config); + Cache cache =3D manager.getCache("cache"); + + cache.put("key", "value"); + assertTrue(cache.size() =3D=3D 1); + assertTrue(cache.containsKey("key")); + + String value =3D (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 =3D new DefaultCacheManager(GlobalConfi= guration.getClusteredDefault()); + + // Create a cache + Cache cache =3D manager.getCache(); + + cache.put("key", "value"); + assertTrue(cache.size() =3D=3D 1); + assertTrue(cache.containsKey("key")); + + String value =3D (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")); + } +} --===============7463470991895183268==--