You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2020/04/13 11:58:01 UTC

[commons-jcs] branch master updated (43ed9a5 -> b9b4477)

This is an automated email from the ASF dual-hosted git repository.

tv pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git.


    from 43ed9a5  Cleanup, use ElapsedTimer
     new d44e03f  Move test-only class to src/test/java
     new e7d6421  Remove useless test
     new 07eaa52  Add reason for error message
     new ff58598  Move from arrays to collections
     new 6d0825d  Add lost license header
     new b9b4477  Reactivate tests. Make database caches more robust

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 commons-jcs-core/pom.xml                           |   4 -
 .../org/apache/commons/jcs/admin/JCSAdminBean.java | 113 ++++++++------------
 .../org/apache/commons/jcs/admin/JCSJMXBean.java   |  15 +--
 .../jcs/auxiliary/disk/jdbc/JDBCDiskCache.java     |  52 +++++----
 .../disk/jdbc/hsql/HSQLDiskCacheFactory.java       | 116 +++++++--------------
 .../auxiliary/remote/server/RemoteCacheServer.java |   7 +-
 .../engine/control/CompositeCacheConfigurator.java |   2 +-
 .../jcs/engine/control/CompositeCacheManager.java  |   9 +-
 .../jcs/utils/threadpool/ThreadPoolManager.java    |  19 ++++
 .../commons/jcs/admin/AdminBeanUnitTest.java       |  32 +++---
 .../block/BlockDiskElementDescriptorUnitTest.java  |  89 ----------------
 .../jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java |  30 ++----
 .../disk/jdbc/hsql/HSQLDiskCacheUnitTest.java      |  36 ++-----
 .../commons/jcs/utils/props/PropertyLoader.java    |   0
 .../src/test/test-conf/TestHSQLDiskCache.ccf       |   1 +
 .../test/test-conf/TestHSQLDiskCacheConcurrent.ccf |   1 +
 16 files changed, 181 insertions(+), 345 deletions(-)
 delete mode 100644 commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java
 rename commons-jcs-core/src/{main => test}/java/org/apache/commons/jcs/utils/props/PropertyLoader.java (100%)


[commons-jcs] 03/06: Add reason for error message

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit 07eaa520841a2a7909d5c14c66fce15e7152ee4f
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 13:54:34 2020 +0200

    Add reason for error message
---
 .../apache/commons/jcs/engine/control/CompositeCacheConfigurator.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java
index 938eb35..c132376 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java
@@ -475,7 +475,7 @@ public class CompositeCacheConfigurator
             }
             catch (Exception e)
             {
-                log.error( "Could not instantiate auxiliary cache named \"{0}\"", regName );
+                log.error( "Could not instantiate auxiliary cache named \"{0}\"", regName, e );
                 return null;
             }
 


[commons-jcs] 02/06: Remove useless test

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit e7d642140895374cd3ae4704121eb9436ab3d056
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 13:53:38 2020 +0200

    Remove useless test
---
 .../block/BlockDiskElementDescriptorUnitTest.java  | 89 ----------------------
 1 file changed, 89 deletions(-)

diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java
deleted file mode 100644
index 336b101..0000000
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.apache.commons.jcs.auxiliary.disk.block;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import junit.framework.TestCase;
-
-/**
- * Simple tests for the element descriptor
- * <p>
- * @author Aaron Smuts
- */
-public class BlockDiskElementDescriptorUnitTest
-    extends TestCase
-{
-    /**
-     * Verify that the memory used per element is reasonable.
-     * <p>
-     * TODO figure out a more precise expectation.
-     * <p>
-     * @throws Exception
-     */
-    public void testMemorySize()
-        throws Exception
-    {
-        // SETUP
-        long memoryBefore = measureMemoryUse();
-//        System.out.println( "Before: " + memoryBefore );
-
-        int numElements = 25000;
-        @SuppressWarnings("unchecked")
-        BlockDiskElementDescriptor<Integer>[] elements = new BlockDiskElementDescriptor[numElements];
-
-        long memoryStart = measureMemoryUse();
-//        System.out.println( "Start: " + memoryStart );
-
-        // DO WORK
-        for ( int i = 0; i < numElements; i++ )
-        {
-            BlockDiskElementDescriptor<Integer> descriptor = new BlockDiskElementDescriptor<>();
-            descriptor.setKey( Integer.valueOf( i ) );
-            descriptor.setBlocks( new int[] { 1, 2 } );
-            elements[i] = descriptor;
-        }
-
-        // VERIFY
-        long memoryEnd = measureMemoryUse();
-//        System.out.println( "End: " + memoryEnd );
-
-        long diff = memoryEnd - memoryStart;
-//        System.out.println( "diff: " + diff );
-
-        long perDiff = diff / numElements;
-//        System.out.println( "per diff: " + perDiff );
-
-        // about 20 bytes each
-        assertTrue( "Too much was used: " + perDiff + " >= 75", perDiff < 75 );
-    }
-
-    /**
-     * Measure memory used by the VM.
-     * @return long
-     * @throws InterruptedException
-     */
-    protected long measureMemoryUse()
-        throws InterruptedException
-    {
-        System.gc();
-        Thread.sleep( 3000 );
-        System.gc();
-        return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
-    }
-}


