public void Run(Configuration configuration)
        {
            idCounter = new AtomicLong(0);
            executorService = Executors.NewCachedThreadPool();
            noActionUpdateListener = new NoActionUpdateListener();

            configuration.Runtime.Threading.IsInternalTimerEnabled = true;
            configuration.Common.AddEventType(typeof(SupportBean));
            configuration.Runtime.Threading.InsertIntoDispatchLocking = Locking.SUSPEND;

            var runtime = EPRuntimeProvider.GetRuntime(GetType().Name, configuration);
            runtime.Initialize();
            epRuntime = runtime.EventService;

            var path = new RegressionPath();
            var epl = "insert into Stream1 select count(*) as cnt from SupportBean#time(7 sec)";
            var compiled = SupportCompileDeployUtil.Compile(epl, configuration, path);
            path.Add(compiled);
            SupportCompileDeployUtil.Deploy(compiled, runtime);

            epl = epl + " output every 10 seconds";
            compiled = SupportCompileDeployUtil.Compile(epl, configuration, path);
            SupportCompileDeployUtil.DeployAddListener(compiled, "insert", noActionUpdateListener, runtime);

            var sendTickEventRunnable = new SendEventRunnable(this, 10000);
            Start(sendTickEventRunnable, 4);

            // Adjust here for long-running test
            SupportCompileDeployUtil.ThreadSleep(3000);
            sendTickEventRunnable.Shutdown = true;

            executorService.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(executorService, 1, TimeUnit.SECONDS);
            runtime.Destroy();
        }
            public void Run(Configuration config)
            {
                config.Runtime.Threading.IsInternalTimerEnabled = true;
                config.Common.TimeSource.TimeUnit = TimeUnit.MICROSECONDS;

                try {
                    EPRuntimeProvider.GetRuntime(GetType().Name, config).Initialize();
                    Assert.Fail();
                }
                catch (ConfigurationException ex) {
                    SupportMessageAssertUtil.AssertMessage(ex, "Internal timer requires millisecond time resolution");
                }

                config.Runtime.Threading.IsInternalTimerEnabled = false;
                var runtime = EPRuntimeProvider.GetRuntime(GetType().Name, config);

                try {
                    runtime.EventService.ClockInternal();
                    Assert.Fail();
                }
                catch (EPException ex) {
                    SupportMessageAssertUtil.AssertMessage(ex, "Internal timer requires millisecond time resolution");
                }

                runtime.Destroy();
            }
示例#3
0
        public void Run(Configuration configuration)
        {
            // Test uses system time
            //
            configuration.Runtime.Threading.IsInternalTimerEnabled = true;
            configuration.Common.AddEventType(typeof(TestEvent));
            var runtime = EPRuntimeProvider.GetRuntime(GetType().Name, configuration);
            runtime.Initialize();

            var path = new RegressionPath();
            var eplCtx = "@Name('ctx') create context theContext " +
                         " initiated by distinct(PartitionKey) TestEvent as test " +
                         " terminated after 100 milliseconds";
            var compiledContext = Compile(eplCtx, configuration, path);
            path.Add(compiledContext);
            Deploy(compiledContext, runtime);

            var eplStmt = "context theContext " +
                          "select sum(Value) as thesum, count(*) as thecnt " +
                          "from TestEvent output snapshot when terminated";
            var compiledStmt = Compile(eplStmt, configuration, path);
            var listener = new SupportUpdateListener();
            DeployAddListener(compiledStmt, "s0", listener, runtime);

            var numLoops = 2000000;
            var numEvents = numLoops * 4;
            for (var i = 0; i < numLoops; i++) {
                if (i % 100000 == 0) {
                    Console.Out.WriteLine("Completed: " + i);
                }

                runtime.EventService.SendEventBean(new TestEvent("TEST", 10), "TestEvent");
                runtime.EventService.SendEventBean(new TestEvent("TEST", -10), "TestEvent");
                runtime.EventService.SendEventBean(new TestEvent("TEST", 25), "TestEvent");
                runtime.EventService.SendEventBean(new TestEvent("TEST", -25), "TestEvent");
            }

            var numDeliveries = listener.NewDataList.Count;
            Console.Out.WriteLine("Done " + numLoops + " loops, have " + numDeliveries + " deliveries");
            Assert.IsTrue(numDeliveries > 3);

            ThreadSleep(1000);

            var sum = 0;
            long count = 0;
            foreach (var @event in listener.NewDataListFlattened) {
                var sumBatch = @event.Get("thesum").AsBoxedInt32();
                // Comment-Me-In: System.out.println(EventBeanUtility.summarize(event));
                if (sumBatch != null) { // can be null when there is nothing to deliver
                    sum += sumBatch.Value;
                    count += @event.Get("thecnt").AsInt64();
                }
            }

            Console.Out.WriteLine("count=" + count + "  sum=" + sum);
            Assert.AreEqual(numEvents, count);
            Assert.AreEqual(0, sum);

            runtime.Destroy();
        }
