commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1717932 - in /commons/proper/jcs/trunk/commons-jcs-core/src: main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/ main/java/org/apache/commons/jcs/auxiliary/remote/http/client/ main/java/org/apache/commons/jcs/utils/discovery/ te...
Date Fri, 04 Dec 2015 11:13:24 GMT
Author: tv
Date: Fri Dec  4 11:13:24 2015
New Revision: 1717932

URL: http://svn.apache.org/viewvc?rev=1717932&view=rev
Log:
Address issues reported by Findbugs

Modified:
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/DiskTestObject.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheSteadyLoadTest.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/memory/fifo/FIFOMemoryCacheUnitTest.java

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java?rev=1717932&r1=1717931&r2=1717932&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
Fri Dec  4 11:13:24 2015
@@ -19,6 +19,23 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import org.apache.commons.jcs.access.exception.CacheException;
 import org.apache.commons.jcs.auxiliary.lateral.LateralElementDescriptor;
 import org.apache.commons.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
@@ -34,20 +51,6 @@ import org.apache.commons.jcs.utils.thre
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketTimeoutException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
 /**
  * Listens for connections from other TCP lateral caches and handles them. The initialization
method
  * starts a listening thread, which creates a socket server. When messages are received they
are
@@ -97,10 +100,10 @@ public class LateralTCPListener<K, V>
     private long listenerId = CacheInfo.listenerId;
 
     /** is this shut down? */
-    private boolean shutdown = false;
+    private AtomicBoolean shutdown;
 
     /** is this terminated? */
-    private boolean terminated = false;
+    private AtomicBoolean terminated;
 
     /**
      * Gets the instance attribute of the LateralCacheTCPListener class.
@@ -155,8 +158,8 @@ public class LateralTCPListener<K, V>
 
             pooledExecutor = Executors.newCachedThreadPool(
                     new DaemonThreadFactory("JCS-LateralTCPListener-"));
-            terminated = false;
-            shutdown = false;
+            terminated = new AtomicBoolean(false);
+            shutdown = new AtomicBoolean(false);
 
             log.info( "Listening on port " + port );
 
@@ -167,10 +170,9 @@ public class LateralTCPListener<K, V>
             receiver.setDaemon( true );
             receiver.start();
         }
-        catch ( Exception ex )
+        catch ( IOException ex )
         {
-            log.error( ex );
-            throw new IllegalStateException( ex.getMessage() );
+            throw new IllegalStateException( ex );
         }
     }
 
@@ -371,16 +373,13 @@ public class LateralTCPListener<K, V>
         }
 
         // TODO handle active deregistration, rather than passive detection
-        synchronized (this)
-        {
-            terminated = true;
-        }
+        terminated.set(true);
     }
 
     @Override
     public synchronized void dispose()
     {
-        terminated = true;
+        terminated.set(true);
         notify();
 
         pooledExecutor.shutdownNow();
@@ -519,17 +518,15 @@ public class LateralTCPListener<K, V>
                     inner: while (true)
                     {
                         // Check to see if we've been asked to exit, and exit
-                        synchronized (LateralTCPListener.this)
+                        if (terminated.get())
                         {
-                            if (terminated)
+                            if (log.isDebugEnabled())
                             {
-                                if (log.isDebugEnabled())
-                                {
-                                    log.debug("Thread terminated, exiting gracefully");
-                                }
-                                break outer;
+                                log.debug("Thread terminated, exiting gracefully");
                             }
+                            break outer;
                         }
+
                         try
                         {
                             socket = serverSocket.accept();
@@ -641,11 +638,11 @@ public class LateralTCPListener<K, V>
                     }
                 }
             }
-            catch ( java.io.EOFException e )
+            catch ( EOFException e )
             {
                 log.info( "Caught java.io.EOFException closing connection." + e.getMessage()
);
             }
-            catch ( java.net.SocketException e )
+            catch ( SocketException e )
             {
                 log.info( "Caught java.net.SocketException closing connection." + e.getMessage()
);
             }
@@ -753,14 +750,13 @@ public class LateralTCPListener<K, V>
     @Override
     public void shutdown()
     {
-        if ( !shutdown )
+        if ( shutdown.compareAndSet(false, true) )
         {
-            shutdown = true;
-
             if ( log.isInfoEnabled() )
             {
                 log.info( "Shutting down TCP Lateral receiver." );
             }
+
             receiver.interrupt();
         }
         else

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java?rev=1717932&r1=1717931&r2=1717932&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
Fri Dec  4 11:13:24 2015
@@ -19,66 +19,33 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheMonitor;
 import org.apache.commons.jcs.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient;
 import org.apache.commons.jcs.engine.CacheStatus;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Set;
 
 /**
  * Upon the notification of a connection error, the monitor changes to operate in a time
driven
  * mode. That is, it attempts to recover the connections on a periodic basis. When all failed
  * connections are restored, it changes back to the failure driven mode.
  */
