Package com.nokia.dempsy.container.mocks

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


   @Test
   public void testMessageDispatch()
   throws Exception
   {
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      outputQueue.poll(1000, TimeUnit.MILLISECONDS);

      assertEquals("did not create MP", 1, container.getProcessorCount());

      TestProcessor mp = (TestProcessor)container.getMessageProcessor("foo");
      assertNotNull("MP not associated with expected key", mp);
      assertEquals("activation count, 1st message", 1, mp.activationCount);
      assertEquals("invocation count, 1st message", 1, mp.invocationCount);

      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      outputQueue.poll(1000, TimeUnit.MILLISECONDS);

      assertEquals("activation count, 2nd message", 1, mp.activationCount);
      assertEquals("invocation count, 2nd message", 2, mp.invocationCount);
   }
View Full Code Here


   @Test
   public void testInvokeOutput()
   throws Exception
   {
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      outputQueue.poll(1000, TimeUnit.MILLISECONDS);
      inputQueue.add(serializer.serialize(new ContainerTestMessage("bar")));
      outputQueue.poll(1000, TimeUnit.MILLISECONDS);

      assertEquals("number of MP instances", 2, container.getProcessorCount());
      assertTrue("queue is empty", outputQueue.isEmpty());
View Full Code Here

      assertTrue("second MP sent output", messageKeys.contains("bar"));
   }

   @Test
   public void testOutputInvoker() throws Exception {
     inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
     ContainerTestMessage out1 = (ContainerTestMessage)serializer.deserialize((byte[]) outputQueue.poll(1000, TimeUnit.MILLISECONDS));
     assertTrue("messages received", (out1 != null) );

     assertEquals("number of MP instances", 1, container.getProcessorCount());
     assertTrue("queue is empty", outputQueue.isEmpty());
   }
View Full Code Here

      final int concurrency = 5;
     
      container.setConcurrency(concurrency);
     
      for (int i = 0; i < numInstances; i++)
         inputQueue.put(serializer.serialize(new ContainerTestMessage("foo" + i)));
      for (int i = 0; i < numInstances; i++)
         assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("number of MP instances", numInstances, container.getProcessorCount());
      assertTrue("queue is empty", outputQueue.isEmpty());
View Full Code Here

      assertEquals("no more messages in queue", 0, outputQueue.size());
   }

   @Test
   public void testEvictable() throws Exception {
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("did not create MP", 1, container.getProcessorCount());

      TestProcessor mp = (TestProcessor)container.getMessageProcessor("foo");
      assertNotNull("MP not associated with expected key", mp);
      assertEquals("activation count, 1st message", 1, mp.activationCount);
      assertEquals("invocation count, 1st message", 1, mp.invocationCount);

      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("activation count, 2nd message", 1, mp.activationCount);
      assertEquals("invocation count, 2nd message", 2, mp.invocationCount);
      TestProcessor prototype = context.getBean(TestProcessor.class);
      int tmpCloneCount = prototype.cloneCount.intValue();
     
      mp.evict.set(true);
      container.evict();
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("Clone count, 2nd message", tmpCloneCount+1, prototype.cloneCount.intValue());
   }
View Full Code Here

   }
  
   @Test
   public void testEvictableWithPassivateException() throws Exception
   {
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("did not create MP", 1, container.getProcessorCount());

      TestProcessor mp = (TestProcessor)container.getMessageProcessor("foo");
      assertNotNull("MP not associated with expected key", mp);
      assertEquals("activation count, 1st message", 1, mp.activationCount);
      assertEquals("invocation count, 1st message", 1, mp.invocationCount);
      mp.throwPassivateException.set(true);

      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("activation count, 2nd message", 1, mp.activationCount);
      assertEquals("invocation count, 2nd message", 2, mp.invocationCount);
      TestProcessor prototype = context.getBean(TestProcessor.class);
      int tmpCloneCount = prototype.cloneCount.intValue();
     
      mp.evict.set(true);
      container.evict();
      assertEquals("Passivate Exception Thrown",1, mp.passivateExceptionCount.get());
     
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("Clone count, 2nd message", tmpCloneCount+1, prototype.cloneCount.intValue());
   }