示例#4
0
        public void SetUp()
        {
            var container = ContainerExtensions.CreateDefaultContainer()
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.Common.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;
            configuration.Common.AddEventType("StockTick", typeof(StockTick).FullName);
            _runtime = EPRuntimeProvider.GetRuntime("TestStockTickerRSI", configuration);
            _runtime.Initialize();

            _stockListener  = new RSIStockTickerListener(_runtime, PERIOD);
            _expressionText = "every tick=StockTick(stockSymbol='" + SYMBOL + "')";
            //_expressionText = "every tick1=StockTick(stockSymbol='GOOG') -> tick2=StockTick(stockSymbol='GOOG')";
            _factory         = _runtime.CompileDeploy(_expressionText).Statements[0];
            _factory.Events += _stockListener.Update;

            var rsiEvent = typeof(RSIEvent).FullName;
            var viewExpr = "select * from " + rsiEvent + ".win:length(1)";

            _rsiListener     = new RSIListener();
            _factory         = _runtime.CompileDeploy(viewExpr).Statements[0];
            _factory.Events += _rsiListener.Update;
            _rsiListener.Reset();
        }
示例#5
0
        public void SetUp()
        {
            var container = ContainerExtensions.CreateDefaultContainer()
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.Runtime.Threading.IsInternalTimerEnabled = false;
            configuration.Common.AddEventType("MarketDataEvent", typeof(MarketDataEvent).FullName);
            configuration.Common.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;

            _runtime = EPRuntimeProvider.GetRuntime("TestTicksPerSecondStatement", configuration);
            _runtime.Initialize();
            _runtime.EventService.AdvanceTime(0);

            TicksPerSecondStatement.Create(_runtime);
            var stmt = TicksFalloffStatement.Create(_runtime);

            _listener    = new SupportUpdateListener();
            stmt.Events += _listener.Update;

            // Use external clocking for the test
            _runtime.EventService.ClockExternal();
        }
示例#6
0
        public void Run(Configuration configuration)
        {
            configuration.Runtime.Threading.IsInternalTimerEnabled = false;
            configuration.Common.AddEventType(typeof(SupportBean));
            var runtime = EPRuntimeProvider.GetRuntime(typeof(ClientRuntimeTimeControlClockType).Name, configuration);

            runtime.EventService.AdvanceTime(0);
            Assert.AreEqual(0, runtime.EventService.CurrentTime);
            Assert.IsTrue(runtime.EventService.IsExternalClockingEnabled());

            runtime.EventService.ClockInternal();
            Assert.IsFalse(runtime.EventService.IsExternalClockingEnabled());
            var waitStart = DateTimeHelper.CurrentTimeMillis;
            var waitTarget = waitStart + 10000;

            long currMillis;
            while ((currMillis = DateTimeHelper.CurrentTimeMillis) < waitTarget) {
                if (runtime.EventService.CurrentTime > 0) {
                    break;
                }
            }

            currMillis = DateTimeHelper.CurrentTimeMillis;
            Assert.AreNotEqual(0, runtime.EventService.CurrentTime);
            Assert.That(currMillis, Is.GreaterThan(runtime.EventService.CurrentTime - 10000));

            runtime.EventService.ClockExternal();
            Assert.IsTrue(runtime.EventService.IsExternalClockingEnabled());
            runtime.EventService.AdvanceTime(0);
            ThreadSleep(500);
            Assert.AreEqual(0, runtime.EventService.CurrentTime);

            runtime.Destroy();
        }
示例#7
0
        public void TestNestedMapProperties()
        {
            var configuration = new Configuration(_container);
            var point         = new Dictionary <string, object>();

            point.Put("X", typeof(int));
            point.Put("Y", typeof(int));

            var figure = new Dictionary <string, object>();

            figure.Put("Name", typeof(string));
            figure.Put("Point", point);

            configuration.Common.AddEventType("Figure", figure);
            var runtime = EPRuntimeProvider.GetRuntime("testNestedMapProperties", configuration);
            var ul      = new SupportUpdateListener();
            var stmt    = CompileUtil.CompileDeploy(runtime, "select * from Figure").Statements[0];

            stmt.Events += ul.Update;

            var source  = new AdapterInputSource(_container, "regression/nestedProperties.csv");
            var spec    = new CSVInputAdapterSpec(source, "Figure");
            var adapter = new CSVInputAdapter(runtime, spec);

            adapter.Start();

            Assert.IsTrue(ul.IsInvoked());
            var e = ul.AssertOneGetNewAndReset();

            Assert.AreEqual(1, e.Get("Point.X"));
        }
