Package org.apache.activemq.leveldb.replicated

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


*/
public class MasterLevelDBStoreTest {

    @Test(timeout = 1000*60*10)
    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 < 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

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.