View Full Code Here

   public void testEvictableWithBusyMp() throws Throwable
   {
      // first set the receiver to failFast
     
      // This forces the instantiation of an Mp
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      // Once the poll finishes the Mp is instantiated and handling messages.
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("did not create MP", 1, container.getProcessorCount());

      TestProcessor mp = (TestProcessor)container.getMessageProcessor("foo");
      assertNotNull("MP not associated with expected key", mp);
      assertEquals("activation count, 1st message", 1, mp.activationCount);
      assertEquals("invocation count, 1st message", 1, mp.invocationCount);
     
      // now we're going to cause the processing to be held up.
      mp.latch = new CountDownLatch(1);
      mp.evict.set(true); // allow eviction

      // sending it a message will now cause it to hang up while processing
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
     
      TestProcessor prototype = context.getBean(TestProcessor.class);

      // keep track of the cloneCount for later checking
      int tmpCloneCount = prototype.cloneCount.intValue();
     
      // invocation count should go to 2
      assertTrue(TestUtils.poll(baseTimeoutMillis, mp, new TestUtils.Condition<TestProcessor>()
            { @Override public boolean conditionMet(TestProcessor o) { return o.invocationCount == 2; } }));
     
      assertNull(outputQueue.peek()); // this is a double check that no message got all the way
     
      // now kick off the evict in a separate thread since we expect it to hang
      // until the mp becomes unstuck.
      final AtomicBoolean evictIsComplete = new AtomicBoolean(false); // this will allow us to see the evict pass complete
      Thread thread = new Thread(new Runnable() { @Override public void run() { container.evict(); evictIsComplete.set(true); } });
      thread.start();
     
      // now check to make sure eviction doesn't complete.
      Thread.sleep(50); // just a little to give any mistakes a change to work themselves through
      assertFalse(evictIsComplete.get()); // make sure eviction didn't finish
     
      mp.latch.countDown(); // this lets it go
     
      // wait until the eviction completes
      assertTrue(TestUtils.poll(baseTimeoutMillis, evictIsComplete, new TestUtils.Condition<AtomicBoolean>()
            { @Override public boolean conditionMet(AtomicBoolean o) { return o.get(); } }));

      // now it comes through.
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("activation count, 2nd message", 1, mp.activationCount);
      assertEquals("invocation count, 2nd message", 2, mp.invocationCount);
     
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("Clone count, 2nd message", tmpCloneCount+1, prototype.cloneCount.intValue());
   }
