Exemplo n.º 1
0
        public virtual void TestStaticMapUpdate()
        {
            Assume.AssumeTrue(!Shell.Windows);
            FilePath tempStaticMapFile = FilePath.CreateTempFile("nfs-", ".map");

            tempStaticMapFile.Delete();
            Configuration conf = new Configuration();

            conf.SetLong(IdMappingConstant.UsergroupidUpdateMillisKey, 1000);
            conf.Set(IdMappingConstant.StaticIdMappingFileKey, tempStaticMapFile.GetPath());
            ShellBasedIdMapping refIdMapping  = new ShellBasedIdMapping(conf, true);
            ShellBasedIdMapping incrIdMapping = new ShellBasedIdMapping(conf);
            BiMap <int, string> uidNameMap    = refIdMapping.GetUidNameMap();
            BiMap <int, string> gidNameMap    = refIdMapping.GetGidNameMap();

            // Force empty map, to see effect of incremental map update of calling
            // getUid()
            incrIdMapping.ClearNameMaps();
            uidNameMap = refIdMapping.GetUidNameMap();
            {
                KeyValuePair <int, string> me = uidNameMap.GetEnumerator().Next();
                int    id   = me.Key;
                string name = me.Value;
                // The static map is empty, so the id found for "name" would be
                // the same as "id"
                int nid = incrIdMapping.GetUid(name);
                Assert.Equal(id, nid);
                // Clear map and update staticMap file
                incrIdMapping.ClearNameMaps();
                int    rid     = id + 10000;
                string smapStr = "uid " + rid + " " + id;
                CreateStaticMapFile(tempStaticMapFile, smapStr);
                // Now the id found for "name" should be the id specified by
                // the staticMap
                nid = incrIdMapping.GetUid(name);
                Assert.Equal(rid, nid);
            }
            // Force empty map, to see effect of incremental map update of calling
            // getGid()
            incrIdMapping.ClearNameMaps();
            gidNameMap = refIdMapping.GetGidNameMap();
            {
                KeyValuePair <int, string> me = gidNameMap.GetEnumerator().Next();
                int    id   = me.Key;
                string name = me.Value;
                // The static map is empty, so the id found for "name" would be
                // the same as "id"
                int nid = incrIdMapping.GetGid(name);
                Assert.Equal(id, nid);
                // Clear map and update staticMap file
                incrIdMapping.ClearNameMaps();
                int    rid     = id + 10000;
                string smapStr = "gid " + rid + " " + id;
                // Sleep a bit to avoid that two changes have the same modification time
                try
                {
                    Thread.Sleep(1000);
                }
                catch (Exception)
                {
                }
                CreateStaticMapFile(tempStaticMapFile, smapStr);
                // Now the id found for "name" should be the id specified by
                // the staticMap
                nid = incrIdMapping.GetGid(name);
                Assert.Equal(rid, nid);
            }
        }
Exemplo n.º 2
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
                         );
        }