Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
TestListener.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.engine.e1.collector.test;
2 
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 
17 public abstract class TestListener {
18 
21  public void onStart(TestInfo testInfo){
22  }
23 
26  public void onStop(TestInfo testInfo){
27  }
28 
31  public void onRun(TestInfo status){
32  }
33 
36  public static class Composer extends TestListener {
37  private static Logger log = LoggerFactory.getLogger(Composer.class);
38 
39  private Iterable<TestListener> listeners;
40 
41  public Composer(Iterable<TestListener> listeners) {
42  this.listeners = listeners;
43  }
44 
45  public static TestListener compose(Iterable<TestListener> collectors){
46  return new Composer(collectors);
47  }
48 
49  @Override
50  public void onStart(TestInfo testInfo) {
51  for (TestListener listener : listeners){
52  try{
53  listener.onStart(testInfo);
54  }catch (RuntimeException ex){
55  log.error("Failed to call on start in {} test-listener", listener.toString(), ex);
56  }
57  }
58  }
59 
60  @Override
61  public void onStop(TestInfo testInfo) {
62  for (TestListener listener : listeners){
63  try{
64  listener.onStop(testInfo);
65  }catch (RuntimeException ex){
66  log.error("Failed to call on stop in {} test-listener", listener.toString(), ex);
67  }
68  }
69  }
70 
71  @Override
72  public void onRun(TestInfo testInfo) {
73  for (TestListener listener : listeners){
74  try{
75  listener.onRun(testInfo);
76  }catch (RuntimeException ex){
77  log.error("Failed to call on run in {} test-listener", listener.toString(), ex);
78  }
79  }
80  }
81  }
82 }