Exemple #1
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();
   }
 }
Exemple #2
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();
   }
 }
  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 testTiming() {
    int c = 2;
    int b = 3;
    int p = 1;
    int t = 1;

    // int c = 1000000;
    // int b = 1;
    // int p = 4;
    // int t = 4;

    // burst size of 1
    // 4 parallel runs of 2000000 messages each.
    // 8000000 messages sent with 4 threads.
    // msgs per sec = 4020100
    // 249 nanoseconds per message
    // response time 996

    // int c = 10000;
    // int b = 1000;
    // int p = 4;
    // int t = 4;

    // burst size of 1000
    // 4 parallel runs of 20000000 messages each.
    // 80000000 messages sent with 4 threads.
    // msgs per sec = 42149631
    // 24 nanoseconds per message

    MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(t);
    try {
      Actor[] senders = new Actor[p];
      int i = 0;
      while (i < p) {
        Mailbox echoMailbox = mailboxFactory.createAsyncMailbox();
        Actor echo = new Echo(echoMailbox);
        echo.setInitialBufferCapacity(b + 10);
        Mailbox senderMailbox = mailboxFactory.createAsyncMailbox();
        if (b == 1) senders[i] = new Sender1(senderMailbox, echo, c, b);
        else senders[i] = new Sender(senderMailbox, echo, c, b);
        senders[i].setInitialBufferCapacity(b + 10);
        i += 1;
      }
      JAParallel parallel = new JAParallel(mailboxFactory.createAsyncMailbox(), senders);
      JAFuture future = new JAFuture();
      future.send(parallel, future);
      future.send(parallel, future);
      long t0 = System.currentTimeMillis();
      future.send(parallel, future);
      long t1 = System.currentTimeMillis();
      System.out.println("" + p + " parallel runs of " + (2L * c * b) + " messages each.");
      System.out.println("" + (2L * c * b * p) + " messages sent with " + t + " threads.");
      if (t1 != t0) System.out.println("msgs per sec = " + ((2L * c * b * p) * 1000L / (t1 - t0)));
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mailboxFactory.close();
    }
  }
Exemple #5
0
 public void test() throws Exception {
   MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10);
   Mailbox mailbox = mailboxFactory.createMailbox();
   Actor5a actor5a = new Actor5a();
   actor5a.initialize(mailbox);
   JAFuture future = new JAFuture();
   boolean response = Parallel.req.send(future, actor5a);
   assertEquals(true, response);
   mailboxFactory.close();
 }
Exemple #6
0
 public void test() {
   MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
   try {
     IfF actor = new IfF();
     actor.initialize(mailboxFactory.createMailbox());
     JAFuture future = new JAFuture();
     System.out.println(SimpleRequest.req.send(future, actor));
   } catch (Throwable e) {
     e.printStackTrace();
   } finally {
     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();
  }
Exemple #8
0
 public void test() {
   MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
   try {
     JAFactory f = new JAFactory();
     f.initialize(mailboxFactory.createMailbox());
     f.defineActorType("Foo", Foo.class);
     Foo foo = (Foo) f.newActor("Foo");
     foo.hi();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     mailboxFactory.close();
   }
 }
 public void test() {
   MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10);
   try {
     JAFuture future = new JAFuture();
     JANBLock nblock = new JANBLock();
     nblock.initialize(mailboxFactory.createAsyncMailbox());
     Driver driver = new Driver();
     driver.initialize(mailboxFactory.createAsyncMailbox(), nblock);
     (new DoItEx()).send(future, driver);
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     mailboxFactory.close();
   }
 }
Exemple #10
0
  public void test() {
    MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
    try {
      JAFuture future = new JAFuture();
      JidFactories factory = new JidFactories();
      factory.initialize(mailboxFactory.createMailbox());

      DoubleJid double1 = (DoubleJid) DoubleJidFactory.fac.newActor(factory.getMailbox(), factory);
      DoubleJid double2 = (DoubleJid) (new CopyJID()).send(future, double1);
      (new SetDouble(1.D)).send(future, double2);
      DoubleJid double3 = (DoubleJid) (new CopyJID()).send(future, double2);

      int sl = GetSerializedLength.req.send(future, double1);
      assertEquals(8, sl);
      sl = GetSerializedLength.req.send(future, double2);
      assertEquals(8, sl);
      sl = GetSerializedLength.req.send(future, double3);
      assertEquals(8, sl);

      double v = GetDouble.req.send(future, double1);
      assertEquals(0.D, v);
      v = GetDouble.req.send(future, double2);
      assertEquals(1.D, v);
      v = GetDouble.req.send(future, double3);
      assertEquals(1.D, v);

      Actor jidJid1 = ActorJidFactory.fac.newActor(factory.getMailbox(), factory);
      SetActor sjvl = new SetActor(JidFactories.DOUBLE_JID_TYPE);
      sjvl.send(future, jidJid1);
      DoubleJid rpa = (DoubleJid) (new ResolvePathname("0")).send(future, jidJid1);
      v = GetDouble.req.send(future, rpa);
      assertEquals(0.D, v);
      (new SetDouble(-1.D)).send(future, rpa);
      rpa = (DoubleJid) (new ResolvePathname("0")).send(future, jidJid1);
      v = GetDouble.req.send(future, rpa);
      assertEquals(-1.D, v);

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mailboxFactory.close();
    }
  }
