Search in sources :

Example 11 with StandbyClientSync

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

the class FailoverSslTestIT method testFailoverPlainServerSecureClient.

@Test
public void testFailoverPlainServerSecureClient() throws Exception {
    FileStore storeS = serverFileStore.fileStore();
    FileStore storeC = clientFileStore.fileStore();
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), storeS);
        StandbyClientSync clientSync = newStandbyClientSync(storeC, serverPort.getPort(), true)) {
        assertFalse(synchronizeAndCompareHead(serverSync, clientSync));
    }
}
Also used : TemporaryFileStore(org.apache.jackrabbit.oak.segment.test.TemporaryFileStore) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) StandbyServerSync(org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync) StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) Test(org.junit.Test)

Example 12 with StandbyClientSync

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

the class MBeanIT method testClientNoServer.

@Test
public void testClientNoServer() throws Exception {
    System.setProperty(StandbyClientSync.CLIENT_ID_PROPERTY_NAME, "Foo");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName status;
    try (StandbyClientSync clientSync = newStandbyClientSync(clientFileStore.fileStore(), serverPort.getPort())) {
        clientSync.start();
        clientSync.run();
        status = new ObjectName(clientSync.getMBeanName());
        assertTrue(jmxServer.isRegistered(status));
        assertEquals("client: Foo", jmxServer.getAttribute(status, "Mode"));
        assertEquals("1", jmxServer.getAttribute(status, "FailedRequests").toString());
        assertEquals("-1", jmxServer.getAttribute(status, "SecondsSinceLastSuccess").toString());
        assertEquals("1", jmxServer.invoke(status, "calcFailedRequests", null, null).toString());
        assertEquals("-1", jmxServer.invoke(status, "calcSecondsSinceLastSuccess", null, null).toString());
    }
    assertTrue(!jmxServer.isRegistered(status));
}
Also used : StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 13 with StandbyClientSync

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

the class MBeanIT method testClientEmptyConfigNoServer.

@Test
public void testClientEmptyConfigNoServer() throws Exception {
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
    try (StandbyClientSync clientSync = newStandbyClientSync(clientFileStore.fileStore(), serverPort.getPort())) {
        clientSync.start();
        clientSync.run();
        Set<ObjectName> instances = jmxServer.queryNames(status, null);
        assertEquals(1, instances.size());
        status = instances.toArray(new ObjectName[0])[0];
        assertEquals(new ObjectName(clientSync.getMBeanName()), status);
        assertTrue(jmxServer.isRegistered(status));
        String m = jmxServer.getAttribute(status, "Mode").toString();
        if (!m.startsWith("client: ")) {
            fail("unexpected mode " + m);
        }
        assertEquals("1", jmxServer.getAttribute(status, "FailedRequests").toString());
        assertEquals("-1", jmxServer.getAttribute(status, "SecondsSinceLastSuccess").toString());
        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 : StandbyClientSync(org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 14 with StandbyClientSync

use of org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync 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());
        StandbyClientSync clientSync = newStandbyClientSync(clientFileStore.fileStore(), serverPort.getPort())) {
        serverSync.start();
        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 15 with StandbyClientSync

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

the class RecoverTestIT method testLocalChanges.

@Test
public void testLocalChanges() throws Exception {
    FileStore storeS = serverFileStore.fileStore();
    FileStore storeC = clientFileStore.fileStore();
    NodeStore store = SegmentNodeStoreBuilders.builder(storeC).build();
    addTestContent(store, "client");
    try (StandbyServerSync serverSync = new StandbyServerSync(serverPort.getPort(), storeS);
        StandbyClientSync cl = newStandbyClientSync(storeC, serverPort.getPort())) {
        serverSync.start();
        store = SegmentNodeStoreBuilders.builder(storeS).build();
        addTestContent(store, "server");
        storeS.flush();
        assertFalse("stores are not expected to be equal", storeS.getHead().equals(storeC.getHead()));
        cl.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)

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