示例#8
0
        public void TestNestedProperties()
        {
            var container = ContainerExtensions.CreateDefaultContainer();

            var configuration = new Configuration(container);

            configuration.Common.AddEventType(typeof(Figure));

            var runtime = EPRuntimeProvider.GetRuntime("testNestedProperties", configuration);
            var ul      = new SupportUpdateListener();

            var stmt = CompileUtil.CompileDeploy(runtime, "select * from Figure").Statements[0];

            stmt.Events += ul.Update;

            var source  = new AdapterInputSource(_container, "regression/nestedProperties.csv");
            var spec    = new CSVInputAdapterSpec(source, "Figure");
            var adapter = new CSVInputAdapter(runtime, spec);

            adapter.Start();

            Assert.IsTrue(ul.IsInvoked());
            var e = ul.AssertOneGetNewAndReset();
            var f = (Figure)e.Underlying;

            Assert.AreEqual(1, f.Point.X);
        }
            public void Run(Configuration config)
            {
                var listener = new SupportRuntimeStateListener();
                var runtime = EPRuntimeProvider.GetRuntime(GetType().Name + "__listenerstatechange", config);
                runtime.AddRuntimeStateListener(listener);
                runtime.Destroy();
                Assert.AreSame(runtime, listener.AssertOneGetAndResetDestroyedEvents());

                runtime.Initialize();
                Assert.AreSame(runtime, listener.AssertOneGetAndResetInitializedEvents());

                runtime.RemoveAllRuntimeStateListeners();
                runtime.Initialize();
                Assert.IsTrue(listener.InitializedEvents.IsEmpty());

                runtime.AddRuntimeStateListener(listener);
                var listenerTwo = new SupportRuntimeStateListener();
                runtime.AddRuntimeStateListener(listenerTwo);
                runtime.Initialize();
                Assert.AreSame(runtime, listener.AssertOneGetAndResetInitializedEvents());
                Assert.AreSame(runtime, listenerTwo.AssertOneGetAndResetInitializedEvents());

                Assert.IsTrue(runtime.RemoveRuntimeStateListener(listener));
                runtime.Initialize();
                Assert.AreSame(runtime, listenerTwo.AssertOneGetAndResetInitializedEvents());
                Assert.IsTrue(listener.InitializedEvents.IsEmpty());

                runtime.Destroy();
            }
示例#10
0
            public void Run(Configuration configuration)
            {
                configuration.Runtime.ExceptionHandling.HandlerFactories.Clear();
                configuration.Compiler.AddPlugInAggregationFunctionForge(
                    "myinvalidagg",
                    typeof(SupportInvalidAggregationFunctionForge));
                configuration.Common.AddEventType(typeof(SupportBean));

                var runtime = EPRuntimeProvider.GetRuntime(
                    typeof(ClientRuntimeExceptionHandlerNoHandler).Name,
                    configuration);

                var epl = "@Name('ABCName') select myinvalidagg() from SupportBean";
                EPDeployment deployment;
                try {
                    var compiled = EPCompilerProvider.Compiler.Compile(epl, new CompilerArguments(configuration));
                    deployment = runtime.DeploymentService.Deploy(compiled);
                }
                catch (Exception t) {
                    throw new EPException(t);
                }

                runtime.EventService.SendEventBean(new SupportBean(), "SupportBean");

                runtime.Destroy();
            }
示例#11
0
        public void Run()
        {
            var container = ContainerExtensions.CreateDefaultContainer()
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            // load config - this defines the XML event types to be processed
            var configFile = "esper.examples.cfg.xml";
            var url        = container.ResourceManager().ResolveResourceURL(configFile);
            var config     = new Configuration(container);

            config.Configure(url);

            // get engine instance
            var runtime = EPRuntimeProvider.GetRuntime(runtimeUri, config);

            // set up statement
            var rfidStmt = RFIDTagsPerSensorStmt.Create(runtime);

            rfidStmt.Events += LogRate;

            // Send events
            var eventCount = 0;

            while (eventCount < numEvents)
            {
                SendEvent(runtime);
                eventCount++;
            }
        }
示例#12
0
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            IDictionary <String, Object> propertyTypes = new LinkedHashMap <String, Object>();

            propertyTypes.Put("myInt", typeof(int));
            propertyTypes.Put("myDouble", typeof(double?));
            propertyTypes.Put("myString", typeof(String));

            _eventTypeName = "mapEvent";
            var configuration = new Configuration(_container);

            configuration.Runtime.Threading.IsInternalTimerEnabled = false;
            configuration.Common.AddEventType(_eventTypeName, propertyTypes);

            _runtime = EPRuntimeProvider.GetRuntime("Adapter", configuration);
            _runtime.Initialize();

            var statementText = "select * from mapEvent#length(5)";
            var statement     = CompileUtil.CompileDeploy(_runtime, statementText).Statements[0];

            _listener         = new SupportUpdateListener();
            statement.Events += _listener.Update;

            // Set the clock to 0
            _currentTime = 0;
            SendTimeEvent(0);

            _coordinator = new AdapterCoordinatorImpl(_runtime, true);

            _propertyOrderNoTimestamp = new[] { "myInt", "myDouble", "myString" };
            var propertyOrderTimestamp = new[] { "timestamp", "myInt", "myDouble", "myString" };

            // A CSVPlayer for a file with timestamps, not looping
            _timestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/timestampOne.csv"), _eventTypeName);
            _timestampsNotLooping.IsUsingEngineThread = true;
            _timestampsNotLooping.PropertyOrder       = propertyOrderTimestamp;
            _timestampsNotLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter for a file with timestamps, looping
            _timestampsLooping                     = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/timestampTwo.csv"), _eventTypeName);
            _timestampsLooping.IsLooping           = true;
            _timestampsLooping.IsUsingEngineThread = true;
            _timestampsLooping.PropertyOrder       = propertyOrderTimestamp;
            _timestampsLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter that sends 10 events per sec, not looping
            _noTimestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/noTimestampOne.csv"), _eventTypeName);
            _noTimestampsNotLooping.EventsPerSec        = 10;
            _noTimestampsNotLooping.PropertyOrder       = _propertyOrderNoTimestamp;
            _noTimestampsNotLooping.IsUsingEngineThread = true;

            // A CSVAdapter that sends 5 events per sec, looping
            _noTimestampsLooping = new CSVInputAdapterSpec(new AdapterInputSource(_container, "regression/noTimestampTwo.csv"), _eventTypeName);
            _noTimestampsLooping.EventsPerSec        = 5;
            _noTimestampsLooping.IsLooping           = true;
            _noTimestampsLooping.PropertyOrder       = _propertyOrderNoTimestamp;
            _noTimestampsLooping.IsUsingEngineThread = true;
        }
