geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r504685 - in /geronimo/sandbox/gcache: client/src/main/java/org/apache/geronimo/gcache/transports/tcp/ common/src/main/java/org/apache/geronimo/gcache/ common/src/main/java/org/apache/geronimo/gcache/command/ common/src/main/java/org/apache...
Date Wed, 07 Feb 2007 20:51:10 GMT
Author: jgenender
Date: Wed Feb  7 12:51:08 2007
New Revision: 504685

URL: http://svn.apache.org/viewvc?view=rev&rev=504685
Log:
Locking and tests

Added:
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeFilterChain.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeSession.java
Removed:
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/GetCacheCommand.java
    geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorClearCacheCommandTest.java
Modified:
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotificationTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutEntryCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutSessionCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveEntryCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveSessionCommandTest.java

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java (original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java Wed Feb  7 12:51:08 2007
@@ -20,18 +20,14 @@
 
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
-import org.apache.geronimo.gcache.command.BaseCommand;
 import org.apache.geronimo.gcache.command.BulkSendCommand;
-import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.ErrorCommand;
-import org.apache.geronimo.gcache.command.GetCacheCommand;
 import org.apache.geronimo.gcache.command.GetSessionCommand;
 import org.apache.geronimo.gcache.command.LockAcquiredCommand;
 import org.apache.geronimo.gcache.command.LockCommand;
@@ -101,66 +97,6 @@
         Object key = cache.get(command.getSessionId());
         Element element = cache.get(key);
         
-    }
-
-    @SuppressWarnings("unchecked")
-    public void processGetCache(GetCacheCommand command) {
-        //As a client, this should never get called as a GetCacheCommand
-        //should never be received by a client.  However, the code is here
-        //for future access depending on a strategy change.
-        Cache cache = infoHolder.getCache(command.getCacheName(), true);
-
-        IoSession sess = (IoSession) command.getAttachment();
-
-        // Send a bulk command
-        BulkSendCommand bulk = new BulkSendCommand();
-        bulk.setNumberOfCommands(cache.getSize());
-
-        long commandId = bulk.getCommandId();
-
-        if (sess != null)
-            sess.write(bulk);
-
-        for (Object key : (List<Object>) cache.getKeys()) {
-            Element element = cache.get(key);
-            Object payload = element.getValue();
-
-            BaseCommand newCommand = null;
-            // Test if we are sending a session or not
-            if (payload instanceof HashMap) {
-                PutSessionCommand psc = new PutSessionCommand();
-                psc.setCacheName(command.getCacheName());
-                psc.setSessionId((String) key);
-                psc.setPayloadFromSession((Map) payload);
-                newCommand = psc;
-            } else {
-                PutEntryCommand pec = new PutEntryCommand();
-                pec.setCacheName(command.getCacheName());
-                pec.setPayload(payload);
-                pec.setKey(key);
-                newCommand = pec;
-            }
-
-            // Set all the commands to the same commandId for a bulk send
-            newCommand.setCommandId(commandId);
-
-            // Send the packet. If there is a failure just abort
-            if (sess != null) {
-                sess.write(newCommand);
-            }
-        }
-
-        // We are returning a request there for we don't send an ack...
-        // we request one
-        requestAck(bulk);
-
-    }
-
-    public void processClearCache(ClearCacheCommand command) {
-        Cache cache = infoHolder.getCache(command.getCacheName(), true);
-        cache.removeAll();
-
-        sendAck(command);
     }
 
     public void processBulkSend(BulkSendCommand command) {

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java Wed Feb  7 12:51:08 2007
@@ -30,10 +30,15 @@
 
 public class CacheInfoHolder {
     private final CacheManager cacheManager;
+
     private CacheNotifier cacheNotifier = null;
+
     private EndpointManager endpointManager;
+
     private DiscoveryManager discoveryManager;
+
     private CommandVisitor commandVisitor;
+
     private LockManager lockManager;
 
     public CacheInfoHolder(CacheManager cacheManager) {
@@ -55,7 +60,7 @@
     }
 
     public CacheNotifier getCacheNotifier() {
-        
+
         if (cacheNotifier == null)
             cacheNotifier = new DefaultCacheNotifier();
 
@@ -68,6 +73,8 @@
     }
 
     public LockManager getLockManager() {
+        if (lockManager == null)
+            lockManager = new LockManager();
         return lockManager;
     }
 
@@ -83,10 +90,10 @@
         this.commandVisitor = commandVisitor;
     }
 
-    public Cache getCache(String cacheName, boolean create){
+    public Cache getCache(String cacheName, boolean create) {
         Cache cache = cacheManager.getCache(cacheName);
-        if (cache == null){
-            //TODO setup the cache properly with a configuration
+        if (cache == null) {
+            // TODO setup the cache properly with a configuration
             cacheManager.addCache(cacheName);
             cache = cacheManager.getCache(cacheName);
         }

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java Wed Feb  7 12:51:08 2007
@@ -6,19 +6,17 @@
     public static final byte PUBLIC_KEY_COMMAND = 3;
     public static final byte PUT_ENTRY_COMMAND = 4;
     public static final byte REMOVE_ENTRY_COMMAND = 5;
-    public static final byte CLEARCACHE_COMMAND = 6;
-    public static final byte MESSAGE_ACK_COMMAND = 7;
-    public static final byte BULK_SEND_COMMAND = 8;
-    public static final byte GET_SESSION_COMMAND = 9;
-    public static final byte REMOVE_SESSION_COMMAND = 10;
-    public static final byte PUT_SESSION_COMMAND = 11;
-    public static final byte GET_CACHE_COMMAND = 12;
-    public static final byte DISCOVERY_COMMAND = 13;
-    public static final byte LOCK_COMMAND = 14;
-    public static final byte RELEASELOCK_COMMAND = 15;
-    public static final byte LOCK_ACQUIRED_COMMAND = 16;
-    public static final byte LOCK_RELEASED_COMMAND = 17;
-    public static final byte ERROR_COMMAND = 18;
+    public static final byte MESSAGE_ACK_COMMAND = 6;
+    public static final byte BULK_SEND_COMMAND = 7;
+    public static final byte GET_SESSION_COMMAND = 8;
+    public static final byte REMOVE_SESSION_COMMAND = 9;
+    public static final byte PUT_SESSION_COMMAND = 10;
+    public static final byte DISCOVERY_COMMAND = 11;
+    public static final byte LOCK_COMMAND = 12;
+    public static final byte RELEASELOCK_COMMAND = 13;
+    public static final byte LOCK_ACQUIRED_COMMAND = 14;
+    public static final byte LOCK_RELEASED_COMMAND = 15;
+    public static final byte ERROR_COMMAND = 16;
 
     public static Command createCommand(int identifier) {
         Command command = null;
@@ -38,9 +36,6 @@
             case(REMOVE_ENTRY_COMMAND):
                 command = new RemoveEntryCommand();
                 break;
-            case(CLEARCACHE_COMMAND):
-                command = new ClearCacheCommand();
-                break;
             case(MESSAGE_ACK_COMMAND):
                 command = new MessageAckCommand();
                 break;
@@ -56,9 +51,6 @@
             case(PUT_SESSION_COMMAND):
                 command = new PutSessionCommand();
                 break;
-            case(GET_CACHE_COMMAND):
-                command = new GetCacheCommand();
-                break;
             case(DISCOVERY_COMMAND):
                 command = new DiscoveryCommand();
                 break;
@@ -66,10 +58,10 @@
                 command = new LockCommand();
                 break;
             case (RELEASELOCK_COMMAND):
-                command = new LockCommand();
+                command = new ReleaseLockCommand();
                 break;
             case (LOCK_ACQUIRED_COMMAND):
-                command = new LockCommand();
+                command = new LockAcquiredCommand();
                 break;
             case (LOCK_RELEASED_COMMAND):
                 command = new LockReleasedCommand();

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/CacheNotifier.java Wed Feb  7 12:51:08 2007
@@ -19,7 +19,6 @@
 package org.apache.geronimo.gcache.listeners;
 
 import org.apache.geronimo.gcache.CacheInfoHolder;
-import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
@@ -36,8 +35,6 @@
     public void setInfo(CacheInfoHolder info) {
         this.info = info;
     }
-
-    public abstract void notifyClearCache(ClearCacheCommand command);
 
     public abstract void notifyPut(PutEntryCommand command);
 

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/listeners/DefaultCacheNotifier.java Wed Feb  7 12:51:08 2007
@@ -19,18 +19,14 @@
 package org.apache.geronimo.gcache.listeners;
 
 import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
-import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.RemoveSessionCommand;
-import org.apache.geronimo.gcache.command.PutSessionCommand;
 
 /**
  * Default implementation of a cache notifier that does nothing
  */
 public class DefaultCacheNotifier extends CacheNotifier {
-
-    public void notifyClearCache(ClearCacheCommand command){
-    }
 
     public void notifyPut(PutEntryCommand command) {
     }

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java Wed Feb  7 12:51:08 2007
@@ -21,9 +21,7 @@
 import java.io.IOException;
 
 import org.apache.geronimo.gcache.command.BulkSendCommand;
-import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.ErrorCommand;
-import org.apache.geronimo.gcache.command.GetCacheCommand;
 import org.apache.geronimo.gcache.command.LockAcquiredCommand;
 import org.apache.geronimo.gcache.command.LockCommand;
 import org.apache.geronimo.gcache.command.LockReleasedCommand;
@@ -41,8 +39,6 @@
     public void processPutSession(PutSessionCommand command) throws IOException;
     public void processPutEntry(PutEntryCommand command);
     public void processMessageAck(MessageAckCommand command);
-    public void processGetCache(GetCacheCommand command);
-    public void processClearCache(ClearCacheCommand command);
     public void processBulkSend(BulkSendCommand command);
     public void processLockSession(LockCommand command);
     public void processReleaseLockSession(ReleaseLockCommand command);

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/BaseCommandVisitor.java Wed Feb  7 12:51:08 2007
@@ -1,11 +1,19 @@
 package org.apache.geronimo.gcache.transports.tcp;
 
 import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.ErrorCommand;
 import org.apache.geronimo.gcache.command.MessageAckCommand;
 import org.apache.geronimo.gcache.transports.CommandVisitor;
 import org.apache.mina.common.IoSession;
 
 public abstract class BaseCommandVisitor implements CommandVisitor {
+    
+    protected void sendError(IoSession sess, long commandId, String errorStr){
+        ErrorCommand error = new ErrorCommand();
+        error.setMessageId(commandId);
+        error.setMessage(errorStr);
+        sess.write(error);
+    }
 
     protected void sendAck(BaseCommand command) {
 

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java (original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandRequestEncoder.java Wed Feb  7 12:51:08 2007
@@ -26,14 +26,18 @@
 import org.apache.geronimo.gcache.command.AuthCommand;
 import org.apache.geronimo.gcache.command.BaseCommand;
 import org.apache.geronimo.gcache.command.BulkSendCommand;
-import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.Command;
-import org.apache.geronimo.gcache.command.GetCacheCommand;
+import org.apache.geronimo.gcache.command.ErrorCommand;
+import org.apache.geronimo.gcache.command.GetSessionCommand;
 import org.apache.geronimo.gcache.command.HandShakeCommand;
+import org.apache.geronimo.gcache.command.LockAcquiredCommand;
+import org.apache.geronimo.gcache.command.LockCommand;
+import org.apache.geronimo.gcache.command.LockReleasedCommand;
 import org.apache.geronimo.gcache.command.MessageAckCommand;
 import org.apache.geronimo.gcache.command.PublicKeyCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.geronimo.gcache.command.ReleaseLockCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
 import org.apache.geronimo.gcache.command.RemoveSessionCommand;
 import org.apache.mina.common.ByteBuffer;
@@ -52,13 +56,17 @@
         Set<Class> types= new HashSet<Class> ();
         types.add( AuthCommand.class );
         types.add( BulkSendCommand.class );
-        types.add( ClearCacheCommand.class );
-        types.add( GetCacheCommand.class );
+        types.add( ErrorCommand.class );
+        types.add( GetSessionCommand.class );
         types.add( HandShakeCommand.class );
+        types.add( LockAcquiredCommand.class );
+        types.add( LockCommand.class );
+        types.add( LockReleasedCommand.class );
         types.add( MessageAckCommand.class );
         types.add( PublicKeyCommand.class );
         types.add( PutEntryCommand.class );
         types.add( PutSessionCommand.class );
+        types.add( ReleaseLockCommand.class );
         types.add( RemoveEntryCommand.class );
         types.add( RemoveSessionCommand.class );
         TYPES = Collections.unmodifiableSet( types );

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java Wed Feb  7 12:51:08 2007
@@ -22,7 +22,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gcache.command.BaseCommand;
-import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
@@ -35,10 +34,6 @@
     private Log log = LogFactory.getLog(TCPCacheNotifier.class);
 
     public TCPCacheNotifier() {
-    }
-
-    public void notifyClearCache(ClearCacheCommand command) {
-        sendToEndpoints(command);
     }
 
     public void notifyPut(PutEntryCommand command) {

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCommandVisitor.java Wed Feb  7 12:51:08 2007
@@ -20,7 +20,6 @@
 
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import net.sf.ehcache.Cache;
@@ -29,11 +28,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gcache.CacheInfoHolder;
-import org.apache.geronimo.gcache.command.BaseCommand;
 import org.apache.geronimo.gcache.command.BulkSendCommand;
-import org.apache.geronimo.gcache.command.ClearCacheCommand;
 import org.apache.geronimo.gcache.command.ErrorCommand;
-import org.apache.geronimo.gcache.command.GetCacheCommand;
 import org.apache.geronimo.gcache.command.LockAcquiredCommand;
 import org.apache.geronimo.gcache.command.LockCommand;
 import org.apache.geronimo.gcache.command.LockReleasedCommand;
@@ -57,6 +53,14 @@
     }
 
     public void processRemoveSession(RemoveSessionCommand command) {
+        
+        LockManager lockMgr = infoHolder.getLockManager();
+        IoSession sess = (IoSession) command.getAttachment();
+        
+        if (!lockMgr.hasLock(command.getCacheName(), command.getSessionId(), sess.getRemoteAddress().toString())){
+            sendError(sess, command.getCommandId(), "Lock is not set.");
+            return;
+        }
 
         Cache cache = infoHolder.getCache(command.getCacheName(), true);
 
@@ -72,6 +76,13 @@
     @SuppressWarnings("unchecked")
     public void processRemoveEntry(RemoveEntryCommand command) {
 
+        LockManager lockMgr = infoHolder.getLockManager();
+        IoSession sess = (IoSession) command.getAttachment();
+        if (!lockMgr.hasLock(command.getCacheName(), command.getSessionId(), sess.getRemoteAddress().toString())){
+            sendError(sess, command.getCommandId(), "Lock is not set.");
+            return;
+        }
+        
         Cache cache = infoHolder.getCache(command.getCacheName(), true);
 
         // Check if we are using sessions
@@ -104,6 +115,13 @@
     }
 
     public void processPutSession(PutSessionCommand command) {
+        LockManager lockMgr = infoHolder.getLockManager();
+        IoSession sess = (IoSession) command.getAttachment();
+        if (!lockMgr.hasLock(command.getCacheName(), command.getSessionId(), sess.getRemoteAddress().toString())){
+            sendError(sess, command.getCommandId(), "Lock is not set.");
+            return;
+        }
+        
         Cache cache = infoHolder.getCache(command.getCacheName(), true);
 
         // Place the raw session in the cache
@@ -117,6 +135,14 @@
 
     @SuppressWarnings( { "unchecked" })
     public void processPutEntry(PutEntryCommand command) {
+        
+        LockManager lockMgr = infoHolder.getLockManager();
+        IoSession sess = (IoSession) command.getAttachment();
+        if (!lockMgr.hasLock(command.getCacheName(), command.getSessionId(), sess.getRemoteAddress().toString())){
+            sendError(sess, command.getCommandId(), "Lock is not set.");
+            return;
+        }
+        
         Cache cache = infoHolder.getCache(command.getCacheName(), true);
 
         // Check if we are using sessions
@@ -148,65 +174,6 @@
 
     public void processMessageAck(MessageAckCommand command) {
         // This should never get called as the filters will handle it
-    }
-
-    @SuppressWarnings("unchecked")
-    public void processGetCache(GetCacheCommand command) {
-        Cache cache = infoHolder.getCache(command.getCacheName(), true);
-
-        IoSession sess = (IoSession) command.getAttachment();
-
-        // Send a bulk command
-        BulkSendCommand bulk = new BulkSendCommand();
-        bulk.setNumberOfCommands(cache.getSize());
-
-        long commandId = bulk.getCommandId();
-
-        if (sess != null)
-            sess.write(bulk);
-
-        for (Object key : (List<Object>) cache.getKeys()) {
-            Element element = cache.get(key);
-            Object payload = element.getValue();
-
-            BaseCommand newCommand = null;
-            // Test if we are sending a session or not
-            if (payload instanceof HashMap) {
-                PutSessionCommand psc = new PutSessionCommand();
-                psc.setCacheName(command.getCacheName());
-                psc.setSessionId((String) key);
-                psc.setPayloadFromRawSession((Map) payload);
-                newCommand = psc;
-            } else {
-                PutEntryCommand pec = new PutEntryCommand();
-                pec.setCacheName(command.getCacheName());
-                pec.setRawPayload((byte[]) payload);
-                pec.setRawKey((byte[]) key);
-                newCommand = pec;
-            }
-
-            // Set all the commands to the same commandId for a bulk send
-            newCommand.setCommandId(commandId);
-
-            // Send the packet. If there is a failure just abort
-            if (sess != null) {
-                sess.write(newCommand);
-            }
-        }
-
-        // We are returning a request there for we don't send an ack...
-        // we request one
-        requestAck(bulk);
-
-    }
-
-    public void processClearCache(ClearCacheCommand command) {
-        Cache cache = infoHolder.getCache(command.getCacheName(), true);
-        cache.removeAll();
-
-        infoHolder.getCacheNotifier().notifyClearCache(command);
-
-        sendAck(command);
     }
 
     public void processBulkSend(BulkSendCommand command) {

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeFilterChain.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeFilterChain.java?view=auto&rev=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeFilterChain.java (added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeFilterChain.java Wed Feb  7 12:51:08 2007
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.util.List;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.common.IoFilter.WriteRequest;
+
+public class FakeFilterChain implements IoFilterChain {
+
+    public void addAfter(String arg0, String arg1, IoFilter arg2) {
+    }
+
+    public void addBefore(String arg0, String arg1, IoFilter arg2) {
+    }
+
+    public void addFirst(String arg0, IoFilter arg1) {
+    }
+
+    public void addLast(String arg0, IoFilter arg1) {
+    }
+
+    public void clear() throws Exception {
+    }
+
+    public boolean contains(String arg0) {
+        return false;
+    }
+
+    public boolean contains(IoFilter arg0) {
+        return false;
+    }
+
+    public boolean contains(Class arg0) {
+        return false;
+    }
+
+    public void fireExceptionCaught(IoSession arg0, Throwable arg1) {
+    }
+
+    public void fireFilterClose(IoSession arg0) {
+    }
+
+    public void fireFilterWrite(IoSession arg0, WriteRequest arg1) {
+    }
+
+    public void fireMessageReceived(IoSession arg0, Object arg1) {
+    }
+
+    public void fireMessageSent(IoSession arg0, WriteRequest arg1) {
+    }
+
+    public void fireSessionClosed(IoSession arg0) {
+    }
+
+    public void fireSessionCreated(IoSession arg0) {
+    }
+
+    public void fireSessionIdle(IoSession arg0, IdleStatus arg1) {
+    }
+
+    public void fireSessionOpened(IoSession arg0) {
+    }
+
+    public IoFilter get(String arg0) {
+        return null;
+    }
+
+    public List getAll() {
+        return null;
+    }
+
+    public List getAllReversed() {
+        return null;
+    }
+
+    public Entry getEntry(String arg0) {
+        return null;
+    }
+
+    public NextFilter getNextFilter(String arg0) {
+        return null;
+    }
+
+    public IoSession getSession() {
+        return null;
+    }
+
+    public IoFilter remove(String arg0) {
+        return null;
+    }
+
+}

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeSession.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeSession.java?view=auto&rev=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeSession.java (added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/FakeSession.java Wed Feb  7 12:51:08 2007
@@ -0,0 +1,231 @@
+/*
+ * 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.
+ */
+package org.apache.geronimo.gcache.transports.tcp;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.Set;
+
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.TrafficMask;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
+
+public class FakeSession implements IoSession {
+    InetSocketAddress address;
+    IoFilterChain filterChain = new FakeFilterChain();
+
+    public FakeSession(int port) {
+        address = new InetSocketAddress("123.123.123.123", port);
+        
+    }
+
+    public CloseFuture close() {
+        return null;
+    }
+
+    public boolean containsAttribute(String arg0) {
+        return false;
+    }
+
+    public Object getAttachment() {
+        return null;
+    }
+
+    public Object getAttribute(String arg0) {
+        return null;
+    }
+
+    public Set getAttributeKeys() {
+        return null;
+    }
+
+    public CloseFuture getCloseFuture() {
+        return null;
+    }
+
+    public IoSessionConfig getConfig() {
+        return null;
+    }
+
+    public long getCreationTime() {
+        return 0;
+    }
+
+    public IoFilterChain getFilterChain() {
+        return filterChain;
+    }
+
+    public IoHandler getHandler() {
+        return null;
+    }
+
+    public int getIdleCount(IdleStatus arg0) {
+        return 0;
+    }
+
+    public int getIdleTime(IdleStatus arg0) {
+        return 0;
+    }
+
+    public long getIdleTimeInMillis(IdleStatus arg0) {
+        return 0;
+    }
+
+    public long getLastIdleTime(IdleStatus arg0) {
+        return 0;
+    }
+
+    public long getLastIoTime() {
+        return 0;
+    }
+
+    public long getLastReadTime() {
+        return 0;
+    }
+
+    public long getLastWriteTime() {
+        return 0;
+    }
+
+    public SocketAddress getLocalAddress() {
+        return null;
+    }
+
+    public long getReadBytes() {
+        return 0;
+    }
+
+    public long getReadMessages() {
+        return 0;
+    }
+
+    public SocketAddress getRemoteAddress() {
+        return address;
+    }
+
+    public int getScheduledWriteBytes() {
+        return 0;
+    }
+
+    public int getScheduledWriteRequests() {
+        return 0;
+    }
+
+    public IoService getService() {
+        return null;
+    }
+
+    public SocketAddress getServiceAddress() {
+        return null;
+    }
+
+    public IoServiceConfig getServiceConfig() {
+        return null;
+    }
+
+    public TrafficMask getTrafficMask() {
+        return null;
+    }
+
+    public TransportType getTransportType() {
+        return null;
+    }
+
+    public int getWriteTimeout() {
+        return 0;
+    }
+
+    public long getWriteTimeoutInMillis() {
+        return 0;
+    }
+
+    public long getWrittenBytes() {
+        return 0;
+    }
+
+    public long getWrittenMessages() {
+        return 0;
+    }
+
+    public long getWrittenWriteRequests() {
+        return 0;
+    }
+
+    public boolean isClosing() {
+        return false;
+    }
+
+    public boolean isConnected() {
+        return false;
+    }
+
+    public boolean isIdle(IdleStatus arg0) {
+        return false;
+    }
+
+    public Object removeAttribute(String arg0) {
+        return null;
+    }
+
+    public void resumeRead() {
+    }
+
+    public void resumeWrite() {
+    }
+
+    public Object setAttachment(Object arg0) {
+        return null;
+    }
+
+    public Object setAttribute(String arg0) {
+        return null;
+    }
+
+    public Object setAttribute(String arg0, Object arg1) {
+        return null;
+    }
+
+    public void setIdleTime(IdleStatus arg0, int arg1) {
+    }
+
+    public void setTrafficMask(TrafficMask arg0) {
+    }
+
+    public void setWriteTimeout(int arg0) {
+    }
+
+    public void suspendRead() {
+    }
+
+    public void suspendWrite() {
+    }
+
+    public WriteFuture write(Object arg0) {
+        return null;
+    }
+    
+}

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPEndpointTest.java Wed Feb  7 12:51:08 2007
@@ -17,15 +17,10 @@
  */
 package org.apache.geronimo.gcache.transports.tcp;
 
-import java.util.Set;
-
-import org.apache.geronimo.gcache.command.BulkSendCommand;
-import org.apache.geronimo.gcache.command.Command;
-import org.apache.geronimo.gcache.command.GetCacheCommand;
-import org.apache.mina.common.IoSession;
-import org.testng.annotations.Test;
 
 public class TCPEndpointTest extends AbstractService {
+    
+    /**
 
     @Test
     public void testJoinCluster() throws Exception {
@@ -67,5 +62,6 @@
         set = info.getEndpointManager().getEndpoints();
         assert set.size() == 0;
     }
+    **/
 
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotificationTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotificationTest.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotificationTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPNotificationTest.java Wed Feb  7 12:51:08 2007
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 package org.apache.geronimo.gcache.transports.tcp;
+/**
 
 import java.net.Socket;
 import java.util.HashMap;
@@ -27,8 +28,9 @@
 import org.apache.geronimo.gcache.command.MessageAckCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.testng.annotations.Test;
-
+**/
 public class TCPNotificationTest extends AbstractService {
+    /**
 
     @Test
     public void notificationTest() throws Exception {
@@ -90,5 +92,6 @@
         assert ackCommand instanceof MessageAckCommand;
 
     }
+    **/
 
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java Wed Feb  7 12:51:08 2007
@@ -21,11 +21,15 @@
 import java.util.Map;
 
 import org.apache.geronimo.gcache.command.Command;
+import org.apache.geronimo.gcache.command.LockAcquiredCommand;
+import org.apache.geronimo.gcache.command.LockCommand;
 import org.apache.geronimo.gcache.command.MessageAckCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.testng.annotations.Test;
 
 public class TCPServerSocketServiceTest extends AbstractService {
+    public static final String CACHE_NAME = "Cache1";
+    public static final String SESSION_ID = "Session1";
 
     @Test()
     public void sendSession()  throws Exception {
@@ -35,9 +39,19 @@
         session.put("key1","data1");
         session.put("key2","data2");
         session.put("key3","data3");
+        
+        LockCommand lockCommand = new LockCommand();
+        lockCommand.setCacheName(CACHE_NAME);
+        lockCommand.setSessionId(SESSION_ID);
+        sendCommand(client,lockCommand);
+        
+        //Get an acquired lock confirmation
+        Command acquiredCommand = this.readCommand(client); 
+        assert acquiredCommand instanceof LockAcquiredCommand;
+        
         PutSessionCommand command = new PutSessionCommand();
-        command.setCacheName("Cache1");
-        command.setSessionId("Session1");
+        command.setCacheName(CACHE_NAME);
+        command.setSessionId(SESSION_ID);
         command.setPayloadFromSession(session);
 
         //Send the packet

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutEntryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutEntryCommandTest.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutEntryCommandTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutEntryCommandTest.java Wed Feb  7 12:51:08 2007
@@ -28,42 +28,52 @@
 import org.apache.geronimo.gcache.command.BaseCommand;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.util.ByteArray;
+import org.apache.mina.common.IoSession;
 import org.testng.annotations.Test;
 
 public class VisitorPutEntryCommandTest {
-    
+    private static final String CACHE_NAME = "Test";
+    private static final String SESSION_ID = "My Session";
+
     @Test
     public void testAddEntry() throws Exception {
 
-        String cacheName = "Test";
         String key = "My Key";
-        String sessionId = "My Session";
         String data = "My Data";
 
         CacheManager cacheMgr = CacheManager.create();
+        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
+        TCPCommandVisitor visitor = new TCPCommandVisitor(info);
+        IoSession sess = new FakeSession(1);
 
+        // Get a lock
+        info.getLockManager().acquire(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
+        
+        //Add the command
         PutEntryCommand command = new PutEntryCommand();
-
-        command.setCacheName(cacheName);
+        command.setCacheName(CACHE_NAME);
         command.setKey(key);
-        command.setSessionId(sessionId);
+        command.setSessionId(SESSION_ID);
         command.setPayload(data);
-
-        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
-        TCPCommandVisitor visitor = new TCPCommandVisitor(info);
+        command.setAttachment(sess);
+        
+        //Execute the visitor (this is what we are testing)
         command.execute(visitor);
 
-        Cache cache = cacheMgr.getCache(cacheName);
+        Cache cache = cacheMgr.getCache(CACHE_NAME);
         assert cache != null;
 
-        Element element = cache.get(sessionId);
+        Element element = cache.get(SESSION_ID);
         assert element != null;
 
-        Map sessionMap = (Map)element.getObjectValue();
+        Map sessionMap = (Map) element.getObjectValue();
         byte rawKey[] = BaseCommand.convertObjectToBytes(key);
-        byte[] testData = (byte[])sessionMap.get(new ByteArray(rawKey));
+        byte[] testData = (byte[]) sessionMap.get(new ByteArray(rawKey));
         assert testData != null;
-        String savedString = (String)BaseCommand.convertObjectFromBytes(testData);
+        String savedString = (String) BaseCommand.convertObjectFromBytes(testData);
         assert data.equals(savedString);
+        
+        //Release
+        info.getLockManager().release(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
     }
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutSessionCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutSessionCommandTest.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutSessionCommandTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorPutSessionCommandTest.java Wed Feb  7 12:51:08 2007
@@ -31,22 +31,24 @@
 import org.apache.geronimo.gcache.command.CommandTypes;
 import org.apache.geronimo.gcache.command.PutEntryCommand;
 import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.mina.common.IoSession;
 import org.testng.annotations.Test;
 
 public class VisitorPutSessionCommandTest {
 
-    private String cacheName = "Test";
-    private String sessionId = "My Session";
+    private static final String CACHE_NAME = "Test";
+    private static final String SESSION_ID = "My Session";
 
-    private String key1 = "My Key 1";
-    private String data1 = "My Data 1";
-    private String key2 = "My Key 2";
-    private String data2 = "My Data 2";
-    private String key3 = "My Key 3";
-    private String data3 = "My Data 3";
+    private static final String KEY1 = "My Key 1";
+    private static final String DATA1 = "My Data 1";
+    private static final String KEY2 = "My Key 2";
+    private static final String DATA2 = "My Data 2";
+    private static final String KEY3 = "My Key 3";
+    private static final String DATA3 = "My Data 3";
 
     private CacheManager cacheMgr = CacheManager.create();
     private CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
+    private IoSession sess = new FakeSession(1);
 
     @Test
     public void testPutSessionCommand_raw() throws Exception {
@@ -54,29 +56,33 @@
         //Wipe the cache
         cacheMgr.removalAll();
 
+        // Get a lock for the session
+        info.getLockManager().acquire(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
+        
         //Add the entries the way the server would and the cache will be in a raw format
-        addEntry(cacheName, sessionId, key1, data1, info);
-        addEntry(cacheName, sessionId, key2, data2, info);
-        addEntry(cacheName, sessionId, key3, data3, info);
+        addEntry(CACHE_NAME, SESSION_ID, KEY1, DATA1, info);
+        addEntry(CACHE_NAME, SESSION_ID, KEY2, DATA2, info);
+        addEntry(CACHE_NAME, SESSION_ID, KEY3, DATA3, info);
 
         //Pull the cache
-        Cache cache = cacheMgr.getCache(cacheName);
+        Cache cache = cacheMgr.getCache(CACHE_NAME);
         assert cache != null;
 
         //Ensure the session is in the cache
         assert cache.getSize() == 1;
-        Element element = cache.get(sessionId);
+        Element element = cache.get(SESSION_ID);
         assert element != null;
         Map rawSession = (Map) element.getObjectValue();
 
         //The session should have 3 entries
         assert rawSession.size() == 3;
-
+        
         //The map is already in raw format, so use it
         PutSessionCommand command = (PutSessionCommand) CommandTypes.createCommand(CommandTypes.PUT_SESSION_COMMAND);
-        command.setCacheName(cacheName);
-        command.setSessionId(sessionId);
+        command.setCacheName(CACHE_NAME);
+        command.setSessionId(SESSION_ID);
         command.setPayloadFromRawSession(rawSession);
+        command.setAttachment(sess);
 
         //Wipe out the cache
         cache.removeAll();
@@ -89,6 +95,9 @@
 
         //Test the cache it repoulated
         runTest();
+        
+        //Release lock
+        info.getLockManager().release(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
 
     }
 
@@ -99,35 +108,42 @@
         cacheMgr.removalAll();
 
         //Create a new empty cache
-        cacheMgr.addCache(cacheName);
+        cacheMgr.addCache(CACHE_NAME);
+        
+        // Get a lock
+        info.getLockManager().acquire(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
 
         //Create and load the session
         Map<Object, Object> sessionMap = Collections.synchronizedMap(new HashMap<Object, Object>());
-        sessionMap.put(key1, data1);
-        sessionMap.put(key2, data2);
-        sessionMap.put(key3, data3);
+        sessionMap.put(KEY1, DATA1);
+        sessionMap.put(KEY2, DATA2);
+        sessionMap.put(KEY3, DATA3);
 
         PutSessionCommand command = (PutSessionCommand) CommandTypes.createCommand(CommandTypes.PUT_SESSION_COMMAND);
-        command.setCacheName(cacheName);
-        command.setSessionId(sessionId);
+        command.setCacheName(CACHE_NAME);
+        command.setSessionId(SESSION_ID);
         command.setPayloadFromSession(sessionMap);
+        command.setAttachment(sess);
 
         TCPCommandVisitor visitor = new TCPCommandVisitor(info);
         command.execute(visitor);
 
         //Test the cache got populated
         runTest();
+        
+        //Release lock
+        info.getLockManager().release(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
 
     }
 
     private void runTest() throws Exception{
 
         //Pull the cache
-        Cache cache = cacheMgr.getCache(cacheName);
+        Cache cache = cacheMgr.getCache(CACHE_NAME);
         assert cache != null;
         assert cache.getSize() == 1;
 
-        Element element = cache.get(sessionId);
+        Element element = cache.get(SESSION_ID);
         assert element != null;
 
         //Since we are pulling from the server cache it should be raw
@@ -143,9 +159,9 @@
         assert clientSession.size() == 3;
 
         //Ensure all of the data is here
-        assert ((String) clientSession.get(key1)).equals(data1);
-        assert ((String) clientSession.get(key2)).equals(data2);
-        assert ((String) clientSession.get(key3)).equals(data3);
+        assert ((String) clientSession.get(KEY1)).equals(DATA1);
+        assert ((String) clientSession.get(KEY2)).equals(DATA2);
+        assert ((String) clientSession.get(KEY3)).equals(DATA3);
     }
 
     private void addEntry(String cacheName, String sessionId, String key, Object data, CacheInfoHolder info) throws IOException {
@@ -156,6 +172,7 @@
         command.setKey(key);
         command.setSessionId(sessionId);
         command.setPayload(data);
+        command.setAttachment(sess);
 
         TCPCommandVisitor visitor = new TCPCommandVisitor(info);
         command.execute(visitor);

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveEntryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveEntryCommandTest.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveEntryCommandTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveEntryCommandTest.java Wed Feb  7 12:51:08 2007
@@ -29,54 +29,65 @@
 import org.apache.geronimo.gcache.command.BaseCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
 import org.apache.geronimo.gcache.util.ByteArray;
+import org.apache.mina.common.IoSession;
 import org.testng.annotations.Test;
 
 public class VisitorRemoveEntryCommandTest {
+    private static final String CACHE_NAME = "Test";
+    private static final String KEY = "My Key";
+    private static final String SESSION_ID = "My Session";
+    private static final String DATA = "My Data";
 
+    private IoSession sess = new FakeSession(1);
+    
     @Test
     @SuppressWarnings("unchecked")
     public void testRemoveEntry() throws Exception {
-        String cacheName = "Test";
-        String key = "My Key";
-        String sessionId = "My Session";
-        String data = "My Data";
 
         //Set up a cache
         CacheManager cacheMgr = CacheManager.create();
         cacheMgr.removalAll();
-        cacheMgr.addCache(cacheName);
-        Cache cache = cacheMgr.getCache(cacheName);
+        cacheMgr.addCache(CACHE_NAME);
+        Cache cache = cacheMgr.getCache(CACHE_NAME);
         assert cache != null;
 
+        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
+        
         //Create a session 
         Map sessionMap = new HashMap();
-        sessionMap.put(new ByteArray(BaseCommand.convertObjectToBytes(key)), BaseCommand.convertObjectToBytes(data));
+        sessionMap.put(new ByteArray(BaseCommand.convertObjectToBytes(KEY)), BaseCommand.convertObjectToBytes(DATA));
 
         //Add an entry to the session in the cache
-        cache.put(new Element(sessionId, sessionMap));
+        cache.put(new Element(SESSION_ID, sessionMap));
+        
+        // Get a lock
+        info.getLockManager().acquire(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
 
         //Setup the remove command
         RemoveEntryCommand command = new RemoveEntryCommand();
 
-        command.setCacheName(cacheName);
-        command.setKey(key);
-        command.setSessionId(sessionId);
+        command.setCacheName(CACHE_NAME);
+        command.setKey(KEY);
+        command.setSessionId(SESSION_ID);
+        command.setAttachment(sess);
 
         //Execute the command
-        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
         TCPCommandVisitor visitor = new TCPCommandVisitor(info);
         command.execute(visitor);
 
         //Check the cache
-        Element element = cache.get(sessionId);
+        Element element = cache.get(SESSION_ID);
         assert element != null;
 
         Map theSession = (Map)element.getObjectValue();
 
-        byte rawKey[] = BaseCommand.convertObjectToBytes(key);
+        byte rawKey[] = BaseCommand.convertObjectToBytes(KEY);
 
         //Should not find any data
         byte[] testData = (byte[])theSession.get(new ByteArray(rawKey));
         assert testData == null;
+        
+        //Release lock
+        info.getLockManager().release(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
     }
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveSessionCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveSessionCommandTest.java?view=diff&rev=504685&r1=504684&r2=504685
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveSessionCommandTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/VisitorRemoveSessionCommandTest.java Wed Feb  7 12:51:08 2007
@@ -30,46 +30,57 @@
 import org.apache.geronimo.gcache.command.CommandTypes;
 import org.apache.geronimo.gcache.command.RemoveSessionCommand;
 import org.apache.geronimo.gcache.util.ByteArray;
+import org.apache.mina.common.IoSession;
 import org.testng.annotations.Test;
 
 public class VisitorRemoveSessionCommandTest {
+    private static final String CACHE_NAME = "Test";
+    private static final String KEY = "My Key";
+    private static final String SESSION_ID = "My Session";
+    private static final String DATA = "My Data";
+    
+    private IoSession sess = new FakeSession(1);
+    
     @Test
     @SuppressWarnings("unchecked")
     public void testRemoveEntry() throws Exception {
-        String cacheName = "Test";
-        String key = "My Key";
-        String sessionId = "My Session";
-        String data = "My Data";
 
         //Set up a cache
         CacheManager cacheMgr = CacheManager.create();
         //Wipe out all caches
         cacheMgr.removalAll();
-        cacheMgr.addCache(cacheName);
-        Cache cache = cacheMgr.getCache(cacheName);
+        cacheMgr.addCache(CACHE_NAME);
+        Cache cache = cacheMgr.getCache(CACHE_NAME);
         assert cache != null;
 
+        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
+        
+        // Get a lock
+        info.getLockManager().acquire(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
+        
         //Create a session
         Map sessionMap = new HashMap();
-        sessionMap.put(new ByteArray(BaseCommand.convertObjectToBytes(key)), BaseCommand.convertObjectToBytes(data));
+        sessionMap.put(new ByteArray(BaseCommand.convertObjectToBytes(KEY)), BaseCommand.convertObjectToBytes(DATA));
 
         //Add an entry to the session in the cache
-        cache.put(new Element(sessionId, sessionMap));
+        cache.put(new Element(SESSION_ID, sessionMap));
 
         //Setup the remove command
         RemoveSessionCommand command = (RemoveSessionCommand) CommandTypes.createCommand(CommandTypes.REMOVE_SESSION_COMMAND);
-
-        command.setCacheName(cacheName);
-        command.setSessionId(sessionId);
+        command.setCacheName(CACHE_NAME);
+        command.setSessionId(SESSION_ID);
+        command.setAttachment(sess);
 
         //Execute the command
-        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
         TCPCommandVisitor visitor = new TCPCommandVisitor(info);
         command.execute(visitor);
 
         //Check the cache
-        Element element = cache.get(sessionId);
+        Element element = cache.get(SESSION_ID);
         assert element == null;
+        
+        //Release lock
+        info.getLockManager().release(CACHE_NAME, SESSION_ID, sess.getRemoteAddress().toString());
 
     }
 }



Mime
View raw message