示例#1
0
        public virtual void TestNegativeCacheEntriesExpire()
        {
            conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsNegativeCacheSecs, 2);
            FakeTimer timer = new FakeTimer();
            // Ensure that stale entries are removed from negative cache every 2 seconds
            Groups groups = new Groups(conf, timer);

            groups.CacheGroupsAdd(Arrays.AsList(myGroups));
            groups.Refresh();
            // Add both these users to blacklist so that they
            // can be added to negative cache
            TestGroupsCaching.FakeGroupMapping.AddToBlackList("user1");
            TestGroupsCaching.FakeGroupMapping.AddToBlackList("user2");
            // Put user1 in negative cache.
            try
            {
                groups.GetGroups("user1");
                NUnit.Framework.Assert.Fail("Did not throw IOException : Failed to obtain groups"
                                            + " from FakeGroupMapping.");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("No groups found for user", e);
            }
            // Check if user1 exists in negative cache
            Assert.True(groups.GetNegativeCache().Contains("user1"));
            // Advance fake timer
            timer.Advance(1000);
            // Put user2 in negative cache
            try
            {
                groups.GetGroups("user2");
                NUnit.Framework.Assert.Fail("Did not throw IOException : Failed to obtain groups"
                                            + " from FakeGroupMapping.");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("No groups found for user", e);
            }
            // Check if user2 exists in negative cache
            Assert.True(groups.GetNegativeCache().Contains("user2"));
            // Advance timer. Only user2 should be present in negative cache.
            timer.Advance(1100);
            NUnit.Framework.Assert.IsFalse(groups.GetNegativeCache().Contains("user1"));
            Assert.True(groups.GetNegativeCache().Contains("user2"));
            // Advance timer. Even user2 should not be present in negative cache.
            timer.Advance(1000);
            NUnit.Framework.Assert.IsFalse(groups.GetNegativeCache().Contains("user2"));
        }
示例#2
0
        public virtual void TestNegativeGroupCaching()
        {
            string user        = "******";
            string failMessage = "Did not throw IOException: ";

            conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsNegativeCacheSecs, 2);
            FakeTimer timer  = new FakeTimer();
            Groups    groups = new Groups(conf, timer);

            groups.CacheGroupsAdd(Arrays.AsList(myGroups));
            groups.Refresh();
            TestGroupsCaching.FakeGroupMapping.AddToBlackList(user);
            // In the first attempt, the user will be put in the negative cache.
            try
            {
                groups.GetGroups(user);
                NUnit.Framework.Assert.Fail(failMessage + "Failed to obtain groups from FakeGroupMapping."
                                            );
            }
            catch (IOException e)
            {
                // Expects to raise exception for the first time. But the user will be
                // put into the negative cache
                GenericTestUtils.AssertExceptionContains("No groups found for user", e);
            }
            // The second time, the user is in the negative cache.
            try
            {
                groups.GetGroups(user);
                NUnit.Framework.Assert.Fail(failMessage + "The user is in the negative cache.");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("No groups found for user", e);
            }
            // Brings back the backend user-group mapping service.
            TestGroupsCaching.FakeGroupMapping.ClearBlackList();
            // It should still get groups from the negative cache.
            try
            {
                groups.GetGroups(user);
                NUnit.Framework.Assert.Fail(failMessage + "The user is still in the negative cache, even "
                                            + "FakeGroupMapping has resumed.");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("No groups found for user", e);
            }
            // Let the elements in the negative cache expire.
            timer.Advance(4 * 1000);
            // The groups for the user is expired in the negative cache, a new copy of
            // groups for the user is fetched.
            Assert.Equal(Arrays.AsList(myGroups), groups.GetGroups(user));
        }
示例#3
0
        public virtual void TestCacheEntriesExpire()
        {
            conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsCacheSecs, 1);
            FakeTimer timer  = new FakeTimer();
            Groups    groups = new Groups(conf, timer);

            groups.CacheGroupsAdd(Arrays.AsList(myGroups));
            groups.Refresh();
            TestGroupsCaching.FakeGroupMapping.ClearBlackList();
            // We make an entry
            groups.GetGroups("me");
            int startingRequestCount = TestGroupsCaching.FakeGroupMapping.GetRequestCount();

            timer.Advance(20 * 1000);
            // Cache entry has expired so it results in a new fetch
            groups.GetGroups("me");
            Assert.Equal(startingRequestCount + 1, TestGroupsCaching.FakeGroupMapping
                         .GetRequestCount());
        }
示例#4
0
        public virtual void TestOnlyOneRequestWhenExpiredEntryExists()
        {
            conf.SetLong(CommonConfigurationKeys.HadoopSecurityGroupsCacheSecs, 1);
            FakeTimer timer  = new FakeTimer();
            Groups    groups = new Groups(conf, timer);

            groups.CacheGroupsAdd(Arrays.AsList(myGroups));
            groups.Refresh();
            TestGroupsCaching.FakeGroupMapping.ClearBlackList();
            TestGroupsCaching.FakeGroupMapping.SetGetGroupsDelayMs(100);
            // We make an initial request to populate the cache
            groups.GetGroups("me");
            int startingRequestCount = TestGroupsCaching.FakeGroupMapping.GetRequestCount();

            // Then expire that entry
            timer.Advance(400 * 1000);
            Thread.Sleep(100);
            AList <Thread> threads = new AList <Thread>();

            for (int i = 0; i < 10; i++)
            {
                threads.AddItem(new _Thread_382(groups));
            }
            // We start a bunch of threads who all see the cached value
            foreach (Thread t in threads)
            {
                t.Start();
            }
            foreach (Thread t_1 in threads)
            {
                t_1.Join();
            }
            // Only one extra request is made
            Assert.Equal(startingRequestCount + 1, TestGroupsCaching.FakeGroupMapping
                         .GetRequestCount());
        }