[commons-jcs] 05/06: Add lost license header

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit 6d0825db7a4ddf31e0c631f8dd8f3fefb0b5ca43
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 13:56:56 2020 +0200

    Add lost license header
---
 .../jcs/utils/threadpool/ThreadPoolManager.java       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
index e492b0c..3c143be 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
@@ -1,5 +1,24 @@
 package org.apache.commons.jcs.utils.threadpool;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;


[commons-jcs] 01/06: Move test-only class to src/test/java

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit d44e03f726925ca607541a56ae5bbfc00b3c4bc5
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 13:52:40 2020 +0200

    Move test-only class to src/test/java
---
 .../java/org/apache/commons/jcs/utils/props/PropertyLoader.java           | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/props/PropertyLoader.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/props/PropertyLoader.java
similarity index 100%
rename from commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/props/PropertyLoader.java
rename to commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/props/PropertyLoader.java


[commons-jcs] 06/06: Reactivate tests. Make database caches more robust

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit b9b4477c4c284f972275b13c16e286cf2a8b1514
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 13:57:45 2020 +0200

    Reactivate tests. Make database caches more robust
---
 commons-jcs-core/pom.xml                           |   4 -
 .../jcs/auxiliary/disk/jdbc/JDBCDiskCache.java     |  52 +++++----
 .../disk/jdbc/hsql/HSQLDiskCacheFactory.java       | 116 +++++++--------------
 .../jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java |  30 ++----
 .../disk/jdbc/hsql/HSQLDiskCacheUnitTest.java      |  36 ++-----
 .../src/test/test-conf/TestHSQLDiskCache.ccf       |   1 +
 .../test/test-conf/TestHSQLDiskCacheConcurrent.ccf |   1 +
 7 files changed, 87 insertions(+), 153 deletions(-)

diff --git a/commons-jcs-core/pom.xml b/commons-jcs-core/pom.xml
index e7bc878..be95c6d 100644
--- a/commons-jcs-core/pom.xml
+++ b/commons-jcs-core/pom.xml
@@ -130,10 +130,6 @@
                   sensitive.
               -->
               <!-- You need to manually run these test cases. -->
