Examples of ProfileSample


Examples of com.sun.sgs.profile.ProfileSample

            throw new NullPointerException("Sample name must not be null");
        }

        String fullName = getCanonicalName(name);
        if (samples.containsKey(fullName)) {
            ProfileSample oldSample = samples.get(fullName);
            // Check minLevel and type
            if (oldSample instanceof AbstractProfileData) {
                AbstractProfileData oldData = (AbstractProfileData) oldSample;
                ProfileLevel oldLevel = oldData.getMinLevel();
                if (oldLevel != minLevel) {
                    throw new IllegalArgumentException(
                            "Sample with name " + name +
                            " already created, but with level " +  oldLevel);
                }
               
                ProfileDataType oldType = oldData.getType();
                if (oldType != type) {
                    throw new  IllegalArgumentException(
                            "Sample with name " + name +
                            " already created, but with type " +  oldType);
                }
            } else {
                // Can't happen in this implementation
                throw new IllegalArgumentException(
                        "Sample with name " + name +
                        " already created with an unknown type");
            }
            return samples.get(fullName);
        } else {
            ProfileSample sample;
            switch (type) {
                case TASK:
                    sample = new TaskProfileSampleImpl(fullName, type,
                                                       minLevel);
                    break;
View Full Code Here

Examples of com.sun.sgs.profile.ProfileSample

            throw new NullPointerException("Sample name must not be null");
        }

        String fullName = getCanonicalName(name);
        if (samples.containsKey(fullName)) {
            ProfileSample oldSample = samples.get(fullName);
            // Check minLevel and type
            if (oldSample instanceof AbstractProfileData) {
                AbstractProfileData oldData = (AbstractProfileData) oldSample;
                ProfileLevel oldLevel = oldData.getMinLevel();
                if (oldLevel != minLevel) {
                    throw new IllegalArgumentException(
                            "Sample with name " + name +
                            " already created, but with level " +  oldLevel);
                }
               
                ProfileDataType oldType = oldData.getType();
                if (oldType != type) {
                    throw new  IllegalArgumentException(
                            "Sample with name " + name +
                            " already created, but with type " +  oldType);
                }
            } else {
                // Can't happen in this implementation
                throw new IllegalArgumentException(
                        "Sample with name " + name +
                        " already created with an unknown type");
            }
            return samples.get(fullName);
        } else {
            ProfileSample sample;
            switch (type) {
                case TASK:
                    sample = new TaskProfileSampleImpl(fullName, type,
                                                       minLevel);
                    break;
View Full Code Here

Examples of com.sun.sgs.profile.ProfileSample

    public void testSample() throws Exception {
        final String name = "sample";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        // Register a counter to be noted at all profiling levels
        final ProfileSample sample =
            cons1.createSample(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 List<Long> testValues = new ArrayList<Long>();
        testValues.add(1L);
        testValues.add(5L);
        testValues.add(-22L);
        // 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("sampleowner");
        final Identity negativeOwner = new DummyIdentity("sampleownerneg");
        SimpleTestListener test = new SimpleTestListener(
            new SampleReportRunnable(sample.getName(),
                                     negativeOwner, positiveOwner,
                                     errorExchanger, testValues));
        profileCollector.addListener(test, true);

        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // We expect to see the test values in listener
                    for (Long v : testValues) {
                        sample.addSample(v);
                    }
                }
            }, positiveOwner);

        AssertionError error =
View Full Code Here

Examples of com.sun.sgs.profile.ProfileSample

    @Test
    public void testSampleLevel() throws Exception {
        final String name = "MySamples";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("cons1");
        final ProfileSample sample =
            cons1.createSample(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>();

        final List<Long> testValues = new ArrayList<Long>();
        testValues.add(101L);
        testValues.add(-22L);
        // 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("samplelevel");
        final Identity negativeOwner = new DummyIdentity("samplelevelneg");
        SimpleTestListener test = new SimpleTestListener(
            new SampleReportRunnable(sample.getName(),
                                     negativeOwner, positiveOwner,
                                     errorExchanger, testValues));
        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 samples.
                    for (Long v : testValues) {
                        sample.addSample(v);
                    }
                }
            }, 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 samples to appear
                    for (Long v : testValues) {
                        sample.addSample(v);
                    }
                }
            }, positiveOwner);
           
        error = errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
View Full Code Here

