示例#1
0
        public virtual void TestDeprecatedKeys()
        {
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetInt("nfs3.server.port", 998);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsServerPortKey, 0) ==
                                          998);
            conf.SetInt("nfs3.mountd.port", 999);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsMountdPortKey, 0) ==
                                          999);
            conf.Set("dfs.nfs.exports.allowed.hosts", "host1");
            NUnit.Framework.Assert.IsTrue(conf.Get(CommonConfigurationKeys.NfsExportsAllowedHostsKey
                                                   ).Equals("host1"));
            conf.SetInt("dfs.nfs.exports.cache.expirytime.millis", 1000);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(Nfs3Constant.NfsExportsCacheExpirytimeMillisKey
                                                      , 0) == 1000);
            conf.SetInt("hadoop.nfs.userupdate.milly", 10);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(IdMappingConstant.UsergroupidUpdateMillisKey
                                                      , 0) == 10);
            conf.Set("dfs.nfs3.dump.dir", "/nfs/tmp");
            NUnit.Framework.Assert.IsTrue(conf.Get(NfsConfigKeys.DfsNfsFileDumpDirKey).Equals
                                              ("/nfs/tmp"));
            conf.SetBoolean("dfs.nfs3.enableDump", false);
            NUnit.Framework.Assert.IsTrue(conf.GetBoolean(NfsConfigKeys.DfsNfsFileDumpKey, true
                                                          ) == false);
            conf.SetInt("dfs.nfs3.max.open.files", 500);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsMaxOpenFilesKey, 0)
                                          == 500);
            conf.SetInt("dfs.nfs3.stream.timeout", 6000);
            NUnit.Framework.Assert.IsTrue(conf.GetInt(NfsConfigKeys.DfsNfsStreamTimeoutKey, 0
                                                      ) == 6000);
            conf.Set("dfs.nfs3.export.point", "/dir1");
            NUnit.Framework.Assert.IsTrue(conf.Get(NfsConfigKeys.DfsNfsExportPointKey).Equals
                                              ("/dir1"));
        }
示例#2
0
        public virtual void TestCheckSequential()
        {
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration config = new NfsConfiguration();

            config.SetBoolean(NfsConfigKeys.LargeFileUpload, false);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (config), false, config);

            ctx.GetPendingWritesForTest()[new OffsetRange(5, 10)] = new WriteCtx(null, 0, 0,
                                                                                 0, null, null, null, 0, false, null);
            ctx.GetPendingWritesForTest()[new OffsetRange(10, 15)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            ctx.GetPendingWritesForTest()[new OffsetRange(20, 25)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            NUnit.Framework.Assert.IsTrue(!ctx.CheckSequential(5, 4));
            NUnit.Framework.Assert.IsTrue(ctx.CheckSequential(9, 5));
            NUnit.Framework.Assert.IsTrue(ctx.CheckSequential(10, 5));
            NUnit.Framework.Assert.IsTrue(ctx.CheckSequential(14, 5));
            NUnit.Framework.Assert.IsTrue(!ctx.CheckSequential(15, 5));
            NUnit.Framework.Assert.IsTrue(!ctx.CheckSequential(20, 5));
            NUnit.Framework.Assert.IsTrue(!ctx.CheckSequential(25, 5));
            NUnit.Framework.Assert.IsTrue(!ctx.CheckSequential(999, 5));
        }
示例#3
0
        public virtual void TestCheckCommitAixCompatMode()
        {
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();
            NfsConfiguration     conf      = new NfsConfiguration();

            conf.SetBoolean(NfsConfigKeys.LargeFileUpload, false);
            // Enable AIX compatibility mode.
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (new NfsConfiguration()), true, conf);

            // Test fall-through to pendingWrites check in the event that commitOffset
            // is greater than the number of bytes we've so far flushed.
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)2);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, null, 1, attr, false
                                                                       );
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            // Test the case when we actually have received more bytes than we're trying
            // to commit.
            ctx.GetPendingWritesForTest()[new OffsetRange(0, 10)] = new WriteCtx(null, 0, 0,
                                                                                 0, null, null, null, 0, false, null);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)10);
            ctx.SetNextOffsetForTest((long)10);
            status = ctx.CheckCommitInternal(5, null, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
        }
