Package org.apache.activemq.leveldb.replicated

Examples of org.apache.activemq.leveldb.replicated.MasterLevelDBStore


        File masterDir = new File("target/activemq-data/leveldb-node1");
        File slaveDir = new File("target/activemq-data/leveldb-node2");
        FileSupport.toRichFile(masterDir).recursiveDelete();
        FileSupport.toRichFile(slaveDir).recursiveDelete();

        final MasterLevelDBStore master = createMaster(masterDir);
        master.setReplicas(2);
        CountDownFuture masterStartLatch = asyncStart(master);

        // Start the store should not complete since we don't have enough
        // replicas.
        assertFalse(masterStartLatch.await(2, TimeUnit.SECONDS));

        // Adding a slave should allow the master startup to complete.
        SlaveLevelDBStore slave = createSlave(master, slaveDir);
        slave.start();

        assertTrue(masterStartLatch.await(2, TimeUnit.SECONDS));

        // New updates should complete quickly now..
        MessageStore ms = master.createQueueMessageStore(new ActiveMQQueue("TEST"));
        CountDownFuture f = asyncAddMessage(ms, "m1");
        assertTrue(f.await(1, TimeUnit.SECONDS));

        // If the slave goes offline, then updates should once again
        // not complete.
        slave.stop();

        f = asyncAddMessage(ms, "m2");
        assertFalse(f.await(2, TimeUnit.SECONDS));

        // Restart and the op should complete.
        slave = createSlave(master, slaveDir);
        slave.start();
        assertTrue(f.await(2, TimeUnit.SECONDS));

        master.stop();
        slave.stop();

    }
View Full Code Here


        ArrayList<String> expected_list = new ArrayList<String>();
        // We will rotate between 3 nodes the task of being the master.
        for (int j = 0; j < 5; j++) {

            MasterLevelDBStore master = createMaster(directories.get(0));
            CountDownFuture masterStart = asyncStart(master);
            SlaveLevelDBStore slave1 = createSlave(master, directories.get(1));
            SlaveLevelDBStore slave2 = createSlave(master, directories.get(2));
            asyncStart(slave2);
            masterStart.await();

            MessageStore ms = master.createQueueMessageStore(new ActiveMQQueue("TEST"));

            LOG.info("Checking: "+master.getDirectory());
            assertEquals(expected_list, getMessages(ms));

            LOG.info("Adding messages...");
            final int TOTAL = 500;
            for (int i = 0; i < TOTAL; i++) {
                if (i % ((int) (TOTAL * 0.10)) == 0) {
                    LOG.info("" + (100 * i / TOTAL) + "% done");
                }

                if (i == 250) {
                    slave1.start();
                    slave2.stop();
                    LOG.info("Checking: "+master.getDirectory());
                    assertEquals(expected_list, getMessages(ms));
                }

                String msgid = "m:" + j + ":" + i;
                addMessage(ms, msgid, playload);
                expected_list.add(msgid);
            }

            LOG.info("Checking: "+master.getDirectory());
            assertEquals(expected_list, getMessages(ms));

            LOG.info("Stopping master: " + master.getDirectory());
            master.stop();

            Thread.sleep(3*1000);
            LOG.info("Stopping slave: " + slave1.getDirectory());
            slave1.stop();

View Full Code Here

        File node2Dir = directories.get(1);
        File node3Dir = directories.get(2);

        ArrayList<String> expected_list = new ArrayList<String>();

        MasterLevelDBStore node1 = createMaster(node1Dir);
        CountDownFuture masterStart = asyncStart(node1);

        // Lets create a 1 slow slave...
        SlaveLevelDBStore node2 = new SlaveLevelDBStore() {
            boolean hitOnce = false;
            @Override
            public TcpTransport create_transport() {
                if( hitOnce ) {
                    return super.create_transport();
                }
                hitOnce = true;
                TcpTransport transport = super.create_transport();
                transport.setMaxReadRate(64*1024);
                return transport;
            }
        };
        configureSlave(node2, node1, node2Dir);
        SlaveLevelDBStore node3 = createSlave(node1, node3Dir);

        asyncStart(node2);
        asyncStart(node3);
        masterStart.await();

        LOG.info("Adding messages...");
        String playload = createPlayload(64 * 1024);
        MessageStore ms = node1.createQueueMessageStore(new ActiveMQQueue("TEST"));
        final int TOTAL = 10;
        for (int i = 0; i < TOTAL; i++) {
            if (i == 8) {
                // Stop the fast slave so that we wait for the slow slave to
                // catch up..
                node3.stop();
            }

            String msgid = "m:" + ":" + i;
            addMessage(ms, msgid, playload);
            expected_list.add(msgid);
        }

        LOG.info("Checking node1 state");
        assertEquals(expected_list, getMessages(ms));

        LOG.info("Stopping node1: " + node1.node_id());
        node1.stop();
        LOG.info("Stopping slave: " + node2.node_id());
        node2.stop();
    }