示例#13
0
        public void TestEngineThread1PerSec()
        {
            _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", MakeConfig("TypeA"));
            _runtime.Initialize();

            var stmt     = CompileDeploy(_runtime, "select symbol, price, volume from TypeA#length(100)").Statements[0];
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            var spec = new CSVInputAdapterSpec(new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE_MULTIPLE), "TypeA");

            spec.EventsPerSec        = 1;
            spec.IsUsingEngineThread = true;

            InputAdapter inputAdapter = new CSVInputAdapter(_runtime, spec);

            inputAdapter.Start();

            Thread.Sleep(1500);
            Assert.AreEqual(1, listener.GetNewDataList().Count);
            listener.Reset();
            Thread.Sleep(300);
            Assert.AreEqual(0, listener.GetNewDataList().Count);

            Thread.Sleep(2000);
            Assert.IsTrue(listener.GetNewDataList().Count >= 2);
        }
示例#14
0
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            _propertyTypes = new Dictionary<String, Object>();
            _propertyTypes.Put("MyInt", typeof(int?));
            _propertyTypes.Put("MyDouble", typeof(double?));
            _propertyTypes.Put("MyString", typeof(String));

            _eventTypeName = "mapEvent";
            var configuration = new Configuration(_container);
            configuration.Runtime.Threading.IsInternalTimerEnabled = false;
            configuration.Common.AddEventType(_eventTypeName, _propertyTypes);
            configuration.Common.AddEventType("myNonMapEvent", typeof(Type).FullName);

            _runtime = EPRuntimeProvider.GetRuntime("CSVProvider", configuration);
            _runtime.Initialize();

            var statementText = "select * from mapEvent#length(5)";
            var statement = CompileDeploy(_runtime, statementText).Statements[0];

            _listener = new SupportUpdateListener();
            statement.Events += _listener.Update;

            // Set the clock to 0
            _currentTime = 0;
            SendTimeEvent(0);

            _propertyOrderNoTimestamps = new[] {"MyInt", "MyDouble", "MyString"};
            _propertyOrderTimestamps = new[] {"timestamp", "MyInt", "MyDouble", "MyString"};
        }
        public void TestReadWritePropsBean()
        {
            var configuration = new Configuration(_container);

            configuration.Common.AddEventType("ExampleMarketDataBeanReadWrite", typeof(ExampleMarketDataBeanReadWrite));
            //configuration.Common.AddImportNamespace(typeof(FileSourceCSV));
            configuration.Common.AddImportNamespace(typeof(DefaultSupportCaptureOp));

            _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", configuration);
            _runtime.Initialize();

            var stmt     = CompileUtil.CompileDeploy(_runtime, "select * from ExampleMarketDataBeanReadWrite#length(100)").Statements[0];
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            var inputAdapter = new CSVInputAdapter(
                _runtime,  // _baseUseCase.Runtime,
                new AdapterInputSource(_container, TestCSVAdapterUseCases.CSV_FILENAME_ONELINE_TRADE), "ReadWrite");

            inputAdapter.Start();

            Assert.AreEqual(1, listener.GetNewDataList().Count);
            var eb = listener.GetNewDataList()[0][0];

            Assert.IsTrue(typeof(ExampleMarketDataBeanReadWrite) == eb.Underlying.GetType());
            Assert.AreEqual(55.5 * 1000, eb.Get("value"));
        }
