@Test public void testCounterType() throws Exception { ProfileCollector collector = getCollector(serverNode); ProfileConsumer cons1 = collector.getConsumer("c1"); ProfileCounter counter = cons1.registerCounter("counter", true, ProfileLevel.MIN); assertTrue(counter.isTaskLocal()); ProfileCounter counter1 = cons1.registerCounter("other", false, ProfileLevel.MIN); assertFalse(counter1.isTaskLocal()); }
/* -- Counter tests -- */ @Test public void testCounterName() throws Exception { final String name = "counter"; ProfileCollector collector = getCollector(serverNode); ProfileConsumer cons1 = collector.getConsumer("c1"); ProfileCounter counter1 = cons1.registerCounter(name, true, ProfileLevel.MAX); assertEquals(name, counter1.getCounterName()); }
@Test public void testCounterTwice() throws Exception { final String name = "counter"; ProfileCollector collector = getCollector(serverNode); ProfileConsumer cons1 = collector.getConsumer("c1"); ProfileCounter counter1 = cons1.registerCounter(name, true, ProfileLevel.MAX); // Try creating with same name and parameters ProfileCounter counter2 = cons1.registerCounter(name, true, ProfileLevel.MAX); assertSame(counter1, counter2); // Try creating with same name and different parameters // Note we expect this behavior to change with upcoming API changes ProfileCounter op3 = cons1.registerCounter(name, false, ProfileLevel.MAX); assertSame(counter1, op3); // Try creating with a different name ProfileCounter counter4 = cons1.registerCounter("somethingelse", true, ProfileLevel.MAX); assertNotSame(counter1, counter4); }
@Test 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.registerCounter(name, true, 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"); TestListener test = new TestListener(new TestCounterReport(name, 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(); } }, taskOwner); AssertionError error = errorExchanger.exchange(null, 100, 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, 100, TimeUnit.MILLISECONDS); if (error != null) { throw new AssertionError(error); } }
@Test 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.registerCounter(name, true, 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"); TestListener test = new TestListener(new TestCounterReport(name, 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, 100, TimeUnit.MILLISECONDS); if (error != null) { // Rethrow with the original error as the cause so we see // both stack traces. throw new AssertionError(error); } txnScheduler.runTask( new TestAbstractKernelRunnable() { public void run() {} }, taskOwner); error = errorExchanger.exchange(null, 100, TimeUnit.MILLISECONDS); if (error != null) { throw new AssertionError(error); } }