#!/usr/bin/env ruby require 'drb' require 'pry' begin begin DRb.start_service("druby://localhost:0") rescue SocketError, Errno::EADDRNOTAVAIL DRb.start_service("druby://:0") end $spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989") rescue DRb::DRbConnError err.puts "No DRb server is running. Running in local process instead ..." end def rspec(file=nil) if file $spec_server.run(["--color", "--format", "s", file], STDERR, STDOUT) else $spec_server.run(["--color", 'spec'], STDERR, STDOUT) end end $service = nil def service $service ||= com.espertech.esper.client.EPServiceProviderManager.getDefaultProvider end $administrator = nil def administrator $administrator ||= service.getEPAdministrator end def compileEPL(query) administrator.compileEPL(query.expression) end def query_string(model) writer = java.io.StringWriter.new formatter = com.espertech.esper.client.soda.EPStatementFormatter.new if model.respond_to?(:toEPLElement) model.toEPLElement(writer) writer.toString elsif model.respond_to?(:toPrecedenceFreeEPL) begin model.toPrecedenceFreeEPL(writer) rescue ArgumentError model.toPrecedenceFreeEPL(writer, formatter) end writer.toString elsif model.is_a?(Java::ComEspertechEsperClientSoda::EPStatementObjectModel) model.toEPL else model.toEPL(writer, formatter) writer.toString end end def compiledExpression(query) model = compileEPL(query) mapping = {} query.targets.each do |target| mapping[target] = target end Norikra::Query.rewrite_query(model, mapping) query_string(model) end puts < rspec 'spec/xxx_spec.rb' or (for all tests) > rspec DESC $LOAD_PATH.push './lib' $LOAD_PATH.push './esper' require 'norikra' require 'java' require 'esper-4.9.0.jar' require 'esper/lib/commons-logging-1.1.1.jar' require 'esper/lib/antlr-runtime-3.2.jar' require 'esper/lib/cglib-nodep-2.2.jar' Pry.start