Author: adulceanu
Date: Wed Aug  9 12:48:08 2017
New Revision: 1804515

URL: http://svn.apache.org/viewvc?rev=1804515&view=rev
Log:
OAK-5902 - Cold standby should allow syncing of blobs bigger than 2.2 GB
Added ignored IT to verify 2.5 GB blob sync

Modified:
    
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java
    
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java?rev=1804515&r1=1804514&r2=1804515&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/DataStoreTestBase.java
 Wed Aug  9 12:48:08 2017
@@ -26,9 +26,11 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.io.IOException;
 import java.util.Random;
 
+import org.apache.commons.io.IOUtils;
 import com.google.common.io.ByteStreams;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -46,10 +48,12 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
 public abstract class DataStoreTestBase extends TestBase {
+    static final long GB = 1024 * 1024 * 1024;
 
     private NetworkErrorProxy proxy;
 
@@ -65,6 +69,25 @@ public abstract class DataStoreTestBase
 
     abstract boolean storesShouldBeEqual();
 
+    private InputStream newRandomInputStream(final long size, final int seed) {
+        return new InputStream() {
+
+            private final Random random = new Random(seed);
+
+            private long count = 0;
+
+            @Override
+            public int read() throws IOException {
+                if (count >= size) {
+                    return -1;
+                }
+                count++;
+                return Math.abs(random.nextInt());
+            }
+
+        };
+    }
+    
     protected byte[] addTestContent(NodeStore store, String child, int size)
             throws CommitFailedException, IOException {
         NodeBuilder builder = store.getRoot().builder();
@@ -79,6 +102,18 @@ public abstract class DataStoreTestBase
         store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
         return data;
     }
+    
+    protected void addTestContentOnTheFly(NodeStore store, String child, long 
size, int seed) throws CommitFailedException, IOException {
+        NodeBuilder builder = store.getRoot().builder();
+        builder.child(child).setProperty("ts", System.currentTimeMillis());
+
+        InputStream randomInputStream = newRandomInputStream(size, seed);
+        Blob blob = store.createBlob(randomInputStream);
+
+        builder.child(child).setProperty("testBlob", blob);
+
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+    }
 
     @Before
     public void before() {
@@ -123,6 +158,44 @@ public abstract class DataStoreTestBase
     }
 
     /*
+     * See OAK-5902.
+     */
+    @Test
+    @Ignore("OAK-6538")
+    public void testSyncBigBlob() throws Exception {
+        final long blobSize = (long) (2.5 * GB);
+        final int seed = 13;
+        
+        FileStore primary = getPrimary();
+        FileStore secondary = getSecondary();
+
+        NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
+        addTestContentOnTheFly(store, "server", blobSize, seed);
+        
+        try (
+                StandbyServerSync serverSync = new 
StandbyServerSync(serverPort.getPort(), primary, 256 * MB);
+                StandbyClientSync cl = newStandbyClientSync(secondary, 
serverPort.getPort(), 50_000)
+        ) {
+            serverSync.start();
+            primary.flush();
+            cl.run();
+            assertEquals(primary.getHead(), secondary.getHead());
+        }
+
+        assertTrue(primary.getStats().getApproximateSize() < MB);
+        assertTrue(secondary.getStats().getApproximateSize() < MB);
+
+        PropertyState ps = secondary.getHead().getChildNode("root")
+                .getChildNode("server").getProperty("testBlob");
+        assertNotNull(ps);
+        assertEquals(Type.BINARY.tag(), ps.getType().tag());
+        Blob b = ps.getValue(Type.BINARY);
+        assertEquals(blobSize, b.length());
+        
+        assertTrue(IOUtils.contentEquals(newRandomInputStream(blobSize, seed), 
b.getNewStream()));
+    }
+    
+    /*
      * See OAK-4969.
      */
     @Test

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java?rev=1804515&r1=1804514&r2=1804515&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/standby/TestBase.java
 Wed Aug  9 12:48:08 2017
@@ -49,11 +49,18 @@ public class TestBase {
     }
 
     public StandbyClientSync newStandbyClientSync(FileStore store, int port) 
throws Exception {
-        return newStandbyClientSync(store, port, false);
+        return newStandbyClientSync(store, port, false, getClientTimeout());
     }
 
     public StandbyClientSync newStandbyClientSync(FileStore store, int port, 
boolean secure) throws Exception {
-        return new StandbyClientSync(getServerHost(), port, store, secure, 
getClientTimeout(), false);
+        return newStandbyClientSync(store, port, secure, getClientTimeout());
     }
 
+    public StandbyClientSync newStandbyClientSync(FileStore store, int port, 
int timeout) throws Exception {
+        return newStandbyClientSync(store, port, false, timeout);
+    }
+
+    public StandbyClientSync newStandbyClientSync(FileStore store, int port, 
boolean secure, int timeout) throws Exception {
+        return new StandbyClientSync(getServerHost(), port, store, secure, 
timeout, false);
+    }
 }


Reply via email to