View Full Code Here

        slave.setLogSize(1023 * 200);
        return slave;
    }

    private MasterLevelDBStore createMaster(File directory) {
        MasterLevelDBStore master = new MasterLevelDBStore();
        master.setDirectory(directory);
        master.setBind("tcp://0.0.0.0:0");
        master.setSecurityToken("foo");
        master.setReplicas(2);
        master.setLogSize(1023 * 200);
        return master;
    }
View Full Code Here

*/
public class MasterLevelDBStoreTest {

    @Test(timeout = 1000*60*60)
    public void testStoppingStoreStopsTransport() throws Exception {
        final MasterLevelDBStore store = new MasterLevelDBStore();
        store.setReplicas(0);

        ExecutorService threads = Executors.newFixedThreadPool(1);
        threads.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    store.start();
                } catch (Exception e) {
                    e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
                }
            }
        });

        // give some time to come up..
        Thread.sleep(2000);
        String address = store.transport_server().getBoundAddress();
        URI bindAddress = new URI(address);
        System.out.println(address);
        Socket socket = new Socket();
        try {
            socket.bind(new InetSocketAddress(bindAddress.getHost(), bindAddress.getPort()));
            fail("We should not have been able to connect...");
        } catch (BindException e) {
            System.out.println("Good. We cannot bind.");
        }


        threads.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    store.stop();
                } catch (Exception e) {
                    e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
                }
            }
        });
View Full Code Here

        File masterDir = new File("target/activemq-data/leveldb-node1");
        File slaveDir = new File("target/activemq-data/leveldb-node2");
        FileSupport.toRichFile(masterDir).recursiveDelete();
        FileSupport.toRichFile(slaveDir).recursiveDelete();

        final MasterLevelDBStore master = createMaster(masterDir);
        master.setReplicas(2);
        CountDownFuture masterStartLatch = asyncStart(master);

        // Start the store should not complete since we don't have enough
        // replicas.
        assertFalse(masterStartLatch.await(2, TimeUnit.SECONDS));

        // Adding a slave should allow the master startup to complete.
        SlaveLevelDBStore slave = createSlave(master, slaveDir);
        slave.start();

        assertTrue(masterStartLatch.await(2, TimeUnit.SECONDS));

        // New updates should complete quickly now..
        MessageStore ms = master.createQueueMessageStore(new ActiveMQQueue("TEST"));
        CountDownFuture f = asyncAddMessage(ms, "m1");
        assertTrue(f.await(1, TimeUnit.SECONDS));

        // If the slave goes offline, then updates should once again
        // not complete.
        slave.stop();

        f = asyncAddMessage(ms, "m2");
        assertFalse(f.await(2, TimeUnit.SECONDS));

        // Restart and the op should complete.
        slave = createSlave(master, slaveDir);
        slave.start();
        assertTrue(f.await(2, TimeUnit.SECONDS));

        master.stop();
        slave.stop();

    }
