Exemple #1
0
 public void test3() {
   MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
   try {
     Mailbox mailbox = mailboxFactory.createMailbox();
     JAFactory factory = new JAFactory();
     factory.initialize(mailbox);
     (new JidFactories()).initialize(mailbox, factory);
     BListJidFactory intListFactory = new BListJidFactory("il", IntegerJidFactory.fac);
     factory.registerActorFactory(intListFactory);
     BListJid intList1 = (BListJid) factory.newActor("il");
     int i = 0;
     while (i < 41) {
       intList1.iAdd(-1);
       IntegerJid ij0 = (IntegerJid) intList1.iGet(-1);
       ij0.setValue(i);
       i += 1;
     }
     i = 0;
     while (i < 41) {
       IntegerJid ij = (IntegerJid) intList1.iGet(i);
       assertEquals(i, (int) ij.getValue());
       i += 1;
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     mailboxFactory.close();
   }
 }
Exemple #2
0
 public void test1() {
   MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
   try {
     Mailbox mailbox = mailboxFactory.createMailbox();
     JAFactory factory = new JAFactory();
     factory.initialize(mailbox);
     (new JidFactories()).initialize(mailbox, factory);
     BListJidFactory stringListFactory = new BListJidFactory("sl", StringJidFactory.fac);
     factory.registerActorFactory(stringListFactory);
     BListJid stringList1 = (BListJid) factory.newActor("sl");
     stringList1.iAdd(0);
     stringList1.iAdd(1);
     stringList1.iAdd(2);
     StringJid sj0 = (StringJid) stringList1.iGet(0);
     StringJid sj1 = (StringJid) stringList1.iGet(1);
     StringJid sj2 = (StringJid) stringList1.iGet(2);
     sj0.setValue("a");
     sj1.setValue("b");
     sj2.setValue("c");
     BListJid stringList2 = (BListJid) stringList1.copyJID(mailbox);
     StringJid s0 = (StringJid) stringList2.iGet(0);
     StringJid s1 = (StringJid) stringList2.iGet(1);
     StringJid s2 = (StringJid) stringList2.iGet(2);
     assertEquals("a", s0.getValue());
     assertEquals("b", s1.getValue());
     assertEquals("c", s2.getValue());
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     mailboxFactory.close();
   }
 }
  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);

    Mailbox dbMailbox = mailboxFactory.createAsyncMailbox();
    CounterDB db = new CounterDB();
    db.initialize(dbMailbox, factory);
    db.initialCapacity = 10000;
    Path directoryPath = FileSystems.getDefault().getPath("TransactionLoggerTimingTest");
    db.setDirectoryPath(directoryPath);
    db.clearDirectory();
    (new OpenDbFile(10000)).send(future, db);

    org.agilewiki.jfile.transactions.transactionAggregator.TransactionAggregator
        transactionAggregator = db.getTransactionAggregator();

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

    transactionLoggerDriver.batch = 10;
    transactionLoggerDriver.count = 10;
    //   transactionLoggerDriver.batch = 10000;
    //   transactionLoggerDriver.count = 1000;

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

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

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

    // latency = 2 ms

    // batch = 10000
    // count = 1000
    // transactions = 10,000,000
    // time = 9.953 seconds
    // throughput = 1,004,722 tps

    db.closeDbFile();
    mailboxFactory.close();
  }
  public void test() throws Exception {
    MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10);
    Mailbox factoryMailbox = mailboxFactory.createMailbox();
    JAFactory factory = new JAFactory(factoryMailbox);
    (new JFileFactories(factoryMailbox)).setParent(factory);
    NullTransactionFactory ntf = new NullTransactionFactory("n");
    factory.registerActorFactory(ntf);
    JAFuture future = new JAFuture();
    Mailbox dbMailbox = mailboxFactory.createAsyncMailbox();
    StatelessDB db = new StatelessDB(dbMailbox);
    db.setParent(factory);
    TransactionProcessor transactionProcessor = new TransactionProcessor(dbMailbox);
    transactionProcessor.setParent(db);

    JFile jFile = new JFile(mailboxFactory.createAsyncMailbox());
    jFile.setParent(transactionProcessor);
    Path path = FileSystems.getDefault().getPath("TransactionLoggerTimingTest.jf");
    System.out.println(path.toAbsolutePath());
    jFile.fileChannel =
        FileChannel.open(
            path, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE);

    Mailbox transactionLoggerMailbox = mailboxFactory.createAsyncMailbox();
    TransactionLogger3 transactionLogger = new TransactionLogger3(transactionLoggerMailbox);
    transactionLogger.setParent(jFile);
    transactionLogger.initialCapacity = 2000;

    TransactionLoggerDriver transactionLoggerDriver =
        new TransactionLoggerDriver(mailboxFactory.createAsyncMailbox());
    transactionLoggerDriver.setParent(transactionLogger);
    transactionLoggerDriver.batch = 1;
    transactionLoggerDriver.count = 1;
    transactionLoggerDriver.win = 3;

    Go.req.send(future, transactionLoggerDriver);
    Go.req.send(future, transactionLoggerDriver);
    long t0 = System.currentTimeMillis();
    Go.req.send(future, transactionLoggerDriver);
    long t1 = System.currentTimeMillis();

    System.out.println("milliseconds: " + (t1 - t0));
    System.out.println(
        "transactions: " + (transactionLoggerDriver.batch * transactionLoggerDriver.count));

    // latency = 2 ms
    // throughput = 500,000 tps

    jFile.fileChannel.close();
    mailboxFactory.close();
  }