-              <exclude>**/BlockDiskElementDescriptorUnitTest.java</exclude>
-              <exclude>**/HSQLDiskCacheConcurrentUnitTest.java</exclude>
-              <exclude>**/HSQLDiskCacheUnitTest.java</exclude>
-              <exclude>**/IndexedDiskCacheOptimizationUnitTest.java</exclude>
               <exclude>**/TestTCPLateralUnitTest.java</exclude>
               <exclude>**/UDPDiscoveryUnitTest.java</exclude>
               <!-- Causes hang in Continuum -->
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
index 508eec2..a60b81d 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
@@ -21,6 +21,7 @@ package org.apache.commons.jcs.auxiliary.disk.jdbc;
 
 import java.io.IOException;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -615,37 +616,44 @@ public class JDBCDiskCache<K, V>
 
         try (Connection con = getDataSource().getConnection())
         {
-            getTableState().setState( TableState.DELETE_RUNNING );
+            // The shrinker thread might kick in before the table is created
+            // So check if the table exists first
+            DatabaseMetaData dmd = con.getMetaData();
+            ResultSet result = dmd.getTables(null, null,
+                    getJdbcDiskCacheAttributes().getTableName(), null);
 
-            long now = System.currentTimeMillis() / 1000;
+            if (result.next())
+            {
+                getTableState().setState( TableState.DELETE_RUNNING );
+                long now = System.currentTimeMillis() / 1000;
 
-            // This is to slow when we push over a million records
-            // String sql = "delete from " +
-            // getJdbcDiskCacheAttributes().getTableName() + " where REGION = '"
-            // + this.getCacheName() + "' and IS_ETERNAL = 'F' and (" + now
-            // + " - UPDATE_TIME_SECONDS) > MAX_LIFE_SECONDS";
+                String sql = "delete from " + getJdbcDiskCacheAttributes().getTableName()
+                    + " where IS_ETERNAL = ? and REGION = ? and ? > SYSTEM_EXPIRE_TIME_SECONDS";
 
-            String sql = "delete from " + getJdbcDiskCacheAttributes().getTableName()
-                + " where IS_ETERNAL = ? and REGION = ? and ? > SYSTEM_EXPIRE_TIME_SECONDS";
+                try (PreparedStatement psDelete = con.prepareStatement( sql ))
+                {
+                    psDelete.setString( 1, "F" );
+                    psDelete.setString( 2, this.getCacheName() );
+                    psDelete.setLong( 3, now );
 
-            try (PreparedStatement psDelete = con.prepareStatement( sql ))
-            {
-                psDelete.setString( 1, "F" );
-                psDelete.setString( 2, this.getCacheName() );
-                psDelete.setLong( 3, now );
+                    setAlive(true);
 
-                setAlive(true);
+                    deleted = psDelete.executeUpdate();
+                }
+                catch ( SQLException e )
+                {
+                    log.error( "Problem creating statement.", e );
+                    setAlive(false);
+                }
 
-                deleted = psDelete.executeUpdate();
+                logApplicationEvent( getAuxiliaryCacheAttributes().getName(), "deleteExpired",
+                                     "Deleted expired elements.  URL: " + getDiskLocation() );
             }
-            catch ( SQLException e )
+            else
             {
-                log.error( "Problem creating statement.", e );
-                setAlive(false);
+                log.warn( "Trying to shrink non-existing table [{0}]",
+                        getJdbcDiskCacheAttributes().getTableName() );
             }
-
-            logApplicationEvent( getAuxiliaryCacheAttributes().getName(), "deleteExpired",
-                                 "Deleted expired elements.  URL: " + getDiskLocation() );
         }
         catch ( SQLException e )
         {
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
index 186e46b..1afb779 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
@@ -20,10 +20,12 @@ package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
  */
 
 import java.sql.Connection;
-import java.sql.DriverManager;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.concurrent.CopyOnWriteArraySet;
+
+import javax.sql.DataSource;
 
 import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
 import org.apache.commons.jcs.auxiliary.disk.jdbc.JDBCDiskCache;
@@ -46,9 +48,6 @@ public class HSQLDiskCacheFactory
     /** The logger */
     private static final Log log = LogManager.getLog( HSQLDiskCacheFactory.class );
 
-    /** The databases. */
-    private CopyOnWriteArraySet<String> databases;
-
     /**
      * This factory method should create an instance of the hsqlcache.
      * <p>
@@ -66,70 +65,30 @@ public class HSQLDiskCacheFactory
 			IElementSerializer elementSerializer )
 			throws SQLException
     {
-        setupDatabase( (JDBCDiskCacheAttributes) rawAttr );
-        return super.createCache(rawAttr, compositeCacheManager, cacheEventLogger, elementSerializer);
-    }
+        // TODO get this from the attributes.
+        System.setProperty( "hsqldb.cache_scale", "8" );
 
-    /**
-     * Initialize this factory
-     */
-    @Override
-    public void initialize()
-    {
-        super.initialize();
-        this.databases = new CopyOnWriteArraySet<>();
+        JDBCDiskCache<K, V> cache = super.createCache(rawAttr, compositeCacheManager,
+                cacheEventLogger, elementSerializer);
+        setupDatabase( cache.getDataSource(), (JDBCDiskCacheAttributes) rawAttr );
+
+        return cache;
     }
 
     /**
-     * Creates the database if it doesn't exist, registers the driver class, etc.
+     * Creates the table if it doesn't exist
      * <p>
-     * @param attributes
+     * @param ds Data Source
+     * @param attributes Cache region configuration
      * @throws SQLException
      */
-    protected void setupDatabase( JDBCDiskCacheAttributes attributes )
+    protected void setupDatabase( DataSource ds, JDBCDiskCacheAttributes attributes )
         throws SQLException
     {
-        if ( attributes == null )
-        {
-            throw new SQLException( "The attributes are null." );
-        }
-
-        // url should start with "jdbc:hsqldb:"
-        String database = attributes.getUrl() + attributes.getDatabase();
-
-        if ( databases.contains( database ) )
-        {
-            log.info("We already setup database [{0}]", database);
-            return;
-        }
-
-        synchronized (databases)
+        try (Connection cConn = ds.getConnection())
         {
-            // TODO get this from the attributes.
-            System.setProperty( "hsqldb.cache_scale", "8" );
-
-            // "org.hsqldb.jdbcDriver"
-            String driver = attributes.getDriverClassName();
-            // "sa"
-            String user = attributes.getUserName();
-            // ""
-            String password = attributes.getPassword();
-
-            try
-            {
-                Class.forName( driver ).newInstance();
-            }
-            catch (Exception e)
-            {
-                throw new SQLException( "Could not initialize driver " + driver, e );
-            }
-
-            Connection cConn = DriverManager.getConnection( database, user, password );
             setupTable( cConn, attributes.getTableName() );
-
-            log.info( "Finished setting up database [{0}]", database);
-
-            databases.add( database );
+            log.info( "Finished setting up table [{0}]", attributes.getTableName());
         }
     }
 
@@ -141,30 +100,29 @@ public class HSQLDiskCacheFactory
      */
     protected void setupTable( Connection cConn, String tableName ) throws SQLException
     {
-        // TODO make the cached nature of the table configurable
-        StringBuilder createSql = new StringBuilder();
-        createSql.append( "CREATE CACHED TABLE ").append( tableName );
-        createSql.append( "( " );
-        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
-        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
-        createSql.append( "ELEMENT               BINARY, " );
-        createSql.append( "CREATE_TIME           TIMESTAMP, " );
-        createSql.append( "UPDATE_TIME_SECONDS   BIGINT, " );
-        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
-        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );
-        createSql.append( "IS_ETERNAL            CHAR(1), " );
-        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
-        createSql.append( ");" );
+        DatabaseMetaData dmd = cConn.getMetaData();
+        ResultSet result = dmd.getTables(null, null, tableName, null);
 
-        try (Statement sStatement = cConn.createStatement())
-        {
-            sStatement.execute( createSql.toString() );
-        }
-        catch ( SQLException e )
+        if (!result.next())
         {
-            if (!"23000".equals(e.getSQLState()))
+            // TODO make the cached nature of the table configurable
+            StringBuilder createSql = new StringBuilder();
+            createSql.append( "CREATE CACHED TABLE ").append( tableName );
+            createSql.append( "( " );
+            createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
+            createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
+            createSql.append( "ELEMENT               BINARY, " );
+            createSql.append( "CREATE_TIME           TIMESTAMP, " );
+            createSql.append( "UPDATE_TIME_SECONDS   BIGINT, " );
+            createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+            createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );
+            createSql.append( "IS_ETERNAL            CHAR(1), " );
+            createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
+            createSql.append( ");" );
+
+            try (Statement sStatement = cConn.createStatement())
             {
-                throw e;
+                sStatement.execute( createSql.toString() );
             }
         }
     }
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java
index 91a0811..4a666b8 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java
@@ -1,5 +1,13 @@
 package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
 
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.jcs.JCS;
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -22,13 +30,6 @@ package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
 import junit.extensions.ActiveTestSuite;
 import junit.framework.Test;
 import junit.framework.TestCase;
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
 
 /**
  * Test which exercises the indexed disk cache. This one uses three different regions for thre
@@ -52,17 +53,6 @@ public class HSQLDiskCacheConcurrentUnitTest
     }
 
     /**
-     * Main method passes this test to the text test runner.
-     * <p>
-     * @param args
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { HSQLDiskCacheConcurrentUnitTest.class.getName() };
-        junit.textui.TestRunner.main( testCaseName );
-    }
-
-    /**
      * A unit test suite for JUnit. Uses ActiveTestSuite to run multiple tests concurrently.
      * <p>
      * @return The test suite
@@ -126,7 +116,6 @@ public class HSQLDiskCacheConcurrentUnitTest
         CacheAccess<String, String> jcs = JCS.getInstance( region );
 
         // Add items to cache
-
         for ( int i = 0; i <= items; i++ )
         {
             jcs.put( i + ":key", region + " data " + i );
@@ -135,7 +124,6 @@ public class HSQLDiskCacheConcurrentUnitTest
 //        System.out.println( jcs.getStats() );
 
         // Test that all items are in cache
-
         for ( int i = 0; i <= items; i++ )
         {
             String value = jcs.get( i + ":key" );
@@ -159,14 +147,12 @@ public class HSQLDiskCacheConcurrentUnitTest
         }
 
         // Remove all the items
-
         for ( int i = 0; i <= items; i++ )
         {
             jcs.remove( i + ":key" );
         }
 
         // Verify removal
-
         for ( int i = 0; i <= items; i++ )
         {
             assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java
index d6c0294..58d7e77 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java
@@ -1,5 +1,14 @@
 package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
 
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.jcs.JCS;
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.access.exception.CacheException;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -20,18 +29,9 @@ package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
  */
 
 import junit.framework.TestCase;
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.access.exception.CacheException;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
 
 /**
- * Test which exercises the indexed disk cache. This one uses three different regions for thre
- * threads.
+ * Test which exercises the HSQL cache.
  */
 public class HSQLDiskCacheUnitTest
     extends TestCase
