Example #1
0
        public void TestWithObservableMessages()
        {
            var gate = new TestGate <CheckPoint>();
            var wss  = new WebSocketServer(LOG, 8844);

            wss.AddWebSocketService <WebSocketTestBehaviour>("/test");
            wss.Start();


            using (var wsc = new WebSocket(LOG, "ws://localhost:8844/test", true))
            {
                wsc.MessageReceived.Subscribe((m) =>
                {
                    gate.Set(CheckPoint.ClientReceived);
                });

                wsc.Connect();

                wsc.Send("Check Observable route works!");

                gate.AssertWaitFor(CheckPoint.ClientReceived, 5000);
            }


            wss.Stop();
        }
Example #2
0
        public void TestConnect()
        {
            var gate = new TestGate <CheckPoint>();
            var wss  = new WebSocketServer(LOG, 8844);

            wss.AddWebSocketService <WebSocketTestBehaviour>("/test");
            wss.Start();


            using (var wsc = new WebSocket(LOG, "ws://localhost:8844/test", true))
            {
                wsc.OnMessage += (sender, e) =>
                {
                    gate.Set(CheckPoint.ClientReceived);
                };

                wsc.Connect();

                wsc.Send("BALUS");

                gate.AssertWaitFor(CheckPoint.ClientReceived, 5000);
            }


            wss.Stop();
        }
Example #3
0
        public void Initialize()
        {
            var common = new CommonConfiguration(1, 100);

            var netconfig = new NetConfiguration("localhost", proxyServer, "testService", 10);
            var toconfig  = new ProxyConfiguration(TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1),
                                                   TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));

            _proxy = new TestGate(netconfig, toconfig, common);
            _proxy.Build();
        }
Example #4
0
        public void Initialize()
        {
            var common   = new CommonConfiguration(1, 100);
            var distrNet = new DistributorNetConfiguration("localhost",
                                                           distrServer1, distrServer12, "testService", 10);
            var distrConf = new DistributorConfiguration(1, "TestRestore",
                                                         TimeSpan.FromMilliseconds(10000000), TimeSpan.FromMilliseconds(500000), TimeSpan.FromMinutes(100),
                                                         TimeSpan.FromMilliseconds(10000000));

            _distr = new DistributorApi(distrNet, distrConf, common);
            _distr.Build();

            var netconfig = new NetConfiguration("localhost", proxyServer, "testService", 10);
            var toconfig  = new ProxyConfiguration(TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1),
                                                   TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));

            _proxy = new TestGate(netconfig, toconfig, common);
            _proxy.Build();

            _distrTest = new TestDistributorGate();
            _writer1   = new TestWriterGate();
            _writer2   = new TestWriterGate();
            _writer3   = new TestWriterGate();
        }
Example #5
0
        public void CollectorNet_ReadFromWriter()
        {
            const int proxyServer   = 22337;
            const int distrServer1  = 22338;
            const int distrServer12 = 22339;
            const int st1           = 22335;
            const int st2           = 22336;

            #region hell

            var writer = new HashWriter(new HashMapConfiguration("TestCollectorNet", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor));
            writer.CreateMap();
            writer.SetServer(0, "localhost", st1, st2);
            writer.Save();

            var common = new CommonConfiguration(1, 100);

            var netconfig = new NetConfiguration("localhost", proxyServer, "testService", 10);
            var toconfig  = new ProxyConfiguration(TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1),
                                                   TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));

            var proxy = new TestGate(netconfig, toconfig, common);

            var distrNet = new DistributorNetConfiguration("localhost",
                                                           distrServer1, distrServer12, "testService", 10);
            var distrConf = new DistributorConfiguration(1, "TestCollectorNet",
                                                         TimeSpan.FromMilliseconds(100000), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(10000));

            var distr = new DistributorApi(distrNet, distrConf, common);

            var storageNet    = new StorageNetConfiguration("localhost", st1, st2, "testService", 10);
            var storageConfig = new StorageConfiguration("TestCollectorNet", 1, 10, TimeSpan.FromHours(1), TimeSpan.FromHours(1),
                                                         TimeSpan.FromHours(1), TimeSpan.FromHours(1), false);

            var storage     = new WriterApi(storageNet, storageConfig, common);
            var async       = new AsyncTaskModule(new QueueConfiguration(4, 10));
            var distributor =
                new DistributorModule(new CollectorModel(new DistributorHashConfiguration(1),
                                                         new HashMapConfiguration("TestCollectorNet", HashMapCreationMode.ReadFromFile, 1, 1,
                                                                                  HashFileType.Collector)), async, new AsyncTasksConfiguration(TimeSpan.FromMinutes(1)));

            var net = new CollectorNetModule(new ConnectionConfiguration("testService", 10),
                                             new ConnectionTimeoutConfiguration(Consts.OpenTimeout, Consts.SendTimeout), distributor);

            distributor.SetNetModule(net);

            var back   = new BackgroundModule(new QueueConfiguration(5, 10));
            var loader = new DataLoader(net, 100, back);

            var parser = new TestIntParser();
            parser.SetCommandsHandler(
                new UserCommandsHandler <TestCommand, Type, TestCommand, int, int, TestDbReader>(
                    new TestUserCommandCreator(), new TestMetaDataCommandCreator()));
            var merge = new OrderMerge(loader, parser);

            var searchModule = new SearchTaskModule("Int", merge, loader, distributor, back, parser);

            storage.Build();
            proxy.Build();
            distr.Build();

            storage.AddDbModule(new TestInMemoryDbFactory());

            storage.Start();
            proxy.Start();
            distr.Start();

            searchModule.Start();
            distributor.Start();
            merge.Start();
            back.Start();
            net.Start();
            async.Start();

            #endregion

            proxy.Int.SayIAmHere("localhost", distrServer1);

            const int count = 20;

            for (int i = 0; i < count; i++)
            {
                var request = proxy.Int.CreateSync(i, i);
                Assert.AreEqual(RequestState.Complete, request.State);
            }

            var reader = searchModule.CreateReader("asc", -1, 20);
            reader.Start();

            for (int i = 0; i < count; i++)
            {
                Assert.IsTrue(reader.IsCanRead);

                reader.ReadNext();

                Assert.AreEqual(i, reader.GetValue(0));
            }
            reader.ReadNext();
            Assert.IsFalse(reader.IsCanRead);

            reader.Dispose();
            back.Dispose();
            net.Dispose();

            storage.Dispose();
            proxy.Dispose();
            distr.Dispose();
            async.Dispose();
        }
