Package com.sun.sgs.profile

Examples of com.sun.sgs.profile.ProfileOperation


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


        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileConsumer cons2 = collector.getConsumer("c2");
        String name = "myOperation";
        {
            ProfileOperation op1 =
                cons1.createOperation(name,
                                      ProfileDataType.TASK, ProfileLevel.MAX);
            ProfileOperation op2 =
                cons2.createOperation(name,
                                      ProfileDataType.TASK, ProfileLevel.MAX);
            assertFalse(op1.getName().equals(op2.getName()));
            assertTrue(op1.getName().contains(name));
            assertTrue(op2.getName().contains(name));
        }
       
        name = "aggOp";
        {
            ProfileOperation op1 =
                cons1.createOperation(name, ProfileDataType.AGGREGATE,
                                      ProfileLevel.MAX);
            ProfileOperation op2 =
                cons2.createOperation(name, ProfileDataType.AGGREGATE,
                                      ProfileLevel.MAX);
            assertFalse(op1.getName().equals(op2.getName()));
            assertTrue(op1.getName().contains(name));
            assertTrue(op2.getName().contains(name));
        }
       
        name = "bothOp";
        {
            ProfileOperation op1 =
                cons1.createOperation(name, ProfileDataType.TASK_AND_AGGREGATE,
                                      ProfileLevel.MAX);
            ProfileOperation op2 =
                cons2.createOperation(name, ProfileDataType.TASK_AND_AGGREGATE,
                                      ProfileLevel.MAX);
            assertFalse(op1.getName().equals(op2.getName()));
            assertTrue(op1.getName().contains(name));
            assertTrue(op2.getName().contains(name));
        }
    }