-public class RemoteHttpCacheMonitor
-    implements Runnable
+public class RemoteHttpCacheMonitor extends AbstractAuxiliaryCacheMonitor
 {
-    /** The logger */
-    private static final Log log = LogFactory.getLog( RemoteHttpCacheMonitor.class );
-
     /** The remote cache that we are monitoring */
     private static RemoteHttpCacheMonitor instance;
 
-    /** Time between checks */
-    private static long idlePeriod = 3 * 1000;
-
     /** Set of remote caches to monitor. This are added on error, if not before. */
-    private final Set<RemoteHttpCache<?, ?>> remoteHttpCaches = new HashSet<RemoteHttpCache<?,
?>>();
-
-    /**
-     * Must make sure RemoteCacheMonitor is started before any remote error can be detected!
-     */
-    private boolean alright = true;
-
-    /** Time driven mode */
-    static final int TIME = 0;
-
-    /** Error driven mode -- only check on health if there is an error */
-    static final int ERROR = 1;
-
-    /** The mode to use */
-    static int mode = ERROR;
-
-    /**
-     * Configures the idle period between repairs.
-     * <p>
-     * @param idlePeriod The new idlePeriod value
-     */
-    public static void setIdlePeriod( long idlePeriod )
-    {
-        if ( idlePeriod > RemoteHttpCacheMonitor.idlePeriod )
-        {
-            RemoteHttpCacheMonitor.idlePeriod = idlePeriod;
-        }
-    }
+    private final ConcurrentHashMap<RemoteHttpCache<?, ?>, RemoteHttpCache<?,
?>> remoteHttpCaches =
+        new ConcurrentHashMap<RemoteHttpCache<?, ?>, RemoteHttpCache<?, ?>>();
 
     /** Constructor for the RemoteCacheMonitor object */
     private RemoteHttpCacheMonitor()
     {
-        super();
+        super("JCS-RemoteHttpCacheMonitor");
+        setIdlePeriod(3000L);
     }
 
     /**
@@ -86,7 +53,7 @@ public class RemoteHttpCacheMonitor
      * <p>
      * @return The instance value
      */
-    static RemoteHttpCacheMonitor getInstance()
+    public static RemoteHttpCacheMonitor getInstance()
     {
         synchronized ( RemoteHttpCacheMonitor.class )
         {
@@ -109,15 +76,19 @@ public class RemoteHttpCacheMonitor
         {
             log.info( "Notified of an error. " + remoteCache );
         }
-        bad();
-        synchronized ( this )
-        {
-            remoteHttpCaches.add( remoteCache );
-            notify();
-        }
+
+        remoteHttpCaches.put( remoteCache, remoteCache );
+        notifyError();
     }
 
-    // Run forever.
+    /**
+     * Clean up all resources before shutdown
+     */
+    @Override
+    protected void dispose()
+    {
+        this.remoteHttpCaches.clear();
+    }
 
     // Avoid the use of any synchronization in the process of monitoring for
     // performance reasons.
@@ -125,124 +96,48 @@ public class RemoteHttpCacheMonitor
     // just skip the monitoring until the next round.
     /** Main processing method for the RemoteCacheMonitor object */
     @Override
-    public void run()
+    public void doWork()
     {
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Monitoring daemon started" );
-        }
-        do
+        // If any cache is in error, it strongly suggests all caches
+        // managed by the
+        // same RmicCacheManager instance are in error. So we fix
+        // them once and for all.
+        for (RemoteHttpCache<?, ?> remoteCache : this.remoteHttpCaches.values())
         {
-            if ( mode == ERROR )
-            {
-                synchronized ( this )
-                {
-                    if ( alright )
-                    {
-                        // make this configurable, comment out wait to enter
-                        // time driven mode
-                        // Failure driven mode.
-                        try
-                        {
-                            if ( log.isDebugEnabled() )
-                            {
-                                log.debug( "FAILURE DRIVEN MODE: cache monitor waiting for
error" );
-                            }
-                            wait();
-                            // wake up only if there is an error.
-                        }
-                        catch ( InterruptedException ignore )
-                        {
-                            // swallow
-                        }
-                    }
-                }
-            }
-            else
-            {
-                if ( log.isDebugEnabled() )
-                {
-                    log.debug( "TIME DRIVEN MODE: cache monitor sleeping for " + idlePeriod
);
-                }
-                // Time driven mode: sleep between each round of recovery
-                // attempt.
-                // will need to test not just check status
-            }
-
             try
             {
-                Thread.sleep( idlePeriod );
-            }
-            catch ( InterruptedException ex )
-            {
-                // ignore;
-            }
-
-            // The "allright" flag must be false here.
-            // Simply presume we can fix all the errors until proven otherwise.
-            synchronized ( this )
-            {
-                alright = true;
-            }
-
-            // Make a copy
-            Set<RemoteHttpCache<?, ?>> remoteCachesToExamine =
-                new HashSet<RemoteHttpCache<?, ?>>();
-            synchronized ( this )
-            {
-                for (RemoteHttpCache<?, ?> remoteCache : this.remoteHttpCaches)
+                if ( remoteCache.getStatus() == CacheStatus.ERROR )
                 {
-                    remoteCachesToExamine.add( remoteCache );
-                }
-            }
-            // If any cache is in error, it strongly suggests all caches
-            // managed by the
-            // same RmicCacheManager instance are in error. So we fix
-            // them once and for all.
-            for (RemoteHttpCache<?, ?> remoteCache : remoteCachesToExamine)
-            {
-                try
-                {
-                    if ( remoteCache.getStatus() == CacheStatus.ERROR )
-                    {
-                        RemoteHttpCacheAttributes attributes = remoteCache.getRemoteHttpCacheAttributes();
+                    RemoteHttpCacheAttributes attributes = remoteCache.getRemoteHttpCacheAttributes();
 
-                        IRemoteHttpCacheClient<Serializable, Serializable> remoteService
= RemoteHttpCacheManager.getInstance()
-                            .createRemoteHttpCacheClientForAttributes( attributes );
+                    IRemoteHttpCacheClient<Serializable, Serializable> remoteService
= RemoteHttpCacheManager.getInstance()
+                        .createRemoteHttpCacheClientForAttributes( attributes );
 
-                        if ( log.isInfoEnabled() )
-                        {
-                            log.info( "Performing Alive check on service " + remoteService
);
-                        }
-                        // If we can't fix them, just skip and re-try in
-                        // the next round.
-                        if ( remoteService.isAlive() )
-                        {
-                            remoteCache.fixCache( remoteService );
-                        }
-                        else
-                        {
-                            bad();
-                        }
-                        break;
+                    if ( log.isInfoEnabled() )
+                    {
+                        log.info( "Performing Alive check on service " + remoteService );
                     }
+                    // If we can't fix them, just skip and re-try in
+                    // the next round.
+                    if ( remoteService.isAlive() )
+                    {
+                        remoteCache.fixCache( remoteService );
+                    }
+                    else
+                    {
+                        allright.set(false);
+                    }
+                    break;
                 }
-                catch ( Exception ex )
-                {
-                    bad();
-                    // Problem encountered in fixing the caches managed by a
-                    // RemoteCacheManager instance.
-                    // Soldier on to the next RemoteHttpCache.
-                    log.error( ex );
-                }
+            }
+            catch ( IOException ex )
+            {
+                allright.set(false);
+                // Problem encountered in fixing the caches managed by a
+                // RemoteCacheManager instance.
+                // Soldier on to the next RemoteHttpCache.
+                log.error( ex );
             }
         }
-        while ( true );
-    }
-
-    /** Sets the "aright" flag to false in a critical section. */
-    private synchronized void bad()
-    {
-        alright = false;
     }
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java?rev=1717932&r1=1717931&r2=1717932&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
Fri Dec  4 11:13:24 2015
@@ -19,14 +19,6 @@ package org.apache.commons.jcs.utils.dis
  * under the License.
  */
 
-import org.apache.commons.jcs.engine.CacheInfo;
-import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
-import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
-import org.apache.commons.jcs.utils.discovery.UDPDiscoveryMessage.BroadcastType;
-import org.apache.commons.jcs.utils.threadpool.DaemonThreadFactory;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -36,6 +28,14 @@ import java.net.MulticastSocket;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadPoolExecutor;
 
+import org.apache.commons.jcs.engine.CacheInfo;
+import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
+import org.apache.commons.jcs.utils.discovery.UDPDiscoveryMessage.BroadcastType;
+import org.apache.commons.jcs.utils.threadpool.DaemonThreadFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /** Receives UDP Discovery messages. */
 public class UDPDiscoveryReceiver
     implements Runnable, IShutdownObserver
@@ -150,7 +150,7 @@ public class UDPDiscoveryReceiver
         throws IOException
     {
         final DatagramPacket packet = new DatagramPacket( mBuffer, mBuffer.length );
-
+        ObjectInputStream objectStream = null;
         Object obj = null;
         try
         {
@@ -167,7 +167,7 @@ public class UDPDiscoveryReceiver
             }
 
             final ByteArrayInputStream byteStream = new ByteArrayInputStream( mBuffer, 0,
packet.getLength() );
-            final ObjectInputStream objectStream = new ObjectInputStreamClassLoaderAware(
byteStream, null );
+            objectStream = new ObjectInputStreamClassLoaderAware( byteStream, null );
             obj = objectStream.readObject();
 
             if ( obj != null && obj instanceof UDPDiscoveryMessage )
@@ -188,6 +188,20 @@ public class UDPDiscoveryReceiver
         {
             log.error( "Error receiving multicast packet", e );
         }
+        finally
+        {
+            if (objectStream != null)
+            {
+                try
+                {
+                    objectStream.close();
+                }
+                catch (IOException e)
+                {
+                    log.error( "Error closing object stream", e );
+                }
+            }
+        }
         return obj;
     }
 

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/DiskTestObject.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/DiskTestObject.java?rev=1717932&r1=1717931&r2=1717932&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/DiskTestObject.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/DiskTestObject.java
Fri Dec  4 11:13:24 2015
@@ -25,8 +25,7 @@ import java.util.Arrays;
 /**
  * Resembles a cached image.
  */
-public class DiskTestObject
-    implements Serializable
+public class DiskTestObject implements Serializable
 {
     /** don't change */
     private static final long serialVersionUID = 1L;
@@ -45,20 +44,35 @@ public class DiskTestObject
      * @param id
      * @param imageBytes
      */
-    public DiskTestObject( Integer id, byte[] imageBytes )
+    public DiskTestObject(Integer id, byte[] imageBytes)
     {
         this.id = id;
         this.imageBytes = imageBytes;
     }
-    
-    public boolean equals(Object other) {
-    	if (other instanceof DiskTestObject) {
-    		DiskTestObject o = (DiskTestObject)other;
-    		if (id != null)
-    			return id.equals(o.id) && Arrays.equals(imageBytes, o.imageBytes);
-    		else if (id ==null && o.id == null)
-    			return Arrays.equals(imageBytes, o.imageBytes);
-    	}
-    	return false;
+
+    /**
+     * @see java.lang.Object#equals(Object other)
+     */
+    @Override
+    public boolean equals(Object other)
+    {
+        if (other instanceof DiskTestObject)
+        {
+            DiskTestObject o = (DiskTestObject) other;
+            if (id != null)
+                return id.equals(o.id) && Arrays.equals(imageBytes, o.imageBytes);
+            else if (id == null && o.id == null) return Arrays.equals(imageBytes,
o.imageBytes);
+        }
+        return false;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode()
+    {
+        return id.hashCode();
     }
+
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheSteadyLoadTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheSteadyLoadTest.java?rev=1717932&r1=1717931&r2=1717932&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheSteadyLoadTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheSteadyLoadTest.java
Fri Dec  4 11:13:24 2015
@@ -19,14 +19,14 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
+import java.text.DecimalFormat;
+import java.util.Random;
+
 import junit.framework.TestCase;
+
 import org.apache.commons.jcs.JCS;
 import org.apache.commons.jcs.access.CacheAccess;
 import org.apache.commons.jcs.auxiliary.disk.DiskTestObject;
-import org.apache.commons.jcs.utils.timing.ElapsedTimer;
-
-import java.text.DecimalFormat;
-import java.util.Random;
 
 /**
  * This allows you to put thousands of large objects into the disk cache and to force removes
to
@@ -66,7 +66,7 @@ public class BlockDiskCacheSteadyLoadTes
 
         CacheAccess<String, DiskTestObject> jcs = JCS.getInstance( ( numPerRun / 2
) + "aSecond" );
 
-        ElapsedTimer timer = new ElapsedTimer();
+//        ElapsedTimer timer = new ElapsedTimer();
         int numToGet = numPerRun * ( runs / 10 );
         for ( int i = 0; i < numToGet; i++ )
         {
@@ -82,7 +82,7 @@ public class BlockDiskCacheSteadyLoadTes
 //        System.out.println( LOG_DIVIDER );
 //        System.out.println( "Start putting" );
 
-        long totalSize = 0;
+//        long totalSize = 0;
         int totalPut = 0;
 
         Random random = new Random( 89 );
@@ -94,7 +94,7 @@ public class BlockDiskCacheSteadyLoadTes
                 // 1/2 upper to upperKB-4 KB
                 int kiloBytes = Math.max( upperKB / 2, random.nextInt( upperKB ) );
                 int bytes = ( kiloBytes ) * 1024;
-                totalSize += bytes;
+//                totalSize += bytes;
                 totalPut++;
                 DiskTestObject object = new DiskTestObject( Integer.valueOf( i ), new byte[bytes]
);
                 jcs.put( String.valueOf( totalPut ), object );

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java?rev=1717932&r1=1717931&r2=1717932&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
Fri Dec  4 11:13:24 2015
@@ -198,38 +198,47 @@ public class MySQLDiskCacheHsqlBackedUni
 
         try
         {
-            sStatement.executeQuery( createSql.toString() );
-            sStatement.close();
+            sStatement.execute( createSql.toString() );
         }
         catch ( SQLException e )
         {
-            if ( e.toString().indexOf( "already exists" ) != -1 )
+            if ("23000".equals(e.getSQLState()))
             {
                 newT = false;
             }
             else
             {
-                // TODO figure out if it exists prior to trying to create it.
-                // log.error( "Problem creating table.", e );
                 throw e;
             }
         }
-
-        String setupData[] = { "create index iKEY on JCS_STORE_MYSQL (CACHE_KEY, REGION)"
};
+        finally
+        {
+            sStatement.close();
+        }
 
         if ( newT )
         {
-            for ( int i = 1; i < setupData.length; i++ )
+            String setupData[] = { "create index iKEY on JCS_STORE_MYSQL (CACHE_KEY, REGION)"
};
+            Statement iStatement = cConn.createStatement();
+
+            try
             {
-                try
+                for ( int i = 0; i < setupData.length; i++ )
                 {
-                    sStatement.executeQuery( setupData[i] );
-                }
-                catch ( SQLException e )
-                {
-                    System.out.println( "Exception: " + e );
+                    try
+                    {
+                        iStatement.execute( setupData[i] );
+                    }
+                    catch ( SQLException e )
+                    {
+                        System.out.println( "Exception: " + e );
+                    }
                 }
             }
-        } // end ifnew
+            finally
+            {
+                iStatement.close();
+            }
+        }
     }
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/memory/fifo/FIFOMemoryCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/memory/fifo/FIFOMemoryCacheUnitTest.java?rev=1717932&r1=1717931&r2=1717932&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/memory/fifo/FIFOMemoryCacheUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/memory/fifo/FIFOMemoryCacheUnitTest.java
Fri Dec  4 11:13:24 2015
@@ -19,15 +19,16 @@ package org.apache.commons.jcs.engine.me
  * under the License.
  */
 
+import java.io.IOException;
+
 import junit.framework.TestCase;
+
 import org.apache.commons.jcs.engine.CacheElement;
 import org.apache.commons.jcs.engine.CompositeCacheAttributes;
 import org.apache.commons.jcs.engine.ElementAttributes;
 import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
 import org.apache.commons.jcs.engine.control.CompositeCache;
 
-import java.io.IOException;
-
 /** Unit tests for the fifo implementation. */
 public class FIFOMemoryCacheUnitTest
     extends TestCase
@@ -65,11 +66,11 @@ public class FIFOMemoryCacheUnitTest
 
         // VERIFY
         assertEquals( "Should have max elements", maxObjects, cache.getSize() );
-        for ( int i = maxObjects; i > maxObjects; i-- )
+        for ( int i = maxObjects; i > 0; i-- )
         {
-            assertNotNull( "Shjould have elemnt " + i, cache.get( "key" + i ) );
+            assertNotNull( "Should have element " + i, cache.get( "key" + i ) );
         }
-        assertNotNull( "Shjould have oneMoreElement", cache.get( "onemore" ) );
+        assertNotNull( "Should have oneMoreElement", cache.get( "onemore" ) );
     }
 
     /**



Mime
View raw message