Package com.sun.sgs.profile

Examples of com.sun.sgs.profile.ProfileCounter


        if (name == null) {
            throw new NullPointerException("Counter name must not be null");
        }
        String fullName = getCanonicalName(name);
        if (counters.containsKey(fullName)) {
            ProfileCounter oldCounter = counters.get(fullName);
            // Check minLevel and type
            if (oldCounter instanceof AbstractProfileData) {
                AbstractProfileData oldData = (AbstractProfileData) oldCounter;
                ProfileLevel oldLevel = oldData.getMinLevel();
                if (oldLevel != minLevel) {
                    throw new IllegalArgumentException(
                            "Counter with name " + name +
                            " already created, but with level " +  oldLevel);
                }
               
                ProfileDataType oldType = oldData.getType();
                if (oldType != type) {
                    throw new  IllegalArgumentException(
                            "Counter with name " + name +
                            " already created, but with type " +  oldType);
                }
            } else {
                // Can't happen in this implementation
                throw new IllegalArgumentException(
                        "Counter with name " + name +
                        " already created with an unknown type");
            }  
            return oldCounter;
        } else {
            ProfileCounter counter;
            switch (type) {
                case TASK:
                    counter = new TaskProfileCounterImpl(fullName, type,
                                                         minLevel);
                    break;
View Full Code Here


    public void testCounter() 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 ProfileCounter counter =
                cons1.createCounter(name, testType, 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>();

        // The owner for our positive test.  The listener uses this owner
        // to find the ProfileReport for the task in this test.
        final Identity positiveOwner = new DummyIdentity("owner");
        final Identity negativeOwner = new DummyIdentity("other");
        SimpleTestListener test = new SimpleTestListener(
            new CounterReportRunnable(counter.getName(), negativeOwner,
                                      positiveOwner, errorExchanger, 1));
        profileCollector.addListener(test, true);

        // We run with the myOwner because we expect to see the
        // value in the test report.
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    counter.incrementCount();
                }
            }, positiveOwner);

        AssertionError error =
            errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
View Full Code Here

    public void testCounterLevel() throws Exception {
        final String name = "MyCounter";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be updated only at the max level
        final ProfileCounter counter =
                cons1.createCounter(name, testType, ProfileLevel.MAX);
       
        // 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>();

        // The owner for our positive test.  The listener uses this owner
        // to find the ProfileReport for the task in this test.
        final Identity positiveOwner = new DummyIdentity("counterlevel");
        final Identity negativeOwner = new DummyIdentity("counterlevelneg");
        SimpleTestListener test = new SimpleTestListener(
            new CounterReportRunnable(counter.getName(), negativeOwner,
                                      positiveOwner, errorExchanger, 1));
        profileCollector.addListener(test, true);

        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // The default profile level is MIN so we don't expect
                    // to see the counter incremented.
                    counter.incrementCount();
                }
            }, negativeOwner);

        AssertionError error =
            errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
        if (error != null) {
            throw new AssertionError(error);
        }

        cons1.setProfileLevel(ProfileLevel.MAX);
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // Because we bumped the consumer's profile level,
                    // we expect the counter
                    counter.incrementCount();
                }
            }, positiveOwner);
           
        error =
            errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
View Full Code Here

   
   @Test(expected=IllegalArgumentException.class)
    public void testCounterIncrementValueBad() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final ProfileCounter counter =
                cons1.createCounter("my counter",
                                    testType, ProfileLevel.MIN);
       
        counter.incrementCount(-1);
    }
View Full Code Here

        final String name = "counter";
        final int incValue = 5;
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be noted at all profiling levels
        final ProfileCounter counter =
                cons1.createCounter(name, testType, 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>();

        // The owner for our positive test.  The listener uses this owner
        // to find the ProfileReport for the task in this test.
        final Identity positiveOwner = new DummyIdentity("counterinc");
        final Identity negativeOwner = new DummyIdentity("counterincneg");
        SimpleTestListener test = new SimpleTestListener(
            new CounterReportRunnable(counter.getName(),
                                      negativeOwner, positiveOwner,
                                      errorExchanger, incValue));
        profileCollector.addListener(test, true);

        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    counter.incrementCount(incValue);
                }
            }, positiveOwner);

        AssertionError error =
            errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
