Package com.nokia.dempsy.monitoring

Examples of com.nokia.dempsy.monitoring.StatsCollector


      runAllCombinations(new Checker()
      {
         @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
            {
View Full Code Here


         @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());
View Full Code Here

      runAllCombinations(new Checker()
      {
         @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(){});

            // 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();
            }

         }
        
         @Override
View Full Code Here

      runAllCombinations(new Checker()
      {
         @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(){});

            // 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();
            }

         }
        
         @Override
View Full Code Here

      runAllCombinations(new Checker()
      {
         @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(){});

            // 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)
                  adaptor2.stop();
              
               statsCollector.stop();
            }

         }
        
         @Override
View Full Code Here

      runAllCombinations(new Checker()
      {
         @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(){});

            // 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();
            }

         }
        
         @Override
View Full Code Here

            runCheck(port,localhost,0);
         }
        
         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();
            }
         }
        
         @Override
         public String toString() { return "transportBatchingMessageLargerAndSmallerMixed"; }
View Full Code Here

//----------------------------------------------------------------------------
  
   public MpContainer setupContainer(Object prototype) throws ContainerException
   {
      DummyDispatcher dispatcher = new DummyDispatcher();
      StatsCollector stats = new StatsCollectorCoda(new ClusterId("test", "test"), new StatsCollectorFactoryCoda().getNamingStrategy());
      JavaSerializer<Object> serializer = new JavaSerializer<Object>();

      manager = new MpContainer(new ClusterId("test","test"));
      manager.setDispatcher(dispatcher);
      manager.setStatCollector(stats);
View Full Code Here

  
   @After
   public void tearDown()
   {
      // Destroy any counts, so we start fresh on the next test
      StatsCollector stats = manager.getStatsCollector();
      if (stats != null)
      {
         ((StatsCollectorCoda)stats).stop();
      }
   }
View Full Code Here

         dempsy.start();

         Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId(FullApplication.class.getSimpleName(),MyAdaptor.class.getSimpleName()));
         Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0);
         final StatsCollector collector = node.getStatsCollector();

         // this checks that the throughput works.
         assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>()
         {
            @Override
View Full Code Here

TOP

Related Classes of com.nokia.dempsy.monitoring.StatsCollector

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.