@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);
}