예제 #1
0
        public virtual void TestHedgedReadLoopTooManyTimes()
        {
            Configuration conf = new Configuration();
            int           numHedgedReadPoolThreads = 5;
            int           hedgedReadTimeoutMillis  = 50;

            conf.SetInt(DFSConfigKeys.DfsDfsclientHedgedReadThreadpoolSize, numHedgedReadPoolThreads
                        );
            conf.SetLong(DFSConfigKeys.DfsDfsclientHedgedReadThresholdMillis, hedgedReadTimeoutMillis
                         );
            conf.SetInt(DFSConfigKeys.DfsClientRetryWindowBase, 0);
            // Set up the InjectionHandler
            DFSClientFaultInjector.instance = Org.Mockito.Mockito.Mock <DFSClientFaultInjector
                                                                        >();
            DFSClientFaultInjector injector = DFSClientFaultInjector.instance;
            int sleepMs = 100;

            Org.Mockito.Mockito.DoAnswer(new _Answer_296(hedgedReadTimeoutMillis, sleepMs)).When
                (injector).FetchFromDatanodeException();
            Org.Mockito.Mockito.DoAnswer(new _Answer_309(sleepMs)).When(injector).ReadFromDatanodeDelay
                ();
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(2).Format(
                true).Build();
            DistributedFileSystem fileSys   = cluster.GetFileSystem();
            DFSClient             dfsClient = fileSys.GetClient();
            FSDataOutputStream    output    = null;
            DFSInputStream        input     = null;
            string filename = "/hedgedReadMaxOut.dat";

            try
            {
                Path file = new Path(filename);
                output = fileSys.Create(file, (short)2);
                byte[] data = new byte[64 * 1024];
                output.Write(data);
                output.Flush();
                output.Write(data);
                output.Flush();
                output.Write(data);
                output.Flush();
                output.Close();
                byte[] buffer = new byte[64 * 1024];
                input = dfsClient.Open(filename);
                input.Read(0, buffer, 0, 1024);
                input.Close();
                NUnit.Framework.Assert.AreEqual(3, input.GetHedgedReadOpsLoopNumForTesting());
            }
            catch (BlockMissingException)
            {
                NUnit.Framework.Assert.IsTrue(false);
            }
            finally
            {
                Org.Mockito.Mockito.Reset(injector);
                IOUtils.Cleanup(null, input);
                IOUtils.Cleanup(null, output);
                fileSys.Close();
                cluster.Shutdown();
            }
        }
예제 #2
0
        public virtual void TestReadFromOneDN()
        {
            HdfsConfiguration configuration = new HdfsConfiguration();
            // One of the goals of this test is to verify that we don't open more
            // than one socket.  So use a different client context, so that we
            // get our own socket cache, rather than sharing with the other test
            // instances.  Also use a really long socket timeout so that nothing
            // gets closed before we get around to checking the cache size at the end.
            string contextName = "testReadFromOneDNContext";

            configuration.Set(DFSConfigKeys.DfsClientContext, contextName);
            configuration.SetLong(DFSConfigKeys.DfsClientSocketTimeoutKey, 100000000L);
            BlockReaderTestUtil util = new BlockReaderTestUtil(1, configuration);
            Path testFile            = new Path("/testConnCache.dat");

            byte[]    authenticData = util.WriteFile(testFile, FileSize / 1024);
            DFSClient client        = new DFSClient(new IPEndPoint("localhost", util.GetCluster().GetNameNodePort
                                                                       ()), util.GetConf());
            ClientContext  cacheContext = ClientContext.Get(contextName, client.GetConf());
            DFSInputStream @in          = client.Open(testFile.ToString());

            Log.Info("opened " + testFile.ToString());
            byte[] dataBuf = new byte[BlockSize];
            // Initial read
            Pread(@in, 0, dataBuf, 0, dataBuf.Length, authenticData);
            // Read again and verify that the socket is the same
            Pread(@in, FileSize - dataBuf.Length, dataBuf, 0, dataBuf.Length, authenticData);
            Pread(@in, 1024, dataBuf, 0, dataBuf.Length, authenticData);
            // No seek; just read
            Pread(@in, -1, dataBuf, 0, dataBuf.Length, authenticData);
            Pread(@in, 64, dataBuf, 0, dataBuf.Length / 2, authenticData);
            @in.Close();
            client.Close();
            NUnit.Framework.Assert.AreEqual(1, ClientContext.GetFromConf(configuration).GetPeerCache
                                                ().Size());
        }
예제 #3
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();
            }
        }