View Full Code Here

        final String name = "counterforstuff";
        final int incValue = 3;
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be noted at all profiling levels
        final ProfileCounter counter =
                cons1.createCounter(name, testType, 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>();

        // The owner for our positive test.  The listener uses this owner
        // to find the ProfileReport for the task in this test.
        final Identity positiveOwner = new DummyIdentity("countermult");
        final Identity negativeOwner = new DummyIdentity("countermultneg");
        SimpleTestListener test = new SimpleTestListener(
            new CounterReportRunnable(counter.getName(), negativeOwner,
                                      positiveOwner, errorExchanger, incValue));
        profileCollector.addListener(test, true);

        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    for (int i = 0; i < incValue; i++) {
                        counter.incrementCount();
                    }
                }
            }, positiveOwner);

        AssertionError error =
View Full Code Here

        final String name = "counterforstuff";
        final int incValue = 5;
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be noted at all profiling levels
        final ProfileCounter counter =
                cons1.createCounter(name, testType, 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>();

        // The owner for our positive test.  The listener uses this owner
        // to find the ProfileReport for the task in this test.
        final Identity positiveOwner = new DummyIdentity("countermult");
        final Identity negativeOwner = new DummyIdentity("countermultneg");
        SimpleTestListener test = new SimpleTestListener(
            new CounterReportRunnable(counter.getName(),
                                      negativeOwner, positiveOwner,
                                      errorExchanger, incValue));
        profileCollector.addListener(test, true);

        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // We expect to see the counter incremented by 5 total
                    counter.incrementCount(2);
                    counter.incrementCount(3);
                }
            }, positiveOwner);

        AssertionError error =
            errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
View Full Code Here

    public void testTaskCounterMultConsumer() throws Exception {
        final String name = "sharedName";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileConsumer cons2 = collector.getConsumer("c2");
        final ProfileCounter counter1 =
                cons1.createCounter(name, testType, ProfileLevel.MIN);
        final ProfileCounter counter2 =
                cons2.createCounter(name, testType, 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 myOwner = new DummyIdentity("me");
        SimpleTestListener test = new SimpleTestListener(
            new Runnable() {
                public void run() {
                    AssertionError error = null;
                    ProfileReport report = SimpleTestListener.report;
                    if (report.getTaskOwner().equals(myOwner)) {
                        try {
                            Map<String, Long> counts =
                                SimpleTestListener.report.
                                    getUpdatedTaskCounters();
                           
                            System.err.println("+++");
                            for (Map.Entry<String, Long> entry :
                                 counts.entrySet())
                            {
                                System.err.println("+ " + entry.getKey() +
                                                   ", " + entry.getValue());
                            }
                           
                           
                        } catch (AssertionError e) {
                            error = e;
                        }
                    }

                    // Signal that we're done, and return the exception
                    try {
                        errorExchanger.exchange(error);
                    } catch (InterruptedException ignored) {
                        // do nothing
                    }
                }
        });
        profileCollector.addListener(test, true);
       
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    counter1.incrementCount();
                    counter2.incrementCount();
                    counter1.incrementCount();
                }
            }, myOwner);
           
        AssertionError error =
View Full Code Here

    /* -- Counter tests -- */
    @Test(expected=NullPointerException.class)
    public void testCounterTaskBadName() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileCounter c1 =
            cons1.createCounter(null, ProfileDataType.TASK, ProfileLevel.MIN);
    }
View Full Code Here

    }
    @Test(expected=NullPointerException.class)
    public void testCounterAggregateBadName() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileCounter c1 =
            cons1.createCounter(null,
                                ProfileDataType.AGGREGATE, ProfileLevel.MIN);
    }
View Full Code Here

TOP

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

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.