Example #6
0
        public void TestConnectClientFirst()
        {
            var gate = new TestGate <CheckPoint>();


            // Create client
            int clientMessageCount = 0;
            int clientCloseCount   = 0;
            int clientRetryCount   = 0;
            var wsc = new WebSocket(LOG, "ws://localhost:8844/test", true);

            wsc.ReconnectDelay = TimeSpan.FromSeconds(3);
            wsc.OnMessage     += (sender, e) =>
            {
                clientMessageCount++;
                gate.Set(CheckPoint.ClientReceived);
            };

            wsc.OnError += (sender, e) =>
            {
            };

            wsc.OnOpen += (sender, e) =>
            {
            };

            wsc.OnClose += (sender, e) =>
            {
                var code = (CloseStatusCode)e.Code;

                if (
                    (code == CloseStatusCode.Normal) ||
                    (code == CloseStatusCode.NoStatus)
                    )
                {
                    clientCloseCount++;
                    gate.Set(CheckPoint.ClientConnectionClosed);
                }
                else
                {
                    clientRetryCount++;
                }
            };

            wsc.ConnectTaskAsync();

            Thread.Sleep(3000);

            // Create server
            var wss = new WebSocketServer(LOG, 8844);

            wss.AddWebSocketService <WebSocketTestBehaviour>("/test");
            wss.Start();

            Thread.Sleep(6000);

            wsc.Send("BALUS");

            gate.AssertWaitFor(CheckPoint.ClientReceived, 5000);

            wss.Stop();
            Thread.Sleep(3000);

            // Create a second server
            var wss2 = new WebSocketServer(LOG, 8844);

            wss2.AddWebSocketService <WebSocketTestBehaviour>("/test");
            wss2.Start();

            Thread.Sleep(6000);

            wsc.Send("New server, old client");

            gate.AssertWaitFor(CheckPoint.ClientReceived, 5000);

            Assert.Equal(2, clientMessageCount);

            wsc.CloseTaskAsync(CloseStatusCode.Normal, "Finished Tests");

            gate.AssertWaitFor(CheckPoint.ClientConnectionClosed, 50000);
            Assert.Equal(1, clientCloseCount);

            // Now close the second sever
            wss2.Stop();
        }
Example #7
0
        public void DistributorApi_ProcessAsyncOperationsFromProxy()
        {
            const int proxyServer   = 22213;
            const int distrServer1  = 22214;
            const int distrServer12 = 22215;
            const int storageServer = 22216;

            #region hell

            var writer = new HashWriter(new HashMapConfiguration("TestClientDistributor", HashMapCreationMode.CreateNew, 1, 1, HashFileType.Distributor));
            writer.CreateMap();
            writer.SetServer(0, "localhost", storageServer, 157);
            writer.Save();

            var netconfig = new NetConfiguration("localhost", proxyServer, "testService", 10);
            var toconfig  = new ProxyConfiguration(TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1),
                                                   TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));
            var common = new CommonConfiguration(1, 100);

            var proxy = new TestGate(netconfig, toconfig, common);

            var distrNet = new DistributorNetConfiguration("localhost",
                                                           distrServer1, distrServer12, "testService", 10);
            var distrConf = new DistributorConfiguration(1, "TestClientDistributor",
                                                         TimeSpan.FromMilliseconds(100000), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1), TimeSpan.FromMilliseconds(10000));

            var distr = new DistributorApi(distrNet, distrConf, common);

            var storageNet    = new StorageNetConfiguration("localhost", storageServer, 157, "testService", 10);
            var storageConfig = new StorageConfiguration("TestClientDistributor", 1, 10, TimeSpan.FromHours(1), TimeSpan.FromHours(1),
                                                         TimeSpan.FromHours(1), TimeSpan.FromHours(1), false);

            var storage = new WriterApi(storageNet, storageConfig, common);

            #endregion

            proxy.Build();
            proxy.Start();

            distr.Build();
            distr.Start();

            proxy.Int.SayIAmHere("localhost", distrServer1);

            storage.Build();
            storage.AddDbModule(new TestInMemoryDbFactory());
            storage.Start();

            const int count = 50;

            for (int i = 0; i < count; i++)
            {
                var state = proxy.Int.CreateSync(i, i);
                Assert.AreEqual(RequestState.Complete, state.State);
            }

            for (int i = 0; i < count; i++)
            {
                RequestDescription description;
                var read = proxy.Int.Read(i, out description);

                Assert.AreEqual(i, read);
                Assert.AreEqual(RequestState.Complete, description.State);
            }

            for (int i = 0; i < count; i++)
            {
                var state = proxy.Int.DeleteSync(i);
                Assert.AreEqual(RequestState.Complete, state.State);
            }

            for (int i = 0; i < count; i++)
            {
                RequestDescription description;
                proxy.Int.Read(i, out description);

                Assert.AreEqual(RequestState.DataNotFound, description.State);
            }

            proxy.Dispose();
            distr.Dispose();
            storage.Dispose();
        }