Package org.agilewiki.jactor

Examples of org.agilewiki.jactor.MailboxFactory


import java.nio.file.StandardOpenOption;

public class TransactionProcessorTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
        Mailbox mailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(mailbox);
        factory.defineActorType("helloWorldTransaction", HelloWorldTransaction.class);
        JAFuture future = new JAFuture();
        Path directoryPath = FileSystems.getDefault().getPath("TransactionProcessorTest");
        StatelessDB db = new StatelessDB(mailboxFactory, factory, directoryPath);
        db.clearDirectory();
        TransactionProcessor transactionProcessor = new TransactionProcessor();
        transactionProcessor.initialize(mailbox, db);

        JFile jFile = new JFile();
        jFile.initialize(mailbox, factory);
        String ts = (new DateTime()).toString("yyyy-MM-dd_HH-mm-ss_SSS");
        Path path = directoryPath.resolve(ts + ".jalog");
        System.out.println(path.toAbsolutePath());
        jFile.open(
                path,
                StandardOpenOption.READ,
                StandardOpenOption.WRITE,
                StandardOpenOption.CREATE);

        RootJid rj = new RootJid();
        rj.initialize(mailbox, db);
        (new SetActor("helloWorldTransaction")).send(future, rj);
        Block block = new LTBlock();
        block.setRootJid(rj);
        long timestamp = System.currentTimeMillis();
        block.setTimestamp(timestamp);
        (new ForcedWriteRootJid(block)).send(future, jFile);

        (new ProcessBlock(block)).send(future, transactionProcessor);

        jFile.close();
        mailboxFactory.close();
    }
View Full Code Here


import java.nio.file.StandardOpenOption;

public class LTFileTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
        Mailbox mailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(mailbox);
        (new JidFactories()).initialize(mailbox, factory);
        JAFuture future = new JAFuture();

        JFile jFile = new JFile();
        jFile.initialize(mailbox, factory);
        Path path = FileSystems.getDefault().getPath("LTFileTest.jalog");
        System.out.println(path.toAbsolutePath());
        jFile.fileChannel = FileChannel.open(
                path,
                StandardOpenOption.READ,
                StandardOpenOption.WRITE,
                StandardOpenOption.CREATE);

        RootJid rj = new RootJid();
        rj.initialize(mailbox, factory);
        Block block = new LTBlock();
        block.setRootJid(rj);
        long timestamp = System.currentTimeMillis();
        block.setTimestamp(timestamp);
        (new ForcedWriteRootJid(block)).send(future, jFile);
        assertEquals(12L, block.getCurrentPosition());

        Block block2 = new LTBlock();
        (new ReadRootJid(block2)).send(future, jFile);
        RootJid rj2 = block2.getRootJid(mailbox, factory);
        assertNotNull(rj2);
        long timestamp2 = block2.getTimestamp();
        assertEquals(timestamp, timestamp2);

        (new ReadRootJid(block2)).send(future, jFile);
        rj2 = block2.getRootJid(mailbox, factory);
        assertNull(rj2);

        jFile.fileChannel.close();
        mailboxFactory.close();
    }
View Full Code Here

import java.nio.file.StandardOpenOption;

public class LFileTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
        Mailbox mailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(mailbox);
        (new JidFactories()).initialize(mailbox, factory);
        JAFuture future = new JAFuture();

        JFile jFile = new JFile();
        jFile.initialize(mailbox, factory);
        Path path = FileSystems.getDefault().getPath("LFileTest.jalog");
        System.out.println(path.toAbsolutePath());
        jFile.fileChannel = FileChannel.open(
                path,
                StandardOpenOption.READ,
                StandardOpenOption.WRITE,
                StandardOpenOption.CREATE);

        RootJid rj = new RootJid();
        rj.initialize(mailbox, factory);
        Block block = new LBlock();
        block.setRootJid(rj);
        (new ForcedWriteRootJid(block)).send(future, jFile);
        assertEquals(4L, block.getCurrentPosition());

        Block block2 = new LBlock();
        (new ReadRootJid(block2)).send(future, jFile);
        RootJid rj2 = block2.getRootJid(mailbox, factory);
        assertNotNull(rj2);

        (new ReadRootJid(block2)).send(future, jFile);
        rj2 = block2.getRootJid(mailbox, factory);
        assertNull(rj2);

        jFile.fileChannel.close();
        mailboxFactory.close();
    }
