Package com.sun.sgs.profile

Examples of com.sun.sgs.profile.AggregateProfileSample


  
   @Test(expected=IllegalArgumentException.class)
   public void testAggregateProfileNegSmoothing() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final AggregateProfileSample samp =
                (AggregateProfileSample)
                    cons1.createSample("foo", testType, ProfileLevel.MIN);
        samp.setSmoothingFactor(-1.1);
   }
View Full Code Here


  
   @Test(expected=IllegalArgumentException.class)
   public void testAggregateProfileBadSmoothing() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final AggregateProfileSample samp =
                (AggregateProfileSample)
                    cons1.createSample("foo", testType, ProfileLevel.MIN);
        samp.setSmoothingFactor(5.0);
   }
View Full Code Here

  
   @Test
   public void testSetSmoothingFactor() throws Exception {
       ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final AggregateProfileSample samp =
                (AggregateProfileSample)
                    cons1.createSample("bar", testType, ProfileLevel.MIN);
        double smooth = 0.5;
        samp.setSmoothingFactor(smooth);
        assertTrue(smooth == samp.getSmoothingFactor());
       
        smooth = 0.9;
        samp.setSmoothingFactor(smooth);
        assertTrue(smooth == samp.getSmoothingFactor());
   }
View Full Code Here

   @Test
   public void testAggregateProfileSample() throws Exception {
        final String name = "sample";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final AggregateProfileSample samp =
                (AggregateProfileSample)
                    cons1.createSample(name, testType, ProfileLevel.MIN);
       
        assertEquals(0, samp.getNumSamples());
        for (Long sample : samp.getSamples()) {
            assertNull(sample);
        }
       

        final long[] testData = {4, 8, 2, -1, 5, 9, 11, 14};
        // capacity defaults to zero, so size should be zero
        samp.addSample(3);
        testStatistics(samp, /*size*/0, /*min*/3, /*max*/3, testData);
       
        samp.setCapacity(100);
       
        samp.addSample(testData[0]);
        testStatistics(samp, /*size*/1, /*min*/3, /*max*/4, testData);
      
        samp.addSample(testData[1]);
        testStatistics(samp, 2, 3, 8, testData);
       
        samp.addSample(testData[2]);
        testStatistics(samp, 3, 2, 8, testData);
       
        samp.addSample(testData[3]);
        testStatistics(samp, 4, -1, 8, testData);
       
        samp.addSample(testData[4]);
        testStatistics(samp, 5, -1, 8, testData);
       
        samp.addSample(testData[5]);
        testStatistics(samp, 6, -1, 9, testData);
        
        samp.addSample(testData[6]);
        testStatistics(samp, 7, -1, 11, testData);
       
        samp.addSample(testData[7]);
        testStatistics(samp, 8, -1, 14, testData);
       
        samp.clearSamples();
        assertEquals(0, samp.getNumSamples());
        for (Long sample : samp.getSamples()) {
            assertNull(sample);
        }
       
        // Add all the data back in, check that min, max, values what we expect
        for (long data : testData) {
            samp.addSample(data);
        }
        testStatistics(samp, 8, -1, 14, testData);
   }
View Full Code Here

  
   @Test
   public void testAggregateProfileSampleCapacity() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final AggregateProfileSample samp1 =
                (AggregateProfileSample)
                    cons1.createSample("s1", testType, ProfileLevel.MIN);
        // default capacity is zero
        assertEquals(0, samp1.getCapacity());
       
        final AggregateProfileSample samp2 =
                (AggregateProfileSample)
                    cons1.createSample("s2", testType, ProfileLevel.MIN);
        samp2.setCapacity(5);
        assertEquals(5, samp2.getCapacity());
       
        // Add 5 samples, then make sure 6th causes the first to go away
        final long[] testData = {1, 2, 3, 4, 5};
        for (int i = 0; i < testData.length; i++) {
            samp2.addSample(testData[i]);
        }
       
        testStatistics(samp2, /*size*/5, /*min*/1, /*max*/5, testData);
       
        final long[] expectedData = {2, 3, 4, 5, 6};
        samp2.addSample(6);
        testStatistics(samp2, 5, 1, 6, expectedData);
       
        final long[] emptyData = {};
        samp2.clearSamples();
        samp2.setCapacity(0);
        for (int i = 0; i < testData.length; i++) {
            samp2.addSample(testData[i]);
        }
        testStatistics(samp2, /*size*/0, /*min*/1, /*max*/5, emptyData);
        samp2.addSample(6);
        testStatistics(samp2, 0, 1, 6, emptyData);
   }
View Full Code Here

    }
    @Test(expected=IllegalArgumentException.class)
    public void testSampleTaskAggregateNegCapacity() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        AggregateProfileSample s1 = (AggregateProfileSample)
            cons1.createSample("foo",
                               ProfileDataType.TASK_AND_AGGREGATE,
                               ProfileLevel.MIN);
        s1.setCapacity(-1);
    }
View Full Code Here

        {
            ProfileSample s3 =
                 cons1.createSample(aggName, ProfileDataType.AGGREGATE,
                                    ProfileLevel.MAX);
           
            AggregateProfileSample s4 = (AggregateProfileSample)
                 cons1.createSample(aggName, ProfileDataType.AGGREGATE,
                                    ProfileLevel.MAX);
            assertSame(s3, s4);
        }
       
View Full Code Here

        expected.add(Long.valueOf(5));
        expected.add(Long.valueOf(-1));
        expected.add(Long.valueOf(2));
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final AggregateProfileSample samp = (AggregateProfileSample)
                cons1.createSample("sample1",
                                   ProfileDataType.TASK_AND_AGGREGATE,
                                   ProfileLevel.MIN);
        final String sampleName = samp.getName();
        // Ensure that a zero capacity aggregate sample sends the sample
        // values to the task listener, but does not accumulate any
        // samples in the global aggregation.
        samp.setCapacity(0);
       
        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 {
                            List<Long> samples =
                                report.getUpdatedTaskSamples().get(sampleName);
                            assertEquals(expected, samples);   
                        } 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);
       
        assertEquals(0, samp.getNumSamples());
        assertNotNull(samp.getSamples());
        for (Long sample : samp.getSamples()) {
            fail("didn't expect to find a sample " + sample);
        }
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    for (long value : expected) {
                        samp.addSample(value);
                    }
                }
            }, myOwner);
           
        AssertionError error =
                errorExchanger.exchange(null, 100, TimeUnit.MILLISECONDS);
        if (error != null) {
            throw new AssertionError(error);
        }
        // No global samples, yet statistics are maintained
        assertEquals(0, samp.getNumSamples());
        assertNotNull(samp.getSamples());
        for (Long sample : samp.getSamples()) {
            fail("didn't expect to find a sample " + sample);
        }
        assertEquals(5, samp.getMaxSample());
        assertEquals(-1, samp.getMinSample());
    }
View Full Code Here

TOP

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

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.