Search in sources :

Example 16 with StandbyClientSync

use of org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync in project jackrabbit-oak by apache.

the class StandbyTestIT method testSync.

@Test
public void testSync() throws Exception {
    final int mb = 1 * 1024 * 1024;
    final int blobSize = 5 * mb;
    FileStore primary = serverFileStore.fileStore();
    FileStore secondary = clientFileStore.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary);
        StandbyClientSync clientSync = newStandbyClientSync(secondary, serverPort.getPort())) {
        serverSync.start();
        byte[] data = addTestContent(store, "server", blobSize, 150);
        primary.flush();
        clientSync.run();
        assertEquals(primary.getHead(), secondary.getHead());
        assertTrue(primary.getStats().getApproximateSize() > blobSize);
        assertTrue(secondary.getStats().getApproximateSize() > blobSize);
        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());
        byte[] testData = new byte[blobSize];
        ByteStreams.readFully(b.getNewStream(), testData);
        assertArrayEquals(data, testData);
    }
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Blob(org.apache.jackrabbit.oak.api.Blob) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 17 with StandbyClientSync

use of org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync in project jackrabbit-oak by apache.

the class StandbyTestIT method testSyncLoop.

/**
     * OAK-2430
     */
@Test
public void testSyncLoop() throws Exception {
    final int blobSize = 25 * 1024;
    final int dataNodes = 5000;
    FileStore primary = serverFileStore.fileStore();
    FileStore secondary = clientFileStore.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary);
        StandbyClientSync clientSync = newStandbyClientSync(secondary, serverPort.getPort())) {
        serverSync.start();
        byte[] data = addTestContent(store, "server", blobSize, dataNodes);
        primary.flush();
        for (int i = 0; i < 5; i++) {
            String cp = store.checkpoint(Long.MAX_VALUE);
            primary.flush();
            clientSync.run();
            assertEquals(primary.getHead(), secondary.getHead());
            assertTrue(store.release(cp));
            clientSync.cleanup();
            assertTrue(secondary.getStats().getApproximateSize() > blobSize);
        }
        assertTrue(primary.getStats().getApproximateSize() > blobSize);
        assertTrue(secondary.getStats().getApproximateSize() > blobSize);
        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());
        byte[] testData = new byte[blobSize];
        ByteStreams.readFully(b.getNewStream(), testData);
        assertArrayEquals(data, testData);
    }
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) Blob(org.apache.jackrabbit.oak.api.Blob) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)17 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)14 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)12 Test (org.junit.Test)12 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 TemporaryFileStore (org.apache.jackrabbit.oak.segment.test.TemporaryFileStore)9 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 Blob (org.apache.jackrabbit.oak.api.Blob)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 Hashtable (java.util.Hashtable)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1