コード例 #1
0
        public void TestCompression()
        {
            var tree     = new RadixTree <Service>();
            var service  = new Service(new string[0], "Service1Test", "Address1Test", 10000, "node1", new string[0]);
            var service2 = new Service(new string[0], "Service1Test", "Address2Test", 10000, "node1", new string[0]);

            tree.AddServiceToRoute("/test1/test2/test3/test4/test5", service);
            tree.AddServiceToRoute("/test1/test2/test3/test4/test5/test6", service2);

            Assert.Equal(1, tree.GetTopNode().ChildrenNodes.Count);

            tree.Compress();

            ////We should have 1 node in the tree
            Assert.Equal(1, tree.GetTopNode().ChildrenNodes.Count);

            ////The key length should be 5 long
            Assert.Equal(5, tree.GetTopNode().ChildrenNodes.KeyLength);

            string matchedpath;
            var    returnservice = tree.GetServiceFromRoute("/test1/test2/test3/test4/test5/test7", out matchedpath);

            Assert.Equal("/test1/test2/test3/test4/test5", matchedpath);
            Assert.Equal(returnservice.ServiceId, service.ServiceId);
        }
コード例 #2
0
        public void TestRemovingAService()
        {
            var tree     = new RadixTree <Service>();
            var service  = new Service(new string[0], "Service1Test", "Address1Test", 10000, "node1", new string[0]);
            var service2 = new Service(new string[0], "Service1Test", "Address2Test", 10000, "node1", new string[0]);

            tree.AddServiceToRoute("/test1/test2/test3/test4/test5", service);
            tree.AddServiceToRoute("/test1/test2/test3/test4/test5/test6", service2);

            string matchedpath;
            var    returnservice = tree.GetServiceFromRoute("/test1/test2/test3/test4/test5/test7", out matchedpath);

            Assert.Equal("/test1/test2/test3/test4/test5", matchedpath);

            //now remove the service
            tree.RemoveService(service);

            //Now we should get no match
            returnservice = tree.GetServiceFromRoute("/test1/test2/test3/test4/test5/test7", out matchedpath);
            Assert.Null(returnservice);
        }