[exo-jcr-commits] exo-jcr SVN: r1515 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Jan 20 11:25:24 EST 2010


Author: pnedonosko
Date: 2010-01-20 11:25:23 -0500 (Wed, 20 Jan 2010)
New Revision: 1515

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestBLOBValue.java
Log:
EXOJCR-404 test for large set of blobs

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestBLOBValue.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestBLOBValue.java	2010-01-20 16:08:29 UTC (rev 1514)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestBLOBValue.java	2010-01-20 16:25:23 UTC (rev 1515)
@@ -5,21 +5,54 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.util.Calendar;
 
+import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.Property;
+import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
 
 public class TestBLOBValue extends JcrAPIBaseTest
 {
    private static final String TEST_ROOT_NAME = "TestBLOBValue";
-   
-   private static final int FILE_SIZE_KB  = 1024;
 
+   private static final int FILE_SIZE_KB = 10 * 1024;
+
+   private static final int FILES_COUNT = 1024;
+
+   private static final String FILE_PATH = "F:/Books/jboss/Manning JBoss in Action Jan 2009.pdf";
+
    private static File testFile;
 
    private Node testRoot;
 
+   private Node addNTFile(String fileName, File blob) throws Exception
+   {
+      Node file = testRoot.addNode(fileName, "nt:file");
+
+      Node contentNode = file.addNode("jcr:content", "nt:resource");
+      // contentNode.setProperty("jcr:encoding", "UTF-8");
+      contentNode.setProperty("jcr:mimeType", "application/octet-stream");
+      InputStream is = new FileInputStream(blob);
+      try
+      {
+         contentNode.setProperty("jcr:data", is);
+      }
+      finally
+      {
+         is.close();
+      }
+      contentNode.setProperty("jcr:lastModified", Calendar.getInstance());
+      return file;
+   }
+
    @Override
    public void setUp() throws Exception
    {
@@ -37,20 +70,38 @@
 
       if (testFile == null)
       {
-         testFile = createBLOBTempFile(FILE_SIZE_KB); // 1MB
+         testFile = createBLOBTempFile(FILE_SIZE_KB);
+         //testFile = new File(FILE_PATH);
       }
    }
 
    @Override
    protected void tearDown() throws Exception
    {
-      testRoot.remove();
-      root.save();
 
-      super.tearDown();
+      if (testRoot.hasProperty("blob"))
+      {
+         testRoot.getProperty("blob").remove();
+         testRoot.save();
+      }
+
+      if (testRoot.hasNodes())
+      {
+         for (NodeIterator children = testRoot.getNodes(); children.hasNext();)
+         {
+            children.nextNode().remove();
+         }
+         
+         testRoot.save();
+      }
+
+      //testRoot.remove();
+      //root.save();
+
+      //super.tearDown();
    }
 
-   public void testAddProperty() throws Exception
+   public void _testAddProperty() throws Exception
    {
       // write
       Property text = testRoot.setProperty("text", "string property");
@@ -66,33 +117,79 @@
       Node troot = user1.getRootNode().getNode(TEST_ROOT_NAME);
       Property tblob = troot.getProperty("blob");
       InputStream blobStream = tblob.getStream();
-      
+
       byte[] buff = new byte[1024];
       int r = 0;
       int size = 0;
-      while ((r = blobStream.read(buff))>=0) {
+      while ((r = blobStream.read(buff)) >= 0)
+      {
          size += r;
       }
-      
-      assertEquals(FILE_SIZE_KB * 1024, size);
+
+      assertEquals(testFile.length(), size);
    }
-   
-   public void testReadProperty() throws Exception
+
+   public void _testReadProperty() throws Exception
    {
       // read
       Property blob = testRoot.getProperty("blob");
       InputStream blobStream = blob.getStream();
-      
+
       byte[] buff = new byte[1024];
       int r = 0;
       int size = 0;
-      while ((r = blobStream.read(buff))>=0) {
+      while ((r = blobStream.read(buff)) >= 0)
+      {
          size += r;
       }
-      
-      assertEquals(FILE_SIZE_KB * 1024, size);
+
+      assertEquals(testFile.length(), size);
    }
 
+   public void testAddNTFiles() throws Exception
+   {
+      // write series of FILES_COUNT adding to each next 1K bytes
+      // do it in one save
+      int size = FILE_SIZE_KB;
+      for (int i = 0; i < FILES_COUNT; i++)
+      {
+         File blob = createBLOBTempFile(size);
+         addNTFile("node" + i, blob);
+
+         size += 1;
+      }
+
+      testRoot.save();
+
+      // it's ready for read
+   }
+
+   public void testReadNTFiles() throws Exception
+   {
+      // read series of FILES_COUNT were added each with size + 1K bytes
+      int size = FILE_SIZE_KB;
+      for (int i = 0; i < FILES_COUNT; i++)
+      {
+         Node file = testRoot.getNode("file" + i);
+
+         Property blob = file.getProperty("jcr:content/jcr:data");
+         InputStream blobStream = blob.getStream();
+
+         byte[] buff = new byte[1024];
+         int r = 0;
+         int bsize = 0;
+         while ((r = blobStream.read(buff)) >= 0)
+         {
+            bsize += r;
+         }
+
+         assertEquals(size * 1024, bsize);
+
+         // calc next
+         size += 1;
+      }
+   }
+
    public void testUpdateProperty() throws Exception
    {
 



More information about the exo-jcr-commits mailing list