Skip to content

Commit

Permalink
Reworked / automated filter tests
Browse files Browse the repository at this point in the history
Failures for Time filters are expected until the fix in PR #217 has been
merged.
  • Loading branch information
PhRX committed Apr 28, 2017
1 parent 2011dbe commit caf87f0
Show file tree
Hide file tree
Showing 13 changed files with 664 additions and 341 deletions.
Expand Up @@ -50,6 +50,6 @@ public void testScenario()


gen = new FlatGenerator(threadGrouping, frameGrouping); gen = new FlatGenerator(threadGrouping, frameGrouping);
scenario.executeAndEnd(gen); scenario.executeAndEnd(gen);
scenario.checkLinearAggregation(new FlatCheckAdapter(gen.getFlat())); scenario.checkFlatAggregation(new FlatCheckAdapter(gen.getFlat()));
} }
} }
@@ -1,122 +1,90 @@
package com.insightfullogic.honest_profiler.core.aggregation.filter; package com.insightfullogic.honest_profiler.core.aggregation.filter;


import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.CONTAINS;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.ENDS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.EQUALS_NR;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.EQUALS_STR;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.GE;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.GT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.LE;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.LT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.MATCHES;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.NOT_CONTAINS;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.NOT_ENDS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.NOT_STARTS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.STARTS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.KEY;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.SELF_COUNT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.SELF_TIME;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.TOTAL_COUNT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.TOTAL_TIME;
import static com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping.BY_FQMN;
import static com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping.BY_ID;
import static com.insightfullogic.honest_profiler.core.aggregation.result.ItemType.ENTRY; import static com.insightfullogic.honest_profiler.core.aggregation.result.ItemType.ENTRY;
import static com.insightfullogic.honest_profiler.framework.AggregationUtil.nano;
import static com.insightfullogic.honest_profiler.framework.LogEventFactory.SCENARIOS;
import static com.insightfullogic.honest_profiler.framework.generator.FlatGenerator.assertAggregationSizeEquals;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.junit.Assert.assertTrue;
import java.util.Collection;


import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;


import com.google.common.base.Predicate; import com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping;
import com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping;
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry; import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry;
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat; import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Flat;
import com.insightfullogic.honest_profiler.framework.ParameterUtil;
import com.insightfullogic.honest_profiler.framework.checker.FlatCheckAdapter;
import com.insightfullogic.honest_profiler.framework.generator.FlatGenerator; import com.insightfullogic.honest_profiler.framework.generator.FlatGenerator;
import com.insightfullogic.honest_profiler.framework.scenario.FltScenario;
import com.insightfullogic.honest_profiler.framework.scenario.ScenarioStraightFilter;
import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario;