示例#4
0
        public virtual void TestCheckCommit()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS, which
            // includes COMMIT_FINISHED, COMMIT_WAIT, COMMIT_INACTIVE_CTX,
            // COMMIT_INACTIVE_WITH_PENDING_WRITE, COMMIT_ERROR, and COMMIT_DO_SYNC.
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetBoolean(NfsConfigKeys.LargeFileUpload, false);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (conf), false, conf);

            OpenFileCtx.COMMIT_STATUS ret;
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx);
            ctx.GetPendingWritesForTest()[new OffsetRange(5, 10)] = new WriteCtx(null, 0, 0,
                                                                                 0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                          );
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)10);
            ctx.SetNextOffsetForTest(10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, null, 1, attr, false
                                                                       );
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            status = ctx.CheckCommitInternal(10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            ret = ctx.CheckCommit(dfsClient, 10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 0);
            ret = ctx.CheckCommit(dfsClient, 11, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            long key = commits.FirstKey();

            NUnit.Framework.Assert.IsTrue(key == 11);
            // Test request with zero commit offset
            Sharpen.Collections.Remove(commits, System.Convert.ToInt64(11));
            // There is one pending write [5,10]
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            key = commits.FirstKey();
            NUnit.Framework.Assert.IsTrue(key == 9);
            // Empty pending writes
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(5, 10));
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
        }
示例#5
0
        public virtual void TestCheckCommitFromReadLargeFileUpload()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with large file upload option
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration config = new NfsConfiguration();

            config.SetBoolean(NfsConfigKeys.LargeFileUpload, true);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (config), false, config);
            FileHandle h = new FileHandle(1);

            // fake handle for "/dumpFilePath"
            OpenFileCtx.COMMIT_STATUS ret;
            WriteManager wm = new WriteManager(new ShellBasedIdMapping(config), config, false
                                               );

            NUnit.Framework.Assert.IsTrue(wm.AddOpenFileStream(h, ctx));
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 0));
            ctx.GetPendingWritesForTest()[new OffsetRange(10, 15)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                            , ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errIo, wm.CommitBeforeRead(dfsClient
                                                                                      , h, 0));
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)6);
            ctx.SetNextOffsetForTest((long)10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, ch, 1, attr, false);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitDoSync, status);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitFinished, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 5));
            // Test request with sequential writes
            status = ctx.CheckCommitInternal(9, ch, 1, attr, true);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait
                                          );
            ret = ctx.CheckCommit(dfsClient, 9, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 9));
            // Test request with non-sequential writes
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 0);
            ret = ctx.CheckCommit(dfsClient, 16, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess, ret
                                            );
            NUnit.Framework.Assert.AreEqual(0, commits.Count);
            // commit triggered by read doesn't wait
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 16));
            // Test request with zero commit offset
            // There is one pending write [10,15]
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(0, commits.Count);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 0));
            // Empty pending writes
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(10, 15)
                                       );
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 0));
        }
示例#6
0
        public virtual void TestCheckCommitLargeFileUpload()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with
            // large file upload option.
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetBoolean(NfsConfigKeys.LargeFileUpload, true);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (conf), false, conf);

            OpenFileCtx.COMMIT_STATUS ret;
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx);
            ctx.GetPendingWritesForTest()[new OffsetRange(10, 15)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                          );
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)8);
            ctx.SetNextOffsetForTest(10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, null, 1, attr, false
                                                                       );
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            // Test commit sequential writes
            status = ctx.CheckCommitInternal(10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait
                                          );
            ret = ctx.CheckCommit(dfsClient, 10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            // Test commit non-sequential writes
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            ret = ctx.CheckCommit(dfsClient, 16, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess
                                          );
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            // Test request with zero commit offset
            Sharpen.Collections.Remove(commits, System.Convert.ToInt64(10));
            // There is one pending write [10,15]
            ret = ctx.CheckCommitInternal(0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            ret = ctx.CheckCommitInternal(9, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 2);
            // Empty pending writes. nextOffset=10, flushed pos=8
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(10, 15)
                                       );
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            // Empty pending writes
            ctx.SetNextOffsetForTest((long)8);
            // flushed pos = 8
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
        }