[exo-jcr-commits] exo-jcr SVN: r492 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/dataflow and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 6 11:16:58 EST 2009


Author: areshetnyak
Date: 2009-11-06 11:16:58 -0500 (Fri, 06 Nov 2009)
New Revision: 492

Added:
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
Log:
EXOJCR-201 : In TransientValueData  was changed serialization mechanism and added test TestTransientVAlueDataSerialization.

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java	2009-11-06 16:14:01 UTC (rev 491)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java	2009-11-06 16:16:58 UTC (rev 492)
@@ -928,8 +928,26 @@
       }
       else
       {
+         // write streams
          out.writeInt(2);
+         //TODO Need optimization in backup service.
+         byte[] buf = new byte[4*1024];
+         
+         if (!spooled) 
+            spoolInputStream();
+         InputStream in = (spoolFile == null ? new ByteArrayInputStream(data) : new FileInputStream(spoolFile));
+         long dataLength = (spoolFile == null ? data.length : spoolFile.length());
+         int len;
+         
+         //write length of spoolFile
+         out.writeLong(dataLength);
+         
+         while ((len = in.read(buf)) > 0)
+           out.write(buf, 0, len);
+         
+         in.close();
       }
+      
       out.writeInt(orderNumber);
       out.writeInt(maxBufferSize);
    }
@@ -946,6 +964,37 @@
          data = new byte[in.readInt()];
          in.readFully(data);
       }
+      else
+      {
+         //read file form stream
+         long lengthSpoolFile = in.readLong();  
+         
+         //TODO May be optimization.
+         SpoolFile sf = SpoolFile.createTempFile("jcrvd", null, tempDirectory);
+         sf.acquire(this);
+         OutputStream outStream = new FileOutputStream(sf); 
+         
+         byte[] buf = new byte[4*1024];
+         
+         while (lengthSpoolFile > 0) {
+            if (lengthSpoolFile - buf.length > 0)
+            {
+               in.readFully(buf);
+               outStream.write(buf);
+            }
+            else
+            {
+               in.readFully(buf, 0, (int) lengthSpoolFile);
+               outStream.write(buf, 0, (int) lengthSpoolFile);
+            }
+            lengthSpoolFile-=buf.length;
+         }
+         outStream.flush();
+         outStream.close();
+         spoolFile = sf;
+         spooled = true;
+      }
+      
       orderNumber = in.readInt();
       maxBufferSize = in.readInt();
    }

Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java	2009-11-06 16:16:58 UTC (rev 492)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.dataflow;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>
+ * Date: 06.11.2009
+ * 
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestTransientValueDataSerialization
+   extends JcrImplBaseTest
+{
+
+   public void testTVDSerialization() throws Exception
+   {
+      File f = createBLOBTempFile(145);
+      f.deleteOnExit();
+
+      // Create TransientValueData instants
+      TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+      tvd.setMaxBufferSize(200*1024);
+      tvd.setFileCleaner(new FileCleaner());
+      
+
+      File out = File.createTempFile("test", ".data");
+      f.deleteOnExit();
+
+      //serialize
+      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+      oos.writeObject(tvd);
+      oos.flush();
+      oos.close();
+
+      //deserialize
+      ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+      TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+      //check
+      assertNotNull(deserializedTransientValueData);
+      assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+      assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+      compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+   }
+   
+   public void testTVDSerialization2M() throws Exception
+   {
+      File f = createBLOBTempFile(2145);
+      f.deleteOnExit();
+
+      // Create TransientValueData instants
+      TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+      tvd.setMaxBufferSize(200*1024);
+      tvd.setFileCleaner(new FileCleaner());
+
+      File out = File.createTempFile("test", ".data");
+      f.deleteOnExit();
+
+      //serialize
+      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+      oos.writeObject(tvd);
+      oos.flush();
+      oos.close();
+
+      //deserialize
+      ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+      TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+      //check
+      assertNotNull(deserializedTransientValueData);
+      assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+      assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+      compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+   }
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the exo-jcr-commits mailing list