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"));
        }
Exemple #2
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++;
            }
        }
        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);
        }
        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;
        }
Exemple #5
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 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();
            }
            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();
            }
Exemple #8
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();
        }
Exemple #9
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();
            }
 public void SetUp()
 {
     DynaLatencySpikeMonitor.Start();
     _runtime = EPRuntimeProvider.GetDefaultRuntime();
     _senderOperationalMeasurement = _runtime.EventService.GetEventSender(typeof(OperationMeasurement).FullName);
     _senderLatencyLimit           = _runtime.EventService.GetEventSender(typeof(LatencyLimit).FullName);
 }
        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();
        }
Exemple #12
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();
        }
Exemple #13
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();
        }
Exemple #14
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();
        }
Exemple #15
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"));
        }
Exemple #16
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);
        }
Exemple #17
0
        public void TestIt()
        {
            var stmtText =
                "insert into ThroughputPerFeed " +
                " select feed, count(*) as cnt " +
                "from " + typeof(FeedEvent).FullName + ".win:time_batch(1 sec) " +
                "group by feed";

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

            var configuration = new Configuration(container);

            configuration.Common.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_INSENSITIVE;

            var runtime = EPRuntimeProvider.GetDefaultRuntime(configuration);
            var stmt    = runtime.DeployStatement(stmtText);

            stmt.Events += DisplayEvents;

            /*
             * while(true)
             * {
             *  FeedEvent event;
             *  event = new FeedEvent(FeedEnum.FEED_A, "IBM", 70);
             *  engine.GetEPRuntime().SendEvent(event);
             *  event = new FeedEvent(FeedEnum.FEED_B, "IBM", 70);
             *  engine.GetEPRuntime().SendEvent(event);
             * }
             */
        }
        public void TestDynamicType()
        {
            var spec = new CSVInputAdapterSpec(
                new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "TypeB");

            var config = new Configuration(_container);

            config.Runtime.Threading.IsInternalTimerEnabled = false;
            _runtime = EPRuntimeProvider.GetDefaultRuntime(config);
            _runtime.Initialize();

            CompileDeploy(_runtime, "@public @buseventtype create schema TypeB(symbol string, price string, volume string)");

            InputAdapter feed = new CSVInputAdapter(_runtime, spec);

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

            stmt.Events += listener.Update;

            Assert.AreEqual(typeof(string), stmt.EventType.GetPropertyType("symbol"));
            Assert.AreEqual(typeof(string), stmt.EventType.GetPropertyType("price"));
            Assert.AreEqual(typeof(string), stmt.EventType.GetPropertyType("volume"));

            feed.Start();
            Assert.AreEqual(1, listener.GetNewDataList().Count);
        }
Exemple #19
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();
            }
        }
Exemple #20
0
        public static void Start()
        {
            var runtime      = EPRuntimeProvider.GetDefaultRuntime();
            var latencyAlert = runtime.DeployStatement(
                "every alert=" + typeof(OperationMeasurement).FullName + "(latency > 20000)");

            latencyAlert.Events += LogLatencyEvent;
        }
        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();
        }
        public static void Start()
        {
            _runtime = EPRuntimeProvider.GetDefaultRuntime();

            var eventName    = typeof(LatencyLimit).FullName;
            var latencyAlert = _runtime.DeployStatement("every newlimit=" + eventName);

            latencyAlert.Events +=
                (sender, e) => { new DynaLatencySpikeMonitor((LatencyLimit)e.NewEvents[0]["newlimit"]); };
        }
Exemple #23
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;
            }
Exemple #24
0
        public void SetUp()
        {
            var configuration = new Configuration(SupportContainer.Reset());

            configuration.Runtime.Threading.IsInternalTimerEnabled = false;
            configuration.Common.AddImportNamespace(typeof(FileSinkFactory));
            configuration.Common.AddImportNamespace(typeof(DefaultSupportSourceOpForge));
            DefaultSupportGraphEventUtil.AddTypeConfiguration(configuration);
            runtime = EPRuntimeProvider.GetDefaultRuntime(configuration);
            runtime.Initialize();
        }
Exemple #25
0
 public void SetUp()
 {
     var configuration = new Configuration();
     configuration.Runtime.Threading.IsInternalTimerEnabled = false;
     configuration.Common.AddImportType(typeof(FileSourceForge));
     configuration.Common.AddImportType(typeof(DefaultSupportCaptureOpForge));
     configuration.Common.AddEventType("MyLineEvent", typeof(MyLineEvent));
     configuration.Common.AddEventType("MyInvalidEvent", typeof(MyInvalidEvent));
     runtime = EPRuntimeProvider.GetDefaultRuntime(configuration);
     runtime.Initialize();
 }
            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));
            }
Exemple #27
0
        public AverageLatencyMonitor()
        {
            var runtime = EPRuntimeProvider.GetDefaultRuntime();

            var statView = runtime.DeployStatement(
                "select * from " + typeof(OperationMeasurement).FullName +
                "#groupwin(CustomerId)" +
                "#groupwin(OperationName)" +
                "#length(100)" +
                "#uni(Latency)");

            statView.Events += (sender, e) => MonitorLatency(e, 10000);
        }
Exemple #28
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();
        }
        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);
        }