Package com.nokia.dempsy.messagetransport

Examples of com.nokia.dempsy.messagetransport.SenderFactory


         @Override
         public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable
         {
            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination(){});

            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            try
            {
              
               boolean shouldBatch = batchOutgoingMessagesDelayMillis >= 0;
              
               if (shouldBatch)
                  batchedAtLeastOnce.set(true);
              
               TcpTransport transport = new TcpTransport();
               transport.setFailFast(getFailFast());

               // by default batching isn't disabled.
               assertFalse(transport.isBatchingDisabled());
              
               if (!shouldBatch)
                  transport.setDisableBatching(true);
              
               if (!shouldBatch)
                  assertTrue(transport.isBatchingDisabled());
              
               assertEquals(!shouldBatch, transport.isBatchingDisabled());
              
               //===========================================
               // setup the sender and receiver
               adaptor = (TcpReceiver)transport.createInbound(null);
               adaptor.setStatsCollector(statsCollector);
               StringListener receiver = new StringListener();
               adaptor.setListener(receiver);

               factory = transport.createOutbound(null, statsCollector);
               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               byte[] messageBytes = "Hello".getBytes();
               Sender sender = factory.getSender(destination);
              
               assertEquals((shouldBatch ? TcpTransport.defaultBatchingDelayMillis : -1), ((TcpSender)sender).getBatchOutgoingMessagesDelayMillis());
              
               sender.send(messageBytes);
               sender.send(messageBytes);
              
               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() < 2;)
                  Thread.sleep(1);
               assertEquals(2,receiver.numMessages.get());

               // verify everything came over ok.
               assertEquals(1,receiver.receivedStringMessages.size());
               assertEquals("Hello",receiver.receivedStringMessages.iterator().next());
              
               if (shouldBatch)
               {
                  // verify the histogram
                  Histogram histogram = ((TcpSender)sender).getBatchingHistogram();
                  assertEquals(calcMean(2),histogram.mean(),0.0000001);
                  assertEquals(1,histogram.count());
               }
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
            }
View Full Code Here


      runAllCombinations(new Checker()
      {
         @Override
         public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable
         {
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            StatsCollector statsCollector = new BasicStatsCollector();
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = new TcpReceiver(null,getFailFast());
               adaptor.setStatsCollector(statsCollector);
               StringListener receiver = new StringListener();
               adaptor.setListener(receiver);
               factory = makeSenderFactory(false,statsCollector,batchOutgoingMessagesDelayMillis); // distruptible sender factory

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
               sender.send("Hello".getBytes());
              
               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() == 0;)
                  Thread.sleep(1);
               assertEquals(1,receiver.numMessages.get());

               // verify everything came over ok.
               assertEquals(1,receiver.receivedStringMessages.size());
               assertEquals("Hello",receiver.receivedStringMessages.iterator().next());
               adaptor.stop();
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
            }
View Full Code Here

            // we're going to batch no matter what the parameter says.
            // We want the batching timeout to be really small
            batchOutgoingMessagesDelayMillis = 175;
           
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
           
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = new TcpReceiver(null,getFailFast());
               adaptor.setStatsCollector(statsCollector);
               StringListener receiver = new StringListener();
               adaptor.setListener(receiver);
              
               // we want to keep track of the number of bytes written
               final long[] flushByteCounts = new long[4]; //
                    
               factory = makeSenderFactory(new BatchingOutputStreamWatcher(flushByteCounts),
                     statsCollector,batchOutgoingMessagesDelayMillis);

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
              
               // send messageBytes
               byte[] messageBytes = "Hello".getBytes();
               int sentBytesPerMessage = messageBytes.length + tcpTransportHeaderSize;
              
               sender.send(messageBytes);
               Thread.sleep(batchOutgoingMessagesDelayMillis * 2);
               sender.send(messageBytes);
               sender.send(messageBytes);
               Thread.sleep(batchOutgoingMessagesDelayMillis * 2);
               sender.send(messageBytes);
              
               // now numBytesLastFlush should be set to the num of bytes that were last flushed.
               // numBytesSent should be the total bytes, even those still in the buffer.
               // Therefore numBytesSent - numBytesLastFlush should be the number of bytes waiting.
               // These are asserted below.
              
               // we've now sent one message more than what's required to cause a flush.
              
               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() < 4;)
                  Thread.sleep(1);
               Thread.sleep(10);
               assertEquals(4,receiver.numMessages.get());

               // verify everything came over ok.
               assertEquals(1,receiver.receivedStringMessages.size());
               assertEquals("Hello",receiver.receivedStringMessages.iterator().next());
              
               assertEquals(sentBytesPerMessage,flushByteCounts[0]);
               assertEquals(sentBytesPerMessage * 2,flushByteCounts[1]);
               assertEquals(sentBytesPerMessage,flushByteCounts[2]);
               assertEquals(0, flushByteCounts[3]);
              
               // verify the histogram
               Histogram histogram = ((TcpSender)sender).getBatchingHistogram();
               assertEquals(calcMean(1,2,1),histogram.mean(),0.0000001);
               assertEquals(3,histogram.count());
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
              
               statsCollector.stop();
