예제 #1
0
        public void EndToEnd_BeforeConnection_Basic()
        {
            var revisions = new Dictionary <UInt32, UInt32>();
            var values    = new Dictionary <UInt32, String>();

            var server = new ZetaWsPublisher("http://+:8004/");

            server.Publish(new StringMessage("Topic 0, message 1"), 0);
            server.Publish(new StringMessage("Topic 1, message 1"), 1);
            server.Publish(new StringMessage("Topic 1, message 2"), 1);
            server.Publish(new StringMessage("Topic 2, message 1"), 2);

            var client = new ZetaWsSubscriber("ws://localhost:8004/");

            client.Subscribe((UInt32 topic, UInt32 revision, StringMessage message) => {
                revisions[topic] = revision;
                values[topic]    = message.Value;
            });

            Thread.Sleep(100);
            Assert.Equal("Topic 0, message 1", values[0]);
            Assert.Equal("Topic 1, message 2", values[1]);
            Assert.Equal("Topic 2, message 1", values[2]);
            Assert.Equal((UInt32)0, revisions[0]);
            Assert.Equal((UInt32)1, revisions[1]);
            Assert.Equal((UInt32)0, revisions[2]);

            client.Dispose();
            Assert.True(client.IsDisposed);
            server.Dispose();
            Assert.True(server.IsDisposed);
        }
예제 #2
0
        public void Subscribe()
        {
            var server = new ZetaWsPublisher("http://+:8001/");
            var client = new ZetaWsSubscriber("ws://localhost:8001/");

            client.Subscribe((UInt32 topic, UInt32 revision, StringMessage message) => { }, 10, 20);
            client.Subscribe((UInt32 topic, UInt32 revision, StringMessage message) => { }, 0, 9);
            client.Subscribe((UInt32 topic, UInt32 revision, StringMessage message) => { }, 21, 30);

            Assert.Throws <InvalidOperationException>(() => {
                client.Subscribe((UInt32 topic, UInt32 revision, StringMessage message) => { }, 10, 20);
            });
            Assert.Throws <InvalidOperationException>(() => {
                client.Subscribe((UInt32 topic, UInt32 revision, StringMessage message) => { }, 0, 10);
            });
            Assert.Throws <InvalidOperationException>(() => {
                client.Subscribe((UInt32 topic, UInt32 revision, StringMessage message) => { }, 20, 30);
            });

            client.Dispose();
            server.Dispose();
        }