View Full Code Here

      // This forces the instantiation of an Mp
      BlockingQueueAdaptor adaptor = context.getBean(BlockingQueueAdaptor.class);
      assertNotNull(adaptor);
      adaptor.setFailFast(true);
     
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      // Once the poll finishes the Mp is instantiated and handling messages.
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("did not create MP", 1, container.getProcessorCount());

      TestProcessor mp = (TestProcessor)container.getMessageProcessor("foo");
      assertNotNull("MP not associated with expected key", mp);
      assertEquals("activation count, 1st message", 1, mp.activationCount);
      assertEquals("invocation count, 1st message", 1, mp.invocationCount);
     
      // now we're going to cause the passivate to be held up.
      mp.blockPassivate = new CountDownLatch(1);
      mp.evict.set(true); // allow eviction

      // now kick off the evict in a separate thread since we expect it to hang
      // until the mp becomes unstuck.
      final AtomicBoolean evictIsComplete = new AtomicBoolean(false); // this will allow us to see the evict pass complete
      Thread thread = new Thread(new Runnable() { @Override public void run() { container.evict(); evictIsComplete.set(true); } });
      thread.start();
     
      Thread.sleep(50); //let it get going.
      assertFalse(evictIsComplete.get()); // check to see we're hung.

      final MetricGetters sc = (MetricGetters)container.getStatsCollector();
      assertEquals(0,sc.getMessageCollisionCount());
     
      // sending it a message will now cause it to have the collision tick up
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
     
      assertTrue(TestUtils.poll(baseTimeoutMillis, sc, new TestUtils.Condition<MetricGetters>()
            { @Override public boolean conditionMet(MetricGetters o) { return o.getMessageCollisionCount() == 1; } }));
     
      // now let the evict finish
      mp.blockPassivate.countDown();
     
      // wait until the eviction completes
      assertTrue(TestUtils.poll(baseTimeoutMillis, evictIsComplete, new TestUtils.Condition<AtomicBoolean>()
            { @Override public boolean conditionMet(AtomicBoolean o) { return o.get(); } }));
     
      // invocationCount should still be 1 from the initial invocation that caused the clone
      assertEquals(1,mp.invocationCount);

      // send a message that should go through
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));

      // Once the poll finishes a new Mp is instantiated and handling messages.
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      TestProcessor mp2 = (TestProcessor)container.getMessageProcessor("foo");
View Full Code Here

     
      // This forces the instantiation of an Mp
      BlockingQueueAdaptor adaptor = context.getBean(BlockingQueueAdaptor.class);
      assertNotNull(adaptor);
     
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
      // Once the poll finishes the Mp is instantiated and handling messages.
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals("did not create MP", 1, container.getProcessorCount());

      TestProcessor mp = (TestProcessor)container.getMessageProcessor("foo");
      assertNotNull("MP not associated with expected key", mp);
      assertEquals("activation count, 1st message", 1, mp.activationCount);
      assertEquals("invocation count, 1st message", 1, mp.invocationCount);
     
      // now we're going to cause the passivate to be held up.
      mp.blockPassivate = new CountDownLatch(1);
      mp.evict.set(true); // allow eviction

      // now kick off the evict in a separate thread since we expect it to hang
      // until the mp becomes unstuck.
      final AtomicBoolean evictIsComplete = new AtomicBoolean(false); // this will allow us to see the evict pass complete
      Thread thread = new Thread(new Runnable() { @Override public void run() { container.evict(); evictIsComplete.set(true); } });
      thread.start();
     
      Thread.sleep(500); //let it get going.
      assertFalse(evictIsComplete.get()); // check to see we're hung.

      final MetricGetters sc = (MetricGetters)container.getStatsCollector();
      assertEquals(0,sc.getMessageCollisionCount());
     
      // sending it a message will now cause it to have the collision tick up
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));
     
      // give it some time.
      Thread.sleep(100);
     
      // make sure there's no collision
      assertEquals(0,sc.getMessageCollisionCount());
     
      // make sure the message didn't get through
      assertNull(outputQueue.peek());
     
      // make sure no message got handled
      assertEquals(1,mp.invocationCount); // 1 is the initial invocation that caused the instantiation.
     
      // now let the evict finish
      mp.blockPassivate.countDown();
     
      // wait until the eviction completes
      assertTrue(TestUtils.poll(baseTimeoutMillis, evictIsComplete, new TestUtils.Condition<AtomicBoolean>()
            { @Override public boolean conditionMet(AtomicBoolean o) { return o.get(); } }));

      // Once the poll finishes a new Mp is instantiated and handling messages.
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      // get the new Mp
      TestProcessor mp2 = (TestProcessor)container.getMessageProcessor("foo");

      // invocationCount should be 1 from the initial invocation that caused the clone, and no more
      assertEquals(1,mp.invocationCount);
      assertEquals(1,mp2.invocationCount);
      assertTrue(mp != mp2);

      // send a message that should go through
      inputQueue.add(serializer.serialize(new ContainerTestMessage("foo")));

      // Once the poll finishes mp2 invocationCount should be incremented
      assertNotNull(outputQueue.poll(baseTimeoutMillis, TimeUnit.MILLISECONDS));

      assertEquals(1,mp.invocationCount);
View Full Code Here

TOP

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

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.