Example #1
0
        public void SingletonComponentRegisteredWithComponentInstance_IsNotDisposed()
        {
            // this component instance is externally-owned
            var disposed       = false;
            var immortalServer = new DisposableComponent {
                Handler = () => disposed = true
            };

            var cat = new ComponentCatalog();

            cat.RegisterComponent <ISampleComponent, DisposableComponent>(immortalServer);
            Assert.IsFalse(disposed);

            var instance = cat.GetComponent <ISampleComponent>();

            AssertEx.IsInstanceOf <DisposableComponent>(instance);

            var reg = cat.GetRegistration(typeof(ISampleComponent));

            cat.CleanUpComponentInstance(reg, instance);
            Assert.IsFalse(disposed);

            immortalServer.Dispose();
            Assert.IsTrue(disposed);
        }
Example #2
0
        private EventServer()
        {
            _catalog = new ComponentCatalog();
            _catalog.RegisterComponent <IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent <IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent <ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent <ITimerTriggeredEvent, TimerTriggeredEvent>(ActivationType.Singleton);

            // Setting compression threshold to 1 byte means that all messages will be compressed.
            // This setting should not be used in production code because smaller packets will grow in size.
            // By default, Zyan only compresses messages larger than 64 kilobytes.
            var tcpBinaryProtocol = new TcpBinaryServerProtocolSetup(8082);

            tcpBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.LZF));
            _tcpBinaryHost = new ZyanComponentHost("TcpBinaryEventTest", tcpBinaryProtocol, _catalog);

            var ipcBinaryProtocol = new IpcBinaryServerProtocolSetup("IpcTestServer");

            ipcBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.DeflateStream));
            _ipcBinaryHost = new ZyanComponentHost("IpcBinaryEventTest", ipcBinaryProtocol, _catalog);

            var tcpCustomProtocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.DeflateStream
            };

            _tcpCustomHost = new ZyanComponentHost("TcpCustomEventTest", tcpCustomProtocol, _catalog);

            var tcpDuplexProtocol = new TcpDuplexServerProtocolSetup(8084, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.DeflateStream
            };

            tcpDuplexProtocol.AddChannelSetting("bindTo", "127.0.0.1");

            _tcpDuplexHost = new ZyanComponentHost("TcpDuplexEventTest", tcpDuplexProtocol, _catalog);

            var httpCustomProtocol = new HttpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod    = CompressionMethod.LZF
            };

            _httpCustomHost = new ZyanComponentHost("HttpCustomEventTest", httpCustomProtocol, _catalog);

            var nullChannelProtocol = new NullServerProtocolSetup(1234);

            _nullChannelHost = new ZyanComponentHost("NullEventTest", nullChannelProtocol, _catalog);

            // use legacy blocking events mode because we check the handlers synchronously
            ZyanSettings.LegacyBlockingEvents        = true;
            ZyanSettings.LegacyBlockingSubscriptions = true;
        }
Example #3
0
        public void SingletonComponentRegisteredWithComponentType_IsDisposed()
        {
            var disposed = false;
            var cat      = new ComponentCatalog();

            cat.RegisterComponent <ISampleComponent, DisposableComponent>(ActivationType.Singleton);
            Assert.IsFalse(disposed);

            var instance = cat.GetComponent <ISampleComponent>();

            AssertEx.IsInstanceOf <DisposableComponent>(instance);
            instance.Handler = () => disposed = true;

            var reg = cat.GetRegistration(typeof(ISampleComponent));

            cat.CleanUpComponentInstance(reg, instance);
            Assert.IsTrue(disposed);
        }
Example #4
0
        public void SingleCallComponentRegisteredWithFactoryMethod_IsDisposed()
        {
            var disposed = false;
            var cat      = new ComponentCatalog();

            cat.RegisterComponent <ISampleComponent>(() => new DisposableComponent {
                Handler = () => disposed = true
            }, ActivationType.SingleCall);
            Assert.IsFalse(disposed);

            var instance = cat.GetComponent <ISampleComponent>();

            AssertEx.IsInstanceOf <DisposableComponent>(instance);

            var reg = cat.GetRegistration(typeof(ISampleComponent));

            cat.CleanUpComponentInstance(reg, instance);
            Assert.IsTrue(disposed);
        }
Example #5
0
        public void SingletonComponentRegisteredWithComponentInstance_IsCleanedUp()
        {
            // this component instance is created outside, but the ownership
            // is transferred to the ComponentCatalog via cleanup delegate
            var disposed     = false;
            var mortalServer = new ReleasableComponent {
                Handler = () => disposed = true
            };

            var cat = new ComponentCatalog();

            cat.RegisterComponent <ISampleComponent, ReleasableComponent>(mortalServer, v => ((ReleasableComponent)v).Release());
            Assert.IsFalse(disposed);

            var instance = cat.GetComponent <ISampleComponent>();

            AssertEx.IsInstanceOf <ReleasableComponent>(instance);

            var reg = cat.GetRegistration(typeof(ISampleComponent));

            cat.CleanUpComponentInstance(reg, instance);
            Assert.IsTrue(disposed);
        }
Example #6
0
        public void SingletonComponentRegisteredWithFactoryMethod_IsDisposed()
        {
            var disposed = false;
            var cat = new ComponentCatalog();
            cat.RegisterComponent<ISampleComponent>(() => new DisposableComponent { Handler = () => disposed = true }, ActivationType.Singleton);
            Assert.IsFalse(disposed);

            var instance = cat.GetComponent<ISampleComponent>();
            AssertEx.IsInstanceOf<DisposableComponent>(instance);

            var reg = cat.GetRegistration(typeof(ISampleComponent));
            cat.CleanUpComponentInstance(reg, instance);
            Assert.IsTrue(disposed);
        }