Exemple #11
0
 public void test() {
   MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
   try {
     JAProperties p1 = new JAProperties();
     p1.initialize(mailboxFactory.createMailbox());
     JAProperties p2 = new JAProperties();
     p2.initialize(p1.getMailbox(), p1);
     JAProperties.setProperty(p1, "a", "foo");
     JAProperties.setProperty(p2, "b", "bar");
     String a = (String) JAProperties.getProperty(p2, "a");
     System.out.println(a);
     String b = (String) JAProperties.getProperty(p2, "b");
     System.out.println(b);
     String c = (String) JAProperties.getProperty(p2, "c");
     System.out.println(c);
   } catch (Throwable e) {
     e.printStackTrace();
   } finally {
     mailboxFactory.close();
   }
 }
Exemple #12
0
  public void test() {
    MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
    try {
      JAFuture future = new JAFuture();
      JidFactories factory = new JidFactories();
      factory.initialize(mailboxFactory.createMailbox());

      RootJidFactory rootJidFactory = new RootJidFactory();
      Actor rootJid1 = rootJidFactory.newActor(factory.getMailbox(), factory);
      int sl = GetSerializedLength.req.send(future, rootJid1);
      assertEquals(0, sl);
      Clear.req.send(future, rootJid1);
      sl = GetSerializedLength.req.send(future, rootJid1);
      assertEquals(0, sl);
      Actor rootJid1a = GetActor.req.send(future, rootJid1);
      assertNull(rootJid1a);
      Actor rpa = (new ResolvePathname("")).send(future, rootJid1);
      assertNotNull(rpa);
      assertEquals(rpa, rootJid1);
      rpa = (new ResolvePathname("0")).send(future, rootJid1);
      assertNull(rpa);
      Actor rootJid11 = (new CopyJID()).send(future, rootJid1);
      assertNotNull(rootJid11);
      sl = GetSerializedLength.req.send(future, rootJid11);
      assertEquals(0, sl);
      rpa = (new ResolvePathname("")).send(future, rootJid11);
      assertNotNull(rpa);
      assertEquals(rpa, rootJid11);
      rpa = (new ResolvePathname("0")).send(future, rootJid11);
      assertNull(rpa);

      StringJidFactory stringJidAFactory = StringJidFactory.fac;
      Actor string1 = stringJidAFactory.newActor(factory.getMailbox(), factory);
      (new SetString("abc")).send(future, string1);
      byte[] sb = GetSerializedBytes.req.send(future, string1);
      (new SetActorBytes(stringJidAFactory, sb)).send(future, rootJid1);
      Actor sj = GetActor.req.send(future, rootJid1);
      assertEquals("abc", GetString.req.send(future, sj));

      Actor rootJid2 = RootJidFactory.fac.newActor(factory.getMailbox(), factory);
      sl = GetSerializedLength.req.send(future, rootJid2);
      assertEquals(0, sl);
      SetActor sjvj = new SetActor(JidFactories.JID_TYPE);
      sjvj.send(future, rootJid2);
      MakeActor mjvj = new MakeActor(JidFactories.JID_TYPE);
      boolean made = mjvj.send(future, rootJid2);
      assertEquals(false, made);
      Actor jidJid2a = GetActor.req.send(future, rootJid2);
      assertNotNull(jidJid2a);
      sl = GetSerializedLength.req.send(future, jidJid2a);
      assertEquals(0, sl);
      sl = GetSerializedLength.req.send(future, rootJid2);
      assertEquals(10, sl);
      rpa = (new ResolvePathname("")).send(future, rootJid2);
      assertNotNull(rpa);
      assertEquals(rpa, rootJid2);
      rpa = (new ResolvePathname("0")).send(future, rootJid2);
      assertNotNull(rpa);
      assertEquals(rpa, jidJid2a);
      Actor rootJid22 = (new CopyJID()).send(future, rootJid2);
      Clear.req.send(future, rootJid2);
      sl = GetSerializedLength.req.send(future, rootJid2);
      assertEquals(0, sl);
      jidJid2a = GetActor.req.send(future, rootJid2);
      assertNull(jidJid2a);
      assertNotNull(rootJid22);
      sl = GetSerializedLength.req.send(future, rootJid22);
      assertEquals(10, sl);
      rpa = (new ResolvePathname("")).send(future, rootJid22);
      assertNotNull(rpa);
      assertEquals(rpa, rootJid22);
      rpa = (new ResolvePathname("0")).send(future, rootJid22);
      assertNotNull(rpa);
      sl = GetSerializedLength.req.send(future, rpa);
      assertEquals(0, sl);

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mailboxFactory.close();
    }
  }