Package org.apache.camel.processor.Throttler

Examples of org.apache.camel.processor.Throttler.TimeSlot


    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(context, null, constant(3), 1000, null, false);
        // calculate will assign a new slot
        throttler.calculateDelay(new DefaultExchange(context));
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (3 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
        assertTrue(slot.isActive());

        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here


    public void testTimeSlotCalculusForPeriod() throws InterruptedException {
        Throttler throttler = new Throttler(context, null, constant(3), 1000, null, false);
        throttler.calculateDelay(new DefaultExchange(context));

        TimeSlot slot = throttler.getSlot();
        assertNotNull(slot);
        assertSame(slot, throttler.nextSlot());

        // we've only used up two of three slots, but now we introduce a time delay
        // so to make the slot not valid anymore
        Thread.sleep((long) (1.5 * 1000));
        assertFalse(slot.isActive());
        assertNotSame(slot, throttler.nextSlot());
    }
View Full Code Here

        assertTrue("Should take at least " + minimumTime + "ms", System.currentTimeMillis() - start >= minimumTime);
    }
   
    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(null, 2, 1000);
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (2 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
       
        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here

        assertTrue("Should take at least " + minimumTime + "ms", System.currentTimeMillis() - start >= minimumTime);
    }
   
    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(null, 2, 1000, null);
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (2 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
       
        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here

        assertTrue("Should take at least " + minimumTime + "ms, was: " + delta, delta >= minimumTime);
    }

    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(null, 2, 1000, null);
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (2 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
       
        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here

        assertTrue("Should take at least " + minimumTime + "ms", System.currentTimeMillis() - start >= minimumTime);
    }
   
    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(null, 2, 1000);
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (2 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
       
        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here

    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(null, constant(3), 1000, null);
        // calculate will assign a new slot
        throttler.calculateDelay(new DefaultExchange(context));
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (3 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
       
        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here

    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(context, null, constant(3), 1000, null, false);
        // calculate will assign a new slot
        throttler.calculateDelay(new DefaultExchange(context));
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (3 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
       
        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here

    public void testTimeSlotCalculus() throws Exception {
        Throttler throttler = new Throttler(context, null, constant(3), 1000, null, false, false);
        // calculate will assign a new slot
        throttler.calculateDelay(new DefaultExchange(context));
        TimeSlot slot = throttler.nextSlot();
        // start a new time slot
        assertNotNull(slot);
        // make sure the same slot is used (3 exchanges per slot)
        assertSame(slot, throttler.nextSlot());
        assertTrue(slot.isFull());
        assertTrue(slot.isActive());

        TimeSlot next = throttler.nextSlot();
        // now we should have a new slot that starts somewhere in the future
        assertNotSame(slot, next);
        assertFalse(next.isActive());
    }
View Full Code Here

    public void testTimeSlotCalculusForPeriod() throws InterruptedException {
        Throttler throttler = new Throttler(context, null, constant(3), 1000, null, false, false);
        throttler.calculateDelay(new DefaultExchange(context));

        TimeSlot slot = throttler.getSlot();
        assertNotNull(slot);
        assertSame(slot, throttler.nextSlot());

        // we've only used up two of three slots, but now we introduce a time delay
        // so to make the slot not valid anymore
        Thread.sleep((long) (1.5 * 1000));
        assertFalse(slot.isActive());
        assertNotSame(slot, throttler.nextSlot());
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.processor.Throttler.TimeSlot

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.