Class TestDataCollector

java.lang.Object
eu.iv4xr.framework.mainConcepts.TestDataCollector
All Implemented Interfaces:
Parsable

public class TestDataCollector extends Object implements Parsable
This class is used to collect information from one or more test-agents. Test-agents collect information in the form of instances of ObservationEvent that they then send to a TestDataCollector. Such a collector collects three types of data:
  • Time-stamped events. These are instances of ObservationEvent.TimeStampedObservationEvent. They are stored chronologically in a list and is useful for debugging. E.g. when a negative verdict is observed, we can see in this list what are the events that preceed it.
  • Verdicts. These are a special kind of time-stamped events that report things that the agent observed as correct as well as as wrong.
  • Coverage events. These are instances of ObservationEvent.CoveragePointEvent representing the coverage-points the test-agent manage to cover.
Author:
Wish
  • Field Details

    • perAgentCoverage

      protected Map<String,​TestDataCollector.CoverageMap> perAgentCoverage
      The coverage-map of each agent. By "each agent" we mean a test-agent that has been registered to this TestDataCollector.
    • collectiveCoverageMap

      protected TestDataCollector.CoverageMap collectiveCoverageMap
      The cummulative coverage-map of all agents. By "agents" we mean the test-agents that have been registered to this TestDataCollector.
    • perAgentEventTrace

      protected Map<String,​TestDataCollector.EventTrace> perAgentEventTrace
      The trace of time-stamped events of each agent.
  • Constructor Details

    • TestDataCollector

      public TestDataCollector()
  • Method Details

    • startTrackingCoveragePoint

      public void startTrackingCoveragePoint(String coveragePointId)
      Add a coverage-point to the set of coverage-points whose coverage will be tracked.
    • registerTestAgent

      public void registerTestAgent(String agentUniqueId)
      Register a test-agent to this data collector. We do not literally pass a test-agent, but rather its id.
      Parameters:
      agentUniqueId - The id of the agent. This is assumed to be unique.
    • registerVisit

      public void registerVisit(String agentUniqueId, ObservationEvent.CoveragePointEvent e)
      Register a visit to a coverage-point by a test-agent.
      Parameters:
      agentUniqueId - Unique id of the test-agent.
      e - An event representing the visit to some coverage point of interest.
    • registerEvent

      public void registerEvent(String agentUniqueId, ObservationEvent.TimeStampedObservationEvent e)
      Register an observation event. This allows a test-agent to register whatever event of interest to this data collector. This will be recorded into the agent's trace. Note that an event can also be a verdict-event, where the test agent reports that it has seen something that is either according to its expectation, or violating it.
      Parameters:
      agentUniqueId - Unique id of the test-agent.
      e - An event representing the observation to record.
    • getTestAgentCoverage

      public Map<String,​Integer> getTestAgentCoverage(String agentUniqueId)
      Return a map describing which coverage-points were covered by the specified agent. If m is the returned map, it maps a set of ObservationEvent.CoveragePointEvent to integers. Each coverage-point-event in the map represents a unique coverage-point to track. The integer it is mapped to is the number of times the coverage-point is visited.
    • getCollectiveCoverage

      public Map<String,​Integer> getCollectiveCoverage()
      Return a map describing which coverage-points were collectively covered all test-agents registered to this TestDataCollector. If m is the returned map, it maps a set of ObservationEvent.CoveragePointEvent to integers. Each coverage-point-event in the map represents a unique coverage-point to track. The integer it is mapped to is the number of times the coverage-point is visited.
    • getTestAgentTrace

      public List<ObservationEvent.TimeStampedObservationEvent> getTestAgentTrace(String agentUniqueId)
      Return the "trace" of the specified test-agent. This trace is a chronologically ordered list of time-stamped events that this test-agent reported to this TestDataCollector. Note that verdicts count as time-stamped events.
    • getTestAgentScalarsTrace

      public List<ObservationEvent.ScalarTracingEvent> getTestAgentScalarsTrace(String agentUniqueId)
      Return the trace of the specified agent, containing only of ScalarTracingEvents.
    • getNumberOfFailVerdictsSeen

      public int getNumberOfFailVerdictsSeen(String agentUniqueId)
      Get the number of negative verdicts reported by the specified test-agent.
    • getNumberOfFailVerdictsSeen

      public int getNumberOfFailVerdictsSeen()
      Get the total number of negative verdicts reported by all test-agents.
    • getNumberOfPassVerdictsSeen

      public int getNumberOfPassVerdictsSeen(String agentUniqueId)
      Get the number of positive verdicts reported by the specified test-agent.
    • getNumberOfPassVerdictsSeen

      public int getNumberOfPassVerdictsSeen()
      Get the total number of positive verdicts reported by all test-agents.
    • getNumberOfUndecidedVerdictsSeen

      public int getNumberOfUndecidedVerdictsSeen(String agentUniqueId)
      Get the number of undecided verdicts reported by the specified test-agent.
    • getNumberOfUndecidedVerdictsSeen

      public int getNumberOfUndecidedVerdictsSeen()
      Get the total number of undecided verdicts reported by all test-agents.
    • getLastFailVerdict

      public ObservationEvent.VerdictEvent getLastFailVerdict(String agentUniqueId)
      Get the last negative verdict reported by the specified test-agent.
    • getLastFailVerdict

      public ObservationEvent.VerdictEvent getLastFailVerdict()
      Get the last reported negative verdict.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parse

      public Parsable parse(String s)
      Specified by:
      parse in interface Parsable
    • save

      public void save(String fname, String covFname) throws IOException
      Save the data collected to files. Collected non-coverage events will be saved to the file fname (if it is not null). Coverage data are saved to covFname, if the latter is not null. Format of the events-file: For verdict-event: agent,time,"VerdictEvent",family,info,verdict For scalar-event: agent,time."ScalarTracingEvent",propname1,val1,propname2,val2,... Formal of coverage-file: coverage-point-name,num-of-total-visits,agent1,num-visit-by-agent1,agent2,...
      Throws:
      IOException
    • reset

      public void reset()
      Reset the agents' traces recorded in this data-collector, and also reset all coverage information tracked by this data-collector (that means reseting their visit-counts to 0).
    • merge

      public TestDataCollector merge(TestDataCollector data2)
      Merge two sets of collected test data. The merged data is put into a new instance of TestDataCollector.
      Parameters:
      data2 - test-date to merge with this test-data.
    • readCollectedTestData

      public static TestDataCollector readCollectedTestData(File file)
      Read collected test data from a file.
    • saveTestAgentScalarsTraceAsCSV

      public void saveTestAgentScalarsTraceAsCSV(String agentUniqueId, String filename) throws IOException
      Export the scalar-trace of an agent to a CSV-file. ';' is used as the separator.
      Throws:
      IOException