Example #7
0
        public void SingletonComponentRegisteredWithComponentType_IsCleanedUp()
        {
            var disposed = false;
            var cat = new ComponentCatalog();
            cat.RegisterComponent<ISampleComponent, ReleasableComponent>(
                ActivationType.Singleton, v => ((ReleasableComponent)v).Release());
            Assert.IsFalse(disposed);

            var instance = cat.GetComponent<ISampleComponent>();
            AssertEx.IsInstanceOf<ReleasableComponent>(instance);
            instance.Handler = () => disposed = true;

            var reg = cat.GetRegistration(typeof(ISampleComponent));
            cat.CleanUpComponentInstance(reg, instance);
            Assert.IsTrue(disposed);
        }
Example #8
0
        public void SingletonComponentRegisteredWithComponentInstance_IsNotDisposed()
        {
            // this component instance is externally-owned
            var disposed = false;
            using (var immortalServer = new DisposableComponent { Handler = () => disposed = true })
            using (var cat = new ComponentCatalog())
            {
                cat.RegisterComponent<ISampleComponent, DisposableComponent>(immortalServer);
                Assert.IsFalse(disposed);

                var instance = cat.GetComponent<ISampleComponent>();
                AssertEx.IsInstanceOf<DisposableComponent>(instance);

                var reg = cat.GetRegistration(typeof(ISampleComponent));
                cat.CleanUpComponentInstance(reg, instance);
                Assert.IsFalse(disposed);

                immortalServer.Dispose();
                Assert.IsTrue(disposed);
            }
        }
Example #9
0
        public void SingletonComponentRegisteredWithComponentInstance_IsCleanedUp()
        {
            // this component instance is created outside, but the ownership
            // is transferred to the ComponentCatalog via cleanup delegate
            var disposed = false;
            var mortalServer = new ReleasableComponent { Handler = () => disposed = true };

            var cat = new ComponentCatalog();
            cat.RegisterComponent<ISampleComponent, ReleasableComponent>(mortalServer, v => ((ReleasableComponent)v).Release());
            Assert.IsFalse(disposed);

            var instance = cat.GetComponent<ISampleComponent>();
            AssertEx.IsInstanceOf<ReleasableComponent>(instance);

            var reg = cat.GetRegistration(typeof(ISampleComponent));
            cat.CleanUpComponentInstance(reg, instance);
            Assert.IsTrue(disposed);
        }
Example #10
0
        private EventServer()
        {
            _catalog = new ComponentCatalog();
            _catalog.RegisterComponent<IEventComponentSingleton, EventComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent<IEventComponentSingleCall, EventComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<ICallbackComponentSingleton, CallbackComponentSingleton>(ActivationType.Singleton);
            _catalog.RegisterComponent<ICallbackComponentSingleCall, CallbackComponentSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<IRequestResponseCallbackSingleCall, RequestResponseCallbackSingleCall>(ActivationType.SingleCall);
            _catalog.RegisterComponent<ITimerTriggeredEvent, TimerTriggeredEvent>(ActivationType.Singleton);

            // Setting compression threshold to 1 byte means that all messages will be compressed.
            // This setting should not be used in production code because smaller packets will grow in size.
            // By default, Zyan only compresses messages larger than 64 kilobytes.
            var tcpBinaryProtocol = new TcpBinaryServerProtocolSetup(8082);
            tcpBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.LZF));
            _tcpBinaryHost = new ZyanComponentHost("TcpBinaryEventTest", tcpBinaryProtocol, _catalog);

            var ipcBinaryProtocol = new IpcBinaryServerProtocolSetup("IpcTestServer");
            ipcBinaryProtocol.AddServerSinkBeforeFormatter(new CompressionServerChannelSinkProvider(1, CompressionMethod.DeflateStream));
            _ipcBinaryHost = new ZyanComponentHost("IpcBinaryEventTest", ipcBinaryProtocol, _catalog);

            var tcpCustomProtocol = new TcpCustomServerProtocolSetup(8083, new NullAuthenticationProvider(), true)
            {
             				CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.DeflateStream
            };
            _tcpCustomHost = new ZyanComponentHost("TcpCustomEventTest", tcpCustomProtocol, _catalog);

            var tcpDuplexProtocol = new TcpDuplexServerProtocolSetup(8084, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.DeflateStream
            };
            tcpDuplexProtocol.AddChannelSetting("bindTo", "127.0.0.1");

            _tcpDuplexHost = new ZyanComponentHost("TcpDuplexEventTest", tcpDuplexProtocol, _catalog);

            var httpCustomProtocol = new HttpCustomServerProtocolSetup(8085, new NullAuthenticationProvider(), true)
            {
                CompressionThreshold = 1,
                CompressionMethod = CompressionMethod.LZF
            };
            _httpCustomHost = new ZyanComponentHost("HttpCustomEventTest", httpCustomProtocol, _catalog);

            var nullChannelProtocol = new NullServerProtocolSetup(1234);
            _nullChannelHost = new ZyanComponentHost("NullEventTest", nullChannelProtocol, _catalog);

            // use legacy blocking events mode because we check the handlers synchronously
            ZyanComponentHost.LegacyBlockingEvents = true;
        }