Exemplo n.º 1
0
        public virtual void TestUpdateMapIncr()
        {
            Configuration conf = new Configuration();

            conf.SetLong(IdMappingConstant.UsergroupidUpdateMillisKey, 600000);
            ShellBasedIdMapping refIdMapping  = new ShellBasedIdMapping(conf, true);
            ShellBasedIdMapping incrIdMapping = new ShellBasedIdMapping(conf);
            // Command such as "getent passwd <userName>" will return empty string if
            // <username> is numerical, remove them from the map for testing purpose.
            BiMap <int, string> uidNameMap = refIdMapping.GetUidNameMap();
            BiMap <int, string> gidNameMap = refIdMapping.GetGidNameMap();

            // Force empty map, to see effect of incremental map update of calling
            // getUserName()
            incrIdMapping.ClearNameMaps();
            uidNameMap = refIdMapping.GetUidNameMap();
            foreach (KeyValuePair <int, string> me in uidNameMap)
            {
                int    id    = me.Key;
                string name  = me.Value;
                string tname = incrIdMapping.GetUserName(id, null);
                Assert.Equal(name, tname);
            }
            Assert.Equal(uidNameMap.Count, incrIdMapping.GetUidNameMap().Count
                         );
            // Force empty map, to see effect of incremental map update of calling
            // getUid()
            incrIdMapping.ClearNameMaps();
            foreach (KeyValuePair <int, string> me_1 in uidNameMap)
            {
                int    id   = me_1.Key;
                string name = me_1.Value;
                int    tid  = incrIdMapping.GetUid(name);
                Assert.Equal(id, tid);
            }
            Assert.Equal(uidNameMap.Count, incrIdMapping.GetUidNameMap().Count
                         );
            // Force empty map, to see effect of incremental map update of calling
            // getGroupName()
            incrIdMapping.ClearNameMaps();
            gidNameMap = refIdMapping.GetGidNameMap();
            foreach (KeyValuePair <int, string> me_2 in gidNameMap)
            {
                int    id    = me_2.Key;
                string name  = me_2.Value;
                string tname = incrIdMapping.GetGroupName(id, null);
                Assert.Equal(name, tname);
            }
            Assert.Equal(gidNameMap.Count, incrIdMapping.GetGidNameMap().Count
                         );
            // Force empty map, to see effect of incremental map update of calling
            // getGid()
            incrIdMapping.ClearNameMaps();
            gidNameMap = refIdMapping.GetGidNameMap();
            foreach (KeyValuePair <int, string> me_3 in gidNameMap)
            {
                int    id   = me_3.Key;
                string name = me_3.Value;
                int    tid  = incrIdMapping.GetGid(name);
                Assert.Equal(id, tid);
            }
            Assert.Equal(gidNameMap.Count, incrIdMapping.GetGidNameMap().Count
                         );
        }