View Full Code Here

            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination(){});

            // we're going to batch no matter what the parameter says.
            batchOutgoingMessagesDelayMillis = 10000;
           
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
           
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = new TcpReceiver(null,getFailFast());
               adaptor.setStatsCollector(statsCollector);
               StringListener receiver = new StringListener();
               adaptor.setListener(receiver);
              
               // we want to keep track of the number of bytes written
               final long[] flushByteCounts = new long[2]; // This should be all that's needed
                    
               factory = makeSenderFactory(new BatchingOutputStreamWatcher(flushByteCounts),
                     statsCollector,batchOutgoingMessagesDelayMillis);

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
              
               int mtu = ((TcpSender)sender).getMtu();
              
               // send enough messages to get one through
               byte[] messageBytes = "Hello".getBytes();
               int numMessagesSent = 0;
               int numBytesSent = 0;
               int numBytesLastFlush = 0;
               while (numBytesSent < mtu)
               {
                  sender.send(messageBytes);
                  numBytesLastFlush = numBytesSent;
                  numBytesSent += messageBytes.length + tcpTransportHeaderSize;
                  numMessagesSent++;
               }
              
               // now numBytesLastFlush should be set to the num of bytes that were last flushed.
               // numBytesSent should be the total bytes, even those still in the buffer.
               // Therefore numBytesSent - numBytesLastFlush should be the number of bytes waiting.
               // These are asserted below.
              
               // we've now sent one message more than what's required to cause a flush.
              
               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() < numMessagesSent;)
                  Thread.sleep(1);
               Thread.sleep(10);
               assertEquals(numMessagesSent,receiver.numMessages.get());

               // verify everything came over ok.
               assertEquals(1,receiver.receivedStringMessages.size());
               assertEquals("Hello",receiver.receivedStringMessages.iterator().next());
              
               assertEquals(numBytesLastFlush,flushByteCounts[0]);
               assertEquals(numBytesSent - numBytesLastFlush, flushByteCounts[1]);
              
               // verify the histogram
               Histogram histogram = ((TcpSender)sender).getBatchingHistogram();
               assertEquals(calcMean((numMessagesSent - 1),1),histogram.mean(),0.0000001);
               assertEquals(2,histogram.count());
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
              
               statsCollector.stop();
View Full Code Here

            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination(){});

            // we're going to batch no matter what the parameter says.
            batchOutgoingMessagesDelayMillis = 10000;
           
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            TcpReceiver adaptor2 = null;
           
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = new TcpReceiver(null,getFailFast());
               adaptor2 = new TcpReceiver(null,getFailFast());
               adaptor.setStatsCollector(statsCollector);
               StringListener receiver = new StringListener();
               adaptor.setListener(receiver);
              
               // we want to keep track of the number of bytes written
               final long[] flushByteCounts = new long[2]; // This should be all that's needed
                    
               factory = makeSenderFactory(new BatchingOutputStreamWatcher(flushByteCounts),
                     statsCollector,batchOutgoingMessagesDelayMillis);

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination
               Destination destination2 = adaptor2.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
               factory.getSender(destination2)// create a second sender to make sure the historgram acts correctly
              
               int mtu = ((TcpSender)sender).getMtu();
              
               // now create a message larger than the mtu by 10%
               Random random = new Random();
               byte[] messageBytes = new byte[(int)(mtu * 1.1)];
               for (int i = 0; i < messageBytes.length; i++)
                  messageBytes[i] = (byte)charSet.charAt(random.nextInt(charSet.length()));
              
               // send the message ... it should be sent without delay.
               sender.send(messageBytes);

               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() == 0;)
                  Thread.sleep(1);
               Thread.sleep(10);
               assertEquals(1,receiver.numMessages.get());

               // verify everything came over ok.
               assertEquals(1,receiver.receivedStringMessages.size());
              
               assertEquals(messageBytes.length + tcpTransportHeaderSize,flushByteCounts[0]);
               assertEquals(0, flushByteCounts[1]);
              
               // verify the histogram
               Histogram histogram = ((TcpSender)sender).getBatchingHistogram();
               assertEquals(1.0D,histogram.mean(),0.0000001);
               assertEquals(1,histogram.count());
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
              
               if (adaptor2 != null)