示例#16
0
        /// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run()
        {
            var container = ContainerExtensions.CreateDefaultContainer();

            // Configure engine with event names to make the statements more readable.
            // This could also be done in a configuration file.
            var configuration = new Configuration(container);

            configuration.Common.AddEventType("TxnEventA", typeof(TxnEventA));
            configuration.Common.AddEventType("TxnEventB", typeof(TxnEventB));
            configuration.Common.AddEventType("TxnEventC", typeof(TxnEventC));

            // Get engine instance
            var runtime = EPRuntimeProvider.GetRuntime(_engineURI, configuration);

            // We will be supplying timer events externally.
            // We will assume that each bucket arrives within a defined period of time.
            runtime.EventService.ClockExternal();

            // Set up statement for listening to combined events
            var combinedEventStmt = CombinedEventStmt.Create(runtime);

            combinedEventStmt.Events += LogCombinedEvents;

            // Set up statements for realtime summary latency data - overall totals and totals per customer and per supplier
            RealtimeSummaryStmt realtimeSummaryStmt = new RealtimeSummaryStmt(runtime);

            realtimeSummaryStmt.TotalsStatement.Events   += LogSummaryTotals;
            realtimeSummaryStmt.CustomerStatement.Events +=
                (sender, e) => LogSummaryGroup("customerId", e);
            realtimeSummaryStmt.SupplierStatement.Events +=
                (sender, e) => LogSummaryGroup("supplierId", e);

            // Set up statement for finding missing events
            var findMissingEventStmt = FindMissingEventStmt.Create(runtime);

            findMissingEventStmt.Events += FindMissingEvent;

            // The feeder to feed the engine
            var feeder = new FeederOutputStream(runtime);

            // Generate transactions
            var source = new TransactionEventSource(_numTransactions);
            var output = new ShuffledBucketOutput(source, feeder, _bucketSize);

            // Feed events
            if (_continuousSimulation)
            {
                while (true)
                {
                    output.Output();
                    Thread.Sleep(5000); // Send a batch every 5 seconds
                }
            }
            else
            {
                output.Output();
            }
        }
        public void Run(Configuration configuration)
        {
            configuration.Runtime.Threading.IsInternalTimerEnabled = true;
            configuration.Common.AddEventType(typeof(TestEvent));

            var runtime = EPRuntimeProvider.GetRuntime(GetType().Name, configuration);
            runtime.Initialize();
            ThreadSleep(100); // allow time for start up

            var path = new RegressionPath();
            var eplContext = "create context theContext " +
                             "context perPartition partition by PartitionKey from TestEvent," +
                             "context per10Seconds start @now end after 100 milliseconds";
            var compiledContext = Compile(eplContext, configuration, path);
            path.Add(compiledContext);
            Deploy(compiledContext, runtime);

            var eplStmt = "context theContext " +
                          "select sum(Value) as thesum, count(*) as thecnt, context.perPartition.key1 as thekey " +
                          "from TestEvent output snapshot when terminated";
            var compiledStmt = Compile(eplStmt, configuration, path);
            var listener = new SupportUpdateListener();
            DeployAddListener(compiledStmt, "s0", listener, runtime);

            var numLoops = 200000;
            var numEvents = numLoops * 4;
            for (var i = 0; i < numLoops; i++) {
                if (i % 100000 == 0) {
                    Console.Out.WriteLine("Completed: " + i);
                }

                runtime.EventService.SendEventBean(new TestEvent("TEST", 10), "TestEvent");
                runtime.EventService.SendEventBean(new TestEvent("TEST", -10), "TestEvent");
                runtime.EventService.SendEventBean(new TestEvent("TEST", 25), "TestEvent");
                runtime.EventService.SendEventBean(new TestEvent("TEST", -25), "TestEvent");
            }

            ThreadSleep(250);

            var numDeliveries = listener.NewDataList.Count;
            Assert.IsTrue(numDeliveries >= 2, "Done " + numLoops + " loops, have " + numDeliveries + " deliveries");

            var sum = 0;
            long count = 0;
            foreach (var @event in listener.NewDataListFlattened) {
                var sumBatch = @event.Get("thesum").AsBoxedInt32();
                if (sumBatch != null) { // can be null when there is nothing to deliver
                    sum += sumBatch.Value;
                    count += @event.Get("thecnt").AsInt64();
                }
            }

            Assert.AreEqual(0, sum);
            Assert.AreEqual(numEvents, count);
            runtime.Destroy();
        }
示例#18
0
            public void Init(int sleepListenerMillis)
            {
                var container     = ContainerExtensions.CreateDefaultContainer();
                var configuration = new Configuration(container);

                configuration.Common.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;
                configuration.Common.AddEventType("Market", typeof(MarketData));
                _runtime          = EPRuntimeProvider.GetRuntime("benchmark", configuration);
                _marketDataSender = _runtime.EventService.GetEventSender("Market");
                _sleepMillis      = sleepListenerMillis;
            }
            public void Run(Configuration config)
            {
                var uriOne = GetType().Name + "_1";
                var runtimeOne = EPRuntimeProvider.GetRuntime(uriOne, config);
                var uriTwo = GetType().Name + "_2";
                var runtimeTwo = EPRuntimeProvider.GetRuntime(uriTwo, config);
                EPAssertionUtil.AssertContains(EPRuntimeProvider.RuntimeURIs, uriOne, uriTwo);
                Assert.IsNotNull(EPRuntimeProvider.GetExistingRuntime(uriOne));
                Assert.IsNotNull(EPRuntimeProvider.GetExistingRuntime(uriTwo));

                config.Common.AddEventType(typeof(SupportBean));
                EPCompiled compiled;
                try {
                    compiled = EPCompilerProvider.Compiler.Compile(
                        "select * from SupportBean",
                        new CompilerArguments(config));
                }
                catch (EPCompileException e) {
                    throw new EPException(e);
                }

                var adminOne = runtimeOne.DeploymentService;
                runtimeOne.Destroy();
                EPAssertionUtil.AssertNotContains(EPRuntimeProvider.RuntimeURIs, uriOne);
                EPAssertionUtil.AssertContains(EPRuntimeProvider.RuntimeURIs, uriTwo);
                Assert.IsNull(EPRuntimeProvider.GetExistingRuntime(uriOne));
                Assert.IsTrue(runtimeOne.IsDestroyed);
                Assert.IsFalse(runtimeTwo.IsDestroyed);

                var stageTwo = runtimeTwo.StageService;
                runtimeTwo.Destroy();
                EPAssertionUtil.AssertNotContains(EPRuntimeProvider.RuntimeURIs, uriOne, uriTwo);
                Assert.IsNull(EPRuntimeProvider.GetExistingRuntime(uriTwo));
                Assert.IsTrue(runtimeOne.IsDestroyed);
                Assert.IsTrue(runtimeTwo.IsDestroyed);

                Assert.That(
                    () => adminOne.Rollout(Collections.SingletonList(new EPDeploymentRolloutCompiled(compiled))),
                    Throws.InstanceOf<EPRuntimeDestroyedException>());

                Assert.That(
                    () => adminOne.Deploy(compiled),
                    Throws.InstanceOf<EPRuntimeDestroyedException>());

                EPAssertionUtil.AssertNotContains(EPRuntimeProvider.RuntimeURIs, uriTwo);

                TryAssertDestroyed(() => DoNothing(runtimeTwo.EventService));
                TryAssertDestroyed(() => DoNothing(runtimeTwo.DeploymentService));
                TryAssertDestroyed(() => DoNothing(runtimeTwo.StageService));
                TryAssertDestroyed(() => stageTwo.GetStage("x"));
                TryAssertDestroyed(() => stageTwo.GetExistingStage("x"));
                TryAssertDestroyed(() => DoNothing(stageTwo.StageURIs));
            }