View Full Code Here

        ArrayList<String> expected_list = new ArrayList<String>();
        // We will rotate between 3 nodes the task of being the master.
        for (int j = 0; j < 10; j++) {

            MasterLevelDBStore master = createMaster(directories.get(0));
            CountDownFuture masterStart = asyncStart(master);
            SlaveLevelDBStore slave1 = createSlave(master, directories.get(1));
            SlaveLevelDBStore slave2 = createSlave(master, directories.get(2));
            asyncStart(slave2);
            masterStart.await();

            LOG.info("Adding messages...");
            MessageStore ms = master.createQueueMessageStore(new ActiveMQQueue("TEST"));
            final int TOTAL = 500;
            for (int i = 0; i < TOTAL; i++) {
                if (i % ((int) (TOTAL * 0.10)) == 0) {
                    LOG.info("" + (100 * i / TOTAL) + "% done");
                }

                if (i == 250) {
                    slave1.start();
                    slave2.stop();
                }

                String msgid = "m:" + j + ":" + i;
                addMessage(ms, msgid);
                expected_list.add(msgid);
            }

            LOG.info("Checking master state");
            assertEquals(expected_list, getMessages(ms));

            LOG.info("Stopping master: " + master.node_id());
            master.stop();
            LOG.info("Stopping slave: " + slave1.node_id());
            slave1.stop();

            // Rotate the dir order so that slave1 becomes the master next.
            directories.addLast(directories.removeFirst());
View Full Code Here

        slave1.setLogSize(1023 * 200);
        return slave1;
    }

    private MasterLevelDBStore createMaster(File directory) {
        MasterLevelDBStore master = new MasterLevelDBStore();
        master.setDirectory(directory);
        master.setBind("tcp://0.0.0.0:0");
        master.setSecurityToken("foo");
        master.setReplicas(2);
        master.setLogSize(1023 * 200);
        return master;
    }
View Full Code Here

        File node2Dir = directories.get(1);
        File node3Dir = directories.get(2);

        ArrayList<String> expected_list = new ArrayList<String>();

        MasterLevelDBStore node1 = createMaster(node1Dir);
        CountDownFuture masterStart = asyncStart(node1);

        // Lets create a 1 slow slave...
        SlaveLevelDBStore node2 = new SlaveLevelDBStore() {
            boolean hitOnce = false;
            @Override
            public TcpTransport create_transport() {
                if( hitOnce ) {
                    return super.create_transport();
                }
                hitOnce = true;
                TcpTransport transport = super.create_transport();
                transport.setMaxReadRate(64*1024);
                return transport;
            }
        };
        configureSlave(node2, node1, node2Dir);
        SlaveLevelDBStore node3 = createSlave(node1, node3Dir);

        asyncStart(node2);
        asyncStart(node3);
        masterStart.await();

        LOG.info("Adding messages...");
        String playload = createPlayload(64 * 1024);
        MessageStore ms = node1.createQueueMessageStore(new ActiveMQQueue("TEST"));
        final int TOTAL = 10;
        for (int i = 0; i < TOTAL; i++) {
            if (i == 8) {
                // Stop the fast slave so that we wait for the slow slave to
                // catch up..
                node3.stop();
            }

            String msgid = "m:" + ":" + i;
            addMessage(ms, msgid, playload);
            expected_list.add(msgid);
        }

        LOG.info("Checking node1 state");
        assertEquals(expected_list, getMessages(ms));

        LOG.info("Stopping node1: " + node1.node_id());
        node1.stop();
        LOG.info("Stopping slave: " + node2.node_id());
        node2.stop();
    }
View Full Code Here

        slave.setLogSize(1023 * 200);
        return slave;
    }

    private MasterLevelDBStore createMaster(File directory) {
        MasterLevelDBStore master = new MasterLevelDBStore();
        master.setDirectory(directory);
        master.setBind("tcp://0.0.0.0:0");
        master.setSecurityToken("foo");
        master.setReplicas(2);
        master.setLogSize(1023 * 200);
        return master;
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.leveldb.replicated.MasterLevelDBStore

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.