Skip to content

Commit

Permalink
Test Diffs (core)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhRX committed May 2, 2017
1 parent 7bdb3e0 commit 3e0b585
Show file tree
Hide file tree
Showing 10 changed files with 1,514 additions and 50 deletions.
@@ -1,12 +1,15 @@
package com.insightfullogic.honest_profiler.core.aggregation.result.diff; package com.insightfullogic.honest_profiler.core.aggregation.result.diff;


import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static java.util.stream.Stream.concat;
import static java.util.stream.Stream.of;


import java.util.Collection; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Stream;


import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node; import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Node;
Expand All @@ -32,7 +35,7 @@ public DiffNode(Node baseNode, Node newNode)
{ {
super(baseNode, newNode); super(baseNode, newNode);


this.children = new HashMap<>(); children = new HashMap<>();
addBaseChildren(baseNode); addBaseChildren(baseNode);
addNewChildren(newNode); addNewChildren(newNode);
} }
Expand Down Expand Up @@ -90,11 +93,11 @@ public DiffNode setNew(Node node)
/** /**
* Returns the children of this node. * Returns the children of this node.
* <p> * <p>
* @return a {@link Collection} containing the children of this node. * @return a {@link List} containing the children of this node.
*/ */
public Collection<DiffNode> getChildren() public List<DiffNode> getChildren()
{ {
return children.values(); return new ArrayList<>(children.values());
} }


/** /**
Expand Down Expand Up @@ -169,4 +172,14 @@ private void addNewChild(Node child)
child.getKey(), child.getKey(),
(k, v) -> v == null ? new DiffNode(null, child) : v.setNew(child)); (k, v) -> v == null ? new DiffNode(null, child) : v.setNew(child));
} }

/**
* Return a {@link Stream} of DiffNodes consisting of this Node and all its descendants.
* <p>
* @return a {@link Stream} of DiffNodes consisting of this Node and all its descendants
*/
public Stream<DiffNode> flatten()
{
return concat(of(this), children.values().stream().flatMap(DiffNode::flatten));
}
} }
Expand Up @@ -2,10 +2,11 @@


import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;


import java.util.Collection; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Stream;


import com.insightfullogic.honest_profiler.core.aggregation.filter.FilterSpecification; import com.insightfullogic.honest_profiler.core.aggregation.filter.FilterSpecification;
import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
Expand Down Expand Up @@ -43,6 +44,8 @@ private TreeDiff(List<DiffNode> entries)
entries.forEach(entry -> data.put(entry.getKey(), entry)); entries.forEach(entry -> data.put(entry.getKey(), entry));
} }


// Instance Accessors

/** /**
* Sets the Base and New {@link Tree}s, and calculates the diff contents. * Sets the Base and New {@link Tree}s, and calculates the diff contents.
* <p> * <p>
Expand All @@ -64,14 +67,24 @@ public void set(Tree baseTree, Tree newTree)


} }


/**
* Returns a {@link Stream} of all {@link DiffNode}s contained in this Tree.
* <p>
* @return a {@link Stream} of all {@link DiffNode}s contained in this Tree
*/
public Stream<DiffNode> flatten()
{
return getData().stream().flatMap(DiffNode::flatten);
}

/** /**
* Returns the {@link DiffNode}s from this Diff. * Returns the {@link DiffNode}s from this Diff.
* <p> * <p>
* @return a {@link Collection} containing the {@link DiffNode}s from this Diff * @return a {@link List} containing the {@link DiffNode}s from this Diff
*/ */
public Collection<DiffNode> getData() public List<DiffNode> getData()
{ {
return data.values(); return new ArrayList<>(data.values());
} }


// AbstractDiff Implementation // AbstractDiff Implementation
Expand Down
@@ -0,0 +1,66 @@
package com.insightfullogic.honest_profiler.core.aggregation.aggregator;

import java.util.Collection;

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

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.diff.FlatDiff;
import com.insightfullogic.honest_profiler.framework.ParameterUtil;
import com.insightfullogic.honest_profiler.framework.checker.FlatDiffCheckAdapter;
import com.insightfullogic.honest_profiler.framework.generator.FlatGenerator;
import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario;