View Full Code Here

            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination(){});

            // we're going to batch no matter what the parameter says.
            batchOutgoingMessagesDelayMillis = 10000;
           
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
           
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = new TcpReceiver(null,getFailFast());
               adaptor.setStatsCollector(statsCollector);
               StringListener receiver = new StringListener();
               adaptor.setListener(receiver);
              
               // we want to keep track of the number of bytes written
               final long[] flushByteCounts = new long[4]; // This should be all that's needed
                    
               factory = makeSenderFactory(new BatchingOutputStreamWatcher(flushByteCounts),
                     statsCollector,batchOutgoingMessagesDelayMillis);

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               Sender sender = factory.getSender(destination);
              
               int mtu = ((TcpSender)sender).getMtu();
              
               // now create a message larger than the mtu by 10%
               Random random = new Random();
               byte[] largeMessageBytes = new byte[(int)(mtu * 1.1)];
               for (int i = 0; i < largeMessageBytes.length; i++)
                  largeMessageBytes[i] = (byte)charSet.charAt(random.nextInt(charSet.length()));
              
               byte[] messageBytes = "Hello".getBytes();
              
               // send the message ... it should be sent without delay.
               sender.send(largeMessageBytes); // this should flush everything
               sender.send(messageBytes); // this should wait for another message.
               sender.send(messageBytes); // this should wait for another message.
               sender.send(largeMessageBytes); // this should flush everything

               // wait for it to be received.
               for (long endTime = System.currentTimeMillis() + baseTimeoutMillis;
                     endTime > System.currentTimeMillis() && receiver.numMessages.get() < 4;)
                  Thread.sleep(1);
               Thread.sleep(10);
               assertEquals(4,receiver.numMessages.get());

               // verify everything came over ok.
               assertEquals(2,receiver.receivedStringMessages.size());
              
               assertEquals(largeMessageBytes.length + tcpTransportHeaderSize,flushByteCounts[0]);
               assertEquals((messageBytes.length + tcpTransportHeaderSize) * 2, flushByteCounts[1]);
               assertEquals(largeMessageBytes.length + tcpTransportHeaderSize,flushByteCounts[2]);
               assertEquals(0,flushByteCounts[3]);
              
               // verify the histogram
               Histogram histogram = ((TcpSender)sender).getBatchingHistogram();
               assertEquals(calcMean(1,2,1),histogram.mean(),0.0000001);
               assertEquals(3,histogram.count());
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
              
               statsCollector.stop();
