Package com.sun.sgs.profile

Examples of com.sun.sgs.profile.AggregateProfileCounter


    public void testAggregateProfileCounter() throws Exception {
        final String name = "counter";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be noted at all profiling levels
        final AggregateProfileCounter counter =
                (AggregateProfileCounter)
                    cons1.createCounter(name, testType, ProfileLevel.MIN);
       
        counter.incrementCount();
        assertEquals(1, counter.getCount());
       
        counter.incrementCount(4);
        assertEquals(5, counter.getCount());
       
        counter.clearCount();
        assertEquals(0, counter.getCount());
       
        counter.incrementCount(2);
        assertEquals(2, counter.getCount());
    }
View Full Code Here


    public void testAggregateProfileCounterNotInTaskReport() throws Exception {
        final String name = "counter";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be noted at all profiling levels
        final AggregateProfileCounter counter =
                (AggregateProfileCounter)
                    cons1.createCounter(name,
                                        ProfileDataType.AGGREGATE,
                                        ProfileLevel.MIN);
       
        // Because the listener is running in a different thread, JUnit
        // is not able to report the assertions and failures.
        // Use an exchanger to synchronize between the threads and communicate
        // any problems.
        final Exchanger<AssertionError> errorExchanger =
                new Exchanger<AssertionError>();

        final Identity positiveOwner = new DummyIdentity("never-used");
        final Identity negativeOwner = new DummyIdentity("neg-owner");
        SimpleTestListener test = new SimpleTestListener(
            new CounterReportRunnable(name, negativeOwner, positiveOwner,
                                      errorExchanger, 1));
        profileCollector.addListener(test, true);

        // We don't expect to see the counter updated in the task report
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    counter.incrementCount();
                }
            }, negativeOwner);

        AssertionError error =
                errorExchanger.exchange(null, 100, TimeUnit.MILLISECONDS);
        if (error != null) {
            // Rethrow with the original error as the cause so we see
            // both stack traces.
            throw new AssertionError(error);
        }
       
        // But we do expect to see the counter updated globally!
        assertEquals(1L, counter.getCount());
    }
View Full Code Here

    public void testTaskAggregateProfileCounter() throws Exception {
        final String name = "counter";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be noted at all profiling levels
        final AggregateProfileCounter counter =
                (AggregateProfileCounter)
                    cons1.createCounter(name,
                                        ProfileDataType.TASK_AND_AGGREGATE,
                                        ProfileLevel.MIN);
       
        // Because the listener is running in a different thread, JUnit
        // is not able to report the assertions and failures.
        // Use an exchanger to synchronize between the threads and communicate
        // any problems.
        final Exchanger<AssertionError> errorExchanger =
                new Exchanger<AssertionError>();

        // Set up a couple of test listeners, each listening for a different
        // task owner
        final Identity positiveOwner = new DummyIdentity("hello");
        final Identity negativeOwner = new DummyIdentity("neg-hello");
        SimpleTestListener test = new SimpleTestListener(
            new CounterReportRunnable(counter.getName(),
                                      negativeOwner, positiveOwner,
                                      errorExchanger, 1));
        profileCollector.addListener(test, true);
       
        // We expect to see the counter updated in the task report
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    counter.incrementCount();
                }
            }, positiveOwner);

        AssertionError error =
                errorExchanger.exchange(null, 100, TimeUnit.MILLISECONDS);
        if (error != null) {
            // Rethrow with the original error as the cause so we see
            // both stack traces.
            throw new AssertionError(error);
        }
       
        // We expect to see the counter updated in the task report,
        // and it should be independent of the last report.
        // Note that we assume the profile listener for the last task
        // has already been called at this point.  This is safe, because
        // we're using the ErrorExchanger to ensure the profile report for
        // the above task has been seen.
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    counter.incrementCount();
                }
            }, positiveOwner);

        error = errorExchanger.exchange(null, 100, TimeUnit.MILLISECONDS);
        if (error != null) {
            // Rethrow with the original error as the cause so we see
            // both stack traces.
            throw new AssertionError(error);
        }
       
        // And we expect to see the counter aggregated
        assertEquals(2, counter.getCount());
    }
View Full Code Here

TOP

Related Classes of com.sun.sgs.profile.AggregateProfileCounter

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.