@@ -61,22 +61,15 @@ public class HSQLDiskCacheUnitTest
         CacheAccess<String, String> jcs = JCS.getInstance( region );
 
         // Add items to cache
-
         for ( int i = 0; i <= items; i++ )
         {
             jcs.put( i + ":key", region + " data " + i );
         }
 
-        //SleepUtil.sleepAtLeast( 1000 );
-
-//        System.out.println( jcs.getStats() );
-
         // Test that all items are in cache
-
         for ( int i = 0; i <= items; i++ )
         {
             String value = jcs.get( i + ":key" );
-
             assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
         }
 
@@ -95,16 +88,13 @@ public class HSQLDiskCacheUnitTest
             assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
         }
 
-
         // Remove all the items
-
         for ( int i = 0; i <= items; i++ )
         {
             jcs.remove( i + ":key" );
         }
 
         // Verify removal
-
         for ( int i = 0; i <= items; i++ )
         {
             assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
@@ -126,7 +116,6 @@ public class HSQLDiskCacheUnitTest
         int items = 20;
 
         // Add items to cache
-
         for ( int i = 0; i <= items; i++ )
         {
             jcs.put( i + ":key", region + " data " + i );
@@ -146,7 +135,6 @@ public class HSQLDiskCacheUnitTest
         for ( int i = 0; i <= items; i++ )
         {
             String value = jcs.get( i + ":key" );
-
             assertNull( "value should be null key = [" + i + ":key] value = [" + value + "]", value );
         }
     }
@@ -166,7 +154,6 @@ public class HSQLDiskCacheUnitTest
         int items = 20;
 
         // Add items to cache
-
         for ( int i = 0; i <= items; i++ )
         {
             jcs.put( i + ":key", region + " data " + i );
@@ -175,14 +162,11 @@ public class HSQLDiskCacheUnitTest
         // a db thread could be updating the disk when
         // Thread.sleep( 500 );
 
-//        System.out.println( jcs.getStats() );
-
         jcs.clear();
 
         for ( int i = 0; i <= items; i++ )
         {
             String value = jcs.get( i + ":key" );
-
             assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
         }
     }
diff --git a/commons-jcs-core/src/test/test-conf/TestHSQLDiskCache.ccf b/commons-jcs-core/src/test/test-conf/TestHSQLDiskCache.ccf
index 5134103..e3fe8b9 100644
--- a/commons-jcs-core/src/test/test-conf/TestHSQLDiskCache.ccf
+++ b/commons-jcs-core/src/test/test-conf/TestHSQLDiskCache.ccf
@@ -67,6 +67,7 @@ jcs.auxiliary.HSQL_NORA.attributes.tableName=JCS_STORE4
 jcs.auxiliary.HSQL_NORA.attributes.testBeforeInsert=false
 jcs.auxiliary.HSQL_NORA.attributes.maxTotal=15
 jcs.auxiliary.HSQL_NORA.attributes.allowRemoveAll=false
+jcs.auxiliary.HSQL_NORA.attributes.useDiskShrinker=false
 jcs.auxiliary.HSQL_NORA.attributes.MaxPurgatorySize=10000000
 jcs.auxiliary.HSQL_NORA.attributes.EventQueueType=POOLED
 jcs.auxiliary.HSQL_NORA.attributes.EventQueuePoolName=disk_cache_event_queue
diff --git a/commons-jcs-core/src/test/test-conf/TestHSQLDiskCacheConcurrent.ccf b/commons-jcs-core/src/test/test-conf/TestHSQLDiskCacheConcurrent.ccf
index 908de0f..8f2eb68 100644
--- a/commons-jcs-core/src/test/test-conf/TestHSQLDiskCacheConcurrent.ccf
+++ b/commons-jcs-core/src/test/test-conf/TestHSQLDiskCacheConcurrent.ccf
@@ -68,6 +68,7 @@ jcs.auxiliary.HSQL_NORA.attributes.tableName=JCS_STORE4
 jcs.auxiliary.HSQL_NORA.attributes.testBeforeInsert=false
 jcs.auxiliary.HSQL_NORA.attributes.maxTotal=15
 jcs.auxiliary.HSQL_NORA.attributes.allowRemoveAll=false
+jcs.auxiliary.HSQL_NORA.attributes.useDiskShrinker=false
 jcs.auxiliary.HSQL_NORA.attributes.MaxPurgatorySize=10000000
 jcs.auxiliary.HSQL_NORA.attributes.EventQueueType=POOLED
 jcs.auxiliary.HSQL_NORA.attributes.EventQueuePoolName=disk_cache_event_queue


[commons-jcs] 04/06: Move from arrays to collections

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git

commit ff58598ebc8b5eb56e46409718d2e9dac7f4111c
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 13:56:13 2020 +0200

    Move from arrays to collections
---
 .../org/apache/commons/jcs/admin/JCSAdminBean.java | 113 ++++++++-------------
 .../org/apache/commons/jcs/admin/JCSJMXBean.java   |  15 +--
 .../auxiliary/remote/server/RemoteCacheServer.java |   7 +-
 .../jcs/engine/control/CompositeCacheManager.java  |   9 +-
 .../commons/jcs/admin/AdminBeanUnitTest.java       |  32 +++---
 5 files changed, 74 insertions(+), 102 deletions(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSAdminBean.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSAdminBean.java
index 550fd74..42fa3b7 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSAdminBean.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSAdminBean.java
@@ -1,5 +1,18 @@
 package org.apache.commons.jcs.admin;
 
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -29,15 +42,6 @@ import org.apache.commons.jcs.engine.control.CompositeCache;
 import org.apache.commons.jcs.engine.control.CompositeCacheManager;
 import org.apache.commons.jcs.engine.memory.behavior.IMemoryCache;
 
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.text.DateFormat;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.Set;
-
 /**
  * A servlet which provides HTTP access to JCS. Allows a summary of regions to be viewed, and
  * removeAll to be run on individual regions or all regions. Also provides the ability to remove
@@ -80,46 +84,34 @@ public class JCSAdminBean implements JCSJMXBean
      * Builds up info about each element in a region.
      * <p>
      * @param cacheName
-     * @return Array of CacheElementInfo objects
-     * @throws Exception
+     * @return List of CacheElementInfo objects
+     * @throws IOException
      */
     @Override
-    public CacheElementInfo[] buildElementInfo( String cacheName )
-        throws Exception
+    public List<CacheElementInfo> buildElementInfo( String cacheName )
+        throws IOException
     {
-        CompositeCache<Serializable, Serializable> cache = cacheHub.getCache( cacheName );
+        CompositeCache<Object, Object> cache = cacheHub.getCache( cacheName );
 
-        Serializable[] keys = cache.getMemoryCache().getKeySet().toArray(new Serializable[0]);
-
-        // Attempt to sort keys according to their natural ordering. If that
-        // fails, get the key array again and continue unsorted.
-        try
-        {
-            Arrays.sort( keys );
-        }
-        catch ( Exception e )
-        {
-            keys = cache.getMemoryCache().getKeySet().toArray(new Serializable[0]);
-        }
+        // Convert all keys to string, store in a sorted map
+        TreeMap<String, ?> keys = new TreeMap<>(cache.getMemoryCache().getKeySet()
+                .stream()
+                .collect(Collectors.toMap(k -> k.toString(), k -> k)));
 
         LinkedList<CacheElementInfo> records = new LinkedList<>();
 
-        ICacheElement<Serializable, Serializable> element;
-        IElementAttributes attributes;
-        CacheElementInfo elementInfo;
-
         DateFormat format = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT );
 
         long now = System.currentTimeMillis();
 
-        for (Serializable key : keys)
+        for (Map.Entry<String, ?> key : keys.entrySet())
         {
-            element = cache.getMemoryCache().getQuiet( key );
+            ICacheElement<?, ?> element = cache.getMemoryCache().getQuiet( key.getValue() );
 
-            attributes = element.getElementAttributes();
+            IElementAttributes attributes = element.getElementAttributes();
 
-            elementInfo = new CacheElementInfo(
-            		String.valueOf( key ),
+            CacheElementInfo elementInfo = new CacheElementInfo(
+            		key.getKey(),
             		attributes.getIsEternal(),
             		format.format(new Date(attributes.getCreateTime())),
             		attributes.getMaxLife(),
@@ -128,7 +120,7 @@ public class JCSAdminBean implements JCSJMXBean
             records.add( elementInfo );
         }
 
-        return records.toArray(new CacheElementInfo[0]);
+        return records;
     }
 
     /**
@@ -136,27 +128,20 @@ public class JCSAdminBean implements JCSJMXBean
      * <p>
      * TODO we need a most light weight method that does not count bytes. The byte counting can
      *       really swamp a server.
-     * @return list of CacheRegionInfo objects
-     * @throws Exception
+     * @return List of CacheRegionInfo objects
      */
     @Override
-    public CacheRegionInfo[] buildCacheInfo()
-        throws Exception
+    public List<CacheRegionInfo> buildCacheInfo()
     {
-        String[] cacheNames = cacheHub.getCacheNames();
-
-        Arrays.sort( cacheNames );
+        TreeSet<String> cacheNames = new TreeSet<>(cacheHub.getCacheNames());
 
         LinkedList<CacheRegionInfo> cacheInfo = new LinkedList<>();
 
-        CacheRegionInfo regionInfo;
-        CompositeCache<?, ?> cache;
-
-        for ( int i = 0; i < cacheNames.length; i++ )
+        for (String cacheName : cacheNames)
         {
-            cache = cacheHub.getCache( cacheNames[i] );
+            CompositeCache<?, ?> cache = cacheHub.getCache( cacheName );
 
-            regionInfo = new CacheRegionInfo(
+            CacheRegionInfo regionInfo = new CacheRegionInfo(
                     cache.getCacheName(),
                     cache.getSize(),
                     cache.getStatus().toString(),
@@ -170,7 +155,7 @@ public class JCSAdminBean implements JCSJMXBean
             cacheInfo.add( regionInfo );
         }
 
-        return cacheInfo.toArray(new CacheRegionInfo[0]);
+        return cacheInfo;
     }
 
 
@@ -269,37 +254,25 @@ public class JCSAdminBean implements JCSJMXBean
     @Override
     public void clearAllRegions() throws IOException
     {
-        if (RemoteCacheServerFactory.getRemoteCacheServer() == null)
+        RemoteCacheServer<?, ?> remoteCacheServer = RemoteCacheServerFactory.getRemoteCacheServer();
+
+        if (remoteCacheServer == null)
         {
             // Not running in a remote cache server.
             // Remove objects from the cache directly, as no need to broadcast removes to client machines...
-
-            String[] names = cacheHub.getCacheNames();
-
-            for (int i = 0; i < names.length; i++)
+            for (String name : cacheHub.getCacheNames())
             {
-                cacheHub.getCache(names[i]).removeAll();
+                cacheHub.getCache(name).removeAll();
             }
         }
         else
         {
             // Running in a remote cache server.
             // Remove objects via the RemoteCacheServer API, so that removes will be broadcast to client machines...
-            try
-            {
-                String[] cacheNames = cacheHub.getCacheNames();
-
-                // Call remoteCacheServer.removeAll(String) for each cacheName...
-                RemoteCacheServer<?, ?> remoteCacheServer = RemoteCacheServerFactory.getRemoteCacheServer();
-                for (int i = 0; i < cacheNames.length; i++)
-                {
-                    String cacheName = cacheNames[i];
-                    remoteCacheServer.removeAll(cacheName);
-                }
-            }
-            catch (IOException e)
+            // Call remoteCacheServer.removeAll(String) for each cacheName...
+            for (String name : cacheHub.getCacheNames())
             {
-                throw new IllegalStateException("Failed to remove all elements from all cache regions: " + e, e);
+                remoteCacheServer.removeAll(name);
             }
         }
     }
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSJMXBean.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSJMXBean.java
index 1cf02d0..41b756a 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSJMXBean.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/JCSJMXBean.java
@@ -1,5 +1,8 @@
 package org.apache.commons.jcs.admin;
 
+import java.io.IOException;
+import java.util.List;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -20,7 +23,6 @@ package org.apache.commons.jcs.admin;
  */
 
 import javax.management.MXBean;
-import java.io.IOException;
 
 /**
  * A MXBean to expose the JCS statistics to JMX
@@ -32,20 +34,19 @@ public interface JCSJMXBean
      * Builds up info about each element in a region.
      * <p>
      * @param cacheName
-     * @return Array of CacheElementInfo objects
-     * @throws Exception
+     * @return List of CacheElementInfo objects
+     * @throws IOException
      */
-    CacheElementInfo[] buildElementInfo( String cacheName ) throws Exception;
+    List<CacheElementInfo> buildElementInfo( String cacheName ) throws IOException;
 
     /**
      * Builds up data on every region.
      * <p>
      * TODO we need a most light weight method that does not count bytes. The byte counting can
      *       really swamp a server.
-     * @return Array of CacheRegionInfo objects
-     * @throws Exception
+     * @return List of CacheRegionInfo objects
      */
-    CacheRegionInfo[] buildCacheInfo() throws Exception;
+    List<CacheRegionInfo> buildCacheInfo();
 
     /**
      * Tries to estimate how much data is in a region. This is expensive. If there are any non serializable objects in
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java
index 4d5f3db..05d271b 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java
@@ -164,13 +164,10 @@ public class RemoteCacheServer<K, V>
 
         // cacheManager would have created a number of ICache objects.
         // Use these objects to set up the cacheListenersMap.
-        String[] list = cacheManager.getCacheNames();
-        for ( int i = 0; i < list.length; i++ )
-        {
-            String name = list[i];
+        cacheManager.getCacheNames().forEach(name -> {
             CompositeCache<K, V> cache = cacheManager.getCache( name );
             cacheListenersMap.put( name, new CacheListeners<>( cache ) );
-        }
+        });
     }
 
     /**
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
index d735a47..85712ff 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
@@ -26,6 +26,7 @@ import java.security.AccessControlException;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Properties;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.Executors;
@@ -628,7 +629,7 @@ public class CompositeCacheManager
             }
 
             // do the traditional shutdown of the regions.
-            Arrays.stream(getCacheNames()).forEach(this::freeCache);
+            getCacheNames().forEach(this::freeCache);
 
             // shut down factories
             auxiliaryFactoryRegistry.values().forEach(AuxiliaryCacheFactory::dispose);
@@ -688,11 +689,11 @@ public class CompositeCacheManager
 
     /**
      * Returns a list of the current cache names.
-     * @return String[]
+     * @return Set<String>
      */
-    public String[] getCacheNames()
+    public Set<String> getCacheNames()
     {
-        return caches.keySet().toArray(new String[caches.size()]);
+        return caches.keySet();
     }
 
     /**
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/admin/AdminBeanUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/admin/AdminBeanUnitTest.java
index 7c84a23..38a75ff 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/admin/AdminBeanUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs/admin/AdminBeanUnitTest.java
@@ -1,5 +1,10 @@
 package org.apache.commons.jcs.admin;
 
+import java.util.List;
+
+import org.apache.commons.jcs.JCS;
+import org.apache.commons.jcs.access.CacheAccess;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -20,8 +25,6 @@ package org.apache.commons.jcs.admin;
  */
 
 import junit.framework.TestCase;
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
 
 /**
  * Test the admin bean that is used by the JCSAdmin.jsp
@@ -49,7 +52,7 @@ public class AdminBeanUnitTest
 
         JCSAdminBean admin = new JCSAdminBean();
 
-        CacheRegionInfo[] regions = admin.buildCacheInfo();
+        List<CacheRegionInfo> regions = admin.buildCacheInfo();
 
         boolean foundRegion = false;
 
@@ -88,11 +91,10 @@ public class AdminBeanUnitTest
 
         JCSAdminBean admin = new JCSAdminBean();
 
-        CacheElementInfo[] elements = admin.buildElementInfo( regionName );
-
-        assertEquals( "Wrong number of elements in the region.", 1, elements.length );
+        List<CacheElementInfo> elements = admin.buildElementInfo( regionName );
+        assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
 
-        CacheElementInfo elementInfo = elements[0];
+        CacheElementInfo elementInfo = elements.get(0);
         assertEquals( "Wrong key." + elementInfo, key, elementInfo.getKey() );
     }
 
@@ -116,18 +118,16 @@ public class AdminBeanUnitTest
         String key = "myKey";
         cache.put( key, "value" );
 
-        CacheElementInfo[] elements = admin.buildElementInfo( regionName );
-
-        assertEquals( "Wrong number of elements in the region.", 1, elements.length );
-
-        CacheElementInfo elementInfo = elements[0];
+        List<CacheElementInfo> elements = admin.buildElementInfo( regionName );
+        assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
 
+        CacheElementInfo elementInfo = elements.get(0);
         assertEquals( "Wrong key.", key, elementInfo.getKey() );
 
         admin.removeItem( regionName, key );
 
-        CacheElementInfo[] elements2 = admin.buildElementInfo( regionName );
-        assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.length );
+        List<CacheElementInfo> elements2 = admin.buildElementInfo( regionName );
+        assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
     }
 
     /**
@@ -148,7 +148,7 @@ public class AdminBeanUnitTest
 
         admin.clearAllRegions();
 
-        CacheElementInfo[] elements2 = admin.buildElementInfo( regionName );
-        assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.length );
+        List<CacheElementInfo> elements2 = admin.buildElementInfo( regionName );
+        assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
     }
 }