View Full Code Here

        
         private void runCheck(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable
         {
            final StatsCollector statsCollector = new StatsCollectorFactoryCoda().createStatsCollector(new ClusterId("test", "test-cluster"), new Destination(){});

            SenderFactory factory = null;
            TcpReceiver adaptor = null;
           
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = new TcpReceiver(null,getFailFast());
               adaptor.setStatsCollector(statsCollector);
              
               // we want to keep track of the number of bytes written
               factory = makeSenderFactory(new OutputStreamFactory() {
                  @Override
                  public OutputStream makeOutputStream(final OutputStream socketOutputStream, final Socket socket) throws IOException
                  {
                     return new OutputStream()
                     {
                        @Override
                        public void write(int b) {  }
                       
                        public void write(byte b[], int off, int len) throws IOException { throw new IOException("Fake IOException"); }
                     };
                  }
               }, statsCollector,batchOutgoingMessagesDelayMillis);

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               TcpSender sender = (TcpSender)factory.getSender(destination);
              
               BlockingQueue<byte[]> internalQueue = sender.sendingQueue;
              
               int mtu = sender.getMtu();
              
               // send enough messages to get one through
               byte[] messageBytes = "Hello".getBytes();
               int numMessagesSent = 0;
               int numBytesSent = 0;
               while (true)
               {
                  int nextBytesSent = numBytesSent + messageBytes.length + tcpTransportHeaderSize;
                  if (nextBytesSent > mtu)
                     break; // don't do the send if we're going to go over the mtu
                  sender.send(messageBytes);
                  numBytesSent += messageBytes.length + tcpTransportHeaderSize;
                  numMessagesSent++;
               }
              
               // give the sender thread time to get the queued messages into the output buffer.
               assertTrue(TestUtils.poll(baseTimeoutMillis, internalQueue,
                     new TestUtils.Condition<BlockingQueue<byte[]>> () { public boolean conditionMet(BlockingQueue<byte[]> o) { return o.size() == 0; }}));
              
               adaptor.stop(); // rip out the downstream to avoid reconnects
               Thread.sleep(200); // give it some time to stop.
              
               // now make it do the send which should fail.
               sender.send(messageBytes);
               numMessagesSent++;
              
               // now wait for a few (potential) failures.
               assertTrue(TestUtils.poll(baseTimeoutMillis, numMessagesSent, new TestUtils.Condition<Integer>()
               {
                  @Override public boolean conditionMet(Integer numMessagesSent) { return numMessagesSent == (int)((MetricGetters)statsCollector).getMessagesNotSentCount()}
               }));
              
               // wait some time, then double check
               Thread.sleep(200);
              
               // now make sure there wheren't any changes that came in after
               assertEquals(numMessagesSent,(int)((MetricGetters)statsCollector).getMessagesNotSentCount());
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
              
               statsCollector.stop();
View Full Code Here

      runAllCombinations(new Checker()
      {
         @Override
         public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable
         {
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            final byte[] message = new byte[1024 * 8];
            BasicStatsCollector statsCollector = new BasicStatsCollector();
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = makeHangingReceiver();
              
               adaptor.setStatsCollector(statsCollector);
               final StringListener receiver = new StringListener();
               adaptor.setListener(receiver);
               factory = makeSenderFactory(false,statsCollector,batchOutgoingMessagesDelayMillis);

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               // send a message
               final TcpSender sender = (TcpSender)factory.getSender(destination);
               sender.setTimeoutMillis(100);
              
               // wait for it to fail
               assertTrue(TestUtils.poll(baseTimeoutMillis, statsCollector, new TestUtils.Condition<BasicStatsCollector>()
               {
                  @Override
                  public boolean conditionMet(BasicStatsCollector o) throws Throwable
                  {
                     // this should eventually fail
                     sender.send(message); // this should work
                     return o.getMessagesNotSentCount() > 0;
                  }
               }));
              
               Thread.sleep(100);

               Long numMessagesReceived = receiver.numMessages.get();
               assertTrue(TestUtils.poll(baseTimeoutMillis, numMessagesReceived, new TestUtils.Condition<Long>()
               {
                  @Override
                  public boolean conditionMet(Long o) throws Throwable
                  {
                     // this should eventually fail
                     sender.send("Hello".getBytes()); // this should work
                     return receiver.numMessages.get() > o.longValue();
                  }
               }));
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
            }

View Full Code Here

   @Test
   public void transportLargeMessage() throws Throwable
   {
      int port = -1;
      boolean localhost = false;
      SenderFactory factory = null;
      TcpReceiver adaptor = null;
      TcpSenderFactory senderFactory = null;
     
      try
      {
         //===========================================
         // setup the sender and receiver
         adaptor = new TcpReceiver(null,getFailFast());
         factory = makeSenderFactory(false,null,500); // distruptible sender factory
         receiveLargeMessageLatch = new CountDownLatch(1);
         adaptor.setListener( new Listener()
         {
            @Override
            public boolean onMessage( byte[] messageBytes, boolean failfast ) throws MessageTransportException
            {
               receivedByteArrayMessage = messageBytes;
               receiveLargeMessageLatch.countDown();
               return true;
            }

            @Override
            public void shuttingDown() { }
         } );

         if (port <= 0) adaptor.setUseEphemeralPort(true);
         if (port > 0) adaptor.setPort(port);
         if (localhost) adaptor.setUseLocalhost(localhost);
         //===========================================

         adaptor.start(); // start the adaptor
         adaptor.start(); // double start ... just want more coverage.

         Destination destination = adaptor.getDestination(); // get the destination
         if (port > 0) adaptor.setPort(port);
         if (localhost) adaptor.setUseLocalhost(localhost);

         senderFactory = makeSenderFactory(false,null,500);

         int size = 1024*1024*10;
         byte[] tosend = new byte[size];
         for (int i = 0; i < size; i++)
            tosend[i] = (byte)i;

         TcpSender sender = (TcpSender)senderFactory.getSender( destination );
         sender.setTimeoutMillis(100000); // extend the timeout because of the larger messages
         sender.send( tosend );

         assertTrue(receiveLargeMessageLatch.await(1,TimeUnit.MINUTES));

         assertArrayEquals( tosend, receivedByteArrayMessage );
        
      }
      finally
      {
         if (factory != null)
            factory.stop();

         if (senderFactory != null)
            senderFactory.stop();

         if (adaptor != null)
View Full Code Here

      runAllCombinations(new Checker()
      {
         @Override
         public void check(int port, boolean localhost, long batchOutgoingMessagesDelayMillis) throws Throwable
         {
            SenderFactory factory = null;
            TcpReceiver adaptor = null;
            BasicStatsCollector statsCollector = new BasicStatsCollector();
            try
            {
               //===========================================
               // setup the sender and receiver
               adaptor = new TcpReceiver(null,getFailFast());
               adaptor.setStatsCollector(statsCollector);
               factory = makeSenderFactory(true,statsCollector, batchOutgoingMessagesDelayMillis); // distruptible sender factory

               if (port > 0) adaptor.setPort(port);
               if (localhost) adaptor.setUseLocalhost(localhost);
               //===========================================

               adaptor.start(); // start the adaptor
               Destination destination = adaptor.getDestination(); // get the destination

               //===========================================
               // Start up sender threads and save the off
               ArrayList<Thread> threadsToJoinOn = new ArrayList<Thread>();
               SenderRunnable[] senders = new SenderRunnable[numThreads];
               for (int i = 0; i < numThreads; i++)
                  threadsToJoinOn.add(i,new Thread(
                        senders[i] = new SenderRunnable(destination,i,factory),"Test Sender for " + i));

               for (Thread thread : threadsToJoinOn)
                  thread.start();
               //===========================================

               //===========================================
               // check that one sender has failed since this is disruptable.
               assertTrue(TestUtils.poll(baseTimeoutMillis, statsCollector, new TestUtils.Condition<BasicStatsCollector>()
               {
                  @Override
                  public boolean conditionMet(BasicStatsCollector o) throws Throwable
                  {
                     return o.getMessagesNotSentCount() > 0;
                  }
               }));
               //===========================================

               //===========================================
               // check that ONLY one failed (the others didn't) when we're not batching. Otherwise
               //  more may fail.
               Thread.sleep(10);
               if (batchOutgoingMessagesDelayMillis >= 0) // if we're batching then we only expect a failure but we don't know how many
                  assertTrue(statsCollector.getMessagesNotSentCount() > 0);
               else
                  assertEquals(1,statsCollector.getMessagesNotSentCount());
               //===========================================
              
               // all of the counts should increase.
               long[] curCounts = new long[numThreads];
               int i = 0;
               for (SenderRunnable sender : senders)
                  curCounts[i++] = sender.sentMessageCount.get();
              
               // ==========================================
               // go until they are all higher. The Senders should still be running
               // and sending successfully (only one failed once) so all counts should
               // be increasing.
               boolean allHigher = false;
               for (long endTime = System.currentTimeMillis() + numThreads * (baseTimeoutMillis); endTime > System.currentTimeMillis() && !allHigher;)
               {
                  allHigher = true;
                  Thread.sleep(1);
                  i = 0;
                  for (SenderRunnable sender : senders)
                     if (curCounts[i++] >= sender.sentMessageCount.get())
                        allHigher = false;
               }
              
               assertTrue(allHigher);
               // ==========================================

               // ==========================================
               // Stop the senders.
               for (SenderRunnable sender : senders)
                  sender.keepGoing.set(false);
              
               // wait until all threads are stopped
               for (Thread t : threadsToJoinOn)
                  t.join(5000);
              
               // make sure everything actually stopped.
               for (SenderRunnable sender : senders)
                  assertTrue(sender.isStopped.get());
               // ==========================================
              
            }
            finally
            {
               if (factory != null)
                  factory.stop();
              
               if (adaptor != null)
                  adaptor.stop();
            }
         }
View Full Code Here

TOP

Related Classes of com.nokia.dempsy.messagetransport.SenderFactory

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.