Package com.comcast.cmb.common.util

Examples of com.comcast.cmb.common.util.ValueAccumulator


    }

    @Test
    public void testAccumulator() {
        ValueAccumulator ac = new ValueAccumulator();
        ac.initializeAllCounters();
        ac.addToCounter(AccumulatorName.UnitTestTime, 10L);
        long val = ac.getCounter(AccumulatorName.UnitTestTime);
        if (val != 10L) {
            fail("should have gotten 10 back. Got:" + val);
        }
    }
View Full Code Here


    volatile boolean fail = false;
    Random r = new Random();
    @Test
    public void testAccumulatorConcurrent() throws Exception {
        final ValueAccumulator ac = new ValueAccumulator();
        ExecutorService executor = Executors.newFixedThreadPool(10);
        Future []jobs = new Future[10];
        for (int i = 0; i <10; i++) {
            jobs[i] = executor.submit(new Runnable() {               
                @Override
                public void run() {
                    ac.initializeAllCounters();
                    long val = 0;
                    while (!Thread.interrupted()) {
                        ac.addToCounter(AccumulatorName.UnitTestTime, 1);
                        long newVal = ac.getCounter(AccumulatorName.UnitTestTime);
                        if (newVal != val + 1) {
                            log.error("Should have incremented by 1. Expoected val:" + (val + 1) + " instead got:" + newVal);
                            fail = true;
                            fail("Should have incremented by 1. Expoected val:" + (val + 1) + " instead got:" + newVal);
                        }
View Full Code Here

TOP

Related Classes of com.comcast.cmb.common.util.ValueAccumulator

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.