Examples of com.sun.sgs.profile.ProfileSample

    @Test
    public void testSampleLevelChange() throws Exception {
        final String name = "samples";
        ProfileCollector collector = getCollector(serverNode);
        final ProfileConsumer cons1 = collector.getConsumer("c1");
        final ProfileSample sample =
            cons1.createSample(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>();

        final List<Long> testValues = new ArrayList<Long>();
        testValues.add(101L);
        testValues.add(-22L);
        // 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("samplechange");
        final Identity negativeOwner = new DummyIdentity("samplechangeneg");
        SimpleTestListener test = new SimpleTestListener(
            new SampleReportRunnable(sample.getName(),
                                     negativeOwner, positiveOwner,
                                     errorExchanger, testValues));
        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 samples.
                    for (Long v : testValues) {
                        sample.addSample(v);
                    }
                }
            }, negativeOwner);

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

        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // We don't expect to see this sample in the report;
                    // the level was still too low.
                    sample.addSample(999L);
                    cons1.setProfileLevel(ProfileLevel.MAX);
                    for (Long v : testValues) {
                        sample.addSample(v);
                    }
                    cons1.setProfileLevel(ProfileLevel.MIN);
                    // Should not see this one, either
                    sample.addSample(-22L);
                }
            }, positiveOwner);
           
        error = errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
        if (error != null) {
View Full Code Here

Examples of com.sun.sgs.profile.ProfileSample

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

Examples of com.sun.sgs.profile.ProfileSample

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

Examples of com.sun.sgs.profile.ProfileSample

    }
    @Test(expected=NullPointerException.class)
    public void testSampleTaskAggregateBadName() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileSample s1 =
            cons1.createSample(null,
                               ProfileDataType.TASK_AND_AGGREGATE,
                               ProfileLevel.MIN);
    }
View Full Code Here

Examples of com.sun.sgs.profile.ProfileSample

        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileConsumer cons2 = collector.getConsumer("c2");
        String name = "mySample";
        {
            ProfileSample samp1 =
                cons1.createSample(name, ProfileDataType.TASK,
                                   ProfileLevel.MAX);
            ProfileSample samp2 =
                cons2.createSample(name, ProfileDataType.TASK,
                                   ProfileLevel.MAX);
            assertFalse(samp1.getName().equals(samp2.getName()));
            assertTrue(samp1.getName().contains(name));
            assertTrue(samp2.getName().contains(name));
        }
       
        name = "aggSample";
        {
            ProfileSample samp1 =
                cons1.createSample(name, ProfileDataType.AGGREGATE,
                                   ProfileLevel.MAX);
            ProfileSample samp2 =
                cons2.createSample(name, ProfileDataType.AGGREGATE,
                                   ProfileLevel.MAX);
            assertFalse(samp1.getName().equals(samp2.getName()));
            assertTrue(samp1.getName().contains(name));
            assertTrue(samp2.getName().contains(name));
        }
       
        name = "bothSample";
        {
            ProfileSample samp1 =
                cons1.createSample(name, ProfileDataType.TASK_AND_AGGREGATE,
                                   ProfileLevel.MAX);
            ProfileSample samp2 =
                cons2.createSample(name, ProfileDataType.TASK_AND_AGGREGATE,
                                   ProfileLevel.MAX);
            assertFalse(samp1.getName().equals(samp2.getName()));
            assertTrue(samp1.getName().contains(name));
            assertTrue(samp2.getName().contains(name));
        }
    }
View Full Code Here

Examples of com.sun.sgs.profile.ProfileSample

    @Test
    public void testSampleTwice() throws Exception {
        final String name = "mySamples";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileSample s1 =
                cons1.createSample(name, ProfileDataType.TASK,
                                   ProfileLevel.MAX);

        // Try creating with same name and parameters
        ProfileSample s2 =
                cons1.createSample(name, ProfileDataType.TASK,
                                   ProfileLevel.MAX);
        assertSame(s1, s2);
       
        // Try creating with same name and different parameters
        try {
            ProfileSample s3 =
                cons1.createSample(name, ProfileDataType.AGGREGATE,
                                   ProfileLevel.MAX);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
        try {
            ProfileSample s3 =
                cons1.createSample(name, ProfileDataType.TASK_AND_AGGREGATE,
                                   ProfileLevel.MAX);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
        try {
            ProfileSample s3 =
                cons1.createSample(name, ProfileDataType.TASK,
                                   ProfileLevel.MIN);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
        try {
            ProfileSample s3 =
                cons1.createSample(name, ProfileDataType.TASK,
                                   ProfileLevel.MEDIUM);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
        {
            ProfileSample s3 =
                cons1.createSample(name, ProfileDataType.TASK,
                                   ProfileLevel.MAX);
            assertSame(s1, s3);  
        }
       
        final String aggName = "aggregateSample";
        {
            ProfileSample s3 =
                 cons1.createSample(aggName, ProfileDataType.AGGREGATE,
                                    ProfileLevel.MAX);
           
            AggregateProfileSample s4 = (AggregateProfileSample)
                 cons1.createSample(aggName, ProfileDataType.AGGREGATE,
                                    ProfileLevel.MAX);
            assertSame(s3, s4);
        }
       
        final String taskAggName = "task aggregate sample";
        {
            ProfileSample s3 =
                cons1.createSample(taskAggName,
                                   ProfileDataType.TASK_AND_AGGREGATE,
                                   ProfileLevel.MAX);
            ProfileSample s4 =
                 cons1.createSample(taskAggName,
                                    ProfileDataType.TASK_AND_AGGREGATE,
                                    ProfileLevel.MAX);
            assertSame(s3, s4);
        }
       
        // Try creating with a different name
        ProfileSample s5 =
            cons1.createSample("somethingelse", ProfileDataType.TASK,
                               ProfileLevel.MAX);
        assertNotSame(s1, s5);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.