Search in sources :

Example 16 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class DataStoreTestBase method testSyncBigBlob.

/*
     * See OAK-5902.
     */
@Test
public void testSyncBigBlob() throws Exception {
    final long blobSize = 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, 8 * MB);
        StandbyClientSync cl = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, 2 * 60 * 1000, false, folder.newFolder())) {
        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());
    try (InputStream randomInputStream = newRandomInputStream(blobSize, seed);
        InputStream blobInputStream = b.getNewStream()) {
        assertTrue(IOUtils.contentEquals(randomInputStream, blobInputStream));
    }
}
Also used : 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) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 17 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class DataStoreTestBase method testSyncUpdatedBinaryProperty.

/*
     * See OAK-4969.
     */
@Test
public void testSyncUpdatedBinaryProperty() throws Exception {
    final int blobSize = 5 * MB;
    FileStore primary = getPrimary();
    FileStore secondary = getSecondary();
    NodeStore store = SegmentNodeStoreBuilders.builder(primary).build();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), primary, MB);
        StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), secondary, false, getClientTimeout(), false, folder.newFolder())) {
        serverSync.start();
        addTestContent(store, "server", blobSize);
        primary.flush();
        clientSync.run();
        assertEquals(primary.getHead(), secondary.getHead());
        addTestContent(store, "server", blobSize);
        primary.flush();
        clientSync.run();
        assertEquals(primary.getHead(), secondary.getHead());
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) 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) Test(org.junit.Test)

Example 18 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class FailoverMultipleClientsTestIT method testMultipleClients.

@Test
public void testMultipleClients() throws Exception {
    FileStore storeS = serverFileStore.fileStore();
    FileStore storeC = clientFileStore1.fileStore();
    FileStore storeC2 = clientFileStore2.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(storeS).build();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), storeS, MB);
        StandbyClientSync cl1 = new StandbyClientSync(getServerHost(), serverPort.getPort(), storeC, false, getClientTimeout(), false, folder.newFolder());
        StandbyClientSync cl2 = new StandbyClientSync(getServerHost(), serverPort.getPort(), storeC2, false, getClientTimeout(), false, folder.newFolder())) {
        serverSync.start();
        SegmentTestUtils.addTestContent(store, "server");
        // this speeds up the test a little bit...
        storeS.flush();
        assertFalse("first client has invalid initial store!", storeS.getHead().equals(storeC.getHead()));
        assertFalse("second client has invalid initial store!", storeS.getHead().equals(storeC2.getHead()));
        assertEquals(storeC.getHead(), storeC2.getHead());
        cl1.run();
        cl2.run();
        assertEquals(storeS.getHead(), storeC.getHead());
        assertEquals(storeS.getHead(), storeC2.getHead());
        cl1.stop();
        SegmentTestUtils.addTestContent(store, "test");
        storeS.flush();
        cl1.run();
        cl2.run();
        assertEquals(storeS.getHead(), storeC2.getHead());
        assertFalse("first client updated in stopped state!", storeS.getHead().equals(storeC.getHead()));
        cl1.start();
        cl1.run();
        assertEquals(storeS.getHead(), storeC.getHead());
    }
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) 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) Test(org.junit.Test)

Example 19 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class MBeanIT method testClientAndServerEmptyConfig.