示例#20
0
            public void Run(Configuration configuration)
            {
                SupportExceptionHandlerFactory.FactoryContexts.Clear();
                SupportExceptionHandlerFactory.Handlers.Clear();
                configuration.Runtime.ExceptionHandling.HandlerFactories.Clear();
                configuration.Runtime.ExceptionHandling.AddClass(typeof(SupportExceptionHandlerFactory));
                configuration.Runtime.ExceptionHandling.AddClass(typeof(SupportExceptionHandlerFactory));
                configuration.Common.AddEventType(typeof(SupportBean));
                configuration.Compiler.AddPlugInAggregationFunctionForge(
                    "myinvalidagg",
                    typeof(SupportInvalidAggregationFunctionForge));

                var runtime = EPRuntimeProvider.GetRuntime(
                    typeof(ClientRuntimeExHandlerGetContext).FullName,
                    configuration);

                SupportExceptionHandlerFactory.FactoryContexts.Clear();
                SupportExceptionHandlerFactory.Handlers.Clear();
                runtime.Initialize();

                var epl = "@Name('ABCName') select myinvalidagg() from SupportBean";
                EPDeployment deployment;
                try {
                    var compiled = EPCompilerProvider.Compiler.Compile(epl, new CompilerArguments(configuration));
                    deployment = runtime.DeploymentService.Deploy(compiled);
                }
                catch (Exception t) {
                    throw new EPException(t);
                }

                var contexts = SupportExceptionHandlerFactory.FactoryContexts;
                Assert.AreEqual(2, contexts.Count);
                Assert.AreEqual(runtime.URI, contexts[0].RuntimeURI);
                Assert.AreEqual(runtime.URI, contexts[1].RuntimeURI);

                var handlerOne = SupportExceptionHandlerFactory.Handlers[0];
                var handlerTwo = SupportExceptionHandlerFactory.Handlers[1];
                runtime.EventService.SendEventBean(new SupportBean(), "SupportBean");

                Assert.AreEqual(1, handlerOne.Contexts.Count);
                Assert.AreEqual(1, handlerTwo.Contexts.Count);
                var ehc = handlerOne.Contexts[0];
                Assert.AreEqual(runtime.URI, ehc.RuntimeURI);
                Assert.AreEqual(epl, ehc.Epl);
                Assert.AreEqual(deployment.DeploymentId, ehc.DeploymentId);
                Assert.AreEqual("ABCName", ehc.StatementName);
                Assert.AreEqual("Sample exception", ehc.Exception.Message);
                Assert.IsNotNull(ehc.CurrentEvent);

                runtime.Destroy();
            }
        private static void TrySend(
            int numThreads,
            int numEvents,
            bool isPreserveOrder,
            Locking locking,
            Configuration configuration)
        {
            configuration.Runtime.Threading.IsListenerDispatchPreserveOrder = isPreserveOrder;
            configuration.Runtime.Threading.ListenerDispatchLocking = locking;
            configuration.Common.AddEventType(typeof(SupportBean));

            var runtime = EPRuntimeProvider.GetRuntime(typeof(MultithreadDeterminismListener).Name, configuration);
            runtime.Initialize();

            // setup statements
            var deployed = SupportCompileDeployUtil.CompileDeploy(
                "@Name('s0') select count(*) as cnt from SupportBean",
                runtime,
                configuration);
            var listener = new SupportMTUpdateListener();
            deployed.Statements[0].AddListener(listener);

            // execute
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadDeterminismListener)).ThreadFactory);
            var future = new IFuture<bool>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                future[i] = threadPool.Submit(new SendEventCallable(i, runtime, new GeneratorEnumerator(numEvents)));
            }

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS);
            SupportCompileDeployUtil.AssertFutures(future);

            var events = listener.GetNewDataListFlattened();
            var result = new long[events.Length];
            for (var i = 0; i < events.Length; i++) {
                result[i] = events[i].Get("cnt").AsInt64();
            }
            //log.info(".trySend result=" + Arrays.toString(result));

            // assert result
            Assert.AreEqual(numEvents * numThreads, events.Length);
            for (var i = 0; i < numEvents * numThreads; i++) {
                Assert.AreEqual(result[i], (long) i + 1);
            }

            runtime.Destroy();
        }
