public void TestDefaultEngine()
        {
            Assert.AreEqual("default", EPServiceProviderManager.GetDefaultProvider().URI);
            var engineDefault = EPServiceProviderManager.GetDefaultProvider();

            Assert.IsTrue(engineDefault.EPRuntime.IsExternalClockingEnabled);

            var engine = EPServiceProviderManager.GetProvider("default");

            Assert.AreSame(engineDefault, engine);

            engine = EPServiceProviderManager.GetProvider(null);
            Assert.AreSame(engineDefault, engine);

            engine = EPServiceProviderManager.GetProvider(null, SupportConfigFactory.GetConfiguration());
            Assert.AreSame(engineDefault, engine);

            var uris = EPServiceProviderManager.ProviderURIs;

            Assert.IsTrue(uris.Contains("default"));

            _epService.Dispose();
            try {
                var temp = _epService.EPRuntime;
                Assert.Fail();
            }
            catch (EPServiceDestroyedException) {
                // expected
            }
            try {
                var temp = _epService.EPAdministrator;
                Assert.Fail();
            }
            catch (EPServiceDestroyedException) {
                // expected
            }
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, "default");

            // test destroy
            var config    = SupportConfigFactory.GetConfiguration();
            var uriOne    = GetType().FullName + "_1";
            var engineOne = EPServiceProviderManager.GetProvider(uriOne, config);
            var uriTwo    = GetType().FullName + "_2";
            var engineTwo = EPServiceProviderManager.GetProvider(uriTwo, config);

            EPAssertionUtil.AssertContains(EPServiceProviderManager.ProviderURIs, uriOne, uriTwo);
            Assert.IsNotNull(EPServiceProviderManager.GetExistingProvider(uriOne));
            Assert.IsNotNull(EPServiceProviderManager.GetExistingProvider(uriTwo));

            engineOne.Dispose();
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, uriOne);
            EPAssertionUtil.AssertContains(EPServiceProviderManager.ProviderURIs, uriTwo);
            Assert.IsNull(EPServiceProviderManager.GetExistingProvider(uriOne));

            engineTwo.Dispose();
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, uriOne, uriTwo);
            Assert.IsNull(EPServiceProviderManager.GetExistingProvider(uriTwo));
        }
            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));
            }
        private void RunAssertionDestroy()
        {
            // test destroy
            Configuration     config    = SupportConfigFactory.GetConfiguration();
            string            uriOne    = GetType().FullName + "_1";
            EPServiceProvider engineOne = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, uriOne, config);
            string            uriTwo    = GetType().FullName + "_2";
            EPServiceProvider engineTwo = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, uriTwo, config);

            EPAssertionUtil.AssertContains(EPServiceProviderManager.ProviderURIs, uriOne, uriTwo);
            Assert.IsNotNull(EPServiceProviderManager.GetExistingProvider(uriOne));
            Assert.IsNotNull(EPServiceProviderManager.GetExistingProvider(uriTwo));

            engineOne.Dispose();
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, uriOne);
            EPAssertionUtil.AssertContains(EPServiceProviderManager.ProviderURIs, uriTwo);
            Assert.IsNull(EPServiceProviderManager.GetExistingProvider(uriOne));

            engineTwo.Dispose();
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, uriOne, uriTwo);
            Assert.IsNull(EPServiceProviderManager.GetExistingProvider(uriTwo));

            try {
                Assert.NotNull(engineTwo.EPRuntime);
                Assert.Fail();
            } catch (EPServiceDestroyedException) {
                // expected
            }
            try {
                Assert.NotNull(engineTwo.EPAdministrator);
                Assert.Fail();
            } catch (EPServiceDestroyedException) {
                // expected
            }
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, uriTwo);
        }