geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r448745 - in /geronimo/sandbox/gcache/server/src: main/java/org/apache/geronimo/gcache/command/BaseCommand.java test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
Date Thu, 21 Sep 2006 23:51:45 GMT
Author: jgenender
Date: Thu Sep 21 16:51:44 2006
New Revision: 448745

URL: http://svn.apache.org/viewvc?view=rev&rev=448745
Log:
Tidy up

Modified:
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/command/BaseCommand.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java

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=448745&r1=448744&r2=448745
==============================================================================
--- 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
Thu Sep 21 16:51:44 2006
@@ -164,6 +164,26 @@
 
     protected byte[] convertObjectToBytes(Object object) throws IOException {
 
+        if (object instanceof Serializable) {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream stream = new ObjectOutputStream(baos);
+            stream.writeObject(object);
+            stream.flush();
+            stream.close();
+            return baos.toByteArray();
+        } else {
+            throw new RuntimeException("Invalid argument - Object"
+                    + " is not an instance of java.io.Serializable"
+                    + " or MarshalAware");
+        }
+
+        /**
+         *
+         * I don't think MarshalAware is necessary here anymore...Bill?
+         *
+         * Commenting this out until Bill agrees
+         *
+         *
         if (object instanceof MarshalAware) {
             ByteArrayOutputStream baos = new ByteArrayOutputStream(34);
             WritableByteChannel channel = Channels.newChannel(baos);
@@ -182,6 +202,8 @@
                     + " is not an instance of java.io.Serializable"
                     + " or MarshalAware");
         }
+         *
+         */
     }
 
 }

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=448745&r1=448744&r2=448745
==============================================================================
--- 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
Thu Sep 21 16:51:44 2006
@@ -27,7 +27,37 @@
 public class CachePayloadBaseCommandTest {
 
     @Test
-    public void testCacheValueBaseCommand() throws Exception {
+    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";



Mime
View raw message