示例#22
0
        public void TestExistingTypeNoOptions()
        {
            _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", MakeConfig("TypeA", _useBean));
            _runtime.Initialize();

            var stmt     = CompileDeploy(_runtime, "select symbol, price, volume from TypeA#length(100)").Statements[0];
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            (new CSVInputAdapter(_runtime, new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "TypeA")).Start();

            Assert.AreEqual(1, listener.GetNewDataList().Count);
        }
        public void TestReadWritePropsBean()
        {
            var configuration = new Configuration(_container);

            configuration.Common.AddEventType("ExampleMarketDataBeanReadWrite", typeof(ExampleMarketDataBeanReadWrite));
            configuration.Common.AddImportNamespace(typeof(FileSourceCSV));
            configuration.Common.AddImportNamespace(typeof(DefaultSupportCaptureOp));

            _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", configuration);
            _runtime.Initialize();

            var stmt     = CompileUtil.CompileDeploy(_runtime, "select * from ExampleMarketDataBeanReadWrite#length(100)").Statements[0];
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            var inputAdapter = new CSVInputAdapter(
                _runtime, new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "ExampleMarketDataBeanReadWrite");

            inputAdapter.Start();

            Assert.AreEqual(1, listener.GetNewDataList().Count);
            var eb = listener.GetNewDataList()[0][0];

            Assert.IsTrue(typeof(ExampleMarketDataBeanReadWrite) == eb.Underlying.GetType());
            Assert.AreEqual(55.5 * 1000, eb.Get("value"));

            // test graph
            var graph =
                "create dataflow ReadCSV " +
                "FileSource -> mystream<ExampleMarketDataBeanReadWrite> { file: '" + CSV_FILENAME_ONELINE_TRADE + "', hasTitleLine: true }" +
                "DefaultSupportCaptureOp(mystream) {}";
            var deployment = CompileUtil.CompileDeploy(_runtime, graph);

            var outputOp = new DefaultSupportCaptureOp();
            var instance = _runtime.DataFlowService.Instantiate(
                deployment.DeploymentId,
                "ReadCSV",
                new EPDataFlowInstantiationOptions().WithOperatorProvider(new DefaultSupportGraphOpProvider(outputOp)));

            instance.Run();
            var received = outputOp.GetAndReset()[0].ToArray();

            Assert.That(received.Length, Is.EqualTo(1));
            Assert.That(received[0], Is.InstanceOf <ExampleMarketDataBean>());
            Assert.That(
                ((ExampleMarketDataBeanReadWrite)received[0]).Value,
                Is.EqualTo(55.5 * 1000.0));
        }
示例#24
0
        public static void TryInvalidConfigurationRuntime(
            Configuration config,
            Consumer<Configuration> configurer,
            string expected)
        {
            config.Common.AddEventType(typeof(SupportBean));
            configurer.Invoke(config);

            try {
                EPRuntimeProvider.GetRuntime(Guid.NewGuid().ToString(), config);
                Assert.Fail();
            }
            catch (ConfigurationException ex) {
                AssertMessage(ex, expected);
            }
        }
示例#25
0
        private void TrySource(AdapterInputSource source)
        {
            var spec = new CSVInputAdapterSpec(source, "TypeC");

            _runtime = EPRuntimeProvider.GetRuntime("testPlayFromInputStream", MakeConfig("TypeC"));
            _runtime.Initialize();
            InputAdapter feed = new CSVInputAdapter(_runtime, spec);

            var stmt     = CompileUtil.CompileDeploy(_runtime, "select * from TypeC#length(100)").Statements[0];
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            feed.Start();
            Assert.AreEqual(1, listener.GetNewDataList().Count);
        }
示例#26
0
        public virtual void SetUp()
        {
            var container = ContainerExtensions.CreateDefaultContainer();

            var configuration = new Configuration(container);

            configuration.Common.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;
            configuration.Common.AddEventType("TxnEventA", typeof(TxnEventA));
            configuration.Common.AddEventType("TxnEventB", typeof(TxnEventB));
            configuration.Common.AddEventType("TxnEventC", typeof(TxnEventC));

            _runtime = EPRuntimeProvider.GetRuntime("TestStmtBase", configuration);
            _runtime.Initialize();

            _eventService = _runtime.EventService;
        }