@RunWith(Parameterized.class)
public class FlatDiffAggregatorTest
{
@Parameters(name = "{0} <-> {1} : <{1},{2}>")
public static Collection<Object[]> data()
{
return ParameterUtil.getDiffScenariosAndGroupings();
}

// Instance Properties

private SimplifiedLogScenario baseScenario;
private SimplifiedLogScenario newScenario;
private ThreadGrouping threadGrouping;
private FrameGrouping frameGrouping;

// Instance Constructors

public FlatDiffAggregatorTest(SimplifiedLogScenario baseScenario,
SimplifiedLogScenario newScenario,
ThreadGrouping threadGrouping,
FrameGrouping frameGrouping)
{
this.baseScenario = baseScenario;
this.newScenario = newScenario;
this.threadGrouping = threadGrouping;
this.frameGrouping = frameGrouping;
}

// Actual Test Method

@Test
public void testScenario()
{
FlatGenerator baseGen;
FlatGenerator newGen;

baseGen = new FlatGenerator(threadGrouping, frameGrouping);
baseScenario.executeAndEnd(baseGen);

newGen = new FlatGenerator(threadGrouping, frameGrouping);
newScenario.executeAndEnd(newGen);

FlatDiff diff = new FlatDiff();
diff.set(baseGen.getFlat(), newGen.getFlat());

baseScenario.checkFlatDiffAggregation(newScenario, new FlatDiffCheckAdapter(diff));
}
}
@@ -0,0 +1,66 @@
package com.insightfullogic.honest_profiler.core.aggregation.aggregator;

import java.util.Collection;

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

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.diff.TreeDiff;
import com.insightfullogic.honest_profiler.framework.ParameterUtil;
import com.insightfullogic.honest_profiler.framework.checker.TreeDiffCheckAdapter;
import com.insightfullogic.honest_profiler.framework.generator.TreeGenerator;
import com.insightfullogic.honest_profiler.framework.scenario.SimplifiedLogScenario;

@RunWith(Parameterized.class)
public class TreeDiffAggregatorTest
{
@Parameters(name = "{0} <-> {1} : <{1},{2}>")
public static Collection<Object[]> data()
{
return ParameterUtil.getDiffScenariosAndGroupings();
}

// Instance Properties

private SimplifiedLogScenario baseScenario;
private SimplifiedLogScenario newScenario;
private ThreadGrouping threadGrouping;
private FrameGrouping frameGrouping;

// Instance Constructors

public TreeDiffAggregatorTest(SimplifiedLogScenario baseScenario,
SimplifiedLogScenario newScenario,
ThreadGrouping threadGrouping,
FrameGrouping frameGrouping)
{
this.baseScenario = baseScenario;
this.newScenario = newScenario;
this.threadGrouping = threadGrouping;
this.frameGrouping = frameGrouping;
}

// Actual Test Method

@Test
public void testScenario()
{
TreeGenerator baseGen;
TreeGenerator newGen;

baseGen = new TreeGenerator(threadGrouping, frameGrouping);
baseScenario.executeAndEnd(baseGen);

newGen = new TreeGenerator(threadGrouping, frameGrouping);
newScenario.executeAndEnd(newGen);

TreeDiff diff = new TreeDiff();
diff.set(baseGen.getTree(), newGen.getTree());

baseScenario.checkTreeDiffAggregation(newScenario, new TreeDiffCheckAdapter(diff));
}
}
Expand Up @@ -43,6 +43,21 @@ public static final List<Object[]> getScenariosAndGroupings()
return result; return result;
} }


public static final List<Object[]> getDiffScenariosAndGroupings()
{
List<Object[]> result = new ArrayList<>();
SCENARIOS.forEach(
sc -> asList(ThreadGrouping.values())
.forEach(tg -> asList(FrameGrouping.values()).forEach(fg ->
{
result.add(new Object[]
{ sc, SCENARIOS.get(6), tg, fg });
result.add(new Object[]
{ sc, SCENARIOS.get(7), tg, fg });
})));
return result;
}

public static final List<Object[]> getFilterScenarios() public static final List<Object[]> getFilterScenarios()
{ {
List<Object[]> result = new ArrayList<>(); List<Object[]> result = new ArrayList<>();
Expand Down

0 comments on commit 3e0b585

Please sign in to comment.