@RunWith(Parameterized.class)
public class FlatFilterTest public class FlatFilterTest
{ {
@Test @Parameters(name = "{0} : <{1},{2}> {3}")
public void testFlatFiltering() public static Collection<Object[]> data()
{ {
FlatGenerator gen = new FlatGenerator(BY_ID, BY_FQMN); return ParameterUtil.getFilterScenarios();
SCENARIOS.get(7).executeAndEnd(gen); // return ParameterUtil.getScenariosAndGroupings();

}
check(gen, SELF_COUNT, EQUALS_NR, 99, 0, entry -> entry.getSelfCnt() == 99);
check(gen, SELF_COUNT, EQUALS_NR, 0, 1, entry -> entry.getSelfCnt() == 0);
check(gen, SELF_COUNT, EQUALS_NR, 48, 1, entry -> entry.getSelfCnt() == 48);
check(gen, SELF_COUNT, EQUALS_NR, 19, 2, entry -> entry.getSelfCnt() == 19);

check(gen, SELF_COUNT, GT, 19, 1, entry -> entry.getSelfCnt() > 19);
check(gen, SELF_COUNT, GE, 19, 3, entry -> entry.getSelfCnt() >= 19);
check(gen, SELF_COUNT, LT, 19, 3, entry -> entry.getSelfCnt() < 19);
check(gen, SELF_COUNT, LE, 19, 5, entry -> entry.getSelfCnt() <= 19);

check(gen, TOTAL_COUNT, EQUALS_NR, 0, 0, entry -> entry.getTotalCnt() == 0);
check(gen, TOTAL_COUNT, EQUALS_NR, 72, 1, entry -> entry.getTotalCnt() == 72);

check(gen, TOTAL_COUNT, GT, 72, 2, entry -> entry.getTotalCnt() > 72);
check(gen, TOTAL_COUNT, GE, 72, 3, entry -> entry.getTotalCnt() >= 72);
check(gen, TOTAL_COUNT, LT, 72, 3, entry -> entry.getTotalCnt() < 72);
check(gen, TOTAL_COUNT, LE, 72, 4, entry -> entry.getTotalCnt() <= 72);

check(gen, SELF_TIME, EQUALS_NR, nano(99), 0, entry -> entry.getSelfTime() == nano(99));
check(gen, SELF_TIME, EQUALS_NR, nano(0), 1, entry -> entry.getSelfTime() == nano(0));
check(gen, SELF_TIME, EQUALS_NR, nano(19), 2, entry -> entry.getSelfTime() == nano(19));
check(gen, SELF_TIME, EQUALS_NR, nano(48), 1, entry -> entry.getSelfTime() == nano(48));

check(gen, SELF_TIME, GT, nano(19), 1, entry -> entry.getSelfTime() > nano(19));
check(gen, SELF_TIME, GE, nano(19), 3, entry -> entry.getSelfTime() >= nano(19));
check(gen, SELF_TIME, LT, nano(19), 3, entry -> entry.getSelfTime() < nano(19));
check(gen, SELF_TIME, LE, nano(19), 5, entry -> entry.getSelfTime() <= nano(19));


check(gen, TOTAL_TIME, EQUALS_NR, nano(0), 0, entry -> entry.getTotalTime() == 0); // Instance Properties
check(gen, TOTAL_TIME, EQUALS_NR, nano(72), 1, entry -> entry.getTotalTime() == nano(72));


check(gen, TOTAL_TIME, GT, nano(72), 2, entry -> entry.getTotalTime() > nano(72)); private SimplifiedLogScenario scenario;
check(gen, TOTAL_TIME, GE, nano(72), 3, entry -> entry.getTotalTime() >= nano(72)); private ThreadGrouping threadGrouping;
check(gen, TOTAL_TIME, LT, nano(72), 3, entry -> entry.getTotalTime() < nano(72)); private FrameGrouping frameGrouping;
check(gen, TOTAL_TIME, LE, nano(72), 4, entry -> entry.getTotalTime() <= nano(72)); private FltScenario<?> filterScenario;


check(gen, KEY, CONTAINS, "blah", 0, entry -> entry.getKey().contains("blah")); // Instance Constructors


check(gen, KEY, CONTAINS, "Test", 0, entry -> entry.getKey().contains("Test")); public FlatFilterTest(SimplifiedLogScenario scenario,
check(gen, KEY, CONTAINS, "Qu", 2, entry -> entry.getKey().contains("Qu")); ThreadGrouping threadGrouping,
check(gen, KEY, STARTS_WITH, "com.test", 6, entry -> entry.getKey().startsWith("com.test")); FrameGrouping frameGrouping,
check(gen, KEY, ENDS_WITH, "baz()", 1, entry -> entry.getKey().endsWith("baz()")); FltScenario<?> filterScenario)
check( {
gen, this.scenario = scenario;
KEY, this.threadGrouping = threadGrouping;
EQUALS_STR, this.frameGrouping = frameGrouping;
"com.test.Fnord.fnord()", this.filterScenario = filterScenario;
1,
entry -> entry.getKey().equals("com.test.Fnord.fnord()"));
check(
gen,
KEY,
MATCHES,
".*om.+Fno.*",
1,
entry -> entry.getKey().matches(".*om.+Fno.*"));
check(gen, KEY, NOT_CONTAINS, "Baz", 5, entry -> !entry.getKey().contains("Baz"));
check(gen, KEY, NOT_ENDS_WITH, "qux()", 5, entry -> !entry.getKey().endsWith("qux()"));
check(gen, KEY, NOT_STARTS_WITH, "com", 0, entry -> !entry.getKey().startsWith("com"));
} }


private <U> void check(FlatGenerator gen, Target target, Comparison comparison, U value, // Actual Test Method
int filteredSize, Predicate<Entry> predicate)
@Test
public void testScenario()
{ {
Flat filtered = gen.filter(flatFilter(target, comparison, value)); FlatGenerator gen = new FlatGenerator(threadGrouping, frameGrouping);
scenario.executeAndEnd(gen);


assertAggregationSizeEquals(filtered, filteredSize); try
assertAllEntriesSatisfy(filtered, predicate); {
check(
gen,
filterScenario.getTarget(),
filterScenario.getComparison(),
filterScenario.getValue(),
filterScenario.getScenarioFilter());
}
catch (AssertionError ae)
{
throw new AssertionError(filterScenario.toString() + " Failed ->", ae);
}
} }


private <U> void assertAllEntriesSatisfy(Flat flat, Predicate<Entry> predicate) private <U> void check(FlatGenerator gen, Target target, Comparison comparison, U value,
ScenarioStraightFilter filter)
{ {
for (Entry entry : flat.getData()) try
{
Flat filtered = gen.filter(flatFilter(target, comparison, value));
scenario.checkFlatAggregation(new FlatCheckAdapter(filtered), filter);
}
catch (AssertionError ae)
{ {
assertTrue(predicate.apply(entry)); throw new AssertionError("Failure : Unfiltered =\n" + gen.getFlat(), ae);
} }
} }


Expand Down
@@ -1,133 +1,89 @@
package com.insightfullogic.honest_profiler.core.aggregation.filter; package com.insightfullogic.honest_profiler.core.aggregation.filter;


import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.CONTAINS;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.ENDS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.EQUALS_NR;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.EQUALS_STR;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.GE;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.GT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.LE;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.LT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.MATCHES;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.NOT_CONTAINS;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.NOT_ENDS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.NOT_STARTS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Comparison.STARTS_WITH;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.KEY;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.SELF_COUNT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.SELF_TIME;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.TOTAL_COUNT;
import static com.insightfullogic.honest_profiler.core.aggregation.filter.Target.TOTAL_TIME;
import static com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping.BY_FQMN;
import static com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping.BY_ID;
import static com.insightfullogic.honest_profiler.core.aggregation.result.ItemType.ENTRY; import static com.insightfullogic.honest_profiler.core.aggregation.result.ItemType.ENTRY;
import static com.insightfullogic.honest_profiler.framework.AggregationUtil.nano; import static com.insightfullogic.honest_profiler.framework.ParameterUtil.getFilterScenarios;
import static com.insightfullogic.honest_profiler.framework.LogEventFactory.SCENARIOS;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.junit.Assert.assertTrue;


import java.util.List; import java.util.Collection;


import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;


import com.google.common.base.Predicate; import com.insightfullogic.honest_profiler.core.aggregation.grouping.FrameGrouping;
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Entry; import com.insightfullogic.honest_profiler.core.aggregation.grouping.ThreadGrouping;
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node; import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node;
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree; import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree;
import com.insightfullogic.honest_profiler.framework.checker.TreeCheckAdapter;
import com.insightfullogic.honest_profiler.framework.generator.TreeGenerator; import com.insightfullogic.honest_profiler.framework.generator.TreeGenerator;
import com.insightfullogic.honest_profiler.framework.scenario.FltScenario;
import com.insightfullogic.honest_profiler.framework.scenario.ScenarioStraightFilter;
import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario;


@RunWith(Parameterized.class)
public class TreeFilterTest public class TreeFilterTest
{ {
@Test @Parameters(name = "{0} : <{1},{2}> {3}")
public void testTreeFiltering() public static Collection<Object[]> data()
{ {
TreeGenerator gen = new TreeGenerator(BY_ID, BY_FQMN); return getFilterScenarios();
SCENARIOS.get(7).executeAndEnd(gen); }

check(gen, SELF_COUNT, EQUALS_NR, 99, 0, entry -> entry.getSelfCnt() == 99);
check(gen, SELF_COUNT, EQUALS_NR, 14, 1, entry -> entry.getSelfCnt() == 14);
check(gen, SELF_COUNT, EQUALS_NR, 3, 3, entry -> entry.getSelfCnt() == 3);

check(gen, SELF_COUNT, GT, 14, 2, entry -> entry.getSelfCnt() > 14);
check(gen, SELF_COUNT, GE, 14, 3, entry -> entry.getSelfCnt() >= 14);
check(gen, SELF_COUNT, LT, 14, 28, entry -> entry.getSelfCnt() < 19);
check(gen, SELF_COUNT, LE, 14, 28, entry -> entry.getSelfCnt() <= 19);

check(gen, TOTAL_COUNT, EQUALS_NR, 0, 0, entry -> entry.getTotalCnt() == 0);
check(gen, TOTAL_COUNT, EQUALS_NR, 6, 1, entry -> entry.getTotalCnt() == 6);

check(gen, TOTAL_COUNT, GT, 14, 2, entry -> entry.getTotalCnt() > 14);
check(gen, TOTAL_COUNT, GE, 14, 3, entry -> entry.getTotalCnt() >= 14);
check(gen, TOTAL_COUNT, LT, 14, 25, entry -> entry.getTotalCnt() < 14);
check(gen, TOTAL_COUNT, LE, 14, 26, entry -> entry.getTotalCnt() <= 14);

check(gen, SELF_TIME, EQUALS_NR, nano(99), 0, entry -> entry.getSelfTime() == nano(99));
check(gen, SELF_TIME, EQUALS_NR, nano(14), 1, entry -> entry.getSelfTime() == nano(14));
check(gen, SELF_TIME, EQUALS_NR, nano(3), 3, entry -> entry.getSelfTime() == nano(3));

check(gen, SELF_TIME, GT, nano(14), 2, entry -> entry.getSelfTime() > nano(14));
check(gen, SELF_TIME, GE, nano(14), 3, entry -> entry.getSelfTime() >= nano(14));
check(gen, SELF_TIME, LT, nano(14), 28, entry -> entry.getSelfTime() < nano(14));
check(gen, SELF_TIME, LE, nano(14), 28, entry -> entry.getSelfTime() <= nano(14));


check(gen, TOTAL_TIME, EQUALS_NR, nano(0), 0, entry -> entry.getTotalTime() == 0); // Instance Properties
check(gen, TOTAL_TIME, EQUALS_NR, nano(6), 1, entry -> entry.getTotalTime() == nano(6));


check(gen, TOTAL_TIME, GT, nano(14), 2, entry -> entry.getTotalTime() > nano(14)); private SimplifiedLogScenario scenario;
check(gen, TOTAL_TIME, GE, nano(14), 3, entry -> entry.getTotalTime() >= nano(14)); private ThreadGrouping threadGrouping;
check(gen, TOTAL_TIME, LT, nano(14), 25, entry -> entry.getTotalTime() < nano(14)); private FrameGrouping frameGrouping;
check(gen, TOTAL_TIME, LE, nano(14), 26, entry -> entry.getTotalTime() <= nano(14)); private FltScenario<?> filterScenario;


check(gen, KEY, CONTAINS, "blah", 0, entry -> entry.getKey().contains("blah")); // Instance Constructors


check(gen, KEY, CONTAINS, "Test", 0, entry -> entry.getKey().contains("Test")); public TreeFilterTest(SimplifiedLogScenario scenario,
check(gen, KEY, CONTAINS, "Qu", 9, entry -> entry.getKey().contains("Qu")); ThreadGrouping threadGrouping,
check( FrameGrouping frameGrouping,
gen, FltScenario<?> filterScenario)
KEY, {
STARTS_WITH, this.scenario = scenario;
"com.test", this.threadGrouping = threadGrouping;
28, this.frameGrouping = frameGrouping;
entry -> entry.getKey().startsWith("com.test")); this.filterScenario = filterScenario;
check(gen, KEY, ENDS_WITH, "baz()", 20, entry -> entry.getKey().endsWith("baz()"));
check(
gen,
KEY,
EQUALS_STR,
"com.test.Fnord.fnord()",
19,
entry -> entry.getKey().equals("com.test.Fnord.fnord()"));
check(
gen,
KEY,
MATCHES,
".*om.+Fno.*",
19,
entry -> entry.getKey().matches(".*om.+Fno.*"));
check(gen, KEY, NOT_CONTAINS, "Baz", 28, entry -> !entry.getKey().contains("Baz"));
check(gen, KEY, NOT_ENDS_WITH, "qux()", 28, entry -> !entry.getKey().endsWith("qux()"));
check(gen, KEY, NOT_STARTS_WITH, "com", 10, entry -> !entry.getKey().startsWith("com"));
} }


private <U> void check(TreeGenerator gen, Target target, Comparison comparison, U value, // Actual Test Method
int filteredCount, Predicate<Entry> predicate)
@Test
public void testScenario()
{ {
Tree filtered = gen.filter(treeFilter(target, comparison, value)); TreeGenerator gen = new TreeGenerator(threadGrouping, frameGrouping);
scenario.executeAndEnd(gen);


assertLeavesSatisfy(filtered, filteredCount, predicate); try
{
check(
gen,
filterScenario.getTarget(),
filterScenario.getComparison(),
filterScenario.getValue(),
filterScenario.getScenarioFilter());
}
catch (AssertionError ae)
{
throw new AssertionError(filterScenario.toString() + " Failed ->", ae);
}
} }


private <U> void assertLeavesSatisfy(Tree tree, int count, Predicate<Entry> predicate) private <U> void check(TreeGenerator gen, Target target, Comparison comparison, U value,
ScenarioStraightFilter filter)
{ {
List<Node> nodes = tree.flatten().filter(node -> node.getChildren().size() == 0) try
.collect(toList()); {

Tree filtered = gen.filter(treeFilter(target, comparison, value));
Assert.assertEquals("Unexpected number of leaf Nodes", count, nodes.size()); scenario.checkTreeAggregation(new TreeCheckAdapter(filtered), filter);
for (Node entry : nodes) }
catch (AssertionError ae)
{ {
assertTrue(predicate.apply(entry)); throw new AssertionError("Failure : Unfiltered =\n" + gen.getTree(), ae);
} }
} }


Expand Down

0 comments on commit caf87f0

Please sign in to comment.