示例#27
0
        public void Run()
        {
            var container = ContainerExtensions.CreateDefaultContainer(false)
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.Common.AddEventType("PriceLimit", typeof(PriceLimit));
            configuration.Common.AddEventType("StockTick", typeof(StockTick));

            Log.Info("Setting up EPL");

            var runtime = EPRuntimeProvider.GetRuntime(_engineURI, configuration);

            runtime.Initialize();

            var eventService = runtime.EventService;

            new StockTickerMonitor(runtime, new StockTickerResultListener());

            Log.Info("Generating test events: 1 million ticks, ratio 2 hits, 100 stocks");
            var generator = new StockTickerEventGenerator();
            var stream    = generator.MakeEventStream(1000000, 500000, 100, 25, 30, 48, 52, false);

            Log.Info("Generating " + stream.Count + " events");

            Log.Info("Sending " + stream.Count + " limit and tick events");
            foreach (var @event in stream)
            {
                eventService.SendEventBean(@event, @event.GetType().Name);

                if (_continuousSimulation)
                {
                    try {
                        Thread.Sleep(200);
                    }
                    catch (ThreadInterruptedException e) {
                        Log.Debug("Interrupted", e);
                        break;
                    }
                }
            }

            Log.Info("Done.");
        }
        public void SetUp()
        {
            _listener = new StockTickerResultListener();

            var container = ContainerExtensions.CreateDefaultContainer(false)
                            .InitializeDefaultServices()
                            .InitializeDatabaseDrivers();

            var configuration = new Configuration(container);

            configuration.Common.AddEventType("PriceLimit", typeof(PriceLimit).FullName);
            configuration.Common.AddEventType("StockTick", typeof(StockTick).FullName);

            _runtime = EPRuntimeProvider.GetRuntime("TestStockTickerMultithreaded", configuration);
            _runtime.Initialize();
            new StockTickerMonitor(_runtime, _listener);
        }
        public void Run()
        {
            Log.Info("Setting up engine instance.");

            var container = ContainerExtensions.CreateDefaultContainer();

            var config = new Configuration(container);

            config.Common.EventMeta.DefaultEventRepresentation = EventUnderlyingType.MAP; // use Map-type events for testing
            config.Compiler.AddPlugInVirtualDataWindow("sample", "samplevdw", typeof(SampleVirtualDataWindowFactory).FullName);
            config.Common.AddEventType(typeof(SampleTriggerEvent));
            config.Common.AddEventType(typeof(SampleJoinEvent));
            config.Common.AddEventType(typeof(SampleMergeEvent));

            var runtime = EPRuntimeProvider.GetRuntime("LargeExternalDataExample", config);

            // First: Create an event type for rows of the external data - here the example use a Map-based event and any of the other types (POJO, XML) can be used as well.
            // Populate event property names and types.
            // Note: the type must match the data returned by virtual data window indexes.
            CompileDeploy(runtime, "create schema SampleEvent as (key1 string, key2 string, value1 int, value2 double)");

            Log.Info("Creating named window with virtual.");

            // Create Named Window holding SampleEvent instances
            CompileDeploy(runtime, "create window MySampleWindow.sample:samplevdw() as SampleEvent");

            // Example subquery
            Log.Info("Running subquery example.");
            RunSubquerySample(runtime);

            // Example joins
            Log.Info("Running join example.");
            RunJoinSample(runtime);

            // Sample FAF
            Log.Info("Running fire-and-forget query example.");
            RunSampleFireAndForgetQuery(runtime);

            // Sample On-Merge
            Log.Info("Running on-merge example.");
            RunSampleOnMerge(runtime);

            // Cleanup
            Log.Info("Destroying engine instance, sample completed successfully.");
            runtime.Destroy();
        }
示例#30
0
        private void RunAssertion(
            FilterServiceProfile profile,
            Configuration configuration)
        {
            configuration.Runtime.Execution.FilterServiceProfile = profile;
            configuration.Common.AddEventType(typeof(MyEvent));

            var runtimeURI = GetType().Name + "_" + profile;
            var runtime = EPRuntimeProvider.GetRuntime(runtimeURI, configuration);

            var path = new RegressionPath();
            var eplContext = "create context MyContext start @now end after 100 milliseconds;\n";
            var compiledContext = SupportCompileDeployUtil.Compile(eplContext, configuration, path);
            SupportCompileDeployUtil.Deploy(compiledContext, runtime);
            path.Add(compiledContext);

            var epl = "context MyContext select FieldOne, count(*) as cnt from MyEvent " +
                      "group by FieldOne output last when terminated;\n";
            var compiledStmt = SupportCompileDeployUtil.Compile(epl, configuration, path);
            var listeners = new SupportUpdateListener[100];

            for (var i = 0; i < 100; i++) {
                listeners[i] = new SupportUpdateListener();
                var stmtName = "s" + i;
                SupportCompileDeployUtil.DeployAddListener(compiledStmt, stmtName, listeners[i], runtime);
            }

            var eventCount = 100000; // keep this divisible by 1000
            for (var i = 0; i < eventCount; i++) {
                var group = Convert.ToString(eventCount % 1000);
                runtime.EventService.SendEventBean(new MyEvent(Convert.ToString(i), group), "MyEvent");
            }

            SupportCompileDeployUtil.ThreadSleep(2000);

            AssertReceived(eventCount, listeners);

            try {
                runtime.DeploymentService.UndeployAll();
            }
            catch (EPUndeployException e) {
                throw new EPException(e);
            }

            runtime.Destroy();
        }