View Full Code Here

    @Test
    public void testOperationTwice() throws Exception {
        final String name = "myOperation";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileOperation op1 =
                cons1.createOperation(name,
                                      ProfileDataType.TASK, ProfileLevel.MAX);

        // Try creating with same name and parameters
        ProfileOperation op2 =
                cons1.createOperation(name,
                                      ProfileDataType.TASK, ProfileLevel.MAX);
        assertSame(op1, op2);
       
        // Try creating with same name and different parameters
        try {
            ProfileOperation op3 =
                cons1.createOperation(name,
                                      ProfileDataType.AGGREGATE,
                                      ProfileLevel.MAX);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
        try {
            ProfileOperation op3 =
                cons1.createOperation(name,
                                      ProfileDataType.TASK_AND_AGGREGATE,
                                      ProfileLevel.MAX);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
        try {
            ProfileOperation op3 =
                cons1.createOperation(name, ProfileDataType.TASK,
                                      ProfileLevel.MIN);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
        try {
            ProfileOperation op3 =
                cons1.createOperation(name, ProfileDataType.TASK,
                                      ProfileLevel.MEDIUM);
            fail("Expected IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            System.err.println(expected);
        }
       
        // Try creating with a different name
        ProfileOperation op4 =
                cons1.createOperation("somethingelse",
                                      ProfileDataType.TASK, ProfileLevel.MAX);
        assertNotSame(op1, op4);
    }
View Full Code Here

    @Test
    public void testOperationType() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        ProfileOperation op1 =
            cons1.createOperation("op1", ProfileDataType.TASK,
                                  ProfileLevel.MAX);
        assertTrue(op1 instanceof TaskProfileOperation);
        assertFalse(op1 instanceof AggregateProfileOperation);
        ProfileOperation op2 =
            cons1.createOperation("op2", ProfileDataType.AGGREGATE,
                                  ProfileLevel.MAX);
        assertFalse(op2 instanceof TaskProfileOperation);
        assertTrue(op2 instanceof AggregateProfileOperation);
       
        ProfileOperation op3 =
            cons1.createOperation("op3", ProfileDataType.TASK_AND_AGGREGATE,
                                  ProfileLevel.MAX);
        assertTrue(op3 instanceof TaskProfileOperation);
        assertTrue(op3 instanceof AggregateProfileOperation);
    }
View Full Code Here

    {
        if (name == null) {
            throw new NullPointerException("Operation name must not be null");
        }
        String fullName = getCanonicalName(name);
  ProfileOperation op = ops.get(fullName);
       
  if (op == null) {
            switch (type) {
                case TASK:
                    op = new TaskProfileOperationImpl(fullName, type, minLevel);
View Full Code Here

    /** {@inheritDoc} */
    public void propertyChange(PropertyChangeEvent event) {
  if (event.getPropertyName().
                equals("com.sun.sgs.profile.newop"))
        {       
      ProfileOperation op = (ProfileOperation) (event.getNewValue());
      opCounts.put(op.getName(), 0L);
  } else {
      if (event.getPropertyName().
                    equals("com.sun.sgs.profile.threadcount"))
            {
    threadCount = ((Integer) (event.getNewValue())).intValue();
View Full Code Here

    /** {@inheritDoc} */
    public void propertyChange(PropertyChangeEvent event) {
  if (event.getPropertyName().
                equals("com.sun.sgs.profile.newop"))
        {         
      ProfileOperation op = (ProfileOperation) (event.getNewValue());
      sOpCounts.put(op.getName(), 0L);
      fOpCounts.put(op.getName(), 0L);
  }
    }
View Full Code Here

   
    @Test
    public void testOperationMaxLevel() throws Exception {
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final ProfileOperation op =
                cons1.createOperation("something", 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("opmax");
        final Identity negativeOwner = new DummyIdentity("opmaxneg");
        SimpleTestListener test = new SimpleTestListener(
            new OperationReportRunnable(op.getName(),
                                        negativeOwner, positiveOwner,
                                        errorExchanger));
        profileCollector.addListener(test, true);

        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // We do not expect to see this reported.
                    op.report();
                }
            }, negativeOwner);

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

        cons1.setProfileLevel(ProfileLevel.MEDIUM);
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // No report expected:  the level is still too low
                    op.report();
                }
            }, negativeOwner);
           
        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() {
                    op.report();
                }
            }, positiveOwner);
           
        error = errorExchanger.exchange(null, TIMEOUT, TimeUnit.MILLISECONDS);
        if (error != null) {
View Full Code Here

    public void testOperationMultiple() throws Exception {
        final String opName = "something";
        final String op1Name = "else";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final ProfileOperation op =
                cons1.createOperation(opName, testType, ProfileLevel.MIN);
        final ProfileOperation op1 =
                cons1.createOperation(op1Name, 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 {
                            List<String> ops =
                                SimpleTestListener.report.getReportedOperations();
                            for (String po : ops) {
                                System.err.println(po);
                            }
                            int opIndex1 = ops.indexOf(op.getName());
                            int opIndex2 = ops.lastIndexOf(op.getName());
                            int op1Index1 = ops.indexOf(op1.getName());
                            int op1Index2 = ops.lastIndexOf(op1.getName());

                            // We expect to see op twice, and op1 once
                            assertTrue(opIndex1 != -1);
                            assertTrue(opIndex2 != -1);
                            assertTrue(op1Index1 != -1);
                            assertTrue(op1Index2 == op1Index1);

                            // We expect the op ordering to be maintained
                            assertTrue(opIndex1 < op1Index1);
                            assertTrue(op1Index1 < opIndex2);
                        } 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() {
                    // We expect to see the operation in the profile report
                    op.report();
                    op1.report();
                    op.report();
                }
            }, myOwner);
           
        AssertionError error =
View Full Code Here

    public void testTaskAggregateOperationUnique() throws Exception {
        final String opName = "something";
        final String op1Name = "else";
        ProfileCollector collector = getCollector(serverNode);
        ProfileConsumer cons1 = collector.getConsumer("c1");
        final ProfileOperation op =
                cons1.createOperation(opName,
                                      ProfileDataType.TASK_AND_AGGREGATE,
                                      ProfileLevel.MIN);
        final ProfileOperation op1 =
                cons1.createOperation(op1Name,
                                      ProfileDataType.TASK_AND_AGGREGATE,
                                      ProfileLevel.MIN);
        final AggregateProfileOperation opAgg = (AggregateProfileOperation) op;
        final AggregateProfileOperation op1Agg =
                (AggregateProfileOperation) op1;
       
        // 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 {
                            List<String> ops =
                                report.getReportedOperations();
                            System.err.println("+++");
                            for (String name : ops) {
                                assertTrue(name.contains(opName)
                                        || name.contains(op1Name));
                               
                                System.err.println("+ " + name);
                            }
                            System.err.println("+++");
                           
                            // Our aggregate counter knows that it was updated
                            assertEquals(4, opAgg.getCount());
                            assertEquals(2, op1Agg.getCount());
                           
                           
                           
                        } 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);

        op.report();
        op1.report();
        assertEquals(1, opAgg.getCount());
        assertEquals(1, op1Agg.getCount());
        op.report();
        assertEquals(2, opAgg.getCount());
       
        txnScheduler.runTask(
            new TestAbstractKernelRunnable() {
    public void run() {
                    // We expect to see the operations in the profile report
                    op.report();
                    op1.report();
                    op.report();
                }
            }, myOwner);
           
        AssertionError error =
View Full Code Here

TOP

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

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.