Esempio n. 1
0
        public virtual void TestManyDfsClientsWhereSomeNotOpen()
        {
            // First DFSClient has no files open so doesn't renew leases.
            DFSClient mockClient1 = CreateMockClient();

            Org.Mockito.Mockito.DoReturn(false).When(mockClient1).RenewLease();
            NUnit.Framework.Assert.AreSame(renewer, LeaseRenewer.GetInstance(FakeAuthority, FakeUgiA
                                                                             , mockClient1));
            // Set up a file so that we start renewing our lease.
            DFSOutputStream mockStream1 = Org.Mockito.Mockito.Mock <DFSOutputStream>();
            long            fileId      = 456L;

            renewer.Put(fileId, mockStream1, mockClient1);
            // Second DFSClient does renew lease
            DFSClient mockClient2 = CreateMockClient();

            Org.Mockito.Mockito.DoReturn(true).When(mockClient2).RenewLease();
            NUnit.Framework.Assert.AreSame(renewer, LeaseRenewer.GetInstance(FakeAuthority, FakeUgiA
                                                                             , mockClient2));
            // Set up a file so that we start renewing our lease.
            DFSOutputStream mockStream2 = Org.Mockito.Mockito.Mock <DFSOutputStream>();

            renewer.Put(fileId, mockStream2, mockClient2);
            // Wait for lease to get renewed
            GenericTestUtils.WaitFor(new _Supplier_156(mockClient1, mockClient2), 100, 10000);
            // should not throw!
            renewer.CloseFile(fileId, mockClient1);
            renewer.CloseFile(fileId, mockClient2);
        }
Esempio n. 2
0
 /// <summary>Get a renewer.</summary>
 private LeaseRenewer Get(string authority, UserGroupInformation ugi)
 {
     lock (this)
     {
         LeaseRenewer.Factory.Key k = new LeaseRenewer.Factory.Key(authority, ugi);
         LeaseRenewer             r = renewers[k];
         if (r == null)
         {
             r           = new LeaseRenewer(k);
             renewers[k] = r;
         }
         return(r);
     }
 }
Esempio n. 3
0
 /// <summary>Remove the given renewer.</summary>
 private void Remove(LeaseRenewer r)
 {
     lock (this)
     {
         LeaseRenewer stored = renewers[r.factorykey];
         //Since a renewer may expire, the stored renewer can be different.
         if (r == stored)
         {
             if (!r.ClientsRunning())
             {
                 Sharpen.Collections.Remove(renewers, r.factorykey);
             }
         }
     }
 }
Esempio n. 4
0
        public virtual void TestInstanceSharing()
        {
            // Two lease renewers with the same UGI should return
            // the same instance
            LeaseRenewer lr = LeaseRenewer.GetInstance(FakeAuthority, FakeUgiA, MockDfsclient
                                                       );
            LeaseRenewer lr2 = LeaseRenewer.GetInstance(FakeAuthority, FakeUgiA, MockDfsclient
                                                        );

            NUnit.Framework.Assert.AreSame(lr, lr2);
            // But a different UGI should return a different instance
            LeaseRenewer lr3 = LeaseRenewer.GetInstance(FakeAuthority, FakeUgiB, MockDfsclient
                                                        );

            NUnit.Framework.Assert.AreNotSame(lr, lr3);
            // A different authority with same UGI should also be a different
            // instance.
            LeaseRenewer lr4 = LeaseRenewer.GetInstance("someOtherAuthority", FakeUgiB, MockDfsclient
                                                        );

            NUnit.Framework.Assert.AreNotSame(lr, lr4);
            NUnit.Framework.Assert.AreNotSame(lr3, lr4);
        }
Esempio n. 5
0
 public _Runnable_296(LeaseRenewer _enclosing, int id)
 {
     this._enclosing = _enclosing;
     this.id         = id;
 }
Esempio n. 6
0
 public virtual void SetupMocksAndRenewer()
 {
     MockDfsclient = CreateMockClient();
     renewer       = LeaseRenewer.GetInstance(FakeAuthority, FakeUgiA, MockDfsclient);
     renewer.SetGraceSleepPeriod(FastGracePeriod);
 }
Esempio n. 7
0
        public virtual void TestLeaseAbort()
        {
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Build();

            try
            {
                cluster.WaitActive();
                NamenodeProtocols  preSpyNN = cluster.GetNameNodeRpc();
                NamenodeProtocols  spyNN    = Org.Mockito.Mockito.Spy(preSpyNN);
                DFSClient          dfs      = new DFSClient(null, spyNN, conf, null);
                byte[]             buf      = new byte[1024];
                FSDataOutputStream c_out    = CreateFsOut(dfs, dirString + "c");
                c_out.Write(buf, 0, 1024);
                c_out.Close();
                DFSInputStream     c_in  = dfs.Open(dirString + "c");
                FSDataOutputStream d_out = CreateFsOut(dfs, dirString + "d");
                // stub the renew method.
                Org.Mockito.Mockito.DoThrow(new RemoteException(typeof(SecretManager.InvalidToken
                                                                       ).FullName, "Your token is worthless")).When(spyNN).RenewLease(Matchers.AnyString
                                                                                                                                          ());
                // We don't need to wait the lease renewer thread to act.
                // call renewLease() manually.
                // make it look like the soft limit has been exceeded.
                LeaseRenewer originalRenewer = dfs.GetLeaseRenewer();
                dfs.lastLeaseRenewal = Time.MonotonicNow() - HdfsConstants.LeaseSoftlimitPeriod -
                                       1000;
                try
                {
                    dfs.RenewLease();
                }
                catch (IOException)
                {
                }
                // Things should continue to work it passes hard limit without
                // renewing.
                try
                {
                    d_out.Write(buf, 0, 1024);
                    Log.Info("Write worked beyond the soft limit as expected.");
                }
                catch (IOException)
                {
                    NUnit.Framework.Assert.Fail("Write failed.");
                }
                // make it look like the hard limit has been exceeded.
                dfs.lastLeaseRenewal = Time.MonotonicNow() - HdfsConstants.LeaseHardlimitPeriod -
                                       1000;
                dfs.RenewLease();
                // this should not work.
                try
                {
                    d_out.Write(buf, 0, 1024);
                    d_out.Close();
                    NUnit.Framework.Assert.Fail("Write did not fail even after the fatal lease renewal failure"
                                                );
                }
                catch (IOException e)
                {
                    Log.Info("Write failed as expected. ", e);
                }
                // If aborted, the renewer should be empty. (no reference to clients)
                Sharpen.Thread.Sleep(1000);
                NUnit.Framework.Assert.IsTrue(originalRenewer.IsEmpty());
                // unstub
                Org.Mockito.Mockito.DoNothing().When(spyNN).RenewLease(Matchers.AnyString());
                // existing input streams should work
                try
                {
                    int num = c_in.Read(buf, 0, 1);
                    if (num != 1)
                    {
                        NUnit.Framework.Assert.Fail("Failed to read 1 byte");
                    }
                    c_in.Close();
                }
                catch (IOException e)
                {
                    Log.Error("Read failed with ", e);
                    NUnit.Framework.Assert.Fail("Read after lease renewal failure failed");
                }
                // new file writes should work.
                try
                {
                    c_out = CreateFsOut(dfs, dirString + "c");
                    c_out.Write(buf, 0, 1024);
                    c_out.Close();
                }
                catch (IOException e)
                {
                    Log.Error("Write failed with ", e);
                    NUnit.Framework.Assert.Fail("Write failed");
                }
            }
            finally
            {
                cluster.Shutdown();
            }
        }