View Full Code Here

import java.nio.file.StandardOpenOption;

public class LTA32FileTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
        Mailbox mailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(mailbox);
        (new JidFactories()).initialize(mailbox, factory);
        JAFuture future = new JAFuture();

        JFile jFile = new JFile();
        jFile.initialize(mailbox, factory);
        Path path = FileSystems.getDefault().getPath("LT32FileTest.jalog");
        System.out.println(path.toAbsolutePath());
        jFile.fileChannel = FileChannel.open(
                path,
                StandardOpenOption.READ,
                StandardOpenOption.WRITE,
                StandardOpenOption.CREATE);

        RootJid rj = new RootJid();
        rj.initialize(mailbox, factory);
        Block block = new LTA32Block();
        block.setRootJid(rj);
        long timestamp = System.currentTimeMillis();
        block.setTimestamp(timestamp);
        (new ForcedWriteRootJid(block)).send(future, jFile);
        assertEquals(20L, block.getCurrentPosition());

        Block block2 = new LTA32Block();
        (new ReadRootJid(block2)).send(future, jFile);
        RootJid rj2 = block2.getRootJid(mailbox, factory);
        assertNotNull(rj2);
        long timestamp2 = block2.getTimestamp();
        assertEquals(timestamp, timestamp2);

        (new ReadRootJid(block2)).send(future, jFile);
        rj2 = block2.getRootJid(mailbox, factory);
        assertNull(rj2);

        jFile.fileChannel.close();
        mailboxFactory.close();
    }
View Full Code Here

import org.agilewiki.jid.scalar.vlens.actor.RootJid;

public class LBlockTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
        Mailbox mailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(mailbox);
        (new JidFactories()).initialize(mailbox, factory);

        RootJid rj = new RootJid();
        rj.initialize(mailbox, factory);
        LBlock lb1 = new LBlock();
        lb1.setRootJid(rj);
        byte[] bs = lb1.serialize();

        int hl = lb1.headerLength();
        int rjl = rj.getSerializedLength();
        assertEquals(bs.length, hl + rjl);

        byte[] h = new byte[hl];
        System.arraycopy(bs, 0, h, 0, hl);
        byte[] sd = new byte[rjl];
        System.arraycopy(bs, hl, sd, 0, rjl);

        LBlock lb2 = new LBlock();
        int rjl2 = lb2.setHeaderBytes(h);
        lb2.setRootJidBytes(sd);
        RootJid rj2 = lb2.getRootJid(mailbox, factory);

        mailboxFactory.close();
    }
View Full Code Here

import java.nio.file.StandardOpenOption;

public class LA32FileTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
        Mailbox mailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(mailbox);
        (new JidFactories()).initialize(mailbox, factory);
        JAFuture future = new JAFuture();

        JFile jFile = new JFile();
        jFile.initialize(mailbox, factory);
        Path path = FileSystems.getDefault().getPath("LT32FileTest.jalog");
        System.out.println(path.toAbsolutePath());
        jFile.fileChannel = FileChannel.open(
                path,
                StandardOpenOption.READ,
                StandardOpenOption.WRITE,
                StandardOpenOption.CREATE);

        RootJid rj = new RootJid();
        rj.initialize(mailbox, factory);
        Block block = new LA32Block();
        block.setRootJid(rj);
        (new ForcedWriteRootJid(block)).send(future, jFile);
        assertEquals(12L, block.getCurrentPosition());

        Block block2 = new LA32Block();
        (new ReadRootJid(block2)).send(future, jFile);
        RootJid rj2 = block2.getRootJid(mailbox, factory);
        assertNotNull(rj2);

        (new ReadRootJid(block2)).send(future, jFile);
        rj2 = block2.getRootJid(mailbox, factory);
        assertNull(rj2);

        jFile.fileChannel.close();
        mailboxFactory.close();
    }
View Full Code Here

import java.nio.file.Path;

