Example #1
0
 public void Fail_to_get_exact_match_only_from_GetValues()
 {
     XUriMap<XUri> map = new XUriMap<XUri>();
     List<XUri> expected = new List<XUri>();
     Add(map, new XUri("channel:///deki/pages"));
     Add(map, new XUri("channel:///deki/pages/mod"));
     IEnumerable<XUri> matches = map.GetValues(new XUri("channel:///deki/pages/mod/foo"));
     List<XUri> matchList = new List<XUri>(matches);
     Assert.AreEqual(0, matchList.Count);
 }
Example #2
0
 public void Exact_Match()
 {
     XUriMap<string> map = new XUriMap<string>();
     string key = "foo/bar";
     map[new XUri("test://foo/bar")] = key;
     string match;
     int similarity;
     XUri test = new XUri("test://foo/bar");
     map.TryGetValue(test, out match, out similarity);
     Assert.AreEqual(key, match);
     Assert.AreEqual(test.MaxSimilarity, similarity);
 }
Example #3
0
        public void Schemes_should_be_differentiated()
        {
            XUriMap <string> map = new XUriMap <string>();

            map[new XUri("test1://foo/bar/boo")] = "t1/foo/bar";
            map[new XUri("test2://foo/bar/baz")] = "t2/foo/bar";
            string match;
            int    similarity;

            map.TryGetValue(new XUri("test2://foo/bar/boo"), out match, out similarity);
            Assert.IsNull(match, match);
        }
Example #4
0
        public void Fail_to_get_exact_match_only_from_GetValues()
        {
            XUriMap <XUri> map      = new XUriMap <XUri>();
            List <XUri>    expected = new List <XUri>();

            Add(map, new XUri("channel:///deki/pages"));
            Add(map, new XUri("channel:///deki/pages/mod"));
            IEnumerable <XUri> matches   = map.GetValues(new XUri("channel:///deki/pages/mod/foo"));
            List <XUri>        matchList = new List <XUri>(matches);

            Assert.AreEqual(0, matchList.Count);
        }
Example #5
0
        public void Partial_Match()
        {
            XUriMap <string> map = new XUriMap <string>();
            string           key = "foo/bar";

            map[new XUri("test://foo/bar")] = key;
            string match;
            int    similarity;
            XUri   test = new XUri("test://foo/bar/baz");

            map.TryGetValue(test, out match, out similarity);
            Assert.AreEqual(key, match);
            Assert.AreEqual(test.MaxSimilarity - 1, similarity);
        }
Example #6
0
 public void Get_best_match()
 {
     XUriMap<string> map = new XUriMap<string>();
     string foobarbaz = "foobarbaz";
     map[new XUri("test://foo")] = "foo";
     map[new XUri("test://foo/bar")] = "foobar";
     map[new XUri("test://foo/bar/baz")] = foobarbaz;
     map[new XUri("test://foo/baz")] = "foobaz";
     map[new XUri("test://foo/bar/baz/beep/sdfdsfsd")] = "dfdsfdsfsdf";
     map[new XUri("test://foo/baz/beep/bar")] = "foobazbeepbar";
     string match;
     int similarity;
     XUri test = new XUri("test://foo/bar/baz/beep");
     map.TryGetValue(test, out match, out similarity);
     Assert.AreEqual(foobarbaz, match);
     Assert.AreEqual(test.MaxSimilarity - 1, similarity);
 }
Example #7
0
 public void Get_all_matches()
 {
     XUriMap<XUri> map = new XUriMap<XUri>();
     List<XUri> expected = new List<XUri>();
     expected.Add(Add(map, new XUri("channel:///deki/pages/tweak/wobble")));
     expected.Add(Add(map, new XUri("channel:///deki/pages/tweak/wonk")));
     expected.Add(Add(map, new XUri("channel:///deki/pages/mod")));
     expected.Add(Add(map, new XUri("channel:///deki/pages/create")));
     expected.Add(Add(map, new XUri("channel:///deki/pages/delete")));
     Add(map, new XUri("channel:///deki/users/create"));
     Add(map, new XUri("channel:///dream/pages"));
     IEnumerable<XUri> matches = map.GetValues(new XUri("channel:///deki/pages/*"));
     List<XUri> matchList = new List<XUri>(matches);
     Assert.AreEqual(expected.Count, matchList.Count);
     foreach(XUri match in matchList) {
         Assert.Contains(match,expected);
     }
 }