@Test
public void testClientAndServerEmptyConfig() throws Exception {
    System.setProperty(StandbyClientSync.CLIENT_ID_PROPERTY_NAME, "Bar");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName clientStatus, serverStatus;
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), serverFileStore.fileStore(), MB);
        StandbyClientSync clientSync = new StandbyClientSync(getServerHost(), serverPort.getPort(), clientFileStore.fileStore(), false, getClientTimeout(), false, folder.newFolder())) {
        serverSync.start();
        serverFileStore.fileStore().flush();
        clientSync.start();
        clientSync.run();
        clientStatus = new ObjectName(clientSync.getMBeanName());
        serverStatus = new ObjectName(serverSync.getMBeanName());
        ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
        Set<ObjectName> instances = jmxServer.queryNames(status, null);
        assertEquals(3, instances.size());
        ObjectName connectionStatus = null;
        for (ObjectName s : instances) {
            if (!s.equals(clientStatus) && !s.equals(serverStatus)) {
                connectionStatus = s;
            }
        }
        assertNotNull(connectionStatus);
        assertTrue(jmxServer.isRegistered(clientStatus));
        assertTrue(jmxServer.isRegistered(serverStatus));
        assertTrue(jmxServer.isRegistered(connectionStatus));
        String m = jmxServer.getAttribute(clientStatus, "Mode").toString();
        if (!m.startsWith("client: ")) {
            fail("unexpected mode " + m);
        }
        assertEquals("primary", jmxServer.getAttribute(serverStatus, "Mode"));
        assertEquals(true, jmxServer.getAttribute(serverStatus, "Running"));
        assertEquals(true, jmxServer.getAttribute(clientStatus, "Running"));
        assertEquals("0", jmxServer.getAttribute(clientStatus, "FailedRequests").toString());
        assertEquals("0", jmxServer.getAttribute(clientStatus, "SecondsSinceLastSuccess").toString());
        assertEquals("0", jmxServer.invoke(clientStatus, "calcFailedRequests", null, null).toString());
        assertEquals("0", jmxServer.invoke(clientStatus, "calcSecondsSinceLastSuccess", null, null).toString());
        Thread.sleep(1000);
        assertEquals("0", jmxServer.getAttribute(clientStatus, "FailedRequests").toString());
        assertEquals("1", jmxServer.getAttribute(clientStatus, "SecondsSinceLastSuccess").toString());
        assertEquals("0", jmxServer.invoke(clientStatus, "calcFailedRequests", null, null).toString());
        assertEquals("1", jmxServer.invoke(clientStatus, "calcSecondsSinceLastSuccess", null, null).toString());
        assertEquals(1L, jmxServer.getAttribute(connectionStatus, "TransferredSegments"));
        // stop the master
        jmxServer.invoke(serverStatus, "stop", null, null);
        assertEquals(false, jmxServer.getAttribute(serverStatus, "Running"));
        m = jmxServer.getAttribute(serverStatus, "Status").toString();
        if (!m.equals(StandbyStatusMBean.STATUS_STOPPED) && !m.equals("channel unregistered")) {
            fail("unexpected Status" + m);
        }
        // restart the master
        jmxServer.invoke(serverStatus, "start", null, null);
        assertEquals(true, jmxServer.getAttribute(serverStatus, "Running"));
        assertEquals(true, jmxServer.getAttribute(clientStatus, "Running"));
        m = jmxServer.getAttribute(serverStatus, "Status").toString();
        if (!m.equals(StandbyStatusMBean.STATUS_RUNNING) && !m.equals("channel unregistered")) {
            fail("unexpected Status" + m);
        }
        // stop the slave
        jmxServer.invoke(clientStatus, "stop", null, null);
        assertEquals(true, jmxServer.getAttribute(serverStatus, "Running"));
        assertEquals(false, jmxServer.getAttribute(clientStatus, "Running"));
        assertEquals(StandbyStatusMBean.STATUS_STOPPED, jmxServer.getAttribute(clientStatus, "Status"));
        // restart the slave
        jmxServer.invoke(clientStatus, "start", null, null);
        assertEquals(true, jmxServer.getAttribute(clientStatus, "Running"));
        assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(clientStatus, "Status"));
    }
    assertTrue(!jmxServer.isRegistered(clientStatus));
    assertTrue(!jmxServer.isRegistered(serverStatus));
}
Also used : StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 20 with StandbyServerSync

use of org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync in project jackrabbit-oak by apache.

the class MBeanIT method testServerEmptyConfig.

@Test
public void testServerEmptyConfig() throws Exception {
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), serverFileStore.fileStore(), 1 * MB)) {
        serverSync.start();
        Set<ObjectName> instances = jmxServer.queryNames(status, null);
        assertEquals(1, instances.size());
        status = instances.toArray(new ObjectName[0])[0];
        assertEquals(new ObjectName(serverSync.getMBeanName()), status);
        assertTrue(jmxServer.isRegistered(status));
        assertEquals("primary", jmxServer.getAttribute(status, "Mode"));
        String m = jmxServer.getAttribute(status, "Status").toString();
        if (!m.equals(StandbyStatusMBean.STATUS_RUNNING) && !m.equals("channel unregistered")) {
            fail("unexpected Status " + m);
        }
        assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(status, "Status"));
        assertEquals(true, jmxServer.getAttribute(status, "Running"));
        jmxServer.invoke(status, "stop", null, null);
        assertEquals(false, jmxServer.getAttribute(status, "Running"));
        assertEquals(StandbyStatusMBean.STATUS_STOPPED, jmxServer.getAttribute(status, "Status"));
        jmxServer.invoke(status, "start", null, null);
        assertEquals(true, jmxServer.getAttribute(status, "Running"));
        assertEquals(StandbyStatusMBean.STATUS_RUNNING, jmxServer.getAttribute(status, "Status"));
    }
    assertTrue(!jmxServer.isRegistered(status));
}
Also used : StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)23 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)21 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)18 Test (org.junit.Test)16 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)15 TemporaryFileStore (org.apache.jackrabbit.oak.segment.test.TemporaryFileStore)12 Blob (org.apache.jackrabbit.oak.api.Blob)6 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 InputStream (java.io.InputStream)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 NetworkErrorProxy (org.apache.jackrabbit.oak.segment.test.proxy.NetworkErrorProxy)2 Stopwatch (com.google.common.base.Stopwatch)1 ServerSocket (java.net.ServerSocket)1 SegmentGCOptions (org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions)1 FileStoreBuilder (org.apache.jackrabbit.oak.segment.file.FileStoreBuilder)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 Ignore (org.junit.Ignore)1