public class RecoveryTimingTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10);
        Mailbox factoryMailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(factoryMailbox);
        (new JidFactories()).initialize(factoryMailbox, factory);
        (new JFileFactories()).initialize(factoryMailbox, factory);
        factory.defineActorType("n", IncrementCounterTransaction.class);
        JAFuture future = new JAFuture();

        Path directoryPath = FileSystems.getDefault().getPath("TransactionLoggerTimingTest");
        CounterDB db = new CounterDB(mailboxFactory, factory, directoryPath);

        long t0 = System.currentTimeMillis();
        (new OpenDbFile(10000)).send(future, db);
        long t1 = System.currentTimeMillis();

        int transactions = db.getCounter();
        System.out.println("milliseconds: " + (t1 - t0));
        System.out.println("transactions: " + transactions);
        System.out.println("transactions per second = " + (1000L * transactions / (t1 - t0)));
        //tps = 956,937
        mailboxFactory.close();
    }
View Full Code Here

import java.nio.file.Path;

public class CounterTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10);
        Mailbox factoryMailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(factoryMailbox);
        (new JidFactories()).initialize(factoryMailbox, factory);
        (new JFileFactories()).initialize(factoryMailbox, factory);
        factory.defineActorType("inc", IncrementCounterTransaction.class);
        factory.defineActorType("get", GetCounterTransaction.class);
        Path directoryPath = FileSystems.getDefault().getPath("CounterTest");
        JAFuture future = new JAFuture();
        AggregateTransaction inc = new AggregateTransaction("inc");
        AggregateTransaction get = new AggregateTransaction("get");

        System.out.println("db1");
        CounterDB db1 = new CounterDB(mailboxFactory, factory, directoryPath);
        db1.clearDirectory();
        (new OpenDbFile(10000)).send(future, db1);
        TransactionAggregator transactionAggregator1 = db1.getTransactionAggregator();
        inc.sendEvent(transactionAggregator1);
        int total1 = (Integer) (new AggregateTransaction("get")).send(future, transactionAggregator1);
        assertEquals(1, total1);
        db1.closeDbFile();

        System.out.println("db2");
        CounterDB db2 = new CounterDB(mailboxFactory, factory, directoryPath);
        (new OpenDbFile(10000)).send(future, db2);
        TransactionAggregator transactionAggregator2 = db2.getTransactionAggregator();
        inc.sendEvent(transactionAggregator2);
        inc.sendEvent(transactionAggregator2);
        int total2 = (Integer) (new AggregateTransaction("get")).send(future, transactionAggregator2);
        assertEquals(3, total2);
        db2.closeDbFile();

        System.out.println("db3");
        CounterDB db3 = new CounterDB(mailboxFactory, factory, directoryPath);
        (new OpenDbFile(10000)).send(future, db3);
        TransactionAggregator transactionAggregator3 = db3.getTransactionAggregator();
        inc.sendEvent(transactionAggregator3);
        inc.sendEvent(transactionAggregator3);
        inc.sendEvent(transactionAggregator3);
        int total3 = (Integer) get.send(future, transactionAggregator3);
        assertEquals(6, total3);
        db3.closeDbFile();

        mailboxFactory.close();
    }
View Full Code Here

import java.nio.file.Path;

public class TransactionLoggerTimingTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10);
        Mailbox factoryMailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(factoryMailbox);
        (new JFileFactories()).initialize(factoryMailbox, factory);
        IncrementCounterFactory ntf = new IncrementCounterFactory("n");
        factory.registerActorFactory(ntf);
        JAFuture future = new JAFuture();
        AggregateTransaction aggregateTransaction = new AggregateTransaction(ntf);

        Path directoryPath = FileSystems.getDefault().getPath("TransactionLoggerTimingTest");
        CounterDB db = new CounterDB(mailboxFactory, factory, directoryPath);
        db.clearDirectory();
        (new OpenDbFile(10000)).send(future, db);

        TransactionAggregator transactionAggregator = db.getTransactionAggregator();

        TransactionAggregatorDriver transactionAggregatorDriver =
                new TransactionAggregatorDriver();
        transactionAggregatorDriver.initialize(mailboxFactory.createAsyncMailbox(), transactionAggregator);
        transactionAggregatorDriver.setInitialBufferCapacity(10000);
        transactionAggregatorDriver.win = 3;
        transactionAggregatorDriver.aggregateTransaction = aggregateTransaction;

        transactionAggregatorDriver.batch = 10;
        transactionAggregatorDriver.count = 10;

        //System.out.println("###########################################################");
        //transactionAggregatorDriver.batch = 10000;
        //transactionAggregatorDriver.count = 1000;

        Go.req.send(future, transactionAggregatorDriver);
        Finish.req.send(future, transactionAggregator);
        long t0 = System.currentTimeMillis();
        Go.req.send(future, transactionAggregatorDriver);
        Finish.req.send(future, transactionAggregator);
        long t1 = System.currentTimeMillis();

        int transactions = transactionAggregatorDriver.batch * transactionAggregatorDriver.count;
        assertEquals(2 * transactions, db.getCounter());

        System.out.println("milliseconds: " + (t1 - t0));
        System.out.println("transactions: " + transactions);
        if (t1 != t0)
            System.out.println("transactions per second = " + (1000L * transactions / (t1 - t0)));

        //latency = 402 microseconds

        //batch = 10000
        //count = 1000
        //transactions = 10,000,000
        //throughput = 4,056,795 tps

        db.closeDbFile();
        mailboxFactory.close();
    }
