Package com.nokia.dempsy.container.mocks

Examples of com.nokia.dempsy.container.mocks.MockInputMessage


         imIn = new CountDownLatch(NTHREADS);
         dispatcher.latch = new CountDownLatch(NTHREADS);
        
         ArrayList<MockInputMessage> in = new ArrayList<MockInputMessage>();
         for (int j = 0; j < NTHREADS; j++)
            in.add(new MockInputMessage("key" + j));
     
         SendMessageThread.latch = new CountDownLatch(in.size());
         for (MockInputMessage m: in)
            sendMessage(container, m, false);
        
View Full Code Here


         imIn = new CountDownLatch(3 * NTHREADS);
         dispatcher.latch = new CountDownLatch(3 * NTHREADS);

         ArrayList<MockInputMessage> in = new ArrayList<MockInputMessage>();
         for (int j = 0; j < (3 * NTHREADS); j++)
            in.add(new MockInputMessage("key" + j));
     
         SendMessageThread.latch = new CountDownLatch(in.size());
         for (MockInputMessage m: in)
         {
            sendMessage(container, m,false);
View Full Code Here

      finishLatch = new CountDownLatch(3 * NTHREADS);
      imIn = new CountDownLatch(3 * NTHREADS);
      dispatcher.latch = new CountDownLatch(3 * NTHREADS);
      ArrayList<MockInputMessage> in = new ArrayList<MockInputMessage>();
      for (int j = 0; j < (3 * NTHREADS); j++)
         in.add(new MockInputMessage("key" + j));
     
      // load up the queue with messages, none get discarded
      SendMessageThread.latch = new CountDownLatch(in.size());
      for (MockInputMessage m: in)
      {
         sendMessage(container, m,false);
         assertEquals(0, stats.getDiscardedMessageCount());
      }
     
      // Add another message.  Since processing is wating on the start latch,
      /// it shoulld be discarded
      assertTrue(imIn.await(2, TimeUnit.SECONDS)); // this means they're all in
      // need to directly dispatch it to avoid a race condition
      container.dispatch(new MockInputMessage("key" + 0), false);
      assertEquals(1, stats.getDiscardedMessageCount());
      container.dispatch(new MockInputMessage("key" + 1), false);
      assertEquals(2, stats.getDiscardedMessageCount());
     
      checkStat(stats);
      startLatch.countDown();
      checkStat(stats);
View Full Code Here

      dispatcher.latch = new CountDownLatch(4 * NTHREADS); // this counts down whenever a message is dispatched
      SendMessageThread.latch = new CountDownLatch(4 * NTHREADS); // when spawning a thread to send a message into an MpContainer, this counts down once the message sending is complete

      // invoke NTHREADS * 4 discrete messages each of which should cause an Mp to be created
      for (int i = 0; i < (NTHREADS * 4); i++)
         sendMessage(container, new MockInputMessage("key" + i),false);
     
      // wait for all of the messages to have been sent.
      assertTrue("Timeout waiting on message to be sent",SendMessageThread.latch.await(2, TimeUnit.SECONDS));
     
      // wait for all of the messages to have been handled by the new Mps
      assertTrue("Timeout on initial messages", finishLatch.await(4, TimeUnit.SECONDS));
     
      // the above can be triggered while still within the message processor handler so we wait
      //  for the stats collector to have registered the processed messages.
      Thread.yield(); // give the threads a chance to return after updating the latch
      for (long endTime = System.currentTimeMillis() + 10000; stats.getInFlightMessageCount() > 0 && endTime > System.currentTimeMillis();)
         Thread.sleep(1); // give worker threads a chance to finish returning post latch

      // with the startLatch set to 0 these should all complete.
      assertEquals(0,stats.getInFlightMessageCount());
      assertEquals(4 * NTHREADS, stats.getProcessedMessageCount());

      startLatch = new CountDownLatch(1); // now we are going to hold the Mps inside the message handler
     
      // we are going to send 2 messages (per thread)
      finishLatch = new CountDownLatch(2 * NTHREADS);
      // ... and wait for the 2 message (per thread) to be in process (this startLatch will hold these from exiting)
      imIn = new CountDownLatch(2 * NTHREADS); // (2 messages + 4 output) * nthreads

      // send 2 message (per thread) which will be held up by the startLatch
      for (int i = 0; i < (2 * NTHREADS); i++)
      {
         sendMessage(container, new MockInputMessage("key" + i),false);
         assertEquals(0, stats.getDiscardedMessageCount());
      }
     
      // there ought to be 2 * NTHREADS inflight ops since the startLatch isn't triggered
      assertTrue("Timeout on initial messages", imIn.await(4, TimeUnit.SECONDS));
View Full Code Here

      imIn = new CountDownLatch(0);
      dispatcher.latch = new CountDownLatch(10 * NTHREADS);
     
      SendMessageThread.latch = new CountDownLatch(NTHREADS * 4);
      for (int i = 0; i < (NTHREADS * 4); i++)
         sendMessage(container, new MockInputMessage("key" + i),false);
      assertTrue("Timeout on initial messages", finishLatch.await(4, TimeUnit.SECONDS));
      Thread.yield()// cover any deltas between mp decrementing latch and returning
      assertTrue("Timeout waiting on message to be sent",SendMessageThread.latch.await(2, TimeUnit.SECONDS));
      checkStat(stats);

      assertEquals(NTHREADS * 4, stats.getProcessedMessageCount());

      startLatch = new CountDownLatch(1);
      finishLatch = new CountDownLatch(6 * NTHREADS); // (4 output + 2 msg) * nthreads
      // Generate an output message but force a failure.
      forceOutputException = true;
      container.outputPass(); // this should be ok inline.
      forceOutputException = false;
      assertEquals(0, stats.getDiscardedMessageCount())// no discarded messages
      assertEquals(NTHREADS * 4, stats.getMessageFailedCount()); // all output messages should have failed.
     
      // run it again without the null pointer exception
      finishOutputLatch = new CountDownLatch(NTHREADS * 4);
      container.outputPass(); // this should be ok inline.
      assertEquals(0, stats.getDiscardedMessageCount())// no discarded messages
      assertEquals(NTHREADS * 4, stats.getMessageFailedCount()); // all output messages should have failed.
      assertEquals(2 * (NTHREADS * 4), stats.getProcessedMessageCount());
      checkStat(stats);
     
      imIn = new CountDownLatch(2 * NTHREADS);
      finishLatch = new CountDownLatch(2 * NTHREADS);
      SendMessageThread.latch = new CountDownLatch(NTHREADS * 2);
      // put 2 * nthreads messages on the queue, expect no discards
      for (int i = 0; i < (2 * NTHREADS); i++)
      {
         sendMessage(container, new MockInputMessage("key" + i),false);
         assertEquals(0, stats.getDiscardedMessageCount());
      }

      assertTrue("Timeout on initial messages", imIn.await(4, TimeUnit.SECONDS));
      assertEquals(0, stats.getDiscardedMessageCount());
View Full Code Here

TOP

Related Classes of com.nokia.dempsy.container.mocks.MockInputMessage

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.