jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r706918 - in /jackrabbit/trunk/jackrabbit-spi/src: main/java/org/apache/jackrabbit/spi/QValue.java test/java/org/apache/jackrabbit/spi/QValueFactoryTest.java
Date Wed, 22 Oct 2008 09:18:14 GMT
Author: angela
Date: Wed Oct 22 02:18:14 2008
New Revision: 706918

URL: http://svn.apache.org/viewvc?rev=706918&view=rev
Log:
JCR-1828: Improvement in comment of QValue.getLength() ((and adjust test cases))
remove QValueFactoryTest#testBinarySerializable: this is an implementation specific test for
the factory impl in spi-commons. the general QValue contract does not mandate the value to
be Serializable (at least it doesn't state so and consequently we can't rely on that)

Modified:
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValue.java
    jackrabbit/trunk/jackrabbit-spi/src/test/java/org/apache/jackrabbit/spi/QValueFactoryTest.java

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValue.java?rev=706918&r1=706917&r2=706918&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValue.java (original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QValue.java Wed
Oct 22 02:18:14 2008
@@ -53,7 +53,8 @@
     public int getType();
 
     /**
-     * Returns the length of the internal value.<br>
+     * Returns the length of the internal value or -1 if the implementation
+     * cannot determine the length at this time.<br>
      * NOTE: for {@link PropertyType#NAME} and {@link PropertyType#PATH} the
      * length of the internal value must not be used for indicating the length
      * of a property such as retrieved by calling {@link Property#getLength()}

Modified: jackrabbit/trunk/jackrabbit-spi/src/test/java/org/apache/jackrabbit/spi/QValueFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/test/java/org/apache/jackrabbit/spi/QValueFactoryTest.java?rev=706918&r1=706917&r2=706918&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/test/java/org/apache/jackrabbit/spi/QValueFactoryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/test/java/org/apache/jackrabbit/spi/QValueFactoryTest.java
Wed Oct 22 02:18:14 2008
@@ -19,23 +19,17 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.RepositoryException;
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
-import java.util.Calendar;
-import java.util.Arrays;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.File;
-import java.io.ByteArrayOutputStream;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream;
-import java.io.BufferedInputStream;
+import java.util.Calendar;
 
 /** <code>QValueFactoryTest</code>... */
 public class QValueFactoryTest extends AbstractSPITest {
@@ -59,6 +53,12 @@
         reference = getProperty("reference");
     }
 
+    private static void assertValueLength(QValue v, long expectedLength) throws RepositoryException
{
+        long length = v.getLength();
+        if (length != -1) {
+            assertEquals(expectedLength, length);
+        }
+    }
 
     public void testIllegalType() throws RepositoryException {
         try {
@@ -403,7 +403,7 @@
         QValue v = factory.create(new byte[] {'a', 'b', 'c'});
 
         assertEquals(PropertyType.BINARY, v.getType());
-        assertEquals(3, v.getLength());
+        assertValueLength(v, 3);
 
         assertEquals("abc", v.getString());
 
@@ -416,7 +416,7 @@
         QValue v = factory.create(new byte[0]);
 
         assertEquals(PropertyType.BINARY, v.getType());
-        assertEquals(0, v.getLength());
+        assertValueLength(v, 0);
 
         assertEquals("", v.getString());
 
@@ -431,7 +431,7 @@
         QValue v = factory.create(in);
 
         assertEquals(PropertyType.BINARY, v.getType());
-        assertEquals(3, v.getLength());
+        assertValueLength(v, 3);
 
         assertEquals("abc", v.getString());
 
@@ -446,7 +446,7 @@
         QValue v = factory.create(in);
 
         assertEquals(PropertyType.BINARY, v.getType());
-        assertEquals(0, v.getLength());
+        assertValueLength(v, 0);
 
         assertEquals("", v.getString());
 
@@ -466,7 +466,7 @@
         QValue v = factory.create(f);
 
         assertEquals(PropertyType.BINARY, v.getType());
-        assertEquals(3, v.getLength());
+        assertValueLength(v, 3);
 
         assertEquals("abc", v.getString());
 
@@ -482,7 +482,7 @@
         QValue v = factory.create(f);
 
         assertEquals(PropertyType.BINARY, v.getType());
-        assertEquals(0, v.getLength());
+        assertValueLength(v, 0);
 
         assertEquals("", v.getString());
 
@@ -491,53 +491,6 @@
         assertEquals("", new String(out.toByteArray()));
     }
 
-    public void testBinarySerializable() throws Exception {
-        runBinarySerializableTest(1); // 1k
-        runBinarySerializableTest(10); // 10k
-        runBinarySerializableTest(100); // 100k
-        runBinarySerializableTest(1000); // 1M
-    }
-
-    /**
-     * Runs binary serializable test using a stream with a size of kBytes.
-     * @param size in kBytes.
-     */
-    private void runBinarySerializableTest(int size) throws Exception {
-        File tmp = File.createTempFile("test", "bin");
-        OutputStream out = new FileOutputStream(tmp);
-        byte[] stuff = new byte[1024];
-        Arrays.fill(stuff, (byte) 7);
-        for (int i = 0; i < size; i++) {
-            out.write(stuff);
-        }
-        out.close();
-        InputStream in = new FileInputStream(tmp);
-        QValue v = factory.create(in);
-        in.close();
-        tmp.delete();
-        ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        ObjectOutputStream oout = new ObjectOutputStream(bout);
-        oout.writeObject(v);
-        oout.close();
-        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
-        ObjectInputStream oin = new ObjectInputStream(bin);
-        QValue serValue = (QValue) oin.readObject();
-        try {
-            InputStream in1 = new BufferedInputStream(v.getStream());
-            InputStream in2 = new BufferedInputStream(serValue.getStream());
-            int i;
-            while ((i = in1.read()) > -1) {
-                assertEquals(i, in2.read());
-            }
-            assertEquals(in2.read(), -1);
-            in1.close();
-            in2.close();
-        } finally {
-            v.discard();
-            serValue.discard();
-        }
-    }
-
     /**
      *
      * @param out



Mime
View raw message