Package org.apache.jackrabbit.oak.plugins.segment.standby.client

Examples of org.apache.jackrabbit.oak.plugins.segment.standby.client.StandbyClient


            parser.printHelpOn(System.err);
            System.exit(1);
        }

        FileStore store = null;
        StandbyClient failoverClient = null;
        try {
            store = new FileStore(new File(nonOptions.get(0)), 256);
            failoverClient = new StandbyClient(
                    options.has(host)? options.valueOf(host) : defaultHost,
                    options.has(port)? options.valueOf(port) : defaultPort,
                    store,
                    options.has(secure) && options.valueOf(secure));
            if (!options.has(interval)) {
                failoverClient.run();
            } else {
                ScheduledSyncService syncService = new ScheduledSyncService(failoverClient, options.valueOf(interval));
                syncService.startAsync();
                syncService.awaitTerminated();
            }
        } finally {
            if (store != null) {
                store.close();
            }
            if (failoverClient != null) {
                failoverClient.close();
            }
        }
    }
View Full Code Here


        NodeStore store = new SegmentNodeStore(storeS);
        final StandbyServer server = new StandbyServer(port, storeS);
        server.start();
        addTestContent(store, "server");

        StandbyClient cl = new StandbyClient("127.0.0.1", port, storeC);
        cl.run();

        try {
            assertEquals(storeS.getHead(), storeC.getHead());
        } finally {
            server.close();
            cl.close();
        }

    }
View Full Code Here

    public static void main(String[] args) throws Exception {
        File d = createTmpTargetDir("FailoverLiveTest");
        d.delete();
        d.mkdir();
        FileStore s = new FileStore(d, 256, false);
        StandbyClient cl = new StandbyClient("127.0.0.1", 8023, s);
        try {
            cl.run();
        } finally {
            s.close();
            cl.close();
        }
    }
View Full Code Here

        final StandbyServer server = new StandbyServer(port, storeS);
        server.start();
        SegmentTestUtils.addTestContent(store, "server");
        storeS.flush()// this speeds up the test a little bit...

        StandbyClient cl1 = new StandbyClient("127.0.0.1", port, storeC);
        StandbyClient cl2 = new StandbyClient("127.0.0.1", port, storeC2);

        try {
            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");
            cl2.run();

            assertEquals(storeS.getHead(), storeC2.getHead());
            assertFalse("first client updated in stopped state!", storeS.getHead().equals(storeC.getHead()));

            cl1.start();
            assertEquals(storeS.getHead(), storeC.getHead());
        } finally {
            server.close();
            cl1.close();
            cl2.close();
        }
    }
View Full Code Here

        assertTrue(!jmxServer.isRegistered(status));
    }

    @Test
    public void testClientEmptyConfigNoServer() throws Exception {
        final StandbyClient client = new StandbyClient("127.0.0.1", this.port, this.storeC);
        client.start();

        final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
        try {
            Set<ObjectName> instances = jmxServer.queryNames(status, null);
            assertEquals(1, instances.size());
            status = instances.toArray(new ObjectName[0])[0];
            assertEquals(new ObjectName(client.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_STOPPED, jmxServer.getAttribute(status, "Status"));

            assertEquals(false, 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(false, jmxServer.getAttribute(status, "Running"));
            assertEquals(StandbyStatusMBean.STATUS_STOPPED, jmxServer.getAttribute(status, "Status"));
        } finally {
            client.close();
        }

        assertTrue(!jmxServer.isRegistered(status));
    }
View Full Code Here

    }

    @Test
    public void testClientNoServer() throws Exception {
        System.setProperty(StandbyClient.CLIENT_ID_PROPERTY_NAME, "Foo");
        final StandbyClient client = new StandbyClient("127.0.0.1", this.port, this.storeC);
        client.start();

        final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName status = new ObjectName(client.getMBeanName());
        try {
            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());
        } finally {
            client.close();
        }

        assertTrue(!jmxServer.isRegistered(status));
    }
View Full Code Here

    public void testClientAndServerEmptyConfig() throws Exception {
        final StandbyServer server = new StandbyServer(this.port, this.storeS);
        server.start();

        System.setProperty(StandbyClient.CLIENT_ID_PROPERTY_NAME, "Bar");
        final StandbyClient client = new StandbyClient("127.0.0.1", this.port, this.storeC);
        client.start();

        final MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName status = new ObjectName(StandbyStatusMBean.JMX_NAME + ",id=*");
        ObjectName clientStatus = new ObjectName(client.getMBeanName());
        ObjectName serverStatus = new ObjectName(server.getMBeanName());
        try {
            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("master", 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(new Long(2), jmxServer.getAttribute(connectionStatus, "TransferredSegments"));
            assertEquals(new Long(128), jmxServer.getAttribute(connectionStatus, "TransferredSegmentBytes"));

            // 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_STARTING) && !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"));

        } finally {
            client.close();
            server.close();
        }

        assertTrue(!jmxServer.isRegistered(clientStatus));
        assertTrue(!jmxServer.isRegistered(serverStatus));
View Full Code Here

        final StandbyServer server = new StandbyServer(port, storeS, true);
        server.start();
        addTestContent(store, "server");
        storeS.flush()// this speeds up the test a little bit...

        StandbyClient cl = new StandbyClient("127.0.0.1", port, storeC, true);
        cl.run();

        try {
            assertEquals(storeS.getHead(), storeC.getHead());
        } finally {
            server.close();
            cl.close();
        }
    }
View Full Code Here

        final StandbyServer server = new StandbyServer(port, storeS, true);
        server.start();
        addTestContent(store, "server");
        storeS.flush()// this speeds up the test a little bit...

        StandbyClient cl = new StandbyClient("127.0.0.1", port, storeC);
        cl.run();

        try {
            assertFalse("stores are equal but shouldn't!", storeS.getHead().equals(storeC.getHead()));
        } finally {
            server.close();
            cl.close();
        }
    }
View Full Code Here

        final StandbyServer server = new StandbyServer(port, storeS);
        server.start();
        addTestContent(store, "server");
        storeS.flush()// this speeds up the test a little bit...

        StandbyClient cl = new StandbyClient("127.0.0.1", port, storeC, true);
        cl.run();

        try {
            assertFalse("stores are equal but shouldn't!", storeS.getHead().equals(storeC.getHead()));
        } finally {
            server.close();
            cl.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.plugins.segment.standby.client.StandbyClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.