Example #8
0
        public void Get_best_match()
        {
            XUriMap <string> map       = new XUriMap <string>();
            string           foobarbaz = "foobarbaz";

            map[new XUri("test://foo")]         = "foo";
            map[new XUri("test://foo/bar")]     = "foobar";
            map[new XUri("test://foo/bar/baz")] = foobarbaz;
            map[new XUri("test://foo/baz")]     = "foobaz";
            map[new XUri("test://foo/bar/baz/beep/sdfdsfsd")] = "dfdsfdsfsdf";
            map[new XUri("test://foo/baz/beep/bar")]          = "foobazbeepbar";
            string match;
            int    similarity;
            XUri   test = new XUri("test://foo/bar/baz/beep");

            map.TryGetValue(test, out match, out similarity);
            Assert.AreEqual(foobarbaz, match);
            Assert.AreEqual(test.MaxSimilarity - 1, similarity);
        }
Example #9
0
        public void Get_all_matches()
        {
            XUriMap <XUri> map      = new XUriMap <XUri>();
            List <XUri>    expected = new List <XUri>();

            expected.Add(Add(map, new XUri("channel:///deki/pages/tweak/wobble")));
            expected.Add(Add(map, new XUri("channel:///deki/pages/tweak/wonk")));
            expected.Add(Add(map, new XUri("channel:///deki/pages/mod")));
            expected.Add(Add(map, new XUri("channel:///deki/pages/create")));
            expected.Add(Add(map, new XUri("channel:///deki/pages/delete")));
            Add(map, new XUri("channel:///deki/users/create"));
            Add(map, new XUri("channel:///dream/pages"));
            IEnumerable <XUri> matches   = map.GetValues(new XUri("channel:///deki/pages/*"));
            List <XUri>        matchList = new List <XUri>(matches);

            Assert.AreEqual(expected.Count, matchList.Count);
            foreach (XUri match in matchList)
            {
                Assert.Contains(match, expected);
            }
        }
Example #10
0
 private XUri Add(XUriMap<XUri> map, XUri uri)
 {
     map.Add(uri, uri);
     return uri;
 }
Example #11
0
 public void Schemes_should_be_differentiated()
 {
     XUriMap<string> map = new XUriMap<string>();
     map[new XUri("test1://foo/bar/boo")] = "t1/foo/bar";
     map[new XUri("test2://foo/bar/baz")] = "t2/foo/bar";
     string match;
     int similarity;
     map.TryGetValue(new XUri("test2://foo/bar/boo"), out match, out similarity);
     Assert.IsNull(match,match);
 }
Example #12
0
        protected override Yield Stop(Result result)
        {
            if(!IsRunning) {
                result.Return();
                yield break;
            }
            try {

                // BUG #810: announce to all root-level services that we're shutting down

                // shutdown all services, except host and sub-services (the latter should be cleaned-up by their owners)
                _log.Debug("Stopping stand-alone services");
                Dictionary<string, ServiceEntry> services;
                lock(_services) {
                    services = new Dictionary<string, ServiceEntry>(_services);
                }
                foreach(KeyValuePair<string, ServiceEntry> entry in services) {
                    if((entry.Value.Owner == null) && !(ReferenceEquals(this, entry.Value.Service))) {
                        StopService(entry.Value.Service.Self);
                    }
                }

                // now destroy support services
                _log.Debug("Stopping host");
            } catch(Exception ex) {
                _log.ErrorExceptionMethodCall(ex, "Stop: host failed to deinitialize");
            }

            // stop storage service
            if(_storage != null) {
                yield return _storage.Delete(new Result<DreamMessage>(TimeSpan.MaxValue)).CatchAndLog(_log);
                _storage = null;
            }

            // check if any inner services failed to stop
            foreach(KeyValuePair<string, ServiceEntry> entry in _services) {
                _log.WarnMethodCall("Stop: service did not shutdown", entry.Key);
            }

            // invoke base.Stop
            yield return Coroutine.Invoke(base.Stop, new Result()).CatchAndLog(_log);

            // BUG #835: we should use a counter and timeout to shutdown properly
            Thread.Sleep(2000);

            // deinitialize fields
            _blueprints = null;
            _registeredTypes.Clear();
            _infos.Clear();
            _activities.Clear();
            _features = new DreamFeatureDirectory();
            _services.Clear();
            _responseCache.Clear();
            _aliases = new XUriMap<XUri>();

            // mark host as not running
            Plug.RemoveEndpoint(this);
            _running = false;
            _shutdown.Set();
            result.Return();
        }
Example #13
0
 private XUri Add(XUriMap <XUri> map, XUri uri)
 {
     map.Add(uri, uri);
     return(uri);
 }