From f6e357ef18a0c44038fc0ea723c1ec7910bb3f30 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 9 Dec 2012 22:43:23 +0100 Subject: woot --- .../java/io/trygvis/esper/testing/esper/Test3.java | 110 +++++++++++++++++++++ .../esper/testing/jenkins/JenkinsClient.java | 2 + .../esper/testing/jenkins/JenkinsServer.java | 2 +- src/main/resources/logback-test.xml | 20 ---- src/main/resources/logback.xml | 20 ++++ .../esper/testing/jenkins/JenkinsServerTest.java | 2 + 6 files changed, 135 insertions(+), 21 deletions(-) create mode 100755 src/main/java/io/trygvis/esper/testing/esper/Test3.java delete mode 100755 src/main/resources/logback-test.xml create mode 100755 src/main/resources/logback.xml 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> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssLatest")); + Option> option = client.fetchRss(URI.create(server.url.toASCIIString() + "/rssAll")); if (option.isNone()) { return; diff --git a/src/main/resources/logback-test.xml b/src/main/resources/logback-test.xml deleted file mode 100755 index 1a63a5f..0000000 --- a/src/main/resources/logback-test.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %-30logger{1} - %msg%n - - - - - - - - - - - - - - - diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100755 index 0000000..1a63a5f --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,20 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %-30logger{1} - %msg%n + + + + + + + + + + + + + + + diff --git a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java index cf3a84a..d0630b8 100644 --- a/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java +++ b/src/test/java/io/trygvis/esper/testing/jenkins/JenkinsServerTest.java @@ -6,6 +6,8 @@ import static io.trygvis.esper.testing.jenkins.JenkinsServer.*; public class JenkinsServerTest extends TestCase { public void testUrlGeneration() { +// assertEquals("https://jenkins.puppetlabs.com/job/Hiera%20%28master%29/74/api/xml", createJobUrl("https://jenkins.puppetlabs.com/job/Hiera%20%28master%29/facter=1.6.x,puppet=2.7.x,ruby=ruby-1.8.7,rvm=%23rvm/74/api/xml").toASCIIString()); + assertEquals("https://builds.apache.org/job/james-server-trunk/", createJobUrl("https://builds.apache.org/job/james-server-trunk/org.apache.james$james-server-dnsservice-library/3417/").toASCIIString()); assertEquals("http://ci.jruby.org/job/rails-master/", createJobUrl("http://ci.jruby.org/job/rails-master/component=activeresource,label=master/3577/").toASCIIString()); -- cgit v1.2.3