View Full Code Here

import java.nio.file.Path;

public class ImdbTimingTest extends TestCase {
    public void test()
            throws Exception {
        MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10);
        Mailbox factoryMailbox = mailboxFactory.createMailbox();
        JAFactory factory = new JAFactory();
        factory.initialize(factoryMailbox);
        (new JidFactories()).initialize(factoryMailbox, factory);
        (new JFileFactories()).initialize(factoryMailbox, factory);
        JAFuture future = new JAFuture();

        Path directoryPath = FileSystems.getDefault().getPath("ImdbTimingTest");
        OpenDbFile openDbFile = new OpenDbFile(10000);
        System.out.println("online");

        AggregateTransaction aggregateIncrementTransaction =
                IncrementIntegerTransactionFactory.at(factoryMailbox, "counter");

        IMDB db1 = new IMDB(mailboxFactory, factory, directoryPath);
        db1.clearDirectory();
        openDbFile.send(future, db1);
        TransactionAggregator transactionAggregator1 = db1.getTransactionAggregator();

        TransactionAggregatorDriver transactionAggregatorDriver =
                new TransactionAggregatorDriver();
        transactionAggregatorDriver.initialize(mailboxFactory.createAsyncMailbox(), transactionAggregator1);
        transactionAggregatorDriver.setInitialBufferCapacity(1024);
        transactionAggregatorDriver.win = 3;
        transactionAggregatorDriver.aggregateTransaction = aggregateIncrementTransaction;

        transactionAggregatorDriver.batch = 1;
        transactionAggregatorDriver.count = 1;

        //System.out.println("###########################################################");
        //transactionAggregatorDriver.batch = 10000;
        //transactionAggregatorDriver.count = 1000;

        Go.req.send(future, transactionAggregatorDriver);
        GetIntegerTransaction git = new GetIntegerTransaction();
        git.initialize(factoryMailbox);
        git.setValue("counter");
        byte[] gitBytes = git.getSerializedBytes();
        AggregateTransaction aggregateGetTransaction =
                new AggregateTransaction(JFileFactories.GET_INTEGER_TRANSACTION, gitBytes);
        long t8 = System.currentTimeMillis();
        int k = 0;
        int total1 = 0;
        while (k < 10) {
            total1 = (Integer) aggregateGetTransaction.send(future, transactionAggregator1);
            k += 1;
        }
        long t9 = System.currentTimeMillis();
        assertEquals(transactionAggregatorDriver.batch * transactionAggregatorDriver.count, total1);
        System.out.println("latency = " + (t9 - t8) + " microseconds");

        long t0 = System.currentTimeMillis();
        Go.req.send(future, transactionAggregatorDriver);
        Finish.req.send(future, transactionAggregator1);
        long t1 = System.currentTimeMillis();

        int transactions = transactionAggregatorDriver.batch * transactionAggregatorDriver.count;

        System.out.println("milliseconds: " + (t1 - t0));
        System.out.println("transactions: " + transactions);
        System.out.println("transactions per second = " + (1000L * transactions / (t1 - t0)));

        //latency = 296 microseconds

        //batch = 10,000
        //count = 1,000
        //transactions = 10,000,000
        //throughput = 1,385,041 tps

        db1.closeDbFile();
        mailboxFactory.close();
    }
View Full Code Here

TOP

Related Classes of org.agilewiki.jactor.MailboxFactory

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.