diff options
Diffstat (limited to 'src/main/java')
3 files changed, 113 insertions, 1 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/esper/Test3.java b/src/main/java/io/trygvis/esper/testing/esper/Test3.java new file mode 100755 index 0000000..70c4dc3 --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/esper/Test3.java @@ -0,0 +1,110 @@ +package io.trygvis.esper.testing.esper; + +import com.espertech.esper.client.*; +import io.trygvis.esper.testing.*; +import org.slf4j.*; + +import java.util.*; + +import static java.lang.Thread.*; + +public class Test3 { + private static final String JDBC_URL = "jdbc:h2:mem:esper;DB_CLOSE_DELAY=-1"; +// private static final String JDBC_URL = "jdbc:h2:tcp://127.0.0.1/esper;DB_CLOSE_DELAY=-1"; + + Logger logger; + EPRuntime runtime; + + public static void main(String[] args) throws Exception { + Config.loadFromDisk(); + new Test3().work(); + } + + private void work() throws Exception { + logger = LoggerFactory.getLogger("app"); + + Configuration config = new Configuration(); + + ConfigurationDBRef configurationDBRef = new ConfigurationDBRef(); + configurationDBRef.setDriverManagerConnection("org.h2.Driver", JDBC_URL, "", ""); + configurationDBRef.setConnectionAutoCommit(false); + config.addDatabaseReference("db1", configurationDBRef); + config.addEventTypeAutoName(getClass().getPackage().getName()); + EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); + runtime = epService.getEPRuntime(); + EPAdministrator administrator = epService.getEPAdministrator(); + +// String expression = "select avg(price) from OrderEvent.win:time(30 sec)"; +// String expression = "select * from pattern [every b=NewBuildEvent() -> (timer:interval(3 seconds) and not NewBuildEvent(uuid = b.uuid))]"; + +// String expression = "insert into BuildLastHour " + +// "select job, " + +// "sum(case result when 'SUCCESS' then 1 else 0 end) as successes, " + +// "sum(case result when 'FAILURE' then 1 else 0 end) as failures " + +// "from NewBuildEvent.win:time_batch(3 sec) group by job"; + + String expression = "insert into BuildLastHour " + + "select job, " + + "sum(case result when 'SUCCESS' then 1 else 0 end) as successes, " + + "sum(case result when 'FAILURE' then 1 else 0 end) as failures " + + "from NewBuildEvent.win:length(10) " + + "group by job " + + "having " + + "sum(case result when 'SUCCESS' then 1 else 0 end) > 1 AND " + + "count(result) > 3"; + + EPStatement statement = administrator.createEPL(expression); + + statement.addListener(new GenericListener(logger)); + + UUID job1 = UUID.fromString("11111111-1111-1111-1111-111111111111"); + UUID job2 = UUID.fromString("22222222-2222-2222-2222-222222222222"); + + send(job1, "SUCCESS"); sleep(100); + send(job2, "SUCCESS"); sleep(100); + send(job2, "FAILURE"); sleep(100); + send(job2, "SUCCESS"); sleep(100); + send(job2, "SUCCESS"); sleep(100); + + Timer timer = new Timer(); + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + logger.info("tick"); + } + }, 0, 1000); + + while(true) { + sleep(1000); + } + } + + public void send(UUID job, String result) { + logger.info("Inserting " + result); + runtime.sendEvent(new NewBuildEvent(job, UUID.randomUUID(), result)); + } + + class NewBuildEvent { + private UUID job; + private UUID uuid; + private String result; + + NewBuildEvent(UUID job, UUID uuid, String result) { + this.job = job; + this.uuid = uuid; + this.result = result; + } + + public UUID getJob() { + return job; + } + + public UUID getUuid() { + return uuid; + } + + public String getResult() { + return result; + } + } +} diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java index 0b2883f..2b3ca13 100755 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsClient.java @@ -140,7 +140,9 @@ public class JenkinsClient { String name = root.getName(); switch (name) { + // I don't know the different between a "matrix build" and "matrix run" case "matrixBuild": + case "matrixRun": case "mavenModuleSetBuild": case "mavenBuild": case "freeStyleBuild": diff --git a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java index 1d11aa8..089c7d0 100644 --- a/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java +++ b/src/main/java/io/trygvis/esper/testing/jenkins/JenkinsServer.java @@ -26,7 +26,7 @@ public class JenkinsServer implements TransactionalActor { long start = currentTimeMillis(); JenkinsDao dao = new JenkinsDao(c); - Option<List<JenkinsEntryXml>> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssLatest")); + Option<List<JenkinsEntryXml>> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssAll")); if (option.isNone()) { return; |