geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r449081 - in /geronimo/sandbox/gcache/server/src: main/java/org/apache/geronimo/gcache/ main/java/org/apache/geronimo/gcache/command/ main/java/org/apache/geronimo/gcache/server/core/ main/java/org/apache/geronimo/gcache/server/listeners/ m...
Date Fri, 22 Sep 2006 20:44:57 GMT
Author: jgenender
Date: Fri Sep 22 13:44:55 2006
New Revision: 449081

URL: http://svn.apache.org/viewvc?view=rev&rev=449081
Log:
Add commands, tests, and ehceche

Added:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java   (contents, props changed)
      - copied, changed from r448740, geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java   (with props)
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java   (with props)
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java   (contents, props changed)
      - copied, changed from r448740, geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java   (with props)
Removed:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoader.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPBootstrapCacheLoaderFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListener.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerListenerFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerProvider.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPCacheManagerPeerProviderFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/TCPSynchronousListener.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java
Modified:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/core/GCacheThread.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Cache;
+import org.apache.geronimo.gcache.server.listeners.CacheNotifier;
+import org.apache.geronimo.gcache.server.listeners.DefaultCacheNotifier;
+
+public class CacheInfoHolder {
+    public final CacheManager cacheManager;
+    public CacheNotifier cacheNotifier = null;
+
+    public CacheInfoHolder(CacheManager cacheManager) {
+        this.cacheManager = cacheManager;
+    }
+
+    public CacheManager getCacheManager() {
+        return cacheManager;
+    }
+
+    public CacheNotifier getCacheNotifier() {
+        
+        if (cacheNotifier == null)
+            cacheNotifier = new DefaultCacheNotifier();
+
+        return cacheNotifier;
+    }
+
+    public void setCacheNotifier(CacheNotifier cacheNotifier) {
+        this.cacheNotifier = cacheNotifier;
+    }
+
+    public Cache getCache(String cacheName, boolean create){
+        Cache cache = cacheManager.getCache(cacheName);
+        if (cache == null){
+            //TODO setup the cache properly with a configuration
+            cacheManager.addCache(cacheName);
+            cache = cacheManager.getCache(cacheName);
+        }
+
+        return cache;
+    }
+
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/CacheInfoHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java Fri Sep 22 13:44:55 2006
@@ -21,6 +21,7 @@
 import org.apache.geronimo.gcache.util.ByteArrayOutputStream;
 import org.apache.geronimo.gcache.util.ByteArrayInputStream;
 import org.apache.geronimo.gcache.marshal.MarshalAware;
+import org.apache.geronimo.gcache.CacheInfoHolder;
 
 import java.io.IOException;
 import java.io.Serializable;
@@ -35,6 +36,7 @@
 public class BaseCommand implements Command {
 
     private String commandId = null;
+    private String cacheName = null;
 
     public String getCommandId() {
         return commandId;
@@ -44,18 +46,28 @@
         this.commandId = commandId;
     }
 
-    public void execute() {
+    public String getCacheName() {
+        return cacheName;
+    }
+
+    public void setCacheName(String cacheName) {
+        this.cacheName = cacheName;
+    }
+
+    public void execute(CacheInfoHolder info) {
         // nothing to do in the base
     }
 
     public void readExternal(ReadableByteChannel channel) throws IOException {
         // this is the root so no super impl, others should call super first
+        cacheName = readString(channel);
         commandId = readString(channel);
 
     }
 
     public void writeExternal(WritableByteChannel channel) throws IOException {
         // this is the root so no super impl, others should call super first
+        writeString(channel, cacheName);
         writeString(channel, commandId);
     }
 
@@ -67,7 +79,7 @@
         return baos.toByteArray();
     }
 
-    protected Object convertObjectFromBytes(byte data[]) throws IOException {
+    public static Object convertObjectFromBytes(byte data[]) throws IOException {
         if (data == null)
             return null;
 
@@ -90,6 +102,9 @@
         } else {
             throw new IOException("Could not read identifier length from the channel");
         }
+        if (idLength == -1)
+            return null;
+
         buffer = null;
         // should read idLength * 2 bytes from the channel to get the string
         // the length method on String returns the number of 16 bit characters
@@ -109,13 +124,19 @@
 
         // first the length of the string
         ByteBuffer buffer = ByteBuffer.allocateDirect(4);
-        buffer.putInt(str.length());
+        if (str != null)
+            buffer.putInt(str.length());
+        else
+            buffer.putInt(-1);
+
         buffer.flip();
         channel.write(buffer);
 
         // now write the string - buffer comes back flipped
-        buffer = Charset.defaultCharset().encode(str);
-        channel.write(buffer);
+        if (str != null){
+            buffer = Charset.defaultCharset().encode(str);
+            channel.write(buffer);
+        }
     }
 
     protected byte[] readBytes(ReadableByteChannel channel) throws IOException {
@@ -133,7 +154,7 @@
         }
         buffer = null;
 
-        if (idLength == 0)
+        if (idLength == -1)
             return null;
 
         //Read the bytes
@@ -153,7 +174,7 @@
         if (bytes != null)
             buffer.putInt(bytes.length);
         else{
-            buffer.putInt(0);
+            buffer.putInt(-1);
         }
         buffer.flip();
         channel.write(buffer);
@@ -162,7 +183,7 @@
             channel.write(ByteBuffer.wrap(bytes));
     }
 
-    protected byte[] convertObjectToBytes(Object object) throws IOException {
+    public static byte[] convertObjectToBytes(Object object) throws IOException {
 
         if (object instanceof Serializable) {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CacheBaseCommand.java Fri Sep 22 13:44:55 2006
@@ -18,11 +18,11 @@
  */
 package org.apache.geronimo.gcache.command;
 
+import org.apache.geronimo.gcache.util.ByteArray;
+
 import java.io.IOException;
-import java.nio.ByteBuffer;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
-import java.nio.charset.Charset;
 
 public class CacheBaseCommand extends BaseCommand {
 
@@ -30,13 +30,17 @@
     private String sessionId;
 
     // The key to store the payload under
-    private String key;
+    private byte[] key;
+
+    public boolean hasSession(){
+        return sessionId != null;
+    }
 
-    public String getKey() {
+    public byte[] getRawKey() {
         return key;
     }
 
-    public void setKey(String key) {
+    public void setRawKey(byte[] key) {
         this.key = key;
     }
 
@@ -48,11 +52,27 @@
         this.sessionId = sessionId;
     }
 
+    public void setKey(Object value) throws IOException {
+        setRawKey(convertObjectToBytes(value));
+    }
+
+    public Object getKey() throws IOException{
+        return convertObjectFromBytes(getRawKey());
+    }
+
+    public ByteArray getHashableKey(){
+        if (key == null){
+            return null;
+        }
+
+        return new ByteArray(key);
+    }
+    
     public void readExternal(ReadableByteChannel channel) throws IOException {
         super.readExternal(channel);
 
         //Process what we want read
-        key = readString(channel);
+        key = this.readBytes(channel);
         sessionId = readString(channel);
     }
 
@@ -60,7 +80,7 @@
         super.writeExternal(channel);
 
         //Process what we want to write
-        writeString(channel, key);
+        writeBytes(channel, key);
         writeString(channel, sessionId);
     }
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommand.java Fri Sep 22 13:44:55 2006
@@ -42,19 +42,19 @@
     }
 
 
-    public void setPayloadObject(Object value) throws IOException {
-        setPayload(convertObjectToBytes(value));
+    public void setPayload(Object value) throws IOException {
+        setRawPayload(convertObjectToBytes(value));
     }
 
-    public Object getPayloadObject() throws IOException{
-        return convertObjectFromBytes(getPayload());
+    public Object getPayload() throws IOException{
+        return convertObjectFromBytes(getRawPayload());
     }
 
-    public byte[] getPayload() {
+    public byte[] getRawPayload() {
         return payload;
     }
 
-    public void setPayload(byte[] data) {
+    public void setRawPayload(byte[] data) {
         this.payload = data;
     }
 

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,32 @@
+/*
+ * 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.command;
+
+import net.sf.ehcache.Cache;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+
+public class ClearCacheCommand extends CacheBaseCommand{
+        public void execute(CacheInfoHolder info) {
+        Cache cache = info.getCache(getCacheName(), true);
+        cache.removeAll();
+
+        //Notify peers
+        info.getCacheNotifier().notifyClearCache(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/ClearCacheCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/Command.java Fri Sep 22 13:44:55 2006
@@ -19,6 +19,7 @@
 package org.apache.geronimo.gcache.command;
 
 import org.apache.geronimo.gcache.marshal.MarshalAware;
+import org.apache.geronimo.gcache.CacheInfoHolder;
 
 /**
  * Commands are pushed around the cluster to the various nodes and they are
@@ -28,6 +29,6 @@
     String getCommandId();
 
     void setCommandId(String commandId);
-    
-    void execute();
+
+    void execute(CacheInfoHolder info);
 }

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/CommandTypes.java Fri Sep 22 13:44:55 2006
@@ -1,12 +1,18 @@
 package org.apache.geronimo.gcache.command;
 
 public class CommandTypes {
-    public static final int ADD_ENTRY_COMMAND = 1;
+    public static final int PUT_ENTRY_COMMAND = 1;
+    public static final int REMOVE_ENTRY_COMMAND = 2;
 
     public static Command createCommand(int identifier) {
         Command command = null;
-        if(identifier == ADD_ENTRY_COMMAND) {
-            command = new AddEntryCommand();
+        switch (identifier) {
+            case(PUT_ENTRY_COMMAND):
+                command = new PutEntryCommand();
+                break;
+            case(REMOVE_ENTRY_COMMAND):
+                command = new RemoveEntryCommand();
+                break;
         }
         return command;
     }

Copied: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java (from r448740, geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java?view=diff&rev=449081&p1=geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java&r1=448740&p2=geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/AddEntryCommand.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java Fri Sep 22 13:44:55 2006
@@ -18,10 +18,46 @@
  */
 package org.apache.geronimo.gcache.command;
 
-public class AddEntryCommand extends CachePayloadBaseCommand {
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.util.ByteArray;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
 
-    public void execute() {
-        //TODO: make this add the payload to the local cache then call back to the pusher
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Collections;
+
+public class PutEntryCommand extends CachePayloadBaseCommand {
+
+    public void execute(CacheInfoHolder info) {
+        Cache cache = info.getCache(getCacheName(), true);
+
+        //Check if we are using sessions
+        if (this.hasSession()){
+
+            Map sessionMap = null;
+
+            //We are so use the session maps that is stored
+            Element element = cache.get(getSessionId());
+            if (element != null){
+                sessionMap = (Map)element.getObjectValue();
+            } else {
+                sessionMap = Collections.synchronizedMap(new HashMap());
+            }
+
+            sessionMap.put(getHashableKey(), getRawPayload());
+            
+            //Put the session away
+            cache.put(new Element(getSessionId(), sessionMap));
+
+        } else {
+
+            //No session map so store the value
+            cache.put(new Element(getHashableKey(), getRawPayload()));
+        }
+
+        //Notify peers
+        info.getCacheNotifier().notifyPut(this);
     }
 
 }

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/PutEntryCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,62 @@
+/*
+ * 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.command;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.util.ByteArray;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+import net.sf.ehcache.Element;
+import net.sf.ehcache.Cache;
+
+public class RemoveEntryCommand extends CacheBaseCommand{
+    public void execute(CacheInfoHolder info) {
+        Cache cache = info.getCache(getCacheName(), true);
+
+        //Check if we are using sessions
+        if (this.hasSession()){
+
+            Map sessionMap = null;
+
+            //We are so use the session maps that is stored
+            Element element = cache.get(getSessionId());
+            if (element != null){
+                sessionMap = (Map)element.getObjectValue();
+            } else {
+                sessionMap = Collections.synchronizedMap(new HashMap());
+            }
+
+            sessionMap.remove(getHashableKey());
+
+            //Put the session away
+            cache.put(new Element(getSessionId(), sessionMap));
+
+        } else {
+
+            //No session map so store the value
+            cache.remove(getHashableKey());
+        }
+
+        //Notify peers
+        info.getCacheNotifier().notifyRemove(this);
+    }
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/RemoveEntryCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/core/GCacheThread.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/core/GCacheThread.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/core/GCacheThread.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/core/GCacheThread.java Fri Sep 22 13:44:55 2006
@@ -25,8 +25,6 @@
  */
 public class GCacheThread extends Thread{
 
-    protected static final String GCACHE_NAME = "gcache";
-
     private boolean stopped;
     private boolean running;
     private final ThreadPool pool;
@@ -48,7 +46,6 @@
         running = true;
 
         //TODO configure the cache here
-//        Cache cache = new Cache(GCACHE_NAME);
 
         while(!stopped){
 
@@ -56,7 +53,9 @@
         }
 
         running = false;
-        cacheManager.removeCache(GCACHE_NAME);
+
+        //Remove all the caches
+        cacheManager.removalAll();
         cacheManager.shutdown();
     }
 

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,31 @@
+/*
+ * 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.server.listeners;
+
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+
+public interface CacheNotifier {
+    public void notifyClearCache(ClearCacheCommand command);
+    
+    public void notifyPut(PutEntryCommand command);
+
+    public void notifyRemove(RemoveEntryCommand command);
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/CacheNotifier.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,38 @@
+/*
+ * 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.server.listeners;
+
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+
+/**
+ * Default implementation of a cache notifier that does nothing
+ */
+public class DefaultCacheNotifier implements CacheNotifier {
+
+    public void notifyClearCache(ClearCacheCommand command){
+    }
+
+    public void notifyPut(PutEntryCommand command) {
+    }
+
+    public void notifyRemove(RemoveEntryCommand command) {
+    }
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/DefaultCacheNotifier.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,22 @@
+/*
+ * 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.server.listeners;
+
+public class RegisteredListeners {
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/listeners/RegisteredListeners.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/DefaultSelectionKeyProcessor.java Fri Sep 22 13:44:55 2006
@@ -58,7 +58,8 @@
             int commandIdentifier = buffer.getInt();
             Command command = CommandTypes.createCommand(commandIdentifier);
             command.readExternal(channel);
-            command.execute();
+            //TODO execute the command
+//            command.execute();
         }
 
         // Test for closed connection

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java (added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,108 @@
+/*
+ * 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.util;
+
+public class ByteArray {
+
+    private byte[] array;
+    private int offset;
+    private int length;
+    private int hash = 0;
+
+    /**
+     * Create an instance of this class that wraps ths given array.
+     * This class does not make a copy of the array, it just saves
+     * the reference.
+     */
+    public ByteArray(byte[] array, int offset, int length) {
+        this.array = array;
+        this.offset = offset;
+        this.length = length;
+    }
+
+    public ByteArray(byte[] array) {
+        this(array, 0, array.length);
+    }
+
+    public ByteArray() {
+    }
+
+    public void setBytes(byte[] array) {
+        this.array = array;
+        offset = 0;
+        length = array.length;
+        hash = 0;
+    }
+
+    public void setBytes(byte[] array, int length) {
+        this.array = array;
+        this.offset = 0;
+        this.length = length;
+        this.hash = 0;
+    }
+
+    public void setBytes(byte[] array, int offset, int length) {
+        this.array = array;
+        this.offset = offset;
+        this.length = length;
+        this.hash = 0;
+    }
+
+    public boolean equals(Object other) {
+        if (other instanceof ByteArray) {
+            ByteArray ob = (ByteArray) other;
+            return ByteArray.equals(array, offset, length, ob.array, ob.offset, ob.length);
+        }
+        return false;
+    }
+
+    public int hashCode() {
+
+        if (array == null){
+            return 0;
+        }
+
+        if (this.hash != 0){
+            return this.hash;
+        }
+        byte[] larray = array;
+
+        int hash = length;
+        for (int i = 0; i < length; i++) {
+            hash = hash * 31 + array[i];
+        }
+
+        this.hash = hash;
+
+        return hash;
+    }
+
+    private static boolean equals(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength) {
+
+        if (aLength != bLength)
+            return false;
+
+        for (int i = 0; i < aLength; i++) {
+            if (a[i + aOffset] != b[i + bOffset])
+                return false;
+        }
+        return true;
+    }
+
+}

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java Fri Sep 22 13:44:55 2006
@@ -49,19 +49,30 @@
         assert readCommand.getKey().equals(key);
         assert readCommand.getSessionId().equals(sessionId);
 
-        /**
-        BaseCommand baseCommand = new BaseCommand();
-        String baseCommandId = "base command id";
-        baseCommand.setCommandId(baseCommandId);
+    }
 
-        command.setValue(baseCommand);
+    @Test
+    public void testCacheBaseCommandNoSession() throws Exception {
 
-        ByteArrayInputStream bias = new ByteArrayInputStream(command.getPayload());
+        String commandId = "the command id";
+        String key = "My Key";
+
+        CacheBaseCommand command = new CacheBaseCommand();
+        command.setCommandId(commandId);
+        command.setKey(key);
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        ByteArrayInputStream bias = new ByteArrayInputStream(marshalled);
         ReadableByteChannel channel = Channels.newChannel(bias);
-        BaseCommand readCommand = new BaseCommand();
+        CacheBaseCommand readCommand = new CacheBaseCommand();
         readCommand.readExternal(channel);
-        assert readCommand.getCommandId().equals(baseCommandId);
-         **/
+        assert readCommand.getCommandId().equals(commandId);
+        assert readCommand.getKey().equals(key);
+        assert readCommand.getSessionId() == null;
+        assert readCommand.hasSession() == false;
+
     }
 
 }

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java?view=diff&rev=449081&r1=449080&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java Fri Sep 22 13:44:55 2006
@@ -28,36 +28,7 @@
 
     @Test
     public void testCacheValueBaseCommandSerializable() throws Exception {
-        String commandId = "the command id";
-        String key = "My Key";
-        String sessionId = "My Session Id";
-        String data = "This is some serializable data...";
-
-        CachePayloadBaseCommand command = new CachePayloadBaseCommand();
-        command.setCommandId(commandId);
-        command.setKey(key);
-        command.setSessionId(sessionId);
-        command.setPayloadObject(data);
-
-        //Convert the command to bytes
-        byte[] marshalled = command.marshal();
-
-        ByteArrayInputStream bias = new ByteArrayInputStream(marshalled);
-        ReadableByteChannel channel = Channels.newChannel(bias);
-        CachePayloadBaseCommand readCommand = new CachePayloadBaseCommand();
-        readCommand.readExternal(channel);
-
-        byte readData[] = readCommand.getPayload();
-        String readString = (String)readCommand.convertObjectFromBytes(readData);
-        assert readString.equals(data);
-
-        assert readCommand.getCommandId().equals(commandId);
-        assert readCommand.getKey().equals(key);
-        assert readCommand.getSessionId().equals(sessionId);
-    }
 
-    @Test
-    public void testCacheValueBaseCommandMarshallAware() throws Exception {
         String commandId = "the command id";
         String key = "My Key";
         String sessionId = "My Session Id";
@@ -67,7 +38,7 @@
         command.setCommandId(commandId);
         command.setKey(key);
         command.setSessionId(sessionId);
-        command.setPayloadObject(data);
+        command.setPayload(data);
 
         //Convert the command to bytes
         byte[] marshalled = command.marshal();
@@ -77,7 +48,7 @@
         CachePayloadBaseCommand readCommand = new CachePayloadBaseCommand();
         readCommand.readExternal(channel);
 
-        byte readData[] = readCommand.getPayload();
+        byte readData[] = readCommand.getRawPayload();
         String readString = (String)readCommand.convertObjectFromBytes(readData);
         assert readString.equals(data);
 

Copied: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java (from r448740, geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java?view=diff&rev=449081&p1=geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java&r1=448740&p2=geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java&r2=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/AddEntryCommandTest.java (original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java Fri Sep 22 13:44:55 2006
@@ -19,13 +19,48 @@
 package org.apache.geronimo.gcache.command;
 
 import org.testng.annotations.Test;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.util.ByteArray;
 
-import java.io.ByteArrayInputStream;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
 
-public class AddEntryCommandTest {
+import java.util.Map;
+
+public class PutEntryCommandTest {
+    
     @Test
-    public void testPayload() throws Exception {
+    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);
+
+        PutEntryCommand command = new PutEntryCommand();
+
+        command.setCacheName(cacheName);
+        command.setKey(key);
+        command.setSessionId(sessionId);
+        command.setPayload(data);
+
+        command.execute(info);
+
+        Cache cache = cacheMgr.getCache(cacheName);
+        assert cache != null;
+
+        Element element = cache.get(sessionId);
+        assert element != null;
+
+        Map sessionMap = (Map)element.getObjectValue();
+        byte rawKey[] = command.convertObjectToBytes(key);
+        byte[] testData = (byte[])sessionMap.get(new ByteArray(rawKey));
+        assert testData != null;
+        String savedString = (String)command.convertObjectFromBytes(testData);
+        assert data.equals(savedString);
     }
 }

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java?view=auto&rev=449081
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java (added)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java Fri Sep 22 13:44:55 2006
@@ -0,0 +1,76 @@
+/*
+ * 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.command;
+
+import org.testng.annotations.Test;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.util.ByteArray;
+import net.sf.ehcache.Element;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Cache;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public class RemoveEntryCommandTest {
+
+    @Test
+    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.addCache(cacheName);
+        Cache cache = cacheMgr.getCache(cacheName);
+        assert cache != null;
+
+        //Create a session 
+        Map sessionMap = new HashMap();
+        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));
+
+        //Setup the remove command
+        RemoveEntryCommand command = new RemoveEntryCommand();
+
+        command.setCacheName(cacheName);
+        command.setKey(key);
+        command.setSessionId(sessionId);
+
+        //Execute the command
+        CacheInfoHolder info = new CacheInfoHolder(cacheMgr);
+        command.execute(info);
+
+        //Check the cache
+        Element element = cache.get(sessionId);
+        assert element != null;
+
+        Map theSession = (Map)element.getObjectValue();
+
+        byte rawKey[] = command.convertObjectToBytes(key);
+
+        //Should not find any data
+        byte[] testData = (byte[])theSession.get(new ByteArray(rawKey));
+        assert testData == null